summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@gnu.org>2015-01-28 22:16:14 +0100
committerRuben Rodriguez <ruben@gnu.org>2015-01-28 22:16:14 +0100
commit16f2defa530b36cae7da5e28b5eafef9138adba5 (patch)
treec1415ef31bf1e96da1674aec2fc2c580c87d9e08 /data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder
parent763c090c20c60c13f9b6f50b953323a237fd778a (diff)
Updated to v31.4.0ESR
* Search form in about:icecat now searches in default search engine * Disabled accessibility.blockautorefresh * Replaced references to Open Source with Free Software where applicable * Added html5-video-everywhere v0.1.1 extension: https://github.com/lejenome/html5-video-everywhere * Updated LibreJS to 6.0.8 Build scripts updated to use pbuilder
Diffstat (limited to 'data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder')
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/bug_fix.js9
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler.js291
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/attributes.js22
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_checker.js106
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_gatherer.js452
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/request.js17
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_object.js96
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_properties.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/html_parser.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/url_seen_tester.js93
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/find_js_labels.js158
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/js_web_labels.js191
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/script_hash_worker.js28
13 files changed, 810 insertions, 673 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/bug_fix.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/bug_fix.js
index bba7653..c6bcb16 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/bug_fix.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/bug_fix.js
@@ -3,19 +3,20 @@
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
exports.END_OF_SCRIPT = 'this.narcissusBugFixLibreJS'; // value from parse tree without \n\n
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler.js
index db0c46c..c57c945 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
@@ -30,24 +32,23 @@
var {Cc, Ci, Cu, Cm, Cr} = require("chrome");
-var scriptProperties = require("html_script_finder/dom_handler/script_properties");
+var scriptProperties =
+ require("html_script_finder/dom_handler/script_properties");
const scriptTypes = scriptProperties.scriptTypes;
-
const statusTypes = scriptProperties.statusTypes;
-
const reasons = scriptProperties.reasons;
var urlHandler = require("url_handler/url_handler");
-var WebLabelFinder = require("html_script_finder/web_labels/js_web_labels").WebLabelFinder;
+var WebLabelFinder =
+ require("html_script_finder/web_labels/js_web_labels").WebLabelFinder;
// object model for script entries.
var scriptObject = require("html_script_finder/dom_handler/script_object");
var privacyChecker = require("js_checker/privacy_checker").privacyCheck;
var jsChecker = require("js_checker/js_checker");
-
const types = require("js_checker/constant_types");
var checkTypes = types.checkTypes;
@@ -57,18 +58,18 @@ var stripCDATAClose = /]]>/g;
var isDryRun = require("addon_management/prefchange").isDryRun;
var allowedRef = require('http_observer/allowed_referrers').allowedReferrers;
-
var attributeHelpers = require("html_script_finder/dom_handler/attributes");
// javascript:*
var jsInAttrRe = attributeHelpers.jsInAttrRe;
// the list of all available event attributes
-var intrinsecEvents = attributeHelpers.intrinsecEvents;
+var intrinsicEvents = attributeHelpers.intrinsicEvents;
-var domGatherer = require("html_script_finder/dom_handler/dom_gatherer").domGatherer;
-
-var domChecker = require("html_script_finder/dom_handler/dom_checker").domChecker;
+var domGatherer =
+ require("html_script_finder/dom_handler/dom_gatherer").domGatherer;
+var domChecker =
+ require("html_script_finder/dom_handler/dom_checker").domChecker;
/**
* The DomHandler object takes a whole document,
@@ -77,81 +78,81 @@ var domChecker = require("html_script_finder/dom_handler/dom_checker").domCheck
* DOM depending on the result.
*/
var DomHandler = function() {
- // external object with methods used
- // in DomHandler
- this.domGatherer = null;
-
- // external object with methods used
- // in DomHandler
- this.domChecker = null;
-
- this.dom = null;
- this.pageURL = null;
-
- // fragment found in url.
- this.fragment = null;
-
- // array containing all scripts on a page.
- this.domScripts = null;
-
- // array containing all scripts on a page,
- // data related to them, such as parse tree, ...
- this.inlineScripts = null;
-
- this.externalScripts = null;
-
- // all scripts.
- this.scripts = null;
-
- // keeps track of the number of scripts.
- this.numScripts = 0;
-
- // store the reference to the callback method
- // presumably from htmlParser.
- this.callback = null;
-
- // boolean set to true if external scripts are loaded
- // from the html page.
- this.loadsHtmlExternalScripts = false;
-
- this.jsCheckString = null;
-
- /* object containing boolean property set to false if trivialness
- is not allowed anymore (if another script defines ajax requests,
- ...) */
- this.allowTrivial = null;
-
- // boolean set to true if inline JavaScript
- // is found to be free.
- this.inlineJsFree = null;
-
- // boolean set to true when at least one script
- // has been removed.
- this.hasRemovedScripts = null;
-
- // boolean to check if scripts were removed
- // prevents removeAllJs from running multiple times.
- this.removedAllScripts = null;
-
- // will eventually contain an array of data
- // for the js web labels licenses.
- this.licenseList = null;
-
- // the response status for the page (200, 404, ...)
- this.responseStatus = null;
-
- // count the number of scripts fully tested.
- this.scriptsTested = null;
-
- // number of external scripts to be tested.
- this.numExternalScripts = null;
-
- // number of inline/inattribute scripts
- this.numInlineScripts = null;
+ // external object with methods used
+ // in DomHandler
+ this.domGatherer = null;
+
+ // external object with methods used
+ // in DomHandler
+ this.domChecker = null;
+
+ this.dom = null;
+ this.pageURL = null;
+
+ // fragment found in url.
+ this.fragment = null;
+
+ // array containing all scripts on a page.
+ this.domScripts = [];
+
+ // array containing all scripts on a page,
+ // data related to them, such as parse tree, ...
+ this.inlineScripts = [];
+
+ this.externalScripts = [];
+
+ // all scripts.
+ this.scripts = [];
+
+ // keeps track of the number of scripts.
+ this.numScripts = 0;
+
+ // store the reference to the callback method
+ // presumably from htmlParser.
+ this.callback = function() {};
+
+ // boolean set to true if external scripts are loaded
+ // from the html page.
+ this.loadsHtmlExternalScripts = false;
+
+ this.jsCheckString = null;
+
+ /* object containing boolean property set to false if trivialness
+ is not allowed anymore (if another script defines ajax requests,
+ ...) */
+ this.allowTrivial = null;
+
+ // boolean set to true if inline JavaScript
+ // is found to be free.
+ this.inlineJsFree = null;
+
+ // boolean set to true when at least one script
+ // has been removed.
+ this.hasRemovedScripts = null;
+
+ // boolean to check if scripts were removed
+ // prevents removeAllJs from running multiple times.
+ this.removedAllScripts = null;
+
+ // will eventually contain an array of data
+ // for the js web labels licenses.
+ this.licenseList = [];
+
+ // the response status for the page (200, 404, ...)
+ this.responseStatus = null;
+
+ // number of scripts fully tested.
+ this.scriptsTested = 0;
+
+ // number of external scripts to be tested.
+ this.numExternalScripts = null;
+
+ // number of inline/inattribute scripts
+ this.numInlineScripts = null;
};
/**
- * Initialize properties of the object
+ * Initialize properties of the object
*
* @param {domObject} obj A reference of the DOM object being
* analyzed.
@@ -165,7 +166,8 @@ var DomHandler = function() {
*
*/
DomHandler.prototype.init = function(
- domObject, pageURL, fragment, responseStatus, callback) {
+ domObject, pageURL, fragment, responseStatus, callback
+) {
// initialize object properties.
console.debug('init', pageURL);
@@ -183,10 +185,10 @@ DomHandler.prototype.init = function(
// make callback function available
// for the entire object.
- this.callback = function (dom) {
+ this.callback = function (dom) {
callback(dom);
that.destroy();
- };
+ };
};
DomHandler.prototype.reset = function () {
@@ -223,8 +225,10 @@ DomHandler.prototype.destroy = function () {
//this.reset();
};
-DomHandler.prototype.scriptHasBeenTested = function () {
+DomHandler.prototype.scriptHasBeenTested = function() {
this.scriptsTested++;
+ console.debug('incremented DomHandler.scriptsTested to',
+ this.scriptsTested);
};
/**
@@ -235,22 +239,24 @@ DomHandler.prototype.scriptHasBeenTested = function () {
* for more information.
*
*/
-DomHandler.prototype.scriptHasJsWebLabel = function (script) {
+DomHandler.prototype.scriptHasJsWebLabel = function(script) {
if (this.licenseList) {
var url = urlHandler.resolve(this.pageURL, script.src),
- i = 0,
- len = this.licenseList.length;
+ i = 0,
+ len = this.licenseList.length;
console.debug('looking for web label');
for (; i < len; i++) {
if (this.licenseList[i].fileUrl === url &&
- this.licenseList[i].free === true) {
- console.debug('found something true');
- console.debug(this.licenseList[i].fileUrl, ' is found');
- return true;
- }
+ this.licenseList[i].free === true
+ ) {
+ console.debug('found something true');
+ console.debug(
+ this.licenseList[i].fileUrl, ' is found');
+ return true;
+ }
}
}
return false;
@@ -265,9 +271,9 @@ DomHandler.prototype.scriptHasJsWebLabel = function (script) {
DomHandler.prototype.processScripts = function () {
var that = this;
- // check for the existence of the
+ // check for the existence of the
// js web labels first.
- this.lookForJsWebLabels(function () {
+ this.lookForJsWebLabels(function () {
// gather and check all script elements on
// page.
@@ -284,21 +290,21 @@ DomHandler.prototype.processScripts = function () {
*/
DomHandler.prototype.checkAllScripts = function () {
try {
- console.debug('found in', this.pageURL, JSON.stringify(this.licenseList));
+ console.debug(
+ 'found in', this.pageURL, JSON.stringify(this.licenseList));
console.debug('checkAllScripts triggered async');
// use domGatherer to gather scripts.
this.domGatherer.findScripts();
this.domGatherer.gatherScriptsContent();
- this.domGatherer.gatherIntrinsecEvents();
+ this.domGatherer.gatherIntrinsicEvents();
console.debug('fragment is', this.fragment);
if (
- (this.fragment === undefined ||
- this.fragment === null ||
- this.fragment.indexOf('librejs=true') < 0) &&
- this.responseStatus != 404
+ this.fragment === undefined ||
+ this.fragment === null ||
+ this.fragment.indexOf('librejs=true') < 0
) {
try {
@@ -310,8 +316,8 @@ DomHandler.prototype.checkAllScripts = function () {
this.removeAllJs();
}
} else {
- console.debug('404 or pageworker, removing all js');
- // this is the page Worker to find contact link
+ console.debug('This is a pageworker, removing all js');
+ // this is the Page Worker to find contact link
// just remove all the JS since we don't need it.
console.debug('fragment found, remove js');
this.removeAllJs();
@@ -323,7 +329,7 @@ DomHandler.prototype.checkAllScripts = function () {
/**
* lookForJsWebLabels
- *
+ *
* Checks if a link to a js web label table exists.
* If it does, return an array of objects with the data
* gathered (script name, path, license name, url, ...)
@@ -332,11 +338,11 @@ DomHandler.prototype.checkAllScripts = function () {
DomHandler.prototype.lookForJsWebLabels = function (completed) {
var that = this;
console.debug("calling lookForJsWebLabels");
- if (this.fragment != '#librejs=true') {
+ if (this.fragment !== '#librejs=true') {
var webLabelFinder = new WebLabelFinder();
webLabelFinder.init(
this.dom,
- this.pageURL,
+ this.pageURL,
function (licenseList) {
// assign array returned to property.
that.licenseList = licenseList;
@@ -348,24 +354,23 @@ DomHandler.prototype.lookForJsWebLabels = function (completed) {
}
};
-DomHandler.prototype.checkScriptForJsWebLabels = function (script) {
+DomHandler.prototype.checkScriptForJsWebLabels = function(script) {
var scriptEntry;
if (this.hasSrc(script) && this.scriptHasJsWebLabel(script)) {
-
- // in the list of allowed scripts (through web labels)
- scriptEntry = scriptObject.Script({'type': scriptTypes.EXTERNAL,
+ // This script is in the list of allowed scripts (through web labels)
+ scriptEntry = scriptObject.Script({
+ 'type': scriptTypes.EXTERNAL,
'status': statusTypes.ACCEPTED,
- 'element':script,
- 'url': urlHandler.resolve(this.pageURL, script.src)});
+ 'element': script,
+ 'url': urlHandler.resolve(this.pageURL, script.src)
+ });
scriptEntry.tagAsAccepted(this.pageURL, reasons.FREE);
-
return true;
}
};
-
/**
* hasSrc
* Check the given script has an src attribute.
@@ -386,7 +391,6 @@ DomHandler.prototype.hasSrc = function(script) {
*
*/
DomHandler.prototype.removeScriptIfDependent = function (script) {
-
var nonWindowProps = script.tree.relationChecker.nonWindowProperties;
for (var entry in nonWindowProps) {
@@ -396,11 +400,10 @@ DomHandler.prototype.removeScriptIfDependent = function (script) {
return true;
}
}
-
};
/**
- * removeGivenJs
+ * removeGivenJs
* Remove a single script from the DOM.
* @param script Obj The script element to be removed from the
* DOM.
@@ -412,12 +415,12 @@ DomHandler.prototype.removeGivenJs = function (script, reason, singleton, hash)
console.debug("removing given js hash", hash);
if (script.status != statusTypes.REJECTED &&
- script.status != statusTypes.JSWEBLABEL
- ) {
+ script.status != statusTypes.JSWEBLABEL
+ ) {
console.debug('removing a', script.type);
if (script.type === scriptTypes.ATTRIBUTE &&
- !isAllowed
- ) {
+ !isAllowed
+ ) {
this.removeGivenAttribute(script, reason);
return;
}
@@ -428,7 +431,8 @@ DomHandler.prototype.removeGivenJs = function (script, reason, singleton, hash)
console.debug('removeGivenJs hash is', hash);
script.tagAsRemoved(this.pageURL, reason, hash);
} else {
- script.element.setAttribute('data-librejs-dryrun', 'librejs/blocked');
+ script.element.setAttribute(
+ 'data-librejs-dryrun', 'librejs/blocked');
script.tagAsDryRun(this.pageURL, reason, hash);
}
@@ -439,10 +443,13 @@ DomHandler.prototype.removeGivenJs = function (script, reason, singleton, hash)
// remove src if dry run off.
if (script.element.getAttribute('src') !== undefined) {
- script.element.setAttribute('data-librejs-blocked-src', script.element.getAttribute('src'));
+ script.element.setAttribute(
+ 'data-librejs-blocked-src',
+ script.element.getAttribute('src')
+ );
if (!isAllowed) {
script.element.removeAttribute('src');
- }
+ }
}
if (isAllowed) {
comment_str = 'LibreJS: Script should be blocked, but page is whitelisted.';
@@ -462,11 +469,11 @@ DomHandler.prototype.removeGivenJs = function (script, reason, singleton, hash)
DomHandler.prototype.removeGivenAttribute = function (script, reason) {
var i = 0,
- le = script.jsAttributes.length;
+ le = script.jsAttributes.length;
console.debug('removing given attribute', script, reason);
- script.element.setAttribute('data-librejs-blocked-event',
- JSON.stringify(script.jsAttributes));
+ script.element.setAttribute('data-librejs-blocked-event',
+ JSON.stringify(script.jsAttributes));
script.tagAsRemoved(this.pageURL, reason, script.hash || script.tree.hash);
@@ -477,7 +484,7 @@ DomHandler.prototype.removeGivenAttribute = function (script, reason) {
// only run if not in dry run mode.
for (; i < le; i++) {
console.debug('removing attribute', JSON.stringify(script.jsAttributes));
- script.element.removeAttribute(script.jsAttributes[i].attribute);
+ script.element.removeAttribute(script.jsAttributes[i].attribute);
}
} else {
@@ -502,9 +509,14 @@ DomHandler.prototype.removeAllJs = function (reason) {
try {
this.removeAllArray(this.scripts, reason);
- this.callback(this.dom);
+ this.callback(this.dom);
} catch (x) {
- console.debug('in removeAllJs method: ', x, 'number of scripts is', this.numScripts);
+ console.debug(
+ 'in removeAllJs method: ',
+ x,
+ 'number of scripts is',
+ this.numScripts
+ );
this.callback(this.dom);
}
@@ -520,9 +532,10 @@ DomHandler.prototype.removeAllArray = function(scriptArray, reason) {
for (; i < le; i++) {
script = scriptArray[i];
if (script.type === scriptTypes.INLINE ||
- script.type === scriptTypes.EXTERNAL) {
- this.removeGivenJs(script, reason);
- }
+ script.type === scriptTypes.EXTERNAL
+ ) {
+ this.removeGivenJs(script, reason);
+ }
else if (script.type === scriptTypes.ATTRIBUTE) {
this.removeGivenAttribute(script, reason);
}
@@ -543,7 +556,7 @@ exports.DomHandler = DomHandler;
* @param callback function callback when all the work has been performed.
*/
exports.domHandler = function(
- dom, pageURL, fragment, responseStatus, callback) {
+ dom, pageURL, fragment, responseStatus, callback) {
console.debug("Creating domHandler");
var domHandler = new DomHandler();
domHandler.init(dom, pageURL, fragment, responseStatus, callback);
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/attributes.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/attributes.js
index 6e9ace4..796e718 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/attributes.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/attributes.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
// object model for script entries.
@@ -30,7 +32,7 @@ const statusTypes = scriptProperties.statusTypes;
var jsInAttrRe = /javascript:/ig;
// the list of all available event attributes
-var intrinsecEvents = [
+var intrinsicEvents = [
"onload",
"onunload",
"onclick",
@@ -51,7 +53,7 @@ var intrinsecEvents = [
"onchange"];
exports.jsInAttrRe = jsInAttrRe;
-exports.intrinsecEvents = intrinsecEvents;
+exports.intrinsicEvents = intrinsicEvents;
/**
@@ -102,18 +104,18 @@ exports.findJSinAttribute = function (elem, callback) {
*/
exports.findOnJSAttribute = function (elem, callback) {
- var i = 0, eventsLen = intrinsecEvents.length;
+ var i = 0, eventsLen = intrinsicEvents.length;
var attribPairs = [];
for (; i < eventsLen; i++) {
// looping through all on* attributes
- if (elem.hasAttribute(intrinsecEvents[i])) {
+ if (elem.hasAttribute(intrinsicEvents[i])) {
attribPairs.push({
- attribute: intrinsecEvents[i],
- value: elem.getAttribute(intrinsecEvents[i])
+ attribute: intrinsicEvents[i],
+ value: elem.getAttribute(intrinsicEvents[i])
});
}
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_checker.js
index 76cbc3e..6a98d61 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_checker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_checker.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
@@ -26,13 +28,11 @@
*/
var {Cc, Ci, Cu, Cm, Cr} = require("chrome");
+var timer = require("sdk/timers");
var scriptProperties = require("html_script_finder/dom_handler/script_properties");
-
const scriptTypes = scriptProperties.scriptTypes;
-
const statusTypes = scriptProperties.statusTypes;
-
const reasons = scriptProperties.reasons;
// ensure xhr won't create an infinite loop
@@ -40,19 +40,14 @@ const reasons = scriptProperties.reasons;
var urlTester = require("html_script_finder/url_seen_tester").urlSeenTester;
var urlHandler = require("url_handler/url_handler");
-
var privacyChecker = require("js_checker/privacy_checker").privacyCheck;
var jsChecker = require("js_checker/js_checker");
const types = require("js_checker/constant_types");
-
var checkTypes = types.checkTypes;
-
var stripCDATAOpen = /<\!\[CDATA\[/gi;
var stripCDATAClose = /]]>/g;
-var timer = require("sdk/timers");
-
const getHash = require("script_entries/scripts_cache").scriptsCached.getHash;
var DomChecker = function() {
@@ -154,7 +149,6 @@ DomChecker.prototype.concatAttributes = function(script) {
}
return text;
-
};
/**
@@ -247,6 +241,7 @@ DomChecker.prototype.processInlineCheckResult = function(
DomChecker.prototype.readyForExternal = function() {
"use strict";
+ console.debug('DomChecker.readyForExternal');
// done with those inline scripts, continue with
// the rest.
this.checkExternalScripts();
@@ -260,6 +255,8 @@ DomChecker.prototype.checkSingleInlineScript = function(
"use strict";
var check, text;
+ console.debug('DomChecker.checkSingleInlineScript');
+
try {
check = checker.parseTree.freeTrivialCheck;
@@ -288,36 +285,40 @@ DomChecker.prototype.checkSingleInlineScript = function(
*/
DomChecker.prototype.checkExternalScripts = function() {
"use strict";
- var i = 0,
- len = this.d.externalScripts.length,
- that = this;
- console.debug("externalScripts length", this.d.externalScripts.length);
- if (this.d.removedAllScripts ||
- this.d.externalScripts.length === 0) {
- // all js has already been removed.
- // stop check.
- this.wrapUpBeforeLeaving();
- return;
- }
+ console.debug('DomChecker.checkExternalScripts');
+
+ var i = 0;
+ var len = this.d.externalScripts.length;
+ var that = this;
+
+ console.debug("externalScripts length", len);
+ if (this.d.removedAllScripts || len === 0) {
+ // all js has already been removed.
+ // stop check.
+ this.wrapUpBeforeLeaving();
+ return;
+ }
for (; i < len; i++) {
+ this.xhr(
+ this.d.externalScripts[i],
+ function(script, scriptText) {
+ console.debug("In xhr callback for script url:", script.url);
+ if (scriptText === false) {
+ that.d.removeGivenJs(script);
+ that.d.scriptHasBeenTested();
+ that.externalCheckIsDone();
+ return;
+ }
- this.xhr(this.d.externalScripts[i],
-
- function(script, scriptText) {
- console.debug("doing xhr", script.url);
- if (scriptText === false) {
- that.d.removeGivenJs(script);
- that.d.scriptHasBeenTested();
- that.externalCheckIsDone();
- return;
- }
-
- that.analyzeJs(script,
- scriptText,
- that.checkSingleExternalScript.bind(that));
- });
+ console.debug('about to analyzeJS for script:', script.url);
+ that.analyzeJs(
+ script,
+ scriptText,
+ that.checkSingleExternalScript.bind(that));
+ }
+ );
}
};
@@ -332,8 +333,8 @@ DomChecker.prototype.wrapUpBeforeLeaving = function() {
DomChecker.prototype.analyzeJs = function(script, scriptText, callback) {
"use strict";
+ console.debug('DomChecker.analyzeJs for script:', script.url);
try {
- console.debug("checking ", script.url);
var checker = jsChecker.jsChecker();
var url = "";
if (typeof script.url !== "undefined") {
@@ -356,17 +357,19 @@ DomChecker.prototype.analyzeJs = function(script, scriptText, callback) {
* Check a single external script.
*/
DomChecker.prototype.checkSingleExternalScript = function(
- script, loadedScript, checker) {
+ script, loadedScript, checker
+) {
"use strict";
var check;
+ console.debug('DomChecker.checkSingleExternalScript()');
try {
-
check = checker.parseTree.freeTrivialCheck;
script.tree = checker;
script.result = check;
- console.debug('in checkSingleExternalScript, checker.hash is', checker.hash);
+ console.debug('in checkSingleExternalScript, checker.hash is',
+ checker.hash);
if (script.status != statusTypes.JSWEBLABEL) {
script.status = statusTypes.CHECKED;
}
@@ -391,12 +394,13 @@ DomChecker.prototype.checkSingleExternalScript = function(
} else {
// anything else is nontrivial. Including TRIVIAL_DEFINES_FUNCTION.
console.debug("checker hash for remove is ", checker.hash);
- this.d.removeGivenJs(script, reasons.FUNCTIONS_EXTERNAL, false, checker.hash);
+ this.d.removeGivenJs(
+ script, reasons.FUNCTIONS_EXTERNAL, false, checker.hash);
}
} catch (e) {
console.debug('error in checkExternalScript',
- e, e.lineNumber, 'for script', script.url);
+ e, e.lineNumber, 'for script', script.url);
this.d.removeAllJs();
this.destroy();
@@ -409,6 +413,7 @@ DomChecker.prototype.checkSingleExternalScript = function(
DomChecker.prototype.externalCheckIsDone = function() {
"use strict";
+ console.debug('DomChecker.externalCheckIsDone');
console.debug('scriptsTested is', this.d.scriptsTested);
console.debug('num external', this.d.numExternalScripts);
@@ -416,6 +421,17 @@ DomChecker.prototype.externalCheckIsDone = function() {
if (this.d.scriptsTested >= this.d.numExternalScripts) {
console.debug('wrapping up external');
this.wrapUpBeforeLeaving();
+ } else {
+ var scriptsToCheck = this.d.numExternalScripts - this.d.scriptsTested;
+ console.debug('Not wrapping up! Waiting to check ' + scriptsToCheck +
+ ' more script(s)');
+
+ if (this.d.externalScripts[0]) {
+ console.debug('script 0 is', this.d.externalScripts[0]);
+ }
+ if (this.d.externalScripts[1]) {
+ console.debug('script 1 is', this.d.externalScripts[1]);
+ }
}
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_gatherer.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_gatherer.js
index 5451f53..7bb2569 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_gatherer.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/dom_gatherer.js
@@ -2,23 +2,24 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
-
var scriptProperties = require("html_script_finder/dom_handler/script_properties");
const scriptTypes = scriptProperties.scriptTypes;
@@ -36,7 +37,7 @@ var attributeHelpers = require("html_script_finder/dom_handler/attributes");
var jsInAttrRe = attributeHelpers.jsInAttrRe;
// the list of all available event attributes
-var intrinsecEvents = attributeHelpers.intrinsecEvents;
+var intrinsicEvents = attributeHelpers.intrinsicEvents;
var privacyChecker = require("js_checker/privacy_checker").privacyCheck;
@@ -44,243 +45,228 @@ const types = require("js_checker/constant_types");
var checkTypes = types.checkTypes;
-
-// array reflex valid types as listed in
+// array reflex valid types as listed in
// http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsScriptLoader.cpp#437
// anything appended to end of strings is considered valid:
var jsValidTypes = [
- /^text\/javascript/i,
- /^text\/ecmascript/i,
- /^application\/javascript/i,
- /^application\/ecmascript/i,
- /^application\/x-javascript/i
+ /^text\/javascript/i,
+ /^text\/ecmascript/i,
+ /^application\/javascript/i,
+ /^application\/ecmascript/i,
+ /^application\/x-javascript/i
];
var stripCDATAOpen = /<\!\[CDATA\[/gi;
var stripCDATAClose = /]]>/g;
var stripHtmlCommentsInScript = function (s) {
- s = s.replace(stripCDATAOpen, '');
- s = s.replace(stripCDATAClose, '');
- return s;
+ s = s.replace(stripCDATAOpen, '');
+ s = s.replace(stripCDATAClose, '');
+ return s;
};
-
// gather scripts and javascript in attributes across a dom object.
-var domGathererObject = {
-
- // domHandler object.
- d: null,
-
- /**
- * init
- *
- * assign a reference domHandler object
- * to access/updates its properties.
- *
- */
- init: function (domHandler) {
-
- this.d = domHandler;
-
- },
-
- /**
- * scriptHasInvalidType
- *
- * Checks that a script does not have a js "template" type.
- * Normally any script that has a type attribute other than the
- * few allowed ones is not interpreted. But by security, we only
- * discard a few of them.
- *
- * @param script obj The script element.
- * @return returns true if it matches a template type.
- *
- */
- scriptHasInvalidType: function (script) {
- var i = 0,
- le = jsValidTypes.length;
-
- var type = script.getAttribute('type');
-
- if (type === 'librejs/blocked') {
- // js has already been blocked.
- return true;
- }
-
- if (!type) {
- // type isn't set, don't look further.
- return false;
- }
-
- for (; i < le; i++) {
- if (jsValidTypes[i].test(type)) {
- return false;
- }
- }
-
- // type is invalid and
- // hence cannot be executed.
- return true;
-
-
- },
-
- /**
- * findScripts
- *
- * Assigns the array of scripts in the dom to a property
- * as well as a number of scripts present for looping purposing.
- */
- findScripts: function() {
- this.d.domScripts = this.d.dom.getElementsByTagName('script');
- this.d.numScripts = this.d.domScripts.length;
- },
-
- /**
- * gatherIntrinsecEvents
- *
- * Fetches all the event attributes that might contain JavaScript
- * as well as all element attributes that start with
- * "javascript:".
- *
- */
- gatherIntrinsecEvents: function() {
- var i = 0, j, k,
- all = this.d.dom.getElementsByTagName('*'),
- max = all.length,
- that = this,
- attrLen, attrib, str, scriptEntry;
-
-
-
- for (; i < max; i++) {
-
- // look for attributes with value javascript:*
- attributeHelpers.findJSinAttribute(all[i],
- function (scriptEntry) {
- if (scriptEntry !== false) {
-
- that.d.inlineScripts.push(scriptEntry);
- that.d.scripts.push(scriptEntry);
-
- // add inline script in the count.
- that.d.numInlineScripts++;
-
- }
- });
-
- // look for attributes of on* (onLoad, ...)
- attributeHelpers.findOnJSAttribute(all[i],
- function (scriptEntry) {
- if (scriptEntry !== false) {
- that.d.inlineScripts.push(scriptEntry);
- that.d.scripts.push(scriptEntry);
-
- // add inline script in the count.
- that.d.numInlineScripts++;
- }
- });
-
- }
-
- },
-
- /**
- * gatherScriptsContent
- *
- * Aggregate all content within on-page JavaScript code.
- * Keep a list of all absolute urls to external scripts.
- *
- */
- gatherScriptsContent: function() {
- var i = 0, currentScript = '', absolutePath, scriptEntry,
- that = this;
- try {
- for (; i < this.d.numScripts; i++) {
-
- if (this.d.checkScriptForJsWebLabels(this.d.domScripts[i])) {
- //break;
- absolutePath = urlHandler.resolve(this.d.pageURL, this.d.domScripts[i].src);
- scriptEntry = scriptObject.Script({'type': scriptTypes.EXTERNAL,
- 'status': statusTypes.JSWEBLABEL,
- 'element': this.d.domScripts[i],
- 'url': absolutePath});
- scriptEntry.tree = {};
-
- this.d.externalScripts.push(scriptEntry);
- that.d.scripts.push(scriptEntry);
-
- this.d.loadsHtmlExternalScripts = true;
-
- // increment number of scripts found.
- this.d.numExternalScripts++;
-
- }
-
- // check that script has valid type
- else if (!this.scriptHasInvalidType(this.d.domScripts[i])) {
-
-
- if (this.d.hasSrc(this.d.domScripts[i]) &&
- !this.d.scriptHasJsWebLabel(this.d.domScripts[i])) {
-
- console.debug('an external script', this.d.domScripts[i]);
-
- absolutePath = urlHandler.resolve(this.d.pageURL, this.d.domScripts[i].src);
- scriptEntry = scriptObject.Script({'type': scriptTypes.EXTERNAL,
- 'status': statusTypes.UNCHECKED,
- 'element': this.d.domScripts[i],
- 'url': absolutePath});
- this.d.externalScripts.push(scriptEntry);
- that.d.scripts.push(scriptEntry);
-
- this.d.loadsHtmlExternalScripts = true;
-
- // increment number of scripts found.
- this.d.numExternalScripts++;
-
- }
-
- else if (privacyChecker.checkScriptPrivacyThreat(this.d.domScripts[i].text)) {
-
- this.d.removeGivenJs(scriptObject.Script({'type': scriptTypes.SINGLETON,
- 'status': statusTypes.UNCHECKED,
- 'element': this.d.domScripts[i],
- 'text': this.d.domScripts[i].text
- }), '', true);
- }
-
- else if (this.d.domScripts[i].text !== '') {
- // using else if since script text is
- // ignored if src attribute is set.
- // adding this.narcissusBugFixLibreJS to fix comment bug.
- var bugfix = require('html_script_finder/bug_fix').narcissusBugFixLibreJS;
- currentScript = stripHtmlCommentsInScript(this.d.domScripts[i].text + bugfix);
-
- scriptEntry = scriptObject.Script({'type': scriptTypes.INLINE,
- 'status': statusTypes.UNCHECKED,
- 'element': this.d.domScripts[i],
- 'text': currentScript});
- this.d.inlineScripts.push(scriptEntry);
- this.d.scripts.push(scriptEntry);
-
- // add inline script in the count.
- this.d.numInlineScripts++;
-
- }
- }
- }
- } catch (e) {
- // Any problem arising, we remove the script.
- console.debug('problem gathering scripts', e, e.lineNumber);
- this.d.removeAllJs();
- }
-
- }
+var DomGatherer = function() {
+ // domHandler object.
+ this.d = null;
+};
+/**
+ * init
+ *
+ * assign a reference domHandler object
+ * to access/updates its properties.
+ *
+ */
+DomGatherer.prototype.init = function (domHandler) {
+ this.d = domHandler;
+};
+/**
+ * scriptHasInvalidType
+ *
+ * Checks that a script does not have a js "template" type.
+ * Normally any script that has a type attribute other than the
+ * few allowed ones is not interpreted. But by security, we only
+ * discard a few of them.
+ *
+ * @param script obj The script element.
+ * @return returns true if it matches a template type.
+ *
+ */
+DomGatherer.prototype.scriptHasInvalidType = function (script) {
+ var i = 0,
+ le = jsValidTypes.length;
+
+ var type = script.getAttribute('type');
+
+ if (type === 'librejs/blocked') {
+ // js has already been blocked.
+ return true;
+ }
+
+ if (!type) {
+ // type isn't set, don't look further.
+ return false;
+ }
+
+ for (; i < le; i++) {
+ if (jsValidTypes[i].test(type)) {
+ return false;
+ }
+ }
+
+ // type is invalid and
+ // hence cannot be executed.
+ return true;
+};
+
+/**
+ * findScripts
+ *
+ * Assigns the array of scripts in the dom to a property
+ * as well as a number of scripts present for looping purposing.
+ */
+DomGatherer.prototype.findScripts = function() {
+ this.d.domScripts = this.d.dom.getElementsByTagName('script');
+ this.d.numScripts = this.d.domScripts.length;
+};
+
+/**
+ * gatherIntrinsicEvents
+ *
+ * Fetches all the event attributes that might contain JavaScript
+ * as well as all element attributes that start with
+ * "javascript:".
+ *
+ */
+DomGatherer.prototype.gatherIntrinsicEvents = function() {
+ var i = 0, j, k,
+ all = this.d.dom.getElementsByTagName('*'),
+ max = all.length,
+ that = this,
+ attrLen, attrib, str, scriptEntry;
+
+ for (; i < max; i++) {
+ // look for attributes with value javascript:*
+ attributeHelpers.findJSinAttribute(
+ all[i],
+ function (scriptEntry) {
+ if (scriptEntry !== false) {
+
+ that.d.inlineScripts.push(scriptEntry);
+ that.d.scripts.push(scriptEntry);
+
+ // add inline script in the count.
+ that.d.numInlineScripts++;
+ }
+ });
+
+ // look for attributes of on* (onLoad, ...)
+ attributeHelpers.findOnJSAttribute(
+ all[i],
+ function (scriptEntry) {
+ if (scriptEntry !== false) {
+ that.d.inlineScripts.push(scriptEntry);
+ that.d.scripts.push(scriptEntry);
+
+ // add inline script in the count.
+ that.d.numInlineScripts++;
+ }
+ });
+ }
+
+};
+
+/**
+ * gatherScriptsContent
+ *
+ * Aggregate all content within on-page JavaScript code.
+ * Keep a list of all absolute urls to external scripts.
+ *
+ */
+DomGatherer.prototype.gatherScriptsContent = function() {
+ var i = 0, currentScript = '', absolutePath, scriptEntry,
+ that = this;
+ try {
+ for (; i < this.d.numScripts; i++) {
+ if (this.d.checkScriptForJsWebLabels(this.d.domScripts[i])) {
+ //break;
+ absolutePath = urlHandler.resolve(
+ this.d.pageURL, this.d.domScripts[i].src);
+ scriptEntry = scriptObject.Script(
+ {'type': scriptTypes.EXTERNAL,
+ 'status': statusTypes.JSWEBLABEL,
+ 'element': this.d.domScripts[i],
+ 'url': absolutePath});
+ scriptEntry.tree = {};
+
+ this.d.externalScripts.push(scriptEntry);
+ that.d.scripts.push(scriptEntry);
+
+ this.d.loadsHtmlExternalScripts = true;
+
+ // increment number of scripts found.
+ this.d.numExternalScripts++;
+ }
+
+ // check that script has valid type
+ else if (!this.scriptHasInvalidType(this.d.domScripts[i])) {
+
+
+ if (this.d.hasSrc(this.d.domScripts[i]) &&
+ !this.d.scriptHasJsWebLabel(this.d.domScripts[i])) {
+
+ console.debug('an external script', this.d.domScripts[i]);
+
+ absolutePath = urlHandler.resolve(
+ this.d.pageURL, this.d.domScripts[i].src);
+ scriptEntry = scriptObject.Script(
+ {'type': scriptTypes.EXTERNAL,
+ 'status': statusTypes.UNCHECKED,
+ 'element': this.d.domScripts[i],
+ 'url': absolutePath});
+ this.d.externalScripts.push(scriptEntry);
+ that.d.scripts.push(scriptEntry);
+
+ this.d.loadsHtmlExternalScripts = true;
+
+ // increment number of scripts found.
+ this.d.numExternalScripts++;
+
+ } else if (privacyChecker.checkScriptPrivacyThreat(this.d.domScripts[i].text)) {
+ this.d.removeGivenJs(scriptObject.Script(
+ {'type': scriptTypes.SINGLETON,
+ 'status': statusTypes.UNCHECKED,
+ 'element': this.d.domScripts[i],
+ 'text': this.d.domScripts[i].text
+ }), '', true);
+ } else if (this.d.domScripts[i].text !== '') {
+ // using else if since script text is
+ // ignored if src attribute is set.
+ // adding this.narcissusBugFixLibreJS to fix comment bug.
+ var bugfix = require('html_script_finder/bug_fix').narcissusBugFixLibreJS;
+ currentScript = stripHtmlCommentsInScript(this.d.domScripts[i].text + bugfix);
+
+ scriptEntry = scriptObject.Script(
+ {'type': scriptTypes.INLINE,
+ 'status': statusTypes.UNCHECKED,
+ 'element': this.d.domScripts[i],
+ 'text': currentScript});
+ this.d.inlineScripts.push(scriptEntry);
+ this.d.scripts.push(scriptEntry);
+
+ // add inline script in the count.
+ this.d.numInlineScripts++;
+ }
+ }
+ }
+ } catch (e) {
+ // Any problem arising, we remove the script.
+ console.debug('problem gathering scripts', e, e.lineNumber);
+ this.d.removeAllJs();
+ }
};
/*
@@ -291,11 +277,7 @@ var domGathererObject = {
* @param callback function callback when all the work has been performed.
*/
exports.domGatherer = function (domHandler) {
-
- var domGatherer = Object.create(domGathererObject);
-
- domGatherer.init(domHandler);
-
- return domGatherer;
-
+ var dg = new DomGatherer();
+ dg.init(domHandler);
+ return dg;
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/request.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/request.js
index d1d26d8..a008295 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/request.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/request.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
var timer = require("sdk/timers");
@@ -45,6 +47,8 @@ Request.prototype.init = function(script, callback) {
// set initial url
this.url = this.script.url;
+ console.debug('In Request.init() for url:', this.url);
+
this.responseCallback = callback;
var iOService = Cc["@mozilla.org/network/io-service;1"]
@@ -88,7 +92,8 @@ Request.prototype.request = function() {
var uConv = Cc["@mozilla.org/intl/utf8converterservice;1"]
.createInstance(Ci.nsIUTF8ConverterService);
- this.data = uConv.convertStringToUTF8(this.data, this.charset, true);
+ this.data = uConv.convertStringToUTF8(
+ this.data, this.charset, true);
}
} catch (e) {
console.debug("Issue with nsIUTF8ConverterService", e);
@@ -105,7 +110,7 @@ Request.prototype.request = function() {
};
// Instantiate a Request
-exports.request = function (script, callback) {
+exports.request = function(script, callback) {
var obj = new Request();
obj.init(script, callback);
return obj;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_object.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_object.js
index e919f23..83ae073 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_object.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_object.js
@@ -2,25 +2,28 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
var removedScripts = require("script_entries/removed_scripts").removedScripts;
-var acceptedScripts = require("script_entries/accepted_scripts").acceptedScripts;
+var acceptedScripts = require("script_entries/accepted_scripts")
+ .acceptedScripts;
var dryRunScripts = require("script_entries/dryrun_scripts").dryRunScripts;
var Script = function(props) {
@@ -28,8 +31,19 @@ var Script = function(props) {
// or an external script.
this.type = null;
- // flagged whether it is unchecked, checked,
- // accepted, or rejected, ...
+ /*
+ * Script.status - The script's current status.
+ *
+ * Possible values are:
+ *
+ * 0 - unchecked
+ * 1 - checked
+ * 2 - accepted
+ * 3 - rejected
+ * 4 - jsweblabel
+ *
+ * See script_properties.js for definitions.
+ */
this.status = null;
// contains the dom element
@@ -52,24 +66,24 @@ var Script = function(props) {
Script.prototype.init = function(props) {
// check the required elements are present.
- if (props == undefined) {
+ if (typeof props === 'undefined') {
throw "Error, missing script entry value in script_object.js";
}
// required properties
- if (props.type != undefined) {
+ if (typeof props.type !== 'undefined') {
this.type = props.type;
} else {
throw "type is missing";
}
- if (props.status != undefined) {
+ if (typeof props.status !== 'undefined') {
this.status = props.status;
} else {
throw "status is missing";
}
- if (props.element != undefined) {
+ if (typeof props.element !== 'undefined') {
this.element = props.element;
} else {
throw "element is missing";
@@ -81,10 +95,10 @@ Script.prototype.init = function(props) {
this.jsAttributes = (props.jsAttributes) ? props.jsAttributes : null;
if (typeof this.text !== 'string' &&
- this.tree !== null &&
- typeof this.tree === 'object' &&
- this.tree.hasOwnProperty('jsCode')
- ) {
+ this.tree !== null &&
+ typeof this.tree === 'object' &&
+ this.tree.hasOwnProperty('jsCode')
+ ) {
this.text = this.tree.jsCode;
}
};
@@ -95,16 +109,16 @@ Script.prototype.tagAsDryRun = function(pageURL, reason, hash) {
var url = (inline == false ? this.url : null);
console.debug("url is", url);
this.element.setAttribute('data-librejs', 'dryrun');
-
-
this.element.setAttribute('data-librejs-reason', reason);
- dryRunScripts.addAScript(pageURL, {'inline': inline,
- 'contents': content,
- 'reason': reason,
- 'url': url,
- 'hash': hash
- });
+ dryRunScripts.addAScript(
+ pageURL,
+ {'inline': inline,
+ 'contents': content,
+ 'reason': reason,
+ 'url': url,
+ 'hash': hash
+ });
};
Script.prototype.tagAsAccepted = function(pageURL, reason, hash) {
@@ -113,16 +127,16 @@ Script.prototype.tagAsAccepted = function(pageURL, reason, hash) {
var url = (inline == false ? this.url : null);
console.debug("url is", url);
this.element.setAttribute('data-librejs', 'accepted');
-
-
this.element.setAttribute('data-librejs-reason', reason);
- acceptedScripts.addAScript(pageURL, {'inline': inline,
- 'contents': content,
- 'reason': reason,
- 'url': url,
- 'hash': hash
- });
+ acceptedScripts.addAScript(
+ pageURL,
+ {'inline': inline,
+ 'contents': content,
+ 'reason': reason,
+ 'url': url,
+ 'hash': hash
+ });
};
@@ -150,12 +164,14 @@ Script.prototype.tagAsDryRun = function(pageURL, reason, hash) {
this.element.setAttribute('data-librejs', 'dryrun');
this.element.setAttribute('data-librejs-reason', reason);
- dryRunScripts.addAScript(pageURL, {'inline': inline,
- 'contents': content,
- 'reason': reason,
- 'url': url,
- 'hash': hash
- });
+ dryRunScripts.addAScript(
+ pageURL,
+ {'inline': inline,
+ 'contents': content,
+ 'reason': reason,
+ 'url': url,
+ 'hash': hash
+ });
};
/**
@@ -180,13 +196,9 @@ Script.prototype.removeNarcissusBugLine = function(str) {
*/
Script.prototype.findContentType = function() {
if (this.url != undefined) {
-
return "";
-
} else if (this.text != undefined) {
-
- return this.element.text;
-
+ return this.element.text;
} else if (this.jsAttributes != undefined) {
// return the array.
return JSON.stringify(this.jsAttributes);
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_properties.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_properties.js
index 2eeeedb..07af983 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_properties.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/dom_handler/script_properties.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
exports.scriptTypes = {
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/html_parser.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/html_parser.js
index 69b2acc..a2bae80 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/html_parser.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/html_parser.js
@@ -50,20 +50,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/url_seen_tester.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/url_seen_tester.js
index 6b98ce1..fbba0c0 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/url_seen_tester.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/url_seen_tester.js
@@ -2,86 +2,79 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
var httpRe = /^(http:)/i;
-
var httpsRe = /^(https:)/i;
exports.urlSeenTester = {
-
- whitelist: {},
-
-
- httpToHttps: function (url) {
- try {
-
- if (httpRe.test(url)) {
+ whitelist: {},
- return url.replace(httpRe, 'https:');
+ httpToHttps: function (url) {
+ try {
- } else if (httpsRe.test(url)) {
+ if (httpRe.test(url)) {
- return url.replace(httpsRe, 'http:');
+ return url.replace(httpRe, 'https:');
- } else {
+ } else if (httpsRe.test(url)) {
- return url;
+ return url.replace(httpsRe, 'http:');
- }
- } catch (x) {
- console.debug('error', x);
- }
+ } else {
- },
-
- clearUrls: function () {
- this.whitelist = {};
- },
-
- clearUrl: function (url) {
+ return url;
- if (this.whitelist[url]) {
+ }
+ } catch (x) {
+ console.debug('error', x);
+ }
+ },
- // console.debug('disallowing', url);
- delete this.whitelist[url];
+ clearUrls: function () {
+ this.whitelist = {};
+ },
- }
+ clearUrl: function (url) {
+ if (this.whitelist[url]) {
- },
-
- addUrl: function (url) {
+ // console.debug('disallowing', url);
+ delete this.whitelist[url];
+ }
+ },
- console.debug('adding', url);
+ addUrl: function (url) {
+ console.debug('adding', url);
- if (!this.isWhitelisted(url)) {
+ if (!this.isWhitelisted(url)) {
- console.debug('allowing', url);
- this.whitelist[url] = true;
- }
+ console.debug('allowing', url);
+ this.whitelist[url] = true;
+ }
+ },
- },
+ isWhitelisted: function (url) {
+ if (this.whitelist[url] || this.whitelist[this.httpToHttps(url)]) {
+ console.debug('found to be whitelisted', url);
+ return true;
+ }
+ return false;
+ }
- isWhitelisted: function (url) {
- if (this.whitelist[url] || this.whitelist[this.httpToHttps(url)]) {
- console.debug('found to be whitelisted', url);
- return true;
- }
- return false;
- }
-
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/find_js_labels.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/find_js_labels.js
index d56d650..e392024 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/find_js_labels.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/find_js_labels.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
/**
@@ -24,72 +26,108 @@
* This allows the dom_handler to allow them by default.
*/
-// find table.
-exports.getLicenseList = function (document) {
+/**
+ * @param {Array} licenses - An array of html nodes.
+ *
+ * @return {Array} - An array of simple license objects.
+ */
+function getLicensesArrayFromElements(licenses) {
+ var a = [];
+ // Convert the html node into a simpler object
+ for (var i = 0; i < licenses.length; i++) {
+ a.push({
+ licenseName: licenses[i].textContent,
+ licenseUrl: licenses[i].href
+ });
+ }
+ return a;
+}
- var tbl = document.getElementById("jslicense-labels1"),
- jsList = [],
- i = 0,
- le,
- rows,
- link,
- fileCell,
- licenseCell,
- sourceCell,
- row;
+/**
+ * @param {Array} sources - An array of html nodes.
+ *
+ * @return {Array} - An array of simple source objects.
+ */
+function getSourcesArrayFromElements(sources) {
+ var a = [];
+ for (var i = 0; i < sources.length; i++) {
+ a.push({
+ sourceName: sources[i].textContent,
+ sourceUrl: sources[i].href
+ });
+ }
+ return a;
+}
+// find table.
+exports.getLicenseList = function(document) {
+ var tbl = document.getElementById('jslicense-labels1');
+ var jsList = [];
+ var i = 0;
+ var le;
+ var rows;
+ var link;
+ var fileCell;
+ var licenseCell;
+ var sourceCell;
+ var row;
- if (tbl) {
+ if (tbl) {
+ try {
+ rows = tbl.getElementsByTagName('tr');
+ le = rows.length;
+ var mockElem = {textContent: 'Unknown', href: 'Unknown'};
+ // loop through rows, and add each valid element to
+ // the array.
+ for (; i < le; i++) {
+ row = rows[i].getElementsByTagName('td');
- try {
- rows = tbl.getElementsByTagName("tr");
- le = rows.length;
- var mockElem = {textContent: "Unknown", href: "Unknown" };
- // loop through rows, and add each valid element to
- // the array.
- for (; i < le; i++) {
+ // Find script url
+ if (row[0] && row[0].getElementsByTagName('a')[0]) {
+ fileCell = row[0].getElementsByTagName('a')[0];
+ } else {
+ fileCell = mockElem;
+ }
- row = rows[i].getElementsByTagName('td');
+ // 'licenses' and 'sources' will, for normal cases, just
+ // contain one element. If the fileCell is pointing to a
+ // combined JS file with multiple licenses, though, these
+ // arrays will contain multiple elements.
- if (row[0] && row[0].getElementsByTagName('a')[0]) {
- fileCell = row[0].getElementsByTagName('a')[0];
- } else {
- fileCell = mockElem;
- }
+ // Find license info
+ var licenses = [mockElem];
+ if (row[1] && row[1].getElementsByTagName('a').length > 0) {
+ licenses = getLicensesArrayFromElements(
+ row[1].getElementsByTagName('a'));
+ }
- if (row[1] && row[1].getElementsByTagName('a')[0]) {
- licenseCell = row[1].getElementsByTagName('a')[0];
- } else {
- licenseCell = mockElem;
- }
+ // Find original source info
+ var sources = [mockElem];
+ if (row[2] && row[2].getElementsByTagName('a').length > 0) {
+ sources = getSourcesArrayFromElements(
+ row[2].getElementsByTagName('a'));
+ }
- if (row[2] && row[2].getElementsByTagName('a')[0]) {
- sourceCell = row[2].getElementsByTagName('a')[0];
- } else {
- sourceCell = mockElem;
- }
- if (fileCell.href != 'Unknown') {
- jsList.push({
-
- 'fileName': fileCell.textContent,
- 'fileUrl': fileCell.href,
- 'fileHash': null, // we'll fill this with value when needed to compare script.
+ if (fileCell.href !== 'Unknown') {
+ jsList.push({
+ 'fileName': fileCell.textContent,
+ 'fileUrl': fileCell.href,
- 'licenseName': licenseCell.textContent,
- 'licenseUrl': licenseCell.href, // this will now be a magnet link, most likely.
-
- 'sourceName': sourceCell.textContent,
- 'sourceUrl': sourceCell.href
- });
+ // we'll fill this with value when needed to compare
+ // script.
+ 'fileHash': null,
+
+ 'licenses': licenses,
+ 'sources': sources
+ });
+ }
+ }
+ } catch (e) {
+ console.debug(
+ 'Error fetching JS Web Label licenses',
+ e, e.lineNumber, e.fileName, 'index is', i);
}
-
- }
- } catch (e) {
- console.debug("Error fetching JS Web Label licenses", e,
- e.lineNumber, e.fileName, "index is", i);
}
- }
-
- return jsList;
+ return jsList;
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/js_web_labels.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/js_web_labels.js
index f13091c..ab363d9 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/js_web_labels.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/js_web_labels.js
@@ -2,44 +2,47 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
-// node.js url module. Makes it easier to resole
+// node.js url module. Makes it easier to resolve
// urls in that datauri loaded dom
var urlHandler = require("url_handler/url_handler");
var {Cc, Ci, Cu, Cm, Cr} = require("chrome");
-
var data = require("sdk/self").data;
// license definitions, we are using canonical urls and license
// identifiers.
var licenses = require('js_checker/license_definitions').licenses;
-var getLicenseList = require('html_script_finder/web_labels/find_js_labels').getLicenseList;
+var getLicenseList = require('html_script_finder/web_labels/find_js_labels')
+ .getLicenseList;
const types = require("js_checker/constant_types");
-const addToCache = require("html_script_finder/web_labels/script_hash_worker").addToCache;
+const addToCache = require("html_script_finder/web_labels/script_hash_worker")
+ .addToCache;
// keep web labels in memory so that they can be checked even when they
// are embedded dynamically.
var jsWebLabelEntries = {};
// store the url to js web labels already visited during this session
-var jsLabelsPageVisited = {};
+var jsLabelsPagesVisited = {};
var WebLabelFinder = function () {
this.dom = null;
@@ -54,13 +57,13 @@ WebLabelFinder.prototype.init = function(dom, pageURL, callback) {
var that = this;
this.pageURL = pageURL;
this.dom = dom;
- this.callback = function (a) {
- if (typeof a == 'undefined') {
+ this.callback = function (a) {
+ if (typeof a === 'undefined') {
a = null;
}
// rewrite callback as soon as it is triggered once.
- that.callback = function () {
+ that.callback = function () {
console.debug("Callback already called");
};
@@ -74,12 +77,11 @@ WebLabelFinder.prototype.init = function(dom, pageURL, callback) {
WebLabelFinder.prototype.findJavaScriptLicenses = function () {
this.searchForJsLink();
- if (this.jslicenseURL && !(jsLabelsPageVisited[this.jslicenseURL])) {
+ if (this.jslicenseURL && !(jsLabelsPagesVisited[this.jslicenseURL])) {
// get content from license page.
console.debug('called fetch license page for', this.jslicenseURL);
this.pageContent = this.fetchLicensePage();
- }
- else {
+ } else {
console.debug(this.jslicenseURL, "already visited");
this.callback();
}
@@ -95,26 +97,33 @@ WebLabelFinder.prototype.searchForJsLink = function() {
// loop through all a tags.
for (; i < len; i++) {
- if (linkTags[i].hasAttribute('rel') &&
- linkTags[i].getAttribute('rel') === 'jslicense') {
- return this.formatURL(linkTags[i]);
- }
+ if (
+ (linkTags[i].hasAttribute('rel') &&
+ linkTags[i].getAttribute('rel') === 'jslicense') ||
+ (linkTags[i].hasAttribute('data-jslicense') &&
+ linkTags[i].getAttribute('data-jslicense') === '1')
+ ) {
+ // This page has a web labels link
+ return this.formatURL(linkTags[i]);
+ }
}
}
+
// no js web labels were found. call back.
this.callback();
+ return false;
};
WebLabelFinder.prototype.formatURL = function(link) {
this.jslicenseURL = urlHandler.resolve(this.pageURL, link.href);
this.jslicenseURL = urlHandler.addFragment(this.jslicenseURL, 'librejs=true');
console.debug('license URL found', this.jslicenseURL);
+ return this.jslicenseURL;
};
WebLabelFinder.prototype.fetchLicensePage = function() {
var that = this;
try {
-
var req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
req.onload = function() {
@@ -128,39 +137,115 @@ WebLabelFinder.prototype.fetchLicensePage = function() {
// add these entries to the global
// object for dynamically embedded scripts.
jsWebLabelEntries[that.pageURL] = that.licenseList;
- jsLabelsPageVisited[req._url] = 1;
-
+ jsLabelsPagesVisited[req._url] = 1;
};
console.debug(this.jslicenseURL);
req.open('GET', this.jslicenseURL, true);
req._url = this.jslicenseURL;
req.responseType = "document";
req.send();
-
} catch (e) {
console.debug(e, e.lineNumber, e.fileName, this.jslicenseURL);
this.callback({});
}
+};
+
+/**
+ * @method isLicenseFree
+ * Returns true if the given web labels row refers to a script that
+ * can be executed by LibreJS.
+ *
+ * This method has some side effects :-/
+ *
+ * @param {Object} lic - A license node from a JS web labels page. It's
+ * expected to contain one or more licenses.
+ * @return {Boolean}
+ */
+WebLabelFinder.prototype.isLicenseFree = function(
+ lic, jslicenseURL, callback
+) {
+ // For each license that this license row contains.
+ var isFree = false;
+ // licenseStatuses is later used to determine isFree.
+ var licenseStatuses = [];
+
+ for (var i = 0; i < lic.licenses.length; i++) {
+ var license;
+ var found = false;
+
+ // For each license from the internal license definitions
+ for (license in licenses) {
+ if (found === true) {
+ break;
+ }
+ var licDef = licenses[license];
+ var licArray = [];
+ if (!licDef.canonicalUrl) {
+ continue;
+ }
+ if (typeof licDef.canonicalUrl === 'string') {
+ licArray = [licDef.canonicalUrl];
+ } else {
+ licArray = licDef.canonicalUrl;
+ }
+
+ // For each of the canonical URLs recognized by this license
+ // definition
+ for (var j = 0; j < licArray.length; j++) {
+ if (urlHandler.removeFragment(licArray[j]) ===
+ urlHandler.removeFragment(lic.licenses[i].licenseUrl)
+ ) {
+ if (!require("sdk/url").isValidURI(lic.fileUrl)) {
+ console.debug(lic.fileUrl, " is not a valid URL");
+ callback();
+ }
+
+ // This license was recognized, and it was free. Add it
+ // to the array of license status, which we'll look at
+ // when we're done with this web label row.
+ licenseStatuses.push(true);
+
+ console.debug("about TO ADD TO XHR: ", lic.fileUrl);
+ this.listCheck[lic.fileUrl] = 0;
+ addToCache(lic, 0, jslicenseURL, callback);
+
+ // Break out of the nearest two loops cause we found
+ // a matching license
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+ // Tally up the licenses we were able to match.
+ if (licenseStatuses.length > 0 &&
+ // If the number of licenses we matched is at least one, and
+ // it's the same number as the number of licenses in this Web
+ // Label column, only then can we recognize this script as free.
+ // licenseStatus.length should never be larger than
+ // lic.licenses.length.
+ licenseStatuses.length >= lic.licenses.length
+ ) {
+ isFree = true;
+ }
+
+ return isFree;
};
WebLabelFinder.prototype.matchListWithDefs = function(jslicenseURL) {
- var i = 0,
- len = this.licenseList.length,
- lic,
- licDef,
- urlLength,
- iUrl,
- licArray = null,
+ var that = this;
+ var licDef,
license, script;
var cacheCalls = 0;
- list_check = {};
+ this.listCheck = {};
+
// nested loop.
cacheCalls = 0;
var callback = function (url) {
cacheCalls++;
- list_check[url] = 1;
- if (cacheCalls == Object.keys(list_check).length) {
+ that.listCheck[url] = 1;
+ if (cacheCalls === Object.keys(that.listCheck).length) {
console.debug("triggering callback duh");
// return array to requester object
callback = false;
@@ -173,44 +258,24 @@ WebLabelFinder.prototype.matchListWithDefs = function(jslicenseURL) {
// return array to requester object
if (callback !== false) {
that.callback(that.licenseList);
- console.debug(list_check);
+ console.debug(that.listCheck);
}
}, 15000);
- for (; i < len; i++) {
- lic = this.licenseList[i];
- var that = this;
- for (license in licenses) {
- licDef = licenses[license];
- if (licDef.canonicalUrl !== undefined) {
- if (typeof licDef.canonicalUrl == 'string') {
- // this is a string. make it an array.
- licArray = [licDef.canonicalUrl];
- } else {
- licArray = licDef.canonicalUrl;
- }
- urlLength = licArray.length;
-
- for (iUrl = 0; iUrl < urlLength; iUrl++) {
- if (urlHandler.removeFragment(licArray[iUrl]) === urlHandler.removeFragment(lic.licenseUrl)) {
- if (!require("sdk/url").isValidURI(lic.fileUrl)) {
- console.debug(lic.fileUrl, " is not a valid URL");
- callback();
- }
- lic.free = true;
- var notif = require("ui/notification").createNotification(lic.fileUrl).notification;
- console.debug("about TO ADD TO XHR: ", lic.fileUrl);
- list_check[lic.fileUrl] = 0;
- addToCache(lic, 0, jslicenseURL, callback);
- }
- }
- }
+
+ for (var i = 0; i < this.licenseList.length; i++) {
+ // this.licenseList[i] is the web labels license column
+ var lic = this.licenseList[i];
+ if (this.isLicenseFree(lic, jslicenseURL, callback)) {
+ lic.free = true;
}
}
};
exports.WebLabelFinder = WebLabelFinder;
-// store the web labels harvested across webpages (single session).
+// Store the web labels harvested across webpages (only in this session).
exports.jsWebLabelEntries = jsWebLabelEntries;
+
+exports.jsLabelsPagesVisited = jsLabelsPagesVisited;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/script_hash_worker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/script_hash_worker.js
index e62133e..a8b2fdb 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/script_hash_worker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/html_script_finder/web_labels/script_hash_worker.js
@@ -2,20 +2,22 @@
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
+ * Copyright (C) 2014, 2015 Nik Nyby
*
- * This program is free software: you can redistribute it and/or modify
+ * This file is part of GNU LibreJS.
+ *
+ * GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
const types = require("js_checker/constant_types");
@@ -35,24 +37,28 @@ exports.addToCache = function (lic, delay, jsWebLabelsURL, callback) {
var cb = function (script, contents) {
try {
// add a cache entry.
- var hash = scriptsCached.addEntryIfNotCached(contents,
+ var hash = scriptsCached.addEntryIfNotCached(
+ contents,
types.freeWithComment(
- 'This script is free according to a JS Web Labels page visited recently (at ' +
- jsWebLabelsURL.replace("librejs=true", "") + ' )'),
+ 'This script is free according to a JS Web Labels ' +
+ 'page visited recently (at ' +
+ jsWebLabelsURL.replace("librejs=true", "") + ' )'
+ ),
{},
true,
- lic.fileUrl);
+ lic.fileUrl
+ );
console.debug('returning xhr from', lic.fileUrl);
callback(lic.fileUrl);
} catch (e) {
callback(lic.fileUrl);
}
};
- // just callback after 5 seconds if we don't get the answer yet.
+ // just callback after 5 seconds if we don't get the answer yet.
timers.setTimeout(function() {
cb = function() {};
callback(lic.fileUrl); }, 20000);
- xhr({'url': lic.fileUrl}, cb);},
- delay);
+ xhr({'url': lic.fileUrl}, cb);
+ }, delay);
};