summaryrefslogtreecommitdiff
path: root/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib
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
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')
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/install_uninstall.js39
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/prefchange.js120
-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
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/allowed_referrers.js78
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/caching.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/http_request_observer.js217
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/process_response.js727
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/stream_loader.js19
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js24
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js382
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js133
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js125
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js697
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js48
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js50
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js60
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/main.js201
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/narcissus_parser/narcissus_worker.js67
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/parser/narcissus_worker.js81
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/pref_observer/pref_observer.js72
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/accepted_scripts.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/all_scripts.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/crypto.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/dryrun_scripts.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/free_libraries.js46
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/removed_scripts.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/scripts_cache.js36
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/settings_tab.js106
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/storage.js257
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui.js188
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/notification.js15
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/script_panel.js10
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/ui_info.js256
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_punycode.js729
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_querystring.js180
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_url.js558
-rw-r--r--data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/url_handler.js154
50 files changed, 3992 insertions, 3236 deletions
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/install_uninstall.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/install_uninstall.js
index 6a4999d..c5c150f 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/install_uninstall.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/install_uninstall.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,9 +28,8 @@
const {Cc, Ci, Cu, Cm, Cr} = require("chrome");
const httpObserver = require("http_observer/http_request_observer");
-
-const narcissusWorker = require("narcissus_parser/narcissus_worker");
-
+var narcissusWorker = require("parser/narcissus_worker")
+ .narcissusWorker;
const caching = require("http_observer/caching");
const prompt = Cc["@mozilla.org/embedcomp/prompt-service;1"].
@@ -38,21 +39,19 @@ const prompt = Cc["@mozilla.org/embedcomp/prompt-service;1"].
const tabs = require('sdk/tabs');
/**
- * Stop the httpObserver when the add-on
- * is disabled or removed.
+ * Stop the httpObserver when the add-on is disabled or removed.
*/
exports.onUnload = function(reason) {
-
- if (reason == "disable" ||
- reason == "shutdown" ||
- reason == "upgrade" ||
- reason == "downgrade") {
- require("settings/storage").librejsStorage.writeCacheToDB();
- // remove all http notifications
- httpObserver.removeHttpObserver();
- // remove worker.
- narcissusWorker.stopWorker();
- }
+ if (reason == "disable" ||
+ reason == "shutdown" ||
+ reason == "upgrade" ||
+ reason == "downgrade") {
+ require("settings/storage").librejsStorage.writeCacheToDB();
+ // remove all http notifications
+ httpObserver.removeHttpObserver();
+ // remove worker.
+ narcissusWorker.stopWorker();
+ }
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/prefchange.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/prefchange.js
index 532dd81..910a103 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/prefchange.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/addon_management/prefchange.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 whitelist = [];
@@ -28,65 +30,65 @@ var prompt = Cc['@mozilla.org/embedcomp/prompt-service;1'].
var scriptsCached = require("script_entries/scripts_cache").scriptsCached;
var setWhitelist = function () {
-
- whitelist = [];
-
- var str;
-
- var whitelistString = prefSet.prefs.whitelist.split(',');
-
- for (var i = 0; i < whitelistString.length; i++) {
-
- // remove space, trailing slash, escape any nonalpha except *, replace * with .*
- str = whitelistString[i].replace(" ", "").replace(/\/$/, "").replace(/[^a-z0-9\*]/ig, "\\$&").replace("*", ".*");
-
- if (str !== '') {
- whitelist.push(new RegExp('^https?:\/\/(www\.)?' + str + '/', 'i'));
- }
-
- }
-
+ whitelist = [];
+
+ var str;
+ var whitelistString;
+ if (typeof prefSet.prefs.whitelist === 'undefined') {
+ whitelistString = '';
+ } else {
+ whitelistString = prefSet.prefs.whitelist.split(',');
+ }
+
+ for (var i = 0; i < whitelistString.length; i++) {
+ // remove space, trailing slash, escape any nonalpha except *,
+ // replace * with .*
+ str = whitelistString[i]
+ .replace(" ", "").replace(/\/$/, "")
+ .replace(/[^a-z0-9\*]/ig, "\\$&").replace("*", ".*");
+
+ if (str !== '') {
+ whitelist.push(
+ new RegExp('^https?:\/\/(www\\.)?' + str + '/', 'i'));
+ }
+ }
};
exports.getWhitelist = function () {
- return whitelist;
+ return whitelist;
};
exports.init = function () {
- setWhitelist();
+ setWhitelist();
};
prefSet.on("whitelist", setWhitelist);
-var setDryRun = function () {
- var dryRun = prefSet.prefs.dryrun;
- if (dryRun === true) {
- prompt.alert(null, "LibreJS Dry Run Mode", "Is Dry Run Mode really what you want? LibreJS will still analyze JavaScript on a page, but it will not block any of it. As a result, ALL of the JavaScript on a page will run as is, whether it is free and trivial or not. You will not be warned again. Uncheck that box if you are unsure.");
- scriptsCached.resetCache();
- } else {
- prompt.alert(null, "LibreJS Dry Run Mode", "LibreJS Dry Run Mode is now disabled");
- }
-};
+/*var setDryRun = function () {
+ var dryRun = prefSet.prefs.dryrun;
+ if (dryRun === true) {
+ prompt.alert(null, "LibreJS Dry Run Mode", "Is Dry Run Mode really what you want? LibreJS will still analyze JavaScript on a page, but it will not block any of it. As a result, ALL of the JavaScript on a page will run as is, whether it is free and trivial or not. You will not be warned again. Uncheck that box if you are unsure.");
+ scriptsCached.resetCache();
+ } else {
+ prompt.alert(null, "LibreJS Dry Run Mode", "LibreJS Dry Run Mode is now disabled");
+ }
+};*/
//prefSet.on("dryrun", setDryRun);
-exports.isDryRun = function () {
- /**
- * Returns true if dryRun mode is enabled. False otherwise.
- */
- //return prefSet.prefs.dryrun;
- return false;
-};
-
-
+/*exports.isDryRun = function () {
+ // Returns true if dryRun mode is enabled. False otherwise.
+ //return prefSet.prefs.dryrun;
+ return false;
+};*/
var setComplaintTab = function () {
- var complaintTab = prefSet.prefs.complaint_tab;
- if (complaintTab === true) {
- prompt.alert(null, "Turning on complaint tab", "A complaint tab will be displayed on pages where nonfree nontrivial JavaScript is found and contact information is found as well.");
- } else {
- prompt.alert(null, "Turning off complaint tab", "No complaint tab will appear on pages, even when nonfree nontrivial JavaScript is found.");
- }
+ var complaintTab = prefSet.prefs.complaint_tab;
+ if (complaintTab === true) {
+ prompt.alert(null, "Turning on complaint tab", "A complaint tab will be displayed on pages where nonfree nontrivial JavaScript is found and contact information is found as well.");
+ } else {
+ prompt.alert(null, "Turning off complaint tab", "No complaint tab will appear on pages, even when nonfree nontrivial JavaScript is found.");
+ }
};
prefSet.on("complaint_tab", setComplaintTab);
@@ -97,15 +99,13 @@ exports.isComplaintTab = function () {
return prefSet.prefs.complaint_tab;
};
-
-
var setDisplayNotifications = function () {
- var displayNotifications = prefSet.prefs.display_notifications;
- if (displayNotifications === true) {
- prompt.alert(null, "Turning on notifications", "Notifications with code snippets will now appear while LibreJS is analyzing JavaScript on a page.");
- } else {
- prompt.alert(null, "Turning off notifications", "Notifications of code being analyzed will not be displayed.");
- }
+ var displayNotifications = prefSet.prefs.display_notifications;
+ if (displayNotifications === true) {
+ prompt.alert(null, "Turning on notifications", "Notifications with code snippets will now appear while LibreJS is analyzing JavaScript on a page.");
+ } else {
+ prompt.alert(null, "Turning off notifications", "Notifications of code being analyzed will not be displayed.");
+ }
};
prefSet.on("display_notifications", setDisplayNotifications);
@@ -116,3 +116,11 @@ exports.isDisplayNotifications = function () {
*/
return prefSet.prefs.display_notifications;
};
+
+exports.complaintEmailSubject = function() {
+ return prefSet.prefs.complaint_email_subject;
+};
+
+exports.complaintEmailBody = function() {
+ return prefSet.prefs.complaint_email_body;
+};
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);
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/allowed_referrers.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/allowed_referrers.js
index 4f524a7..39374c9 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/allowed_referrers.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/allowed_referrers.js
@@ -2,74 +2,68 @@
* 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 prefChange = require("addon_management/prefchange");
+var allowed = {};
+
/**
* Contains a list of pages that are allowed
* to execute JavaScript regardless of whether it is
* nonfree and nontrivial.
*/
-exports.allowedReferrers = {
-
- allowed: {},
+var AllowedReferrers = function() {
+};
- addPage: function (url) {
- this.allowed[url] = 1;
- },
+AllowedReferrers.prototype.addPage = function(url) {
+ allowed[url] = 1;
+};
- urlInAllowedReferrers: function (url) {
-
- if (this.allowed[url] === 1) {
+AllowedReferrers.prototype.urlInAllowedReferrers = function (url) {
+ if (allowed[url] === 1) {
return true;
- }
- // check if whitelisted.
- return this.urlInWhitelist(url);
-
- },
-
- urlInWhitelist: function (url) {
- var whitelist = prefChange.getWhitelist();
- var i = 0, le = whitelist.length;
-
- for (; i < le; i++) {
-
+ }
+ // check if whitelisted.
+ return this.urlInWhitelist(url);
+};
+
+AllowedReferrers.prototype.urlInWhitelist = function(url) {
+ var whitelist = prefChange.getWhitelist();
+ var i = 0, le = whitelist.length;
+ for (; i < le; i++) {
if (whitelist[i].test(url)) {
-
return true;
-
}
+ }
+};
- }
-
- },
-
- clearSinglePageEntry: function (url) {
-
- var index = this.allowed[url];
+AllowedReferrers.prototype.clearSinglePageEntry = function(url) {
+ var index = allowed[url];
- if (this.allowed[url] === 1) {
- delete this.allowed[url];
- }
+ if (allowed[url] === 1) {
+ delete allowed[url];
+ }
+};
- },
+AllowedReferrers.prototype.clearAllEntries = function() {
+ allowed = {};
+};
- clearAllEntries: function () {
- this.allowed = {};
- }
-}; \ No newline at end of file
+exports.allowedReferrers = new AllowedReferrers();
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/caching.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/caching.js
index 1463b1c..285f95a 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/caching.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/caching.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 {Cc, Ci, Cu, Cm, Cr} = require("chrome");
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/http_request_observer.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/http_request_observer.js
index 09e66e8..e8c9635 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/http_request_observer.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/http_request_observer.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 {Cc, Ci, Cu, Cm, Cr} = require("chrome");
@@ -30,132 +32,117 @@ var targetMimeTypes = /.*(javascript|ecmascript|html).*/i;
// ensure xhr won't create an infinite loop
// with html content.
var urlTester = require("html_script_finder/url_seen_tester").urlSeenTester;
-
var streamLoader = require("http_observer/stream_loader").streamLoader;
var httpRequestObserver = {
-
- observe: function(request, aTopic, aData) {
-
- console.debug('atopic is', aTopic);
-
- var url, newListener, status;
-
- if (aTopic == "http-on-examine-response" ||
- aTopic == "http-on-examine-cached-response" ||
- aTopic == "http-on-examine-merged-response") {
-
- request.QueryInterface(Ci.nsIHttpChannel);
-
- if (request.URI.scheme != 'chrome' &&
- (request.responseStatus < 300 ||
- request.responseStatus > 399) &&
- (targetMimeTypes.test(request.contentType) ||
- request.contentType == undefined) &&
- (!urlTester.isWhitelisted(request.URI.spec) &&
- !urlTester.isWhitelisted(request.originalURI.spec))) {
-
- newListener = new TracingListener();
- request.QueryInterface(Ci.nsITraceableChannel);
- newListener.originalListener = request.setNewListener(newListener);
-
- }
-
- else if (urlTester.isWhitelisted(request.URI.spec) ||
- urlTester.isWhitelisted(request.originalURI.spec)) {
- urlTester.clearUrl(request.URI.spec);
- urlTester.clearUrl(request.originalURI.spec);
- }
-
- }
- },
-
- QueryInterface : function (aIID) {
- if (aIID.equals(Ci.nsIObserver) ||
- aIID.equals(Ci.nsISupports)) {
- return this;
+ observe: function(request, aTopic, aData) {
+ console.debug('atopic is', aTopic);
+ var url, newListener, status;
+
+ if (aTopic === "http-on-examine-response" ||
+ aTopic === "http-on-examine-cached-response" ||
+ aTopic === "http-on-examine-merged-response"
+ ) {
+ request.QueryInterface(Ci.nsIHttpChannel);
+
+ if (request.URI.scheme !== 'chrome' &&
+ (request.responseStatus < 300 ||
+ request.responseStatus > 399) &&
+ (targetMimeTypes.test(request.contentType) ||
+ request.contentType === undefined) &&
+ (!urlTester.isWhitelisted(request.URI.spec) &&
+ !urlTester.isWhitelisted(request.originalURI.spec))
+ ) {
+ newListener = new TracingListener();
+ request.QueryInterface(Ci.nsITraceableChannel);
+ newListener.originalListener = request.setNewListener(newListener);
+ } else if (urlTester.isWhitelisted(request.URI.spec) ||
+ urlTester.isWhitelisted(request.originalURI.spec)
+ ) {
+ urlTester.clearUrl(request.URI.spec);
+ urlTester.clearUrl(request.originalURI.spec);
+ }
+
+ }
+ },
+
+ QueryInterface: function (aIID) {
+ if (aIID.equals(Ci.nsIObserver) ||
+ aIID.equals(Ci.nsISupports)
+ ) {
+ return this;
+ }
+ throw Cr.NS_NOINTERFACE;
}
- throw Cr.NS_NOINTERFACE;
- }
};
// Copy response listener implementation.
function TracingListener() {
- this.originalListener = null;
- this.streamLoader = streamLoader();
+ this.originalListener = null;
+ this.streamLoader = streamLoader();
}
TracingListener.prototype = {
+ onDataAvailable: function(request, context, inputStream, offset, count) {
+ try {
+ this.streamLoader.loader.onDataAvailable(
+ request, context, inputStream, offset, count);
+ } catch (x) {
+ console.debug(x, x.lineNumber, x.fileName, "In this case, charset is");
+ }
+ },
+
+ onStartRequest: function(request, context) {
+ this.streamLoader.setOriginalListener(this.originalListener);
+ this.streamLoader.loader.onStartRequest(request, context);
+ this.originalListener.onStartRequest(request, context);
+ },
+
+ onStopRequest: function(request, context, statusCode) {
+ try {
+ this.streamLoader.loader.onStopRequest(request, context, statusCode);
+ } catch (e) {
+ console.debug('error in onStopRequest', e, e.lineNumber);
+ }
+ },
+
+ QueryInterface: function (aIID) {
+ if (aIID.equals(Ci.nsIStreamListener) ||
+ aIID.equals(Ci.nsISupports)
+ ) {
+ return this;
+ }
+ throw Cr.NS_NOINTERFACE;
+ },
+};
- onDataAvailable: function(request, context, inputStream, offset, count) {
-
- try {
- this.streamLoader.loader.onDataAvailable(request, context, inputStream, offset, count);
- } catch (x) {
-
- console.debug(x, x.lineNumber, x.fileName, "In this case, charset is");
-
- }
-
- },
-
- onStartRequest: function(request, context) {
-
- this.streamLoader.setOriginalListener(this.originalListener);
- this.streamLoader.loader.onStartRequest(request, context);
- this.originalListener.onStartRequest(request, context);
-
- },
-
- onStopRequest: function(request, context, statusCode) {
-
- try {
- this.streamLoader.loader.onStopRequest(request, context, statusCode);
- } catch (e) {
- console.debug('error in onStopRequest', e, e.lineNumber);
- }
- },
-
- QueryInterface: function (aIID) {
- if (aIID.equals(Ci.nsIStreamListener) ||
- aIID.equals(Ci.nsISupports)) {
- return this;
+exports.startHttpObserver = function() {
+ try {
+ observerService.addObserver(httpRequestObserver,
+ "http-on-examine-response", false);
+ observerService.addObserver(httpRequestObserver,
+ "http-on-examine-cached-response", false);
+ observerService.addObserver(httpRequestObserver,
+ "http-on-examine-merged-response", false);
+ console.debug('turned on http observer');
+ } catch (e) {
+ console.debug(e);
}
- throw Cr.NS_NOINTERFACE;
- },
-
-
};
-observerService.addObserver(httpRequestObserver,
- "http-on-examine-response", false);
-
-observerService.addObserver(httpRequestObserver,
- "http-on-examine-cached-response", false);
-
-observerService.addObserver(httpRequestObserver,
- "http-on-examine-merged-response", false);
-
-
+exports.startHttpObserver();
/* remove observer */
-exports.removeHttpObserver = function () {
-
- try {
-
- observerService.removeObserver(httpRequestObserver,
- "http-on-examine-response");
-
- observerService.removeObserver(httpRequestObserver,
- "http-on-examine-cached-response");
-
- observerService.removeObserver(httpRequestObserver,
- "http-on-examine-merged-response");
-
- console.debug('turned off http observer');
-
- } catch (e) {
- console.debug(e);
- }
-
+exports.removeHttpObserver = function() {
+ try {
+ observerService.removeObserver(httpRequestObserver,
+ "http-on-examine-response");
+ observerService.removeObserver(httpRequestObserver,
+ "http-on-examine-cached-response");
+ observerService.removeObserver(httpRequestObserver,
+ "http-on-examine-merged-response");
+ console.debug('turned off http observer');
+ } catch (e) {
+ console.debug(e);
+ }
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/process_response.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/process_response.js
index 759adf7..c1f5e88 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/process_response.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/process_response.js
@@ -2,23 +2,25 @@
* 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/>.
*/
-/**
+/**
* This module checks http responses by mime type and returns a
* modified response.
*/
@@ -43,7 +45,7 @@ var acceptedScripts = require("script_entries/accepted_scripts").acceptedScripts
// used to display info when a url is whitelisted.
var dryRunScripts = require("script_entries/dryrun_scripts").dryRunScripts;
-// node.js url module. Makes it easier to resolve
+// node.js url module. Makes it easier to resolve
// urls in that datauri loaded dom
var urlHandler = require("url_handler/url_handler");
var isDryRun = require("addon_management/prefchange").isDryRun;
@@ -53,356 +55,377 @@ var htmlMimeTypeRe = /.*(xhtml\+xml|html|multipart\/x-mixed-replace).*/i;
var processResponseObject = {
- data: null,
- myParser: null,
- url: null,
- scriptFinder: null,
- jsCheckString: null,
- referrer: null,
- contentType: null,
- resInfo: null,
- listener: null,
- req: null,
-
- /**
- * starts the handling of a new response.
- */
- init: function (listener, resInfo) {
- this.resInfo = resInfo;
- this.req = resInfo.request;
- /* needed for this.req.referrer */
- this.req.QueryInterface(Ci.nsIHttpChannel);
- this.listener = listener;
- this.setData();
- this.setContentType();
- this.setUrls();
- },
-
- /**
- * genBinaryOutput
- * Set or reset binaryOutputStream and storageStream.
- */
- genBinaryOutput: function () {
- this.storageStream = Cc["@mozilla.org/storagestream;1"].createInstance(Ci.nsIStorageStream);
- this.binaryOutputStream = Cc["@mozilla.org/binaryoutputstream;1"].createInstance(Ci.nsIBinaryOutputStream);
- },
-
- /**
- * Gather the data gathered from onDataAvailable.
- */
- setData: function () {
-
- this.data = this.resInfo.receivedData;
- console.debug("\n\nDump of whole data:\n\n", this.data, "\n\n end of dump");
- // Prevents the http response body from being empty,
- // which would throw an error.
- if (this.data == '' || this.data == undefined) {
- this.data = " ";
- }
-
- },
-
- /**
- * Set a standardized lowercase mime type.
- */
- setContentType: function() {
- if (this.req.contentType != undefined) {
- this.contentType = String(this.req.contentType).toLowerCase();
- }
- },
-
- /**
- * setUrls
- * Set the current URL of the response, and
- * set referrer if applicable.
- */
- setUrls: function() {
-
- if (this.req.URI != undefined) {
- this.fragment = urlHandler.getFragment(this.req.URI.spec);
- console.debug('fragment is', this.fragment);
- this.url = urlHandler.removeFragment(this.req.URI.spec);
- }
- if (this.req.referrer != undefined) {
- this.referrerFragment = urlHandler.getFragment(this.req.referrer.spec);
- this.referrer = urlHandler.removeFragment(this.req.referrer.spec);
- }
- },
-
- /**
- * processHTML
- * Modifies a string of html
- */
- processHTML: function() {
-
- var charset = this.req.contentCharset, myParser;
-
- if (this.req.contentCharset != undefined && this.req.contentCharset != "") {
- charset = this.req.contentCharset;
- } else {
- charset = "";
- }
- acceptedScripts.clearScripts(this.req.URI.spec);
- removedScripts.clearScripts(this.req.URI.spec);
- dryRunScripts.clearScripts(this.req.URI.spec);
-
- console.debug('charset is', charset);
- console.debug('responseStatus for', this.url, 'is', this.req.responseStatus);
-
- // send data to htmlParser, and pass on modified data to
- // originalListener.
-
- myParser = htmlParser.htmlParser().parse(this.data,
- charset,
- this.contentType,
- this.url,
- this.fragment,
- this.req.responseStatus,
- this.htmlParseCallback.bind(this));
- },
-
- /**
- *
- * htmlParseCallback
- *
- * Passed on the callback result to
- * the originalListener.
- *
- */
- htmlParseCallback: function(result) {
-
- var len = result.length;
-
- try {
-
- this.listener.onDataAvailable(this.req,
- this.resInfo.context,
- result.newInputStream(0), 0, len);
-
-
- } catch (e) {
-
- this.req.cancel(this.req.NS_BINDING_ABORTED);
-
- }
-
- this.listener.onStopRequest(this.req,
- this.resInfo.context, this.resInfo.statusCode);
-
- },
-
- /**
- * processJS
- * Process and modify a string of JavaScript.
- */
- processJS: function() {
- var checker, check, jsCheckString,
- that = this;
- //var start = Date.now(), end;
-
- try {
- // make sure script isn't already listed as free
- // in a JS web labels table.
- if (this.checkJsWebLabelsForScript()) {
- // this is free. we are done.
- this.jsListenerCallback();
- return;
-
- }
-
- // analyze javascript in response.
- checker = jsChecker.jsChecker();
- check = checker.searchJs(this.data, function () {
- console.debug("Has been analyzing", that.data);
- that.processJsCallback(checker);
- }, that.url);
-
-
-
- } catch(e) {
-
- // any error is considered nontrivial.
- console.debug('js error in js app, removing script', e);
- console.debug("error", e, e.lineNumber);
- // modify data that will be sent to the browser.
- this.data = '// LibreJS: Script contents were removed when it was loaded from a page, because another script attempted to load this one dynamically. Please place your cursor in the url bar and press the enter key to see the source.';
- this.jsListenerCallback();
- }
-
- },
-
- /**
- * checkJsWebLabelsForScript
- *
- * check whether script that's been received has an entry
- * in a js web labels table (lookup referrer.)
- *
- */
- checkJsWebLabelsForScript: function () {
-
- console.debug('checking script', this.url);
- console.debug('current list is', JSON.stringify(jsWebLabelEntries));
- if (jsWebLabelEntries[this.referrer] != undefined) {
-
- var scriptList = jsWebLabelEntries[this.referrer],
- i = 0,
- len = scriptList.length;
-
- for (; i < len; i++) {
-
- if (scriptList[i].fileUrl === this.url &&
- scriptList[i].free === true) {
-
- console.debug(this.url, "is free and dynamic!");
-
- var scriptObj = {inline: false,
- url: this.url,
- contents: this.url,
- reason: "This script is free (see JS Web Labels page for detail)"};
-
- acceptedScripts.addAScript(this.req.referrer.spec, scriptObj, "Script is free");
-
- return true;
-
- }
-
- }
-
-
- }
-
- },
-
- processJsCallback: function(checker) {
- try {
- var scriptObj;
-
- var jsCheckString = checker.parseTree.freeTrivialCheck;
- console.debug("analyzing js callback for", this.url);
- // for testing only.
- //var jsCheckString = {'type': checkTypes.FREE_SINGLE_ITEM };
- console.debug('jscheckstring is', jsCheckString.type);
-
- if (jsCheckString.type === checkTypes.NONTRIVIAL) {
- if (!allowedRef.urlInAllowedReferrers(this.req.referrer.spec)) {
- //if (true) {
- console.debug("url", this.url, " is found nontrivial", "with reason", jsCheckString.reason);
- scriptObj = {inline: false,
- contents: '',
- removalReason: 'nontrivial',
- reason: jsCheckString.reason,
- url: this.url,
- hash: checker.hash};
- removedScripts.addAScript(this.req.referrer.spec, scriptObj);
-
- // modify data that will be sent to the browser.
- this.data = '// LibreJS: Script contents were removed when it was loaded from a page, because another script attempted to load this one dynamically and its contents appear to be nonfree/nontrivial. Please hit enter in the location bar to see the actual source.';
+ data: null,
+ myParser: null,
+ url: null,
+ scriptFinder: null,
+ jsCheckString: null,
+ referrer: null,
+ contentType: null,
+ resInfo: null,
+ listener: null,
+ req: null,
+
+ /**
+ * starts the handling of a new response.
+ */
+ init: function (listener, resInfo) {
+ this.resInfo = resInfo;
+ this.req = resInfo.request;
+ /* needed for this.req.referrer */
+ this.req.QueryInterface(Ci.nsIHttpChannel);
+ this.listener = listener;
+ this.setData();
+ this.setContentType();
+ this.setUrls();
+ },
+
+ /**
+ * genBinaryOutput
+ * Set or reset binaryOutputStream and storageStream.
+ */
+ genBinaryOutput: function () {
+ this.storageStream = Cc["@mozilla.org/storagestream;1"]
+ .createInstance(Ci.nsIStorageStream);
+ this.binaryOutputStream = Cc["@mozilla.org/binaryoutputstream;1"]
+ .createInstance(Ci.nsIBinaryOutputStream);
+ },
+
+ /**
+ * Gather the data gathered from onDataAvailable.
+ */
+ setData: function () {
+ this.data = this.resInfo.receivedData;
+ //console.debug("\n\nDump of whole data:\n\n", this.data, "\n\n end of dump");
+ // Prevents the http response body from being empty,
+ // which would throw an error.
+ if (this.data == '' || this.data == undefined) {
+ this.data = " ";
+ }
+ },
+
+ /**
+ * Set a standardized lowercase mime type.
+ */
+ setContentType: function() {
+ if (this.req.contentType != undefined) {
+ this.contentType = String(this.req.contentType).toLowerCase();
+ }
+ },
+
+ /**
+ * setUrls
+ * Set the current URL of the response, and
+ * set referrer if applicable.
+ */
+ setUrls: function() {
+
+ if (this.req.URI != undefined) {
+ this.fragment = urlHandler.getFragment(this.req.URI.spec);
+ console.debug('fragment is', this.fragment);
+ this.url = urlHandler.removeFragment(this.req.URI.spec);
+ }
+ if (this.req.referrer != undefined) {
+ this.referrerFragment = urlHandler.getFragment(this.req.referrer.spec);
+ this.referrer = urlHandler.removeFragment(this.req.referrer.spec);
+ }
+ },
+
+ /**
+ * processHTML
+ * Modifies a string of html
+ */
+ processHTML: function() {
+ var charset = this.req.contentCharset, myParser;
+
+ if (this.req.contentCharset != undefined && this.req.contentCharset != "") {
+ charset = this.req.contentCharset;
} else {
- console.debug("writing to dry run", this.url);
- scriptObj = {inline:false,
- contents: '',
- removalReason: 'nontrivial',
- reason: jsCheckString.reason,
- url: this.url,
- hash:checker.hash};
- dryRunScripts.addAScript(this.req.referrer.spec, scriptObj);
+ charset = "";
+ }
+ acceptedScripts.clearScripts(this.req.URI.spec);
+ removedScripts.clearScripts(this.req.URI.spec);
+ dryRunScripts.clearScripts(this.req.URI.spec);
+
+ console.debug('charset is', charset);
+ console.debug(
+ 'responseStatus for', this.url, 'is', this.req.responseStatus);
+
+ // send data to htmlParser, and pass on modified data to
+ // originalListener.
+
+ myParser = htmlParser.htmlParser().parse(
+ this.data,
+ charset,
+ this.contentType,
+ this.url,
+ this.fragment,
+ this.req.responseStatus,
+ this.htmlParseCallback.bind(this));
+ },
+
+ /**
+ *
+ * htmlParseCallback
+ *
+ * Passed on the callback result to
+ * the originalListener.
+ *
+ */
+ htmlParseCallback: function(result) {
+
+ var len = result.length;
+
+ try {
+
+ this.listener.onDataAvailable(
+ this.req,
+ this.resInfo.context,
+ result.newInputStream(0), 0, len);
+
+
+ } catch (e) {
+
+ this.req.cancel(this.req.NS_BINDING_ABORTED);
+
+ }
+
+ this.listener.onStopRequest(
+ this.req,
+ this.resInfo.context, this.resInfo.statusCode);
+
+ },
+
+ /**
+ * processJS
+ * Process and modify a string of JavaScript.
+ */
+ processJS: function() {
+ var checker, check, jsCheckString,
+ that = this;
+ //var start = Date.now(), end;
+
+ try {
+ // make sure script isn't already listed as free
+ // in a JS web labels table.
+ if (this.checkJsWebLabelsForScript()) {
+ // this is free. we are done.
+ this.jsListenerCallback();
+ return;
+
+ }
+
+ // analyze javascript in response.
+ checker = jsChecker.jsChecker();
+ check = checker.searchJs(this.data, function () {
+ //console.debug("Has been analyzing", that.data);
+ that.processJsCallback(checker);
+ }, that.url);
+
+
+
+ } catch(e) {
+
+ // any error is considered nontrivial.
+ console.debug('js error in js app, removing script', e);
+ console.debug("error", e, e.lineNumber);
+ // modify data that will be sent to the browser.
+ this.data = '// LibreJS: Script contents were removed when it was loaded from a page, because another script attempted to load this one dynamically. Please place your cursor in the url bar and press the enter key to see the source.';
+ this.jsListenerCallback();
}
-
- this.jsListenerCallback();
-
- } else if (jsCheckString.type === checkTypes.FREE ||
- jsCheckString.type === checkTypes.FREE_SINGLE_ITEM ||
- jsCheckString.type === checkTypes.TRIVIAL ||
- jsCheckString.type === checkTypes.TRIVIAL_DEFINES_FUNCTION ||
- jsCheckString.type === checkTypes.WHITELISTED) {
- console.debug("found a free script for", this.url, this.req.referrer.spec, jsCheckString.reason);
- console.debug('found a free script', this.req.referrer.spec);
-
- scriptObj = {inline: false,
- contents: '',
- reason: jsCheckString.reason,
- url: this.url,
- hash:checker.hash};
-
- acceptedScripts.addAScript(this.req.referrer.spec, scriptObj);
- this.jsListenerCallback();
- }
-
- //var end = Date.now();
- console.debug('exec time', this.url, ' -- ', end - start);
- } catch (x) {
- console.debug('error', x);
- }
- },
-
- /**
- * ProcessAllTypes
- * Calls processHTML or JS if it finds an appropriate content
- * type. For everything else it just passes on the data to the
- * original listener.
- */
- processAllTypes: function() {
- // toggle xlibrejs if X-LibreJS is set.
-
- // process HTML
- if ((htmlMimeTypeRe.test(this.contentType) ||
- this.req.contentType === undefined)) {
- this.processHTML();
- return;
- }
-
- else {
- // process external JS files that are called from another
- // file (and hence have a referrer).
-
- if (this.referrer != undefined &&
- jsMimeTypeRe.test(this.contentType) &&
- !(acceptedScripts.isFound(this.referrer, {inline: false, contents: this.url})) &&
- !(acceptedScripts.isFound(this.referrer, {inline:false, contents:this.req.originalURI.spec}))) {
-
- // console.debug('process js triggered for', this.url);
- this.processJS();
-
- } else {
- this.jsListenerCallback();
- }
-
- }
-
- },
-
- jsListenerCallback: function () {
-
- var len = this.data.length;
-
- this.genBinaryOutput();
-
- this.storageStream.init(8192, len, null);
- this.binaryOutputStream.setOutputStream(this.storageStream.getOutputStream(0));
- this.binaryOutputStream.writeBytes(this.data, len);
-
- try {
- this.listener.onDataAvailable(this.req,
- this.resInfo.context,
- this.storageStream.newInputStream(0),
- 0, len);
- } catch (e) {
- this.req.cancel(this.req.NS_BINDING_ABORTED);
- }
-
- this.listener.onStopRequest(this.req,
- this.resInfo.context,
- this.resInfo.statusCode);
-
- }
-
-
+
+ },
+
+ /**
+ * checkJsWebLabelsForScript
+ *
+ * check whether script that's been received has an entry
+ * in a js web labels table (lookup referrer.)
+ *
+ */
+ checkJsWebLabelsForScript: function () {
+
+ console.debug('checking script', this.url);
+ console.debug('current list is', JSON.stringify(jsWebLabelEntries));
+ if (jsWebLabelEntries[this.referrer] != undefined) {
+
+ var scriptList = jsWebLabelEntries[this.referrer],
+ i = 0,
+ len = scriptList.length;
+
+ for (; i < len; i++) {
+
+ if (scriptList[i].fileUrl === this.url &&
+ scriptList[i].free === true) {
+
+ console.debug(this.url, "is free and dynamic!");
+
+ var scriptObj = {
+ inline: false,
+ url: this.url,
+ contents: this.url,
+ reason: "This script is free (see JS Web Labels page for detail)"
+ };
+
+ acceptedScripts.addAScript(
+ this.req.referrer.spec, scriptObj, "Script is free");
+
+ return true;
+
+ }
+
+ }
+ }
+ },
+
+ processJsCallback: function(checker) {
+ try {
+ var scriptObj;
+
+ var jsCheckString = checker.parseTree.freeTrivialCheck;
+ console.debug("analyzing js callback for", this.url);
+ // for testing only.
+ //var jsCheckString = {'type': checkTypes.FREE_SINGLE_ITEM };
+ console.debug('jscheckstring is', jsCheckString.type);
+
+ if (jsCheckString.type === checkTypes.NONTRIVIAL) {
+ if (!allowedRef.urlInAllowedReferrers(this.req.referrer.spec)) {
+ //if (true) {
+ console.debug(
+ "url",
+ this.url,
+ " is found nontrivial",
+ "with reason",
+ jsCheckString.reason);
+ scriptObj = {
+ inline: false,
+ contents: '',
+ removalReason: 'nontrivial',
+ reason: jsCheckString.reason,
+ url: this.url,
+ hash: checker.hash
+ };
+ removedScripts.addAScript(this.req.referrer.spec, scriptObj);
+
+ // modify data that will be sent to the browser.
+ this.data = '// LibreJS: Script contents were removed when it was loaded from a page, because another script attempted to load this one dynamically and its contents appear to be nonfree/nontrivial. Please hit enter in the location bar to see the actual source.';
+ } else {
+ console.debug("writing to dry run", this.url);
+ scriptObj = {
+ inline:false,
+ contents: '',
+ removalReason: 'nontrivial',
+ reason: jsCheckString.reason,
+ url: this.url,
+ hash:checker.hash
+ };
+ dryRunScripts.addAScript(this.req.referrer.spec, scriptObj);
+ }
+
+ this.jsListenerCallback();
+
+ } else if (jsCheckString.type === checkTypes.FREE ||
+ jsCheckString.type === checkTypes.FREE_SINGLE_ITEM ||
+ jsCheckString.type === checkTypes.TRIVIAL ||
+ jsCheckString.type === checkTypes.TRIVIAL_DEFINES_FUNCTION ||
+ jsCheckString.type === checkTypes.WHITELISTED) {
+ console.debug(
+ "found a free script for",
+ this.url,
+ this.req.referrer.spec,
+ jsCheckString.reason);
+ console.debug('found a free script', this.req.referrer.spec);
+
+ scriptObj = {inline: false,
+ contents: '',
+ reason: jsCheckString.reason,
+ url: this.url,
+ hash:checker.hash};
+
+ acceptedScripts.addAScript(this.req.referrer.spec, scriptObj);
+ this.jsListenerCallback();
+ }
+
+ //var end = Date.now();
+ console.debug('exec time', this.url, ' -- ', end - start);
+ } catch (x) {
+ console.debug('error', x);
+ }
+ },
+
+ /**
+ * ProcessAllTypes
+ * Calls processHTML or JS if it finds an appropriate content
+ * type. For everything else it just passes on the data to the
+ * original listener.
+ */
+ processAllTypes: function() {
+ // toggle xlibrejs if X-LibreJS is set.
+
+ // process HTML
+ if ((htmlMimeTypeRe.test(this.contentType) ||
+ this.req.contentType === undefined)) {
+ this.processHTML();
+ return;
+ }
+
+ else {
+ // process external JS files that are called from another
+ // file (and hence have a referrer).
+
+ if (this.referrer != undefined &&
+ jsMimeTypeRe.test(this.contentType) &&
+ !(acceptedScripts.isFound(this.referrer, {
+ inline: false, contents: this.url})) &&
+ !(acceptedScripts.isFound(this.referrer, {
+ inline:false, contents:this.req.originalURI.spec}))) {
+
+ // console.debug('process js triggered for', this.url);
+ this.processJS();
+
+ } else {
+ this.jsListenerCallback();
+ }
+
+ }
+
+ },
+
+ jsListenerCallback: function () {
+
+ var len = this.data.length;
+
+ this.genBinaryOutput();
+
+ this.storageStream.init(8192, len, null);
+ this.binaryOutputStream.setOutputStream(
+ this.storageStream.getOutputStream(0));
+ this.binaryOutputStream.writeBytes(this.data, len);
+
+ try {
+ this.listener.onDataAvailable(
+ this.req,
+ this.resInfo.context,
+ this.storageStream.newInputStream(0),
+ 0, len);
+ } catch (e) {
+ this.req.cancel(this.req.NS_BINDING_ABORTED);
+ }
+
+ this.listener.onStopRequest(
+ this.req,
+ this.resInfo.context,
+ this.resInfo.statusCode);
+
+ }
+
+
};
// creates an instance of processResponseObject.
exports.ProcessResponse = function (listener, resInfo) {
- console.debug('triggered');
- var procResponse = Object.create(processResponseObject);
- procResponse.init(listener, resInfo);
- return procResponse;
+ console.debug('triggered');
+ var procResponse = Object.create(processResponseObject);
+ procResponse.init(listener, resInfo);
+ return procResponse;
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/stream_loader.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/stream_loader.js
index bd27132..42187c8 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/stream_loader.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/http_observer/stream_loader.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 {Cc, Ci, Cu, Cm, Cr} = require("chrome");
@@ -25,7 +27,7 @@ var StreamLoader = function() {
this.loader = null;
this.listener = null;
this.originalListener = null;
-}
+};
StreamLoader.prototype.setOriginalListener = function(listener) {
this.originalListener = listener;
@@ -37,7 +39,7 @@ StreamLoader.prototype.init = function() {
this.listener = new StreamListener();
this.listener.callback = function (loader, context, status, data) {
- console.debug("here is the data", data);
+ //console.debug("here is the data", data);
var responseInfo = {'request': loader.channel,
'context': context,
'statusCode': status,
@@ -89,8 +91,9 @@ StreamListener.prototype.onStreamComplete = function onStreamComplete(
StreamListener.prototype.onDetermineCharset = function onDetermineCharset(
loader, context, data) {
var match, regex;
- if (loader.channel.contentCharset != undefined &&
- loader.channel.contentCharset != "") {
+ if (loader.channel.contentCharset !== undefined &&
+ loader.channel.contentCharset !== ""
+ ) {
return loader.channel.contentCharset;
} else {
match = getRegexForContentType(loader.channel.contentType).exec(data);
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js
index 1a3b2a9..a2da0da 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/constant_types.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 debug = require("debug/debug");
@@ -140,49 +142,49 @@ var checkTypes = {
exports.checkTypes = checkTypes;
-exports.emptyTypeObj = function () {
+exports.emptyTypeObj = function() {
return {
'type': null,
'reason': null
};
};
-exports.nontrivialWithComment = function (comment) {
+exports.nontrivialWithComment = function(comment) {
return {
'type': checkTypes.NONTRIVIAL,
'reason': comment
};
};
-exports.trivialWithComment = function (comment) {
+exports.trivialWithComment = function(comment) {
return {
'type': checkTypes.TRIVIAL,
'reason': comment
};
};
-exports.trivialFuncWithComment = function (comment) {
+exports.trivialFuncWithComment = function(comment) {
return {
'type': checkTypes.TRIVIAL_DEFINES_FUNCTION,
'reason': comment
};
};
-exports.freeWithComment = function (comment) {
+exports.freeWithComment = function(comment) {
return {
'type': checkTypes.FREE,
'reason': comment
};
};
-exports.singleFreeWithComment = function (comment) {
+exports.singleFreeWithComment = function(comment) {
return {
'type': checkTypes.FREE_SINGLE_ITEM,
'reason': comment
};
};
-exports.whitelisted = function (comment) {
+exports.whitelisted = function(comment) {
return {
'type': checkTypes.WHITELISTED,
'reason': comment + ' -- whitelisted by user'
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js
index f5690f2..71a262e 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/free_checker.js
@@ -2,24 +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 licenses = require('js_checker/license_definitions');
var simpleStorage = require("sdk/simple-storage");
const LAZY = licenses.types.LAZY;
@@ -35,193 +35,199 @@ var licStartLicEndRe = /@licstartThefollowingistheentirelicensenoticefortheJavaS
var licenseMagnet = /.*@license ?(magnet\:\?xt=urn\:btih\:[0-9A-Za-z]+).*/;
var licenseEndMagnet = /.*@license-end.*/i;
exports.freeCheck = {
- initLicenses: function (licenses) {
- for (var item in licenses) {
- this.stripLicenseToRegexp(licenses[item]);
- }
- },
-
- /**
- * stripLicenseToRegexp
- *
- * Removes all non-alphanumeric characters except for the
- * special tokens, and replace the text values that are
- * hardcoded in license_definitions.js
- *
- */
- stripLicenseToRegexp: function (license) {
- var i = 0,
- max = license.licenseFragments.length,
- item;
-
- for (; i < max; i++) {
- item = license.licenseFragments[i];
- item.regex = patternUtils.removeNonalpha(item.text);
-
- if (license.licenseFragments[i].type === LAZY) {
-
- // do not permit words before. Since "Not" could be added
- // and make it nonfree. e.g.: Not licensed under the GPLv3.
- item.regex = '^(?!.*not).*' + item.regex;
-
- }
-
- item.regex = new RegExp(patternUtils.replaceTokens(item.regex), 'i');
- }
-
- return license;
- },
-
- /**
- * checkNodeFreeLicense
- *
- * Check if the node mentions a free license
- * in one of its comments.
- *
- */
- checkNodeFreeLicense: function (n, queue) {
- var strippedComment,
- magnetLink,
- comment = this.getComment(n),
- list = licenses.licenses,
- i, j,
- max,
- regex,
- frag,
- matchLicStart,
- matchMagnet,
- license,
- isMagnetValid = false;
-
- if (n.counter === 2 &&
- n.parent != undefined &&
- n.parent.type === token.SCRIPT &&
- comment != undefined &&
- comment != " ") {
- strippedComment = patternUtils.removeNonalpha(comment);
- matchLicStart = strippedComment.match(licStartLicEndRe);
- console.debug("matchMagnet is", matchMagnet);
- if (matchLicStart) {
- strippedComment = matchLicStart[1];
- for (license in list) {
- frag = list[license].licenseFragments;
- max = list[license].licenseFragments.length;
- for (i = 0;i < max; i++) {
- if (frag[i].regex.test(strippedComment)) {
- return {licenseName: list[license].licenseName,
- type: types.checkTypes.FREE} ;
-
- }
- }
- }
- }
- return this.matchMagnet(comment, queue); /// check for @license -- @license-end notation.
- }
-
- },
-
- /**
- * matchMagnet
- * Attempts to find valid @license [magnet]
- * and @license-end notation.
- */
- matchMagnet: function (comment, queue) {
- let matchMagnet = comment.match(licenseMagnet);
- if (matchMagnet) {
- let magnetLinkRe = new RegExp(matchMagnet[1].replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
- let list = licenses.licenses;
- let queue_end = queue.length;
-
- for (var license in list) {
- frag = list[license].canonicalUrl;
- console.debug("frag is ", frag);
- if (frag != undefined) {
- max = list[license].canonicalUrl.length;
- console.debug("max is", max);
- for (i = 0;i < max; i++) {
- console.debug("current frag is", frag[i]);
- if (frag[i].match(magnetLinkRe)) {
- for (let i = 0; i < queue_end; i++) {
- console.debug(queue[i]);
- let n = queue[i];
- comment = this.getComment(n);
- if (comment != undefined &&
- comment.match(licenseEndMagnet) &&
- this.checkIsLastNode(n)) {
- // found a closing match. Just accept this script.
- return {licenseName: list[license].licenseName,
- type: types.checkTypes.FREE_SINGLE_ITEM};
+ initLicenses: function (licenses) {
+ for (var item in licenses) {
+ this.stripLicenseToRegexp(licenses[item]);
+ }
+ },
+
+ /**
+ * stripLicenseToRegexp
+ *
+ * Removes all non-alphanumeric characters except for the
+ * special tokens, and replace the text values that are
+ * hardcoded in license_definitions.js
+ *
+ */
+ stripLicenseToRegexp: function (license) {
+ var i = 0,
+ max = license.licenseFragments.length,
+ item;
+
+ for (; i < max; i++) {
+ item = license.licenseFragments[i];
+ item.regex = patternUtils.removeNonalpha(item.text);
+
+ if (license.licenseFragments[i].type === LAZY) {
+
+ // do not permit words before. Since "Not" could be added
+ // and make it nonfree. e.g.: Not licensed under the GPLv3.
+ item.regex = '^(?!.*not).*' + item.regex;
+
+ }
+
+ item.regex = new RegExp(
+ patternUtils.replaceTokens(item.regex), 'i');
+ }
+
+ return license;
+ },
+
+ /**
+ * checkNodeFreeLicense
+ *
+ * Check if the node mentions a free license
+ * in one of its comments.
+ *
+ */
+ checkNodeFreeLicense: function (n, queue) {
+ var strippedComment,
+ magnetLink,
+ comment = this.getComment(n),
+ list = licenses.licenses,
+ i, j,
+ max,
+ regex,
+ frag,
+ matchLicStart,
+ matchMagnet,
+ license,
+ isMagnetValid = false;
+
+ if (n.counter === 2 &&
+ n.parent != undefined &&
+ n.parent.type === token.SCRIPT &&
+ comment != undefined &&
+ comment != " "
+ ) {
+ strippedComment = patternUtils.removeNonalpha(comment);
+ matchLicStart = strippedComment.match(licStartLicEndRe);
+ console.debug("matchMagnet is", matchMagnet);
+ if (matchLicStart) {
+ strippedComment = matchLicStart[1];
+ for (license in list) {
+ frag = list[license].licenseFragments;
+ max = list[license].licenseFragments.length;
+ for (i = 0; i < max; i++) {
+ if (frag[i].regex.test(strippedComment)) {
+ return {
+ licenseName: list[license].licenseName,
+ type: types.checkTypes.FREE
+ };
+
+ }
+ }
+ }
+ }
+ // check for @license -- @license-end notation.
+ return this.matchMagnet(comment, queue);
+ }
+ },
+
+ /**
+ * matchMagnet
+ * Attempts to find valid @license [magnet]
+ * and @license-end notation.
+ */
+ matchMagnet: function (comment, queue) {
+ let matchMagnet = comment.match(licenseMagnet);
+ if (matchMagnet) {
+ let magnetLinkRe = new RegExp(
+ matchMagnet[1].replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
+ );
+ let list = licenses.licenses;
+ let queue_end = queue.length;
+
+ for (var license in list) {
+ frag = list[license].canonicalUrl;
+ console.debug("frag is ", frag);
+ if (frag != undefined) {
+ max = list[license].canonicalUrl.length;
+ console.debug("max is", max);
+ for (i = 0;i < max; i++) {
+ console.debug("current frag is", frag[i]);
+ if (frag[i].match(magnetLinkRe)) {
+ for (let i = 0; i < queue_end; i++) {
+ console.debug(queue[i]);
+ let n = queue[i];
+ comment = this.getComment(n);
+ if (comment != undefined &&
+ comment.match(licenseEndMagnet) &&
+ this.checkIsLastNode(n)
+ ) {
+ // found a closing match. Just accept this script.
+ return {
+ licenseName: list[license].licenseName,
+ type: types.checkTypes.FREE_SINGLE_ITEM
+ };
+ }
+ }
+ }
+ }
}
- }
}
- }
- }
- }
- }
- return;
- },
-
- /**
- * checkIsLastJsNode.
- * returns true if n is the last node.
- * Or if nodes before it are only comments etc (not valid code.)
- * A special LibreJS node is appended at the end of a script tree to
- * check if this is the last (and also for narcissus to keep the last comment
- * in the tree.)
- * TODO: Refactor LibreJS so that END nodes can have a comment.
- */
- checkIsLastNode: function (n) {
- // first check if the comment is part of the very last statement.
- if (n.value == "this" && n.next == undefined) {
- // just make sure the last node is indeed our harmless bit of
- // js.
- if (n.tokenizer) {
- let source = n.tokenizer.source;
- let substring = source.substr(n.start, n.end+23);
- if (substring == END_OF_SCRIPT) {
- return true;
}
- else {
- console.debug("substring is ", substring);
- return false;
+ return;
+ },
+
+ /**
+ * checkIsLastJsNode.
+ * returns true if n is the last node.
+ * Or if nodes before it are only comments etc (not valid code.)
+ * A special LibreJS node is appended at the end of a script tree to
+ * check if this is the last (and also for narcissus to keep the last comment
+ * in the tree.)
+ * TODO: Refactor LibreJS so that END nodes can have a comment.
+ */
+ checkIsLastNode: function (n) {
+ // first check if the comment is part of the very last statement.
+ if (n.value == "this" && n.next == undefined) {
+ // just make sure the last node is indeed our harmless bit of
+ // js.
+ if (n.tokenizer) {
+ let source = n.tokenizer.source;
+ let substring = source.substr(n.start, n.end+23);
+ if (substring == END_OF_SCRIPT) {
+ return true;
+ }
+ else {
+ console.debug("substring is ", substring);
+ return false;
+ }
+ }
+ console.debug("Hurra! This is the end of our script");
+ return true;
}
- }
- console.debug("Hurra! This is the end of our script");
- return true;
- }
- // isn't our last node.
- return false;
- },
-
- /**
- * getComment
- *
- * Grab the comment(s) from the node. Concatenates
- * multiple comments.
- *
- */
- getComment: function (n) {
-
- var i = 0, length, comment = "";
-
- if (n.blockComments == undefined || n.blockComments == " ") {
- return;
- }
-
- length = n.blockComments.length;
- if (length > 0) {
- for (; i < length; i++) {
- comment += n.blockComments[i];
- }
- }
- if (comment == "") {
- return;
- }
- return comment;
-
- }
-
+ // isn't our last node.
+ return false;
+ },
+
+ /**
+ * getComment
+ *
+ * Grab the comment(s) from the node. Concatenates
+ * multiple comments.
+ *
+ */
+ getComment: function (n) {
+ var i = 0, length, comment = "";
+
+ if (n.blockComments == undefined || n.blockComments == " ") {
+ return;
+ }
+
+ length = n.blockComments.length;
+ if (length > 0) {
+ for (; i < length; i++) {
+ comment += n.blockComments[i];
+ }
+ }
+ if (comment == "") {
+ return;
+ }
+ return comment;
+ }
};
exports.freeCheck.initLicenses(licenses.licenses);
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js
index a96eea7..3b03084 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/js_checker.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 {Cc, Ci, Cu, Cm, Cr} = require("chrome");
-const narcissusWorker = require("narcissus_parser/narcissus_worker");
+var narcissusWorker = require("parser/narcissus_worker")
+ .narcissusWorker;
const nonTrivialModule = require("js_checker/nontrivial_checker");
const freeChecker = require("js_checker/free_checker");
@@ -40,33 +43,25 @@ const timer = require("sdk/timers");
var callbackMap = {};
/**
- * This module needs to be updated so that it is asynchronous
- * and to reduce CPU usage --
- *
- * Partly already done in:
- * https://gitorious.org/librejs/librejs/blobs/async/lib/js_checker/js_checker.js
- * data/complain/contact_finder.js on how to proceed.
- *
- */
-/**
*
* Pairs a hash with a given callback
* method from an object.
*
*/
var setHashCallback = function(hash, callback, notification) {
- console.debug("hash is now ", hash);
+ console.debug('setHashCallback', hash);
if (hash in callbackMap && isDryRun()) {
- // work around for issue with dryrun after
- // checking box.
+ // workaround for issue with dryrun after checking box.
// do nothing.
callbackMap[hash] = callback;
- }
- else if (hash in callbackMap) {
- // console.debug("callback", callbackMap[hash]);
- notification.close();
+ } else if (hash in callbackMap) {
+ console.debug("callback", callbackMap[hash]);
+ if (notification && typeof notification.close === 'function') {
+ notification.close();
+ }
throw Error("already being checked.");
} else {
+ console.debug('setting callbackMap for', hash, 'to', callback);
callbackMap[hash] = callback;
}
console.debug("callback is type: ", callback.constructor);
@@ -84,19 +79,22 @@ var removeHashCallback = function(hash) {
*
*/
exports.callbackHashResult = function(hash, result) {
+ console.debug('typeof callbackMap function:', typeof callbackMap[hash]);
+ console.debug('for hash', hash);
try {
callbackMap[hash](result, hash);
} catch (x) {
console.debug('error in jsChecker', x, 'hash:', hash);
// return tree as false.
console.debug("Error with", x);
- if (typeof callbackMap[hash] == 'function') {
+ if (typeof callbackMap[hash] === 'function') {
callbackMap[hash](false, hash);
} else {
console.debug('callbackHashResult Error', x);
}
}
// remove callback after it's been called.
+ console.debug('JsChecker.callbackHashResult: calling removeHashCallback');
removeHashCallback(hash);
};
@@ -127,6 +125,7 @@ var JsChecker = function() {
JsChecker.prototype.searchJs = function(jsCode, resultReady, url) {
var that = this;
var bugfix = require('html_script_finder/bug_fix').narcissusBugFixLibreJS;
+ console.debug('JsChecker.searchJs for script url:', url);
this.url = url;
this.resultReady = resultReady;
this.jsCode = jsCode;
@@ -141,7 +140,8 @@ JsChecker.prototype.searchJs = function(jsCode, resultReady, url) {
console.debug("We have it cached indeed!");
// there is an existing entry for this exact copy
// of script text.
- console.debug('this script result is cached', this.hash, isCached.result.type);
+ console.debug('this script result is cached', this.hash,
+ isCached.result.type);
console.debug("Return right away");
// we are not generating a parse tree.
this.parseTree = {};
@@ -155,21 +155,27 @@ JsChecker.prototype.searchJs = function(jsCode, resultReady, url) {
return;
}
+ console.debug('url is not cached:', url);
+
try {
// no cache, continue.
this.relationChecker = relationChecker.relationChecker();
this.freeToken = types.emptyTypeObj();
this.nontrivialness = types.emptyTypeObj();
- // use this.hash to keep track of comments made by the nontrivial checker code
- // about why/how the code is found to be nontrivial.
- this.nonTrivialChecker = nonTrivialModule.nonTrivialChecker(this.hash);
+ // use this.hash to keep track of comments made by the nontrivial
+ // checker code about why/how the code is found to be nontrivial.
+ this.nonTrivialChecker =
+ nonTrivialModule.nonTrivialChecker(this.hash);
// register callback and hash. So that result
// can be passed.
- setHashCallback(this.hash, this.handleTree.bind(this), this.notification);
+ setHashCallback(
+ this.hash, this.handleTree.bind(this), this.notification);
// parse using ChromeWorker.
+ console.debug(
+ 'JsChecker.searchJs(): starting narcissusWorker.parse()');
narcissusWorker.parse(this.jsCode, this.hash);
} catch (x) {
console.debug('error', x);
@@ -185,7 +191,7 @@ JsChecker.prototype.handleTree = function(tree, errorMessage) {
// error parsing tree. Just return nonfree nontrivial.
this.parseTree = {};
this.parseTree.freeTrivialCheck = types.nontrivialWithComment(
- 'error parsing: ' + errorMessage);
+ 'error parsing: ' + errorMessage);
// cache result with hash of script for future checks.
scriptsCached.addEntry(this.jsCode, this.parseTree.freeTrivialCheck,
@@ -195,7 +201,7 @@ JsChecker.prototype.handleTree = function(tree, errorMessage) {
try {
// no need to keep parseTree in property
this.parseTree = {}; //tree;
- console.debug(tree);
+ //console.debug(tree);
this.walkTree(tree);
} catch (x) {
console.debug(x, x.lineNumber, x.fileName);
@@ -304,20 +310,21 @@ JsChecker.prototype.walkTree = function(node) {
len = n.children.length;
for (i = 0; i < len; i++) {
if (n.children[i] != undefined &&
- n.children[i].visited == undefined) {
- // figure out siblings.
- if (i > 0) {
- n.children[i].previous = n.children[i-1];
- }
-
- if (i < len) {
- n.children[i].next = n.children[i+1];
- }
- // set parent property.
- n.children[i].parent = n;
- n.children[i].visited = true;
- queue.push(n.children[i]);
- }
+ n.children[i].visited == undefined
+ ) {
+ // figure out siblings.
+ if (i > 0) {
+ n.children[i].previous = n.children[i-1];
+ }
+
+ if (i < len) {
+ n.children[i].next = n.children[i+1];
+ }
+ // set parent property.
+ n.children[i].parent = n;
+ n.children[i].visited = true;
+ queue.push(n.children[i]);
+ }
}
}
@@ -330,24 +337,25 @@ JsChecker.prototype.walkTree = function(node) {
n[item] != null &&
typeof n[item] === 'object' &&
n[item].type != undefined &&
- n[item].visited == undefined) {
- n[item].visited = true;
- // set parent property
- n[item].parent = n;
- queue.push(n[item]);
- }
+ n[item].visited == undefined
+ ) {
+ n[item].visited = true;
+ // set parent property
+ n[item].parent = n;
+ queue.push(n[item]);
+ }
}
}
that.checkNode(n);
if (that.freeToken.type === checkTypes.FREE ||
- that.freeToken.type === checkTypes.FREE_SINGLE_ITEM) {
- // nothing more to look for. We are done.
- that.walkTreeComplete(that.freeToken);
- return;
- }
- else if (that.nontrivialness.type === checkTypes.NONTRIVIAL) {
+ that.freeToken.type === checkTypes.FREE_SINGLE_ITEM
+ ) {
+ // nothing more to look for. We are done.
+ that.walkTreeComplete(that.freeToken);
+ return;
+ } else if (that.nontrivialness.type === checkTypes.NONTRIVIAL) {
// nontrivial
// we are done.
that.walkTreeComplete(that.nontrivialness);
@@ -473,8 +481,7 @@ JsChecker.prototype.checkNode = function(n) {
"Script appears to be free under the following license: " +
fc.licenseName);
return;
- }
- else if (fc && fc.type == checkTypes.FREE_SINGLE_ITEM) {
+ } else if (fc && fc.type == checkTypes.FREE_SINGLE_ITEM) {
console.debug("free single item");
this.freeToken = types.singleFreeWithComment(
"Script appears to be free under the following license: " +
@@ -487,9 +494,7 @@ JsChecker.prototype.checkNode = function(n) {
// nontrivial_global is deprecated
this.nontrivialness = tc;
return;
- }
-
- else if (tc.type === checkTypes.TRIVIAL_DEFINES_FUNCTION) {
+ } else if (tc.type === checkTypes.TRIVIAL_DEFINES_FUNCTION) {
this.nontrivialness = tc;
return;
}
@@ -497,15 +502,17 @@ JsChecker.prototype.checkNode = function(n) {
};
JsChecker.prototype.removeNotification = function() {
- if (this.notification && this.notification.close) {
- console.debug("removing", this.shortText);
+ console.debug('JsChecker.removeNotification()');
+ if (this.notification &&
+ typeof this.notification.close === 'function'
+ ) {
+ console.debug('removing', this.shortText);
// remove notification early on.
this.notification.close();
this.notification = null;
}
};
-// create an instance of JsChecker
exports.jsChecker = function() {
return new JsChecker();
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js
index 36711fd..41cfb7b 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/license_definitions.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.types = {
SHORT: 'short',
@@ -32,8 +34,10 @@ var type = exports.types;
exports.licenses = {
CC0: {
licenseName: 'Creative Commons CC0 1.0 Universal',
- canonicalUrl: ['http://creativecommons.org/publicdomain/zero/1.0/legalcode',
- 'magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt'],
+ canonicalUrl: [
+ 'http://creativecommons.org/publicdomain/zero/1.0/legalcode',
+ 'magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt'
+ ],
identifier: 'CC0-1.0',
licenseFragments: []
},
@@ -41,8 +45,10 @@ exports.licenses = {
gplv2: {
licenseName: 'GNU General Public License (GPL) version 2',
- canonicalUrl: ['http://www.gnu.org/licenses/gpl-2.0.html',
- 'magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt'],
+ canonicalUrl: [
+ 'http://www.gnu.org/licenses/gpl-2.0.html',
+ 'magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt'
+ ],
identifier: 'GNU-GPL-2.0',
licenseFragments: [{text: "<THISPROGRAM> 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 2 of the License, or (at your option) any later version.", type: type.SHORT},
{text:"Alternatively, the contents of this file may be used under the terms of either the GNU General Public License Version 2 or later (the \"GPL\"), or the GNU Lesser General Public License Version 2.1 or later (the \"LGPL\"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL.", type: type.SHORT}]
@@ -50,8 +56,10 @@ exports.licenses = {
gplv3: {
licenseName: 'GNU General Public License (GPL) version 3',
- canonicalUrl: ['http://www.gnu.org/licenses/gpl-3.0.html',
- 'magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt'],
+ canonicalUrl: [
+ 'http://www.gnu.org/licenses/gpl-3.0.html',
+ 'magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt'
+ ],
identifier: 'GNU-GPL-3.0',
licenseFragments: [
{text: "The JavaScript code in this page is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License (GNU GPL) as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The code is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. As additional permission under GNU GPL version 3 section 7, you may distribute non-source (e.g., minimized or compacted) forms of that code without the copy of the GNU GPL normally required by section 4, provided you include this license notice and a URL through which recipients can access the Corresponding Source.", type: type.SHORT},
@@ -65,94 +73,137 @@ exports.licenses = {
apache_2License: {
licenseName: 'Apache License, Version 2.0',
- canonicalUrl: ['http://www.apache.org/licenses/LICENSE-2.0',
- 'magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt'],
+ canonicalUrl: [
+ 'http://www.apache.org/licenses/LICENSE-2.0',
+ 'magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt'
+ ],
identifier: 'Apache-2.0',
licenseFragments: [{text: "Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0", type: type.SHORT}]
},
lgpl21: {
licenseName: 'GNU Lesser General Public License, version 2.1',
- canonicalUrl: ['http://www.gnu.org/licenses/lgpl-2.1.html',
- 'magnet:?xt=urn:btih:5de60da917303dbfad4f93fb1b985ced5a89eac2&dn=lgpl-2.1.txt'],
+ canonicalUrl: [
+ 'http://www.gnu.org/licenses/lgpl-2.1.html',
+ 'magnet:?xt=urn:btih:5de60da917303dbfad4f93fb1b985ced5a89eac2&dn=lgpl-2.1.txt'
+ ],
identifier: 'GNU-LGPL-2.1',
licenseFragments: [{text: "<THISLIBRARY> is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.", type: type.SHORT}]
},
lgplv3: {
licenseName: 'GNU Lesser General Public License, version 3',
- canonicalUrl: ['http://www.gnu.org/licenses/lgpl-3.0.html',
- 'magnet:?xt=urn:btih:0ef1b8170b3b615170ff270def6427c317705f85&dn=lgpl-3.0.txt'],
+ canonicalUrl: [
+ 'http://www.gnu.org/licenses/lgpl-3.0.html',
+ 'magnet:?xt=urn:btih:0ef1b8170b3b615170ff270def6427c317705f85&dn=lgpl-3.0.txt'
+ ],
identifier: 'GNU-LGPL-3.0',
licenseFragments: [{text: "<THISPROGRAM> is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.", type: type.SHORT}]
},
agplv3: {
licenseName: 'GNU AFFERO GENERAL PUBLIC LICENSE version 3',
- canonicalUrl: ['http://www.gnu.org/licenses/agpl-3.0.html',
- 'magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt'],
+ canonicalUrl: [
+ 'http://www.gnu.org/licenses/agpl-3.0.html',
+ 'magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt'
+ ],
identifier: 'GNU-AGPL-3.0',
licenseFragments: [{text: "<THISPROGRAM> is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.", type: type.SHORT}]
},
boostSoftware: {
licenseName: 'Boost Software License',
- canonicalUrl: ["magnet:?xt=urn:btih:89a97c535628232f2f3888c2b7b8ffd4c078cec0&dn=Boost-1.0.txt"],
+ canonicalUrl: [
+ 'http://www.boost.org/LICENSE_1_0.txt',
+ 'magnet:?xt=urn:btih:89a97c535628232f2f3888c2b7b8ffd4c078cec0&dn=Boost-1.0.txt'
+ ],
licenseFragments: [{text: "Boost Software License <VERSION> <DATE> Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the \"Software\") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following", type: type.SHORT}]
},
bsd3: {
- licenseName: "The BSD 3-Clause License",
- canonicalUrl: ["magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt"],
+ licenseName: "BSD 3-Clause License",
+ canonicalUrl: [
+ 'http://opensource.org/licenses/BSD-3-Clause',
+ 'magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt'
+ ],
licenseFragments: [{text: "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.", type: type.SHORT}]
},
bsd2: {
- licenseName: "The BSD 2-Clause License",
+ licenseName: "BSD 2-Clause License",
licenseFragments: [{text: "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.", type: type.SHORT}]
},
+ epl_1_0: {
+ licenseName: "Eclipse Public License Version 1.0",
+ identifier: "EPL-1.0",
+ canonicalUrl: [
+ "http://www.eclipse.org/legal/epl-v10.html",
+ "magnet:?xt=urn:btih:4c6a2ad0018cd461e9b0fc44e1b340d2c1828b22&dn=epl-1.0.txt"
+ ],
+ licenseFragments: [
+ {
+ text: "THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE (\"AGREEMENT\"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.",
+ type: type.SHORT
+ }
+ ]
+ },
+
mozillaPublicLicense_2_0: {
licenseName: 'Mozilla Public License Version 2.0',
identifier: 'MPL-2.0',
- canonicalUrl: ['http://www.mozilla.org/MPL/2.0',
- 'magnet:?xt=urn:btih:3877d6d54b3accd4bc32f8a48bf32ebc0901502a&dn=mpl-2.0.txt'],
+ canonicalUrl: [
+ 'http://www.mozilla.org/MPL/2.0',
+ 'magnet:?xt=urn:btih:3877d6d54b3accd4bc32f8a48bf32ebc0901502a&dn=mpl-2.0.txt'
+ ],
licenseFragments: [{text: "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.", type: type.SHORT }]
},
expat: {
licenseName: 'Expat License (sometimes called MIT Licensed)',
identifier: 'Expat',
- canonicalUrl: ['http://www.jclark.com/xml/copying.txt',
- 'magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt'],
+ canonicalUrl: [
+ 'http://www.jclark.com/xml/copying.txt',
+ 'magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt'
+ ],
licenseFragments: [{text: "Copyright <YEAR> <NAME> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.", type: type.SHORT}]
},
X11: {
licenseName: 'X11 License',
- canonicalUrl: ['magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt'],
+ canonicalUrl: [
+ 'magnet:?xt=urn:btih:5305d91886084f776adcf57509a648432709a7c7&dn=x11.txt'
+ ],
licenseFragments: [{text: "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.", type: type.SHORT}]
},
XFree86: {
licenseName: "XFree86 License",
identifier: 'Modified-BSD',
- canonicalUrl: ['http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3', 'http://www.xfree86.org/current/LICENSE4.html', 'magnet:?xt=urn:btih:12f2ec9e8de2a3b0002a33d518d6010cc8ab2ae9&dn=xfree86.txt'],
+ canonicalUrl: [
+ 'http://www.xfree86.org/3.3.6/COPYRIGHT2.html#3',
+ 'http://www.xfree86.org/current/LICENSE4.html',
+ 'magnet:?xt=urn:btih:12f2ec9e8de2a3b0002a33d518d6010cc8ab2ae9&dn=xfree86.txt'
+ ],
licenseFragments: [{text: "All rights reserved.\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution, and in the same place and form as other copyright, license and disclaimer information.\n3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: \"This product includes software developed by The XFree86 Project, Inc (http://www.xfree86.org/) and its contributors\", in the same place and form as other third-party acknowledgments. Alternately, this acknowledgment may appear in the software itself, in the same form and location as other such third-party acknowledgments.4. Except as contained in this notice, the name of The XFree86 Project, Inc shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The XFree86 Project, Inc.", type: type.SHORT}
]
},
FreeBSD: {
licenseName: "FreeBSD License",
- canonicalUrl: ['http://www.freebsd.org/copyright/freebsd-license.html',
- 'magnet:?xt=urn:btih:87f119ba0b429ba17a44b4bffcab33165ebdacc0&dn=freebsd.txt'],
+ canonicalUrl: [
+ 'http://www.freebsd.org/copyright/freebsd-license.html',
+ 'magnet:?xt=urn:btih:87f119ba0b429ba17a44b4bffcab33165ebdacc0&dn=freebsd.txt'
+ ],
licenseFragments: [{text: "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\nRedistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\nRedistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.", type: type.SHORT}]
},
ISC: {
licenseName: "The ISC License",
- canonicalUrl: ['https://www.isc.org/downloads/software-support-policy/isc-license/',
- 'magnet:?xt=urn:btih:b8999bbaf509c08d127678643c515b9ab0836bae&dn=ISC.txt'],
+ canonicalUrl: [
+ 'https://www.isc.org/downloads/software-support-policy/isc-license/',
+ 'magnet:?xt=urn:btih:b8999bbaf509c08d127678643c515b9ab0836bae&dn=ISC.txt'
+ ],
licenseFragments: [{text: "Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.", type: type.SHORT},
{text: "Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.", type: type.SHORT}]
},
@@ -164,14 +215,18 @@ exports.licenses = {
ArtisticLicense2: {
licenseName: "Artistic License 2.0",
- canonicalUrl: ["http://www.perlfoundation.org/artistic_license_2_0",
- "magnet:?xt=urn:btih:54fd2283f9dbdf29466d2df1a98bf8f65cafe314&dn=artistic-2.0.txt"],
+ canonicalUrl: [
+ "http://www.perlfoundation.org/artistic_license_2_0",
+ "magnet:?xt=urn:btih:54fd2283f9dbdf29466d2df1a98bf8f65cafe314&dn=artistic-2.0.txt"
+ ],
licenseFragments: []
},
PublicDomain: {
licenseName: "Public Domain",
- canonicalUrl: ['magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt'],
+ canonicalUrl: [
+ 'magnet:?xt=urn:btih:e95b018ef3580986a04669f1b5879592219e2a7a&dn=public-domain.txt'
+ ],
licenseFragments: []
},
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js
index 0f7332a..6a22992 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_checker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/nontrivial_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/>.
*/
const types = require("js_checker/constant_types");
@@ -27,363 +29,348 @@ const token = types.token;
var checkTypes = types.checkTypes;
var utils = {
+ /**
+ * nodeContains
+ * Checks that node contains both a type and a value.
+ * Shortcut to check for null/undefined.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if matching.
+ */
+ nodeContains: function (n, type, value) {
+ if (n != undefined) {
+ return n.type === type &&
+ n.value === value;
+ }
+ },
+
+ /**
+ * isType
+ * Checks that node is of a certain type.
+ * Shortcut to check for null/undefined.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean}. True if it's the right type.
+ */
+ isType: function (n, type) {
+ return n != undefined && n.type === type;
+ },
+
+ isNotType: function (n, type) {
+ return n != undefined && n.type !== type;
+ },
+
+ /**
+ * hasChildren
+ *
+ * Checks the token on the left
+ * and on the right.
+ *
+ * @param {object} n. The current node being studied.
+ * @param {leftType} token constant. The type on the
+ * left.
+ * @param {rightType} token constant. The type of child
+ * on the right
+ *
+ */
+ hasChildren: function (n, leftType, rightType) {
+ if (types == undefined) {
+ return false;
+ }
+ return this.isType(n.children[0], leftType) &&
+ this.isType(n.children[1], rightType);
+ },
+
+ /**
+ * findScriptTag
+ *
+ * This method should probably be replaced with DOM testing
+ * as regex is rather insufficiant, and this wouldn't cover
+ * tricky constructs as shown in http://ha.ckers.org/xss.html.
+ */
+ findScriptTag: function (n) {
+ return n.value != undefined &&
+ /<script[^>]*?>/i.test(n.value);
+ }
+};
- /**
- * nodeContains
- * Checks that node contains both a type and a value.
- * Shortcut to check for null/undefined.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if matching.
- */
- nodeContains: function (n, type, value) {
- if (n != undefined) {
- return n.type === type &&
- n.value === value;
- }
- },
-
-
- /**
- * isType
- * Checks that node is of a certain type.
- * Shortcut to check for null/undefined.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean}. True if it's the right type.
- */
- isType: function (n, type) {
- return n != undefined && n.type === type;
- },
-
- isNotType: function (n, type) {
- return n != undefined && n.type !== type;
- },
-
-
- /**
- * hasChildren
- *
- * Checks the token on the left
- * and on the right.
- *
- * @param {object} n. The current node being studied.
- * @param {leftType} token constant. The type on the
- * left.
- * @param {rightType} token constant. The type of child
- * on the right
- *
- */
- hasChildren: function (n, leftType, rightType) {
- if (types == undefined) {
- return false;
- }
- return this.isType(n.children[0], leftType) &&
- this.isType(n.children[1], rightType);
- },
-
-
- /**
- * findScriptTag
- *
- * This method should probably be replaced with DOM testing
- * as regex is rather insufficiant, and this wouldn't cover
- * tricky constructs as shown in http://ha.ckers.org/xss.html.
- */
- findScriptTag: function (n) {
- return n.value != undefined &&
- /<script[^>]*?>/i.test(n.value);
- }
+var NonTrivialChecker = function() {
+ this.definesFunction = false;
+ this.hash = null;
+};
+/**
+ * definesFunctionFound
+ *
+ * Returns true if it finds a node of type FUNCTION
+ * that isn't a callback or an IIFE.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ */
+NonTrivialChecker.prototype.definesFunctionFound = function (n) {
+ var isFunction = false;
+ if (n.type === token.FUNCTION &&
+ n.body != undefined) {
+
+ if (n.functionForm !== token.DECLARED_FORM &&
+ ((n.parent.type === token.LIST &&
+ n.parent.parent.type === token.CALL) ||
+ n.parent.type === token.CALL) &&
+ n.name == undefined) {
+ // this is a callback or an immediately
+ // invoked function expression "IIFE".
+ isFunction = false;
+ } else {
+ // this is a regular function declaration or
+ // function expression assigned to a variable.
+ //console.log("THIS DEFINES FUNCTION");
+ isFunction = true;
+ }
+ }
+
+ // look for Function constructor.
+ if (n.type === token.IDENTIFIER &&
+ n.value === 'Function' &&
+ (n.parent.type === token.NEW_WITH_ARGS ||
+ n.parent.type === token.CALL)) {
+ // this is a Function constructor.
+ //console.log("THIS DEFINES FUNCTION");
+ isFunction = true;
+ }
+
+ return isFunction;
};
-var nonTrivialChecker = {
-
- definesFunction: false,
- hash: null,
- /**
- * definesFunctionFound
- *
- * Returns true if it finds a node of type FUNCTION
- * that isn't a callback or an IIFE.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- */
- definesFunctionFound: function (n) {
- var isFunction = false;
- if (n.type === token.FUNCTION &&
- n.body != undefined) {
-
- if (n.functionForm !== token.DECLARED_FORM &&
- ((n.parent.type === token.LIST &&
- n.parent.parent.type === token.CALL) ||
- n.parent.type === token.CALL) &&
- n.name == undefined) {
- // this is a callback or an immediately
- // invoked function expression "IIFE".
- isFunction = false;
- } else {
- // this is a regular function declaration or
- // function expression assigned to a variable.
- //console.log("THIS DEFINES FUNCTION");
- isFunction = true;
- }
-
- }
-
- // look for Function constructor.
- if (n.type === token.IDENTIFIER &&
- n.value === 'Function' &&
- (n.parent.type === token.NEW_WITH_ARGS ||
- n.parent.type === token.CALL)) {
- // this is a Function constructor.
- //console.log("THIS DEFINES FUNCTION");
- isFunction = true;
- }
-
- return isFunction;
- },
-
-
- /**
- * invokesEval
- *
- * Returns true (nontrivial) if it finds any use of
- * the eval function. For simplicity, we assume any
- * use of an identifier "eval" is the eval function.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- */
- invokesEval: function (n) {
- return (n.type === token.CALL &&
- utils.nodeContains(n.children[0], token.IDENTIFIER, 'eval') ||
- n.type === token.IDENTIFIER && n.value === 'eval');
- },
-
- /**
- * evalIdentifier
- *
- * Returns true (nontrivial) if it finds any use of
- * the eval function. For simplicity, we assume any
- * use of an identifier "eval" is the eval function.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- */
- evalIdentifier: function (n) {
- return n.type === token.IDENTIFIER &&
- n.value === 'eval';
- },
-
-
- /**
- * invokesMethodBracketSuffix
- *
- * Finds a method being invoked using the bracket suffix notation
- * rather than the dot notation. It is difficult without keeping track of
- * variable values to check for what method is actually being called.
- * So we're just flagging any use of this construct as nontrivial.
- * e.g., should catch: xhr[a+b]('GET', 'http://www.example.com');
- * Should not catch other uses such as: myArray[num];
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- */
- invokesMethodBracketSuffix: function (n) {
- return n.type === token.CALL && utils.isType(n.children[0], token.INDEX);
- },
-
-
- /**
- * createsXhrObject
- *
- * Creates an xhr object.
- * Since all "new XMLHttpRequest", "XMLHttpRequest()",
- * and "new window.XMLHttpRequest" instantiate the xhr object,
- * we assume (without further proof) that any use
- * of the identifier "XMLHttpRequest" and "ActiveXObject"
- * is an xhr object.
- * Constructs like window[a+b]() are already caught by the
- * bracket suffix check.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- */
- createsXhrObject: function (n) {
- return (n.type === token.IDENTIFIER) &&
- (n.value === 'XMLHttpRequest' ||
- n.value === 'ActiveXObject');
- },
-
-
- /**
- * invokesXhrOpen
- *
- * Here we assume the call of an open method must be an xhr request
- * (and not some other object) by checking the number of arguments.
- * In most cases this method won't be used since createsXhrObject
- * will already have caught the xhr.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- *
- */
- invokesXhrOpen: function (n) {
- return n.type === token.CALL &&
- utils.hasChildren(n, token.DOT, token.LIST) &&
- utils.isType(n.children[0].children[0], token.IDENTIFIER) &&
- utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'open') &&
- n.children[1].children.length > 1;
- },
-
-
- /**
- * createsScriptElement
- *
- * Checks for document.createElement() that create a script. In the case
- * it creates an element from a variable, we assume it's a script. In the
- * future we might want to check for the value of that string variable
- * (e.g., if a variable is assigned 'script', raise a flag)
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- *
- *
- */
- createsScriptElement: function (n) {
- return n.type === token.CALL &&
- utils.hasChildren(n, token.DOT, token.LIST) &&
- utils.isType(n.children[0].children[0], token.IDENTIFIER) &&
- utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'createElement') &&
- (utils.nodeContains(n.children[1].children[0], token.STRING, 'script') ||
- utils.isType(n.children[1].children[0], token.IDENTIFIER));
- },
-
-
- /**
- * writesScriptAsHtmlString
- *
- * catches myObj.write('<script></script>');
- * or any myObj.write(myStringVariable);
- * or concatenation such as:
- * myObj.write('<scri' + stringVariable);
- * or 'something' + 'somethingelse'.
- *
- * To check for javascript here we might want to look at the list
- * from ha.ckers.org/xss.html for the future.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- *
- */
- writesScriptAsHtmlString: function (n) {
- var listArg;
-
- if (n.type === token.CALL &&
- utils.hasChildren(n, token.DOT, token.LIST) &&
- utils.isType(n.children[0].children[0], token.IDENTIFIER) &&
- utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'write')) {
-
- if (utils.isNotType(n.children[1].children[0], token.STRING)) {
- // return true if any operation or concatenation.
- // We are cautious (as it could
- // embed a script) and flag this as nontrivial.
-
- return true;
- }
- return utils.findScriptTag(n.children[1].children[0]);
- } else {
- return false;
- }
- },
-
- /**
- * nontrivial anytime we see an identifier as innerHTML
- */
- innerHTMLIdentifier: function (n) {
- if ((n.type === token.IDENTIFIER ||
- n.type === token.STRING) &&
- n.value === 'innerHTML') {
- return true;
- }
- },
-
-
- /**
- * checkNontrivial
- *
- * Contains all the conditionals that try to identify,
- * step by step, all code that could be flagged as
- * nontrivial.
- *
- * @param {object} n. The current node being studied.
- * @return {boolean} . True if found.
- *
- */
- checkNontrivial: function (n, t) {
-
- if (n.type === token.IDENTIFIER && this.evalIdentifier(n)) {
- //console.log("NONTRIVIAL: eval has been found in code");
- return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code");
- }
-
- if (this.innerHTMLIdentifier(n)) {
- //console.log("NONTRIVIAL: innerHTML identifier");
- return types.nontrivialWithComment("NONTRIVIAL: innerHTML identifier");
- }
-
- // the node is an identifier
- if (n.type === token.IDENTIFIER && this.createsXhrObject(n)) {
- //console.log('NONTRIVIAL: Creates an xhr object');
- return types.nontrivialWithComment('NONTRIVIAL: Creates an xhr object');
- }
-
- // this is a method/function call
- if (n.type === token.CALL) {
-
- if (this.invokesEval(n)) {
- //console.log("NONTRIVIAL: eval has been found in code");
- return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code");
- }
- if (this.invokesMethodBracketSuffix(n)) {
- //console.log('NONTRIVIAL: square bracket suffix method call detected');
+/**
+ * invokesEval
+ *
+ * Returns true (nontrivial) if it finds any use of
+ * the eval function. For simplicity, we assume any
+ * use of an identifier "eval" is the eval function.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ */
+NonTrivialChecker.prototype.invokesEval = function (n) {
+ return (n.type === token.CALL &&
+ utils.nodeContains(n.children[0], token.IDENTIFIER, 'eval') ||
+ n.type === token.IDENTIFIER && n.value === 'eval');
+};
+
+/**
+ * evalIdentifier
+ *
+ * Returns true (nontrivial) if it finds any use of
+ * the eval function. For simplicity, we assume any
+ * use of an identifier "eval" is the eval function.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ */
+NonTrivialChecker.prototype.evalIdentifier = function (n) {
+ return n.type === token.IDENTIFIER && n.value === 'eval';
+};
+
+
+/**
+ * invokesMethodBracketSuffix
+ *
+ * Finds a method being invoked using the bracket suffix notation
+ * rather than the dot notation. It is difficult without keeping track of
+ * variable values to check for what method is actually being called.
+ * So we're just flagging any use of this construct as nontrivial.
+ * e.g., should catch: xhr[a+b]('GET', 'http://www.example.com');
+ * Should not catch other uses such as: myArray[num];
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ */
+NonTrivialChecker.prototype.invokesMethodBracketSuffix = function (n) {
+ return n.type === token.CALL && utils.isType(n.children[0], token.INDEX);
+};
+
+/**
+ * createsXhrObject
+ *
+ * Creates an xhr object.
+ * Since all "new XMLHttpRequest", "XMLHttpRequest()",
+ * and "new window.XMLHttpRequest" instantiate the xhr object,
+ * we assume (without further proof) that any use
+ * of the identifier "XMLHttpRequest" and "ActiveXObject"
+ * is an xhr object.
+ * Constructs like window[a+b]() are already caught by the
+ * bracket suffix check.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ */
+NonTrivialChecker.prototype.createsXhrObject = function (n) {
+ return (n.type === token.IDENTIFIER) &&
+ (n.value === 'XMLHttpRequest' ||
+ n.value === 'ActiveXObject');
+};
+
+/**
+ * invokesXhrOpen
+ *
+ * Here we assume the call of an open method must be an xhr request
+ * (and not some other object) by checking the number of arguments.
+ * In most cases this method won't be used since createsXhrObject
+ * will already have caught the xhr.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ *
+ */
+NonTrivialChecker.prototype.invokesXhrOpen = function (n) {
+ return n.type === token.CALL &&
+ utils.hasChildren(n, token.DOT, token.LIST) &&
+ utils.isType(n.children[0].children[0], token.IDENTIFIER) &&
+ utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'open') &&
+ n.children[1].children.length > 1;
+};
+
+/**
+ * createsScriptElement
+ *
+ * Checks for document.createElement() that create a script. In the case
+ * it creates an element from a variable, we assume it's a script. In the
+ * future we might want to check for the value of that string variable
+ * (e.g., if a variable is assigned 'script', raise a flag)
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ *
+ *
+ */
+NonTrivialChecker.prototype.createsScriptElement = function (n) {
+ return n.type === token.CALL &&
+ utils.hasChildren(n, token.DOT, token.LIST) &&
+ utils.isType(n.children[0].children[0], token.IDENTIFIER) &&
+ utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'createElement') &&
+ (utils.nodeContains(n.children[1].children[0], token.STRING, 'script') ||
+ utils.isType(n.children[1].children[0], token.IDENTIFIER));
+};
+
+/**
+ * writesScriptAsHtmlString
+ *
+ * catches myObj.write('<script></script>');
+ * or any myObj.write(myStringVariable);
+ * or concatenation such as:
+ * myObj.write('<scri' + stringVariable);
+ * or 'something' + 'somethingelse'.
+ *
+ * To check for javascript here we might want to look at the list
+ * from ha.ckers.org/xss.html for the future.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ *
+ */
+NonTrivialChecker.prototype.writesScriptAsHtmlString = function (n) {
+ var listArg;
+
+ if (n.type === token.CALL &&
+ utils.hasChildren(n, token.DOT, token.LIST) &&
+ utils.isType(n.children[0].children[0], token.IDENTIFIER) &&
+ utils.nodeContains(n.children[0].children[1], token.IDENTIFIER, 'write')
+ ) {
+ if (utils.isNotType(n.children[1].children[0], token.STRING)) {
+ // return true if any operation or concatenation.
+ // We are cautious (as it could
+ // embed a script) and flag this as nontrivial.
+
+ return true;
+ }
+ return utils.findScriptTag(n.children[1].children[0]);
+ } else {
+ return false;
+ }
+};
+
+/**
+ * nontrivial anytime we see an identifier as innerHTML
+ */
+NonTrivialChecker.prototype.innerHTMLIdentifier = function (n) {
+ if ((n.type === token.IDENTIFIER ||
+ n.type === token.STRING) &&
+ n.value === 'innerHTML'
+ ) {
+ return true;
+ }
+};
+
+/**
+ * checkNontrivial
+ *
+ * Contains all the conditionals that try to identify,
+ * step by step, all code that could be flagged as
+ * nontrivial.
+ *
+ * @param {object} n. The current node being studied.
+ * @return {boolean} . True if found.
+ *
+ */
+NonTrivialChecker.prototype.checkNontrivial = function (n, t) {
+
+ if (n.type === token.IDENTIFIER && this.evalIdentifier(n)) {
+ //console.log("NONTRIVIAL: eval has been found in code");
return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code");
- }
-
- if (this.invokesXhrOpen(n)) {
- //console.log('NONTRIVIAL: an open method similar to xhr.open is used');
- return types.nontrivialWithComment('NONTRIVIAL: square bracket suffix method call detected');
- }
-
- if (this.createsScriptElement(n)) {
- //console.log('NONTRIVIAL: creates script element dynamically.');
- return types.nontrivialWithComment('NONTRIVIAL: an open method similar to xhr.open is used');
- }
-
- if (this.writesScriptAsHtmlString(n)) {
- //console.log('NONTRIVIAL: writes script as html dynamically.');
- return types.nontrivialWithComment('NONTRIVIAL: creates script element dynamically.');
- }
- }
-
- // The node is a function definition.
- // Most common occurence.
- if (this.definesFunctionFound(n)) {
- return types.trivialFuncWithComment("Script is trivial but defines one or more functions");
- }
-
- // found nothing else, so trivial.
- return types.trivialWithComment("Script is trivial");
-
- }
+ }
+
+ if (this.innerHTMLIdentifier(n)) {
+ //console.log("NONTRIVIAL: innerHTML identifier");
+ return types.nontrivialWithComment("NONTRIVIAL: innerHTML identifier");
+ }
+
+ // the node is an identifier
+ if (n.type === token.IDENTIFIER && this.createsXhrObject(n)) {
+ //console.log('NONTRIVIAL: Creates an xhr object');
+ return types.nontrivialWithComment('NONTRIVIAL: Creates an xhr object');
+ }
+
+ // this is a method/function call
+ if (n.type === token.CALL) {
+
+ if (this.invokesEval(n)) {
+ //console.log("NONTRIVIAL: eval has been found in code");
+ return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code");
+ }
+
+ if (this.invokesMethodBracketSuffix(n)) {
+ //console.log('NONTRIVIAL: square bracket suffix method call detected');
+ return types.nontrivialWithComment("NONTRIVIAL: eval has been found in code");
+ }
+
+ if (this.invokesXhrOpen(n)) {
+ //console.log('NONTRIVIAL: an open method similar to xhr.open is used');
+ return types.nontrivialWithComment('NONTRIVIAL: square bracket suffix method call detected');
+ }
+
+ if (this.createsScriptElement(n)) {
+ //console.log('NONTRIVIAL: creates script element dynamically.');
+ return types.nontrivialWithComment('NONTRIVIAL: an open method similar to xhr.open is used');
+ }
+
+ if (this.writesScriptAsHtmlString(n)) {
+ //console.log('NONTRIVIAL: writes script as html dynamically.');
+ return types.nontrivialWithComment('NONTRIVIAL: creates script element dynamically.');
+ }
+ }
+
+ // The node is a function definition.
+ // Most common occurence.
+ if (this.definesFunctionFound(n)) {
+ return types.trivialFuncWithComment("Script is trivial but defines one or more functions");
+ }
+
+ // found nothing else, so trivial.
+ return types.trivialWithComment("Script is trivial");
};
exports.nonTrivialChecker = function () {
-
- var checker = Object.create(nonTrivialChecker);
-
- return checker;
-}; \ No newline at end of file
+ return new NonTrivialChecker();
+};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js
index 10874fc..b3e84d6 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/pattern_utils.js
@@ -2,39 +2,41 @@
* 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.patternUtils = {
- /**
- * removeNonalpha
- *
- * Remove all nonalphanumeric values, except for
- * < and >, since they are what we use for tokens.
- *
- */
- removeNonalpha: function (str) {
- var regex = /[^a-z0-9<>@]+/gi;
- return str.replace(regex, '');
- },
- removeWhitespace: function (str) {
- return str.replace(/[ \t\r\n]+/gmi,"");
- },
- replaceTokens: function (str) {
- var regex = /<.*?>/gi;
- return str.replace(regex, '.*?');
- }
-}; \ No newline at end of file
+ /**
+ * removeNonalpha
+ *
+ * Remove all nonalphanumeric values, except for
+ * < and >, since they are what we use for tokens.
+ *
+ */
+ removeNonalpha: function (str) {
+ var regex = /[^a-z0-9<>@]+/gi;
+ return str.replace(regex, '');
+ },
+ removeWhitespace: function (str) {
+ return str.replace(/\s+/gmi, '');
+ },
+ replaceTokens: function (str) {
+ var regex = /<.*?>/gi;
+ return str.replace(regex, '.*?');
+ }
+};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js
index b5dad1b..f39e0b7 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_checker.js
@@ -2,47 +2,45 @@
* 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 privacyThreatJs = require('js_checker/privacy_threat_definitions.js');
-var patternUtils = require('js_checker/pattern_utils').patternUtils;
+const privacyThreatJs = require('js_checker/privacy_threat_definitions.js');
+const patternUtils = require('js_checker/pattern_utils').patternUtils;
exports.privacyCheck = {
-
- checkScriptPrivacyThreat: function (currentScript) {
- var list = privacyThreatJs.js,
- i,
- jsRegexp,
- match,
- max,
- check;
-
- currentScript = patternUtils.removeWhitespace(currentScript);
+ checkScriptPrivacyThreat: function (currentScript) {
+ var list = privacyThreatJs.js;
+ var i;
+ var item;
+ var max;
- for (var item in list) {
- max = list[item].length;
+ currentScript = patternUtils.removeWhitespace(currentScript);
- for (i = 0; i < max; i++) {
- if (list[item][i].test(currentScript)) {
- return true;
- }
- }
+ for (item in list) {
+ max = list[item].length;
- }
- }
-
+ for (i = 0; i < max; i++) {
+ if (list[item][i].test(currentScript)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js
index ea6d279..fd04dcf 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/privacy_threat_definitions.js
@@ -2,39 +2,53 @@
* 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.js = {
- /**
- * googleAnalytics
- * Tracking code for Google Analytics.
- * It corresponds to:
- * var _gaq = _gaq || [];
- * _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
- * _gaq.push(['_trackPageview']);
- *
- * (function() {
- * var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- * ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- * var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- * })();
- *
- */
- googleAnalytics: [/var_gaq=_gaq\|\|\[\];_gaq\.push\(\['_setAccount','UA[0-9\-]*?'\]\);(_gaq.push\(\['_setDomainName','[a-z\.]*?'\]\);)?_gaq\.push\(\['_trackPageview'\]\);\(function\(\){varga=document\.createElement\('script'\);ga\.type='text\/javascript\';ga\.async=true;ga\.src=\(\'https:\'==document\.location\.protocol\?'https:\/\/ssl':'http:\/\/www'\)\+'\.google\-analytics\.com\/ga\.js';vars=document\.getElementsByTagName\('script'\)\[0\];s\.parentNode\.insertBefore\(ga,s\);}\)\(\);/ig,
- /vargaJsHost\=\(\(\"https\:\"\=\=document\.location\.protocol\)\?\"https\:\/\/ssl\.\"\:\"http\:\/\/www\.\"\)\;document\.write\(unescape\(\"\%3Cscriptsrc\=\'\"\+gaJsHost\+\"google\-analytics\.com\/ga\.js\'type\=\'text\/javascript\'\%3E\%3C\/script\%3E\"\)\)\;/ig,
- /try{varpageTracker\=\_gat\.\_getTracker\(\"UA[0-9\-]*?\"\)\;pageTracker\.\_trackPageview\(\)\;}catch\(err\){}/ig]
-}; \ No newline at end of file
+ /**
+ * googleAnalytics
+ * Tracking code for Google Analytics.
+ * It corresponds to:
+ * var _gaq = _gaq || [];
+ * _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
+ * _gaq.push(['_trackPageview']);
+ *
+ * (function() {
+ * var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ * ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ * var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ * })();
+ *
+ * It also matches GA code that doesn't track a page view, like this:
+ * var _gaq = _gaq || [];
+ * _gaq.push(['_setAccount', 'UA-5936383-6']);
+ *
+ * (function() {
+ * var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ * ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ * var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ * })();
+ *
+ */
+ googleAnalytics: [
+ /var_gaq=_gaq\|\|\[\];_gaq\.push\(\['_setAccount','UA[0-9\-]*?'\]\);(_gaq.push\(\['_setDomainName','[a-z\.]*?'\]\);)?(_gaq\.push\(\['_trackPageview'\]\);)?\(function\(\){varga=document\.createElement\('script'\);ga\.type='text\/javascript\';ga\.async=true;ga\.src=\(\'https:\'==document\.location\.protocol\?'https:\/\/ssl':'http:\/\/www'\)\+'\.google\-analytics\.com\/ga\.js';vars=document\.getElementsByTagName\('script'\)\[0\];s\.parentNode\.insertBefore\(ga,s\);}\)\(\);/i,
+ /vargaJsHost\=\(\(\"https\:\"\=\=document\.location\.protocol\)\?\"https\:\/\/ssl\.\"\:\"http\:\/\/www\.\"\)\;document\.write\(unescape\(\"\%3Cscriptsrc\=\'\"\+gaJsHost\+\"google\-analytics\.com\/ga\.js\'type\=\'text\/javascript\'\%3E\%3C\/script\%3E\"\)\)\;/i,
+ /try{varpageTracker\=\_gat\.\_getTracker\(\"UA[0-9\-]*?\"\)\;pageTracker\.\_trackPageview\(\)\;}catch\(err\){}/i
+ ]
+};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js
index 1904812..c504444 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_checker.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/js_checker/relation_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/>.
*/
/**
* relation_checker.js
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/main.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/main.js
index 3038eae..ac280a4 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/main.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/main.js
@@ -2,211 +2,70 @@
* 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/>.
*/
// Uncomment the following to start debugging, or do it from about:config.
// var name = "extensions.jid1-KtlZuoiikVfFew@jetpack.sdk.console.logLevel";
// require("sdk/preferences/service").set(name, "all");
-const jsAnalyzer = require("js_checker/js_checker");
-
-var { ToggleButton } = require('sdk/ui/button/toggle');
-const panel = require("sdk/panel");
-
-const pageWorker = require("sdk/page-worker");
-
-const data = require("sdk/self").data;
-const httpObserver = require("http_observer/http_request_observer");
-
const { Cc, Ci } = require("chrome");
-const { getMostRecentBrowserWindow } = require('sdk/window/utils');
-const jetpackID = require("sdk/self").id;
-const tabs = require("sdk/tabs");
-//const prefs = require("preferences/preferences");
-const simpleStorage = require("sdk/simple-storage");
-const addonManage = require("addon_management/install_uninstall");
-var removedScripts = require("script_entries/removed_scripts").removedScripts;
-var acceptedScripts = require("script_entries/accepted_scripts").acceptedScripts;
-const dryRunScripts = require("script_entries/dryrun_scripts").dryRunScripts;
+const librejsStorage = require("settings/storage").librejsStorage;
+let addonManage = require("addon_management/install_uninstall");
+let httpObserver = require("http_observer/http_request_observer");
+let prefObserver = require("pref_observer/pref_observer");
+let prefChange = require("addon_management/prefchange");
+let uiInfo = require("ui/ui_info");
+let scriptPanel = require("ui/script_panel.js");
-const types = require("js_checker/constant_types");
+require('ui');
-// manage preference whitelist.
-const prefChange = require("addon_management/prefchange");
// set whitelist at startup.
prefChange.init();
-
-var allowedRef = require("http_observer/allowed_referrers").allowedReferrers;
-
-var urlHandler = require("url_handler/url_handler");
-
var widgetIsOn = false;
-const librejsStorage = require("settings/storage").librejsStorage;
// read storage file.
var cachedResult = librejsStorage.init();
librejsStorage.generateCacheFromDB();
-
-var uiInfo = require("ui/ui_info");
-var scriptPanel = require("ui/script_panel.js");
-const removeHashCallback = require("js_checker/js_checker").removeHashCallback;
-var panelContent = function () {
-
- let panel = this;
- var message, externalEntries,
- externalScripts, urlTabIndex, tabData;
-
- tabs.activeTab.attach({
- contentScriptFile: [data.url('third_party/jquery-src.js'),
- data.url('script_detector/script_detector.js')],
- contentScriptWhen: 'ready',
-
- onMessage: function (respData) {
- var url = urlHandler.removeFragment(tabs.activeTab.url);
- scriptsData = {'removed': removedScripts.getScripts(url),
- 'accepted': acceptedScripts.getScripts(url),
- 'dryRun': dryRunScripts.getScripts(url)};
- panel.postMessage({'pageURL': url,
- 'urlData': scriptsData,
- 'isAllowed': allowedRef.urlInAllowedReferrers(url)});
- }
-
- });
-
-};
-
-// page mod was here.
-
exports.main = function(options, callbacks) {
if (options.loadReason === 'enable' ||
- options.loadReason === 'install') {
+ options.loadReason === 'install'
+ ) {
addonManage.onLoad();
}
};
-var mainPanel = panel.Panel({
- contentURL: data.url('display_panel/content/display-panel.html'),
- width: 800,
- height: 500,
- contentScriptFile: [
- data.url('third_party/jquery-src.js'),
- data.url('display_panel/main_panel.js')
- ],
- onShow: panelContent,
- onHide: removePanelContent
-});
-
-var toggleButton = ToggleButton({
- id: 'librejs-toggle-switch',
- label: 'LibreJS',
- icon: {
- '16': './widget/images/librejs.png',
- '32': './widget/images/librejs.png',
- '64': './widget/images/librejs.png'
- },
- contentScriptFile: [data.url('widget/widget.js')],
- contentScriptWhen: 'end',
- panel: mainPanel,
- onChange: handleChange
-});
-
-var getWidgetElem = function () {
- let { document } = getMostRecentBrowserWindow();
- var name = "widget:" + jetpackID + '-librejs-toggle-switch';
- var widgetElem = document.getElementById(name);
- return widgetElem;
-};
-
-function handleChange(state) {
- if (state.checked) {
- mainPanel.show({
- position: toggleButton
- });
- }
-}
-
-function removePanelContent() {
- toggleButton.state('window', { checked: false });
-}
-
-mainPanel.port.on('complainButtonClicked', function () {
- mainPanel.hide();
-});
-
-mainPanel.port.on('allowAllClicked', function (url) {
- url = urlHandler.removeFragment(url);
- allowedRef.addPage(url);
- tabs.activeTab.reload();
-});
-
-mainPanel.port.on('disallowAllClicked', function (url) {
- console.debug('url is', url);
- url = urlHandler.removeFragment(url);
- console.debug('before clear, url is in allowedRef', allowedRef.urlInAllowedReferrers(url));
- allowedRef.clearSinglePageEntry(url);
- console.debug('after clear, url is in allowedRef', allowedRef.urlInAllowedReferrers(url));
- mainPanel.hide();
- tabs.activeTab.reload();
-});
-
-mainPanel.port.on('openInTab', function (text) {
- var str = generateDataURI(text);
- tabs.open(str);
-});
-
-var generateDataURI = function (encodedText) {
- return "data:text/html;charset=UTF-8;base64," + encodedText;
-};
-
exports.onUnload = addonManage.onUnload;
exports.onLoad = addonManage.onLoad;
-// move to sub-module later
-const scriptsCached = require("script_entries/scripts_cache").scriptsCached;
-mainPanel.port.on('whitelistByHash', function (hash, url, name, reason) {
- console.debug("hash is", hash);
- url = urlHandler.removeFragment(url);
- /* var cached_result = scriptsCached.isCached(hash);
- console.log("cached_result is", cached_result);
- if (cached_results) {
- reason = cached_result['reason'];
- }*/
- scriptsCached.addEntryByHash(hash, types.whitelisted(reason), {}, true, url);
-});
-
-mainPanel.port.on('removeFromWhitelistByHash', function (hash) {
- scriptsCached.removeEntryByHash(hash);
- removeHashCallback(hash);
-});
-const settings_tab = require("settings/settings_tab");
-var menuitem = require("menuitems").Menuitem({
- id: 'librejs_settings',
- menuid: "menu_ToolsPopup",
- label: "LibreJS",
- onCommand: function() {
- settings_tab.settingsManager.open();
- },
- insertbefore: "menu_pageInfo"
-});
-
-mainPanel.port.on('openSesame', function () {
- // open the settings tab.
- settings_tab.settingsManager.open();
-});
-
+var prefs = require('sdk/preferences/service');
+var isJavaScriptEnabled = prefs.get('javascript.enabled');
+if (!isJavaScriptEnabled) {
+ console.debug('JS disabled in add-on init');
+ // remove all http notifications
+ httpObserver.removeHttpObserver();
+ // TODO: the narcissus worker could also be stopped at this
+ // point, but I'm not doing that right now because I don't
+ // know how to re-enable it.
+ //narcissusWorker.stopWorker();
+} else {
+ console.debug('JS enabled in add-on init');
+}
+prefObserver.register();
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/narcissus_parser/narcissus_worker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/narcissus_parser/narcissus_worker.js
deleted file mode 100644
index 5e28dbb..0000000
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/narcissus_parser/narcissus_worker.js
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
- * *
- * Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
- *
- * This program 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,
- * 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/>.
- *
- */
-
-var data = require("sdk/self").data;
-var {Cu} = require("chrome");
-
-var {ChromeWorker} = Cu.import("resource://gre/modules/Services.jsm", null);
-
-
-var worker = new ChromeWorker(data.url("chrome_worker/narcissus_parser/narcissus_parse.js"));
-
-worker.onmessage = function (e) {
-
- var jsChecker = require("js_checker/js_checker");
-
- try {
-
- jsChecker.callbackHashResult(e.data.hash, e.data.tree);
-
- } catch (x) {
-
- console.debug('error on message', x);
- jsChecker.callbackHashResult(e.data.hash, false);
-
- }
- jsChecker = null;
-};
-
-exports.parse = function (scriptText, hash) {
-
- try {
- // dont display errors for main version.
- worker.onerror = function (e) {
- console.debug('error', e.lineno, 'in', e.filename, 'e', e.message, 'full message', e);
- worker.postMessage(JSON.stringify({'hash': hash}));
- };
-
- var obj = {'code': scriptText, 'hash': hash};
- worker.postMessage(JSON.stringify(obj));
-
- } catch (x) {
- console.debug('error in lib/narcissus_worker.js', x, x.lineNumber);
- }
-
-};
-
-exports.stopWorker = function () {
- console.debug('stopping worker');
- worker.postMessage('stop');
-};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/parser/narcissus_worker.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/parser/narcissus_worker.js
new file mode 100644
index 0000000..a25e279
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/parser/narcissus_worker.js
@@ -0,0 +1,81 @@
+/**
+ * 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 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.
+ *
+ * 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 GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+var data = require("sdk/self").data;
+var {Cu} = require("chrome");
+var {ChromeWorker} = Cu.import("resource://gre/modules/Services.jsm", null);
+var worker = new ChromeWorker(
+ data.url("chrome_worker/parser/parse.js"));
+
+var NarcissusWorker = function() {
+ this.worker = worker;
+ var that = this;
+
+ this.worker.onmessage = function(e) {
+ var jsChecker = require("js_checker/js_checker");
+
+ console.debug('onmessage', e.data.hash);
+ try {
+ console.debug('calling jsChecker.callbackHashResult() for hash:',
+ e.data.hash);
+ jsChecker.callbackHashResult(e.data.hash, e.data.tree);
+ } catch (x) {
+ console.debug('error on message', x);
+ jsChecker.callbackHashResult(e.data.hash, false);
+ }
+ jsChecker = null;
+ };
+
+ // Enabling the catch clause in data/chrome_worker/parser
+ // instead of here because we can get the hash from there.
+ /*this.worker.onerror = function (e) {
+ console.debug(
+ 'error', e.lineno,
+ 'in', e.filename,
+ 'e', e.message,
+ 'full message', e
+ );
+ // can't get hash from this context
+ that.worker.postMessage(JSON.stringify({'hash': null}));
+ };*/
+};
+
+NarcissusWorker.prototype.stopWorker = function() {
+ console.debug('stopping worker');
+ this.worker.postMessage('stop');
+};
+
+NarcissusWorker.prototype.parse = function(scriptText, hash) {
+ console.debug('parsing', hash);
+ try {
+ this.worker.postMessage(JSON.stringify({
+ 'code': scriptText,
+ 'hash': hash
+ }));
+ } catch (x) {
+ console.debug('error in lib/narcissus_worker.js', x, x.lineNumber);
+ }
+
+};
+
+var narcissusWorker = new NarcissusWorker();
+exports.narcissusWorker = narcissusWorker;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/pref_observer/pref_observer.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/pref_observer/pref_observer.js
new file mode 100644
index 0000000..d066c2f
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/pref_observer/pref_observer.js
@@ -0,0 +1,72 @@
+/**
+ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
+ * *
+ * Copyright (C) 2014, 2015 Nik Nyby
+ *
+ * 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.
+ *
+ * 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 GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+var {Cc, Ci} = require("chrome");
+const httpObserver = require("http_observer/http_request_observer");
+
+// https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Preferences#Using_preference_observers
+var prefObserver = {
+ register: function() {
+ // First we'll need the preference services to look for preferences.
+ var prefService = Cc["@mozilla.org/preferences-service;1"]
+ .getService(Ci.nsIPrefService);
+
+ // For this.branch we ask for the preferences for
+ // extensions.myextension. and children
+ this.branch = prefService.getBranch("javascript.");
+
+ // Finally add the observer.
+ this.branch.addObserver("", this, false);
+ },
+
+ unregister: function() {
+ this.branch.removeObserver("", this);
+ },
+
+ observe: function(aSubject, aTopic, aData) {
+ // aSubject is the nsIPrefBranch we're observing (after appropriate QI)
+ // aData is the name of the pref that's been changed (relative to
+ // aSubject)
+ switch (aData) {
+ case "enabled":
+ var prefs = require('sdk/preferences/service');
+ var isJavaScriptEnabled = prefs.get('javascript.enabled');
+ if (!isJavaScriptEnabled) {
+ console.debug('JS disabled in observer');
+ // remove all http notifications
+ httpObserver.removeHttpObserver();
+
+ // TODO: the narcissus worker could also be stopped at this
+ // point, but I'm not doing that right now because I don't
+ // know how to re-enable it.
+ // narcissusWorker.stopWorker();
+ } else {
+ console.debug('JS enabled in observer');
+ httpObserver.startHttpObserver();
+ }
+ break;
+ }
+ }
+};
+
+exports.register = function() {
+ prefObserver.register();
+};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/accepted_scripts.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/accepted_scripts.js
index 1a8ac9a..c732f31 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/accepted_scripts.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/accepted_scripts.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 allScripts = require('script_entries/all_scripts').allScripts;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/all_scripts.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/all_scripts.js
index c08b4ac..2028864 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/all_scripts.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/all_scripts.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 crypto = require('script_entries/crypto');
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/crypto.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/crypto.js
index e8844b1..5fb920f 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/crypto.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/crypto.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 {Cc, Ci, Cu, Cm, Cr} = require("chrome");
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/dryrun_scripts.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/dryrun_scripts.js
index d32263b..87ec482 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/dryrun_scripts.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/dryrun_scripts.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 allScripts = require('script_entries/all_scripts').allScripts;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/free_libraries.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/free_libraries.js
index 5aff728..af2cf61 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/free_libraries.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/free_libraries.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/>.
*/
// THIS MODULE IS DEPRECATED IN FAVOR OF THE NEW WHITELISTING MODULE (LibreJS 6.0)
@@ -28,40 +30,38 @@ var scriptsCached = require("./scripts_cache").scriptsCached;
// find the json database path.
var dbContents = require("sdk/self").data.load("script_libraries/script-libraries.json");
-const AUTHOR_REASON = "this script has been tagged as free software by LibreJS authors";
+const AUTHOR_REASON = "This script has been tagged as free software by LibreJS authors.";
var freeLibraries = JSON.parse(dbContents); /* a database of the free libraries recognized by default */
/*
- *
* List of free libraries and their SHA256 hash.
* This is used to recognize the most common free libraries.
- *
*/
var init = function () {
- // relationChecker, which roughly checks if variables are window
- // variables or not, is useless in this case. Use the same
- // object for all entries.
- var rc = relationChecker();
- var library, hash;
- var freeObj = { "type": 4, "reason": AUTHOR_REASON};
- console.debug("Building init");
- for (hash in freeLibraries) {
- library = freeLibraries[hash];
+ // relationChecker, which roughly checks if variables are window
+ // variables or not, is useless in this case. Use the same
+ // object for all entries.
+ var rc = relationChecker();
+ var library, hash;
+ var freeObj = { "type": 4, "reason": AUTHOR_REASON};
+ console.debug("Building init");
+ for (hash in freeLibraries) {
+ library = freeLibraries[hash];
- // assign empty relationChecker object.
- library.relationChecker = rc;
+ // assign empty relationChecker object.
+ library.relationChecker = rc;
- // make them free and nontrivial.
- library.result = freeObj;
+ // make them free and nontrivial.
+ library.result = freeObj;
- scriptsCached.addObjectEntry(hash, library);
- }
+ scriptsCached.addObjectEntry(hash, library);
+ }
};
-//init();
+//init();
exports.init = init;
exports.AUTHOR_REASON = AUTHOR_REASON;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/removed_scripts.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/removed_scripts.js
index 8f65c4d..b7544e9 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/removed_scripts.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/removed_scripts.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 allScripts = require('script_entries/all_scripts').allScripts;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/scripts_cache.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/scripts_cache.js
index 5bc5c8a..47ab069 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/scripts_cache.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/script_entries/scripts_cache.js
@@ -2,32 +2,42 @@
* 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 relationCheckerObj = require("js_checker/relation_checker").relationChecker;
+var relationCheckerObj = require("js_checker/relation_checker")
+ .relationChecker;
+
+// import free_libraries to populate the cache hash map.
+var free_libraries = require("script_entries/free_libraries");
var crypto = require('script_entries/crypto');
-//const librejsStorage = require("settings/storage").librejsStorage;
const checkTypes = require("js_checker/constant_types").checkTypes;
// cachedResults contains objects with result/relationChecker for
// scripts entries indexed by SHA1sum
var cachedResults = {};
-var ScriptsCached = function() {};
+/**
+ * ScriptsCached keeps a cache of whitelisted scripts in the browser
+ * session.
+ */
+var ScriptsCached = function() {
+};
ScriptsCached.prototype.getHash = function(scriptText) {
require('ui/notification').createNotification(scriptText.substring(0,100));
@@ -160,9 +170,10 @@ ScriptsCached.prototype.getCacheForWriting = function() {
for (let item in cachedResults) {
let type = cachedResults[item].result.type;
if (type != checkTypes.NONTRIVIAL &&
- type != checkTypes.TRIVIAL_DEFINES_FUNCTION) {
- formattedResults[item] = cachedResults[item];
- }
+ type != checkTypes.TRIVIAL_DEFINES_FUNCTION
+ ) {
+ formattedResults[item] = cachedResults[item];
+ }
}
return formattedResults;
};
@@ -173,10 +184,9 @@ ScriptsCached.prototype.getCacheForWriting = function() {
*/
ScriptsCached.prototype.bulkImportCache = function(data) {
cachedResults = data;
- console.debug("Imported data. Number of keys ISSS ", Object.keys(cachedResults).length);
+ console.debug("Imported data. Number of keys ISSS ",
+ Object.keys(cachedResults).length);
console.debug("It looks like ", JSON.stringify(cachedResults));
};
-// import free_libraries to populate the cache hash map.
-//var free_libraries = require("script_entries/free_libraries");
exports.scriptsCached = new ScriptsCached();
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/settings_tab.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/settings_tab.js
index c99deb5..976714a 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/settings_tab.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/settings_tab.js
@@ -2,83 +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/>.
*/
-const addonTab = require("addon-tab");
+const tabs = require("sdk/tabs");
const data = require("sdk/self").data;
const storage = require("settings/storage").librejsStorage;
const scriptsCached = require("script_entries/scripts_cache").scriptsCached;
exports.settingsManager = settingsManager;
-
-
let settingsManager = {
- settings_tab: {
- url: data.url("settings/index.html"),
- tabStyle: {
- 'background-color': '#898168',
- 'background-image': 'none', // important to overwrite bckg when tab is active.
- 'font-weight': 'normal',
- 'font-size': '1.1em',
- 'color': '#444'
- },
- onReady: function (tab) {
- console.debug("populating form");
- var that = this;
- let cache_data = scriptsCached.getCacheForWriting();
- let worker = tab.attach({contentScriptFile: [data.url('settings/js/pagescript-listener.js'),
- data.url('settings/js/pagescript-emitter.js')]});
- worker.port.emit("populate-form", cache_data);
- worker.port.on("rules-form-delete", function (hash) {
- try {
- scriptsCached.removeEntryByHash(hash);
- } catch (e) {
- console.log(e, e.lineNumber, e.filename);
+ settingsTab: {
+ url: data.url("settings/index.html"),
+ onReady: function (tab) {
+ console.debug("populating form");
+ var that = this;
+ let cache_data = scriptsCached.getCacheForWriting();
+ let worker = tab.attach({
+ contentScriptFile: [
+ data.url('settings/js/pagescript-listener.js'),
+ data.url('settings/js/pagescript-emitter.js')
+ ]
+ });
+ worker.port.emit("populate-form", cache_data);
+ worker.port.on("rules-form-delete", function (hash) {
+ try {
+ scriptsCached.removeEntryByHash(hash);
+ } catch (e) {
+ console.log('caught!', e, e.lineNumber, e.filename);
+ }
+ //worker.port.emit("populate-form", scriptsCached.getCacheForWriting());
+ });
+ worker.port.on("rules-form-delete-all", function () {
+ scriptsCached.resetCache();
+ });
+ },
+ onActivate: function (tab) {
+ // just reload the form.
+ console.debug("Tab is activated again");
+ var that = this;
+ let cache_data = scriptsCached.getCacheForWriting();
+ let worker = tab.attach({
+ contentScriptFile: [
+ data.url('settings/js/pagescript-listener.js'),
+ data.url('settings/js/pagescript-emitter.js')
+ ]
+ });
+ worker.port.emit("populate-form", cache_data);
}
- //worker.port.emit("populate-form", scriptsCached.getCacheForWriting());
- });
- worker.port.on("rules-form-delete-all", function () {
- console.log("delete all triggered.");
- scriptsCached.resetCache();
- });
},
- onActivate: function (tab) {
- // just reload the form.
- console.log("Tab is activated again");
- var that = this;
- let cache_data = scriptsCached.getCacheForWriting();
- let worker = tab.attach({contentScriptFile: [data.url('settings/js/pagescript-listener.js'),
- data.url('settings/js/pagescript-emitter.js')]});
- worker.port.emit("populate-form", cache_data);
+
+ init: function () {
+ settings.onLoad(function (data) {});
+ },
+ open: function () {
+ console.debug("settings tab data url is", this.settingsTab.url);
+ tabs.open(this.settingsTab);
}
- },
-
-
- init: function () {
- // do some first time magic.
- settings.onLoad(function (data) {
-
- });
- },
- open: function () {
- console.debug("settings tab data url is", this.settings_tab.url);
- addonTab.open(this.settings_tab);
- }
};
exports.settingsManager = settingsManager;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/storage.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/storage.js
index f77bd13..bc9fe77 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/storage.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/settings/storage.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/>.
*/
/*jshint esnext: true */
@@ -32,133 +34,144 @@ const scriptsCached = require("script_entries/scripts_cache").scriptsCached;
let librejsStorage = {
- file: null,
- filename: 'librejs-whitelist.json',
- data: [],
+ file: null,
+ filename: 'librejs-whitelist.json',
+ data: [],
- onLoad: function (callback) {
- // will read the json file.
- this.init();
- this.read(callback);
- },
-
+ onLoad: function (callback) {
+ // will read the json file.
+ this.init();
+ this.read(callback);
+ },
- init: function () {
- // get the "librejs-whitelist.json" file in the profile directory
- this.file = FileUtils.getFile("ProfD", [this.filename]);
- },
- read: function (callback) {
- // Content type hint is useful on mobile platforms where the filesystem
- // would otherwise try to determine the content type.
- var channel = NetUtil.newChannel(this.file);
- var that = this;
- channel.contentType = "application/json";
- try {
- NetUtil.asyncFetch(channel, function(inputStream, status) {
+ init: function () {
+ // get the "librejs-whitelist.json" file in the profile directory
+ this.file = FileUtils.getFile("ProfD", [this.filename]);
+ },
- if (!components.isSuccessCode(status)) {
- require("script_entries/free_libraries").init();
- that.initialWrite();
+ read: function (callback) {
+ // Content type hint is useful on mobile platforms where the filesystem
+ // would otherwise try to determine the content type.
+ var channel = NetUtil.newChannel(this.file);
+ var that = this;
+ channel.contentType = "application/json";
+ try {
+ NetUtil.asyncFetch(channel, function(inputStream, status) {
+
+ if (!components.isSuccessCode(status)) {
+ require("script_entries/free_libraries").init();
+ that.initialWrite();
+ }
+
+ var raw_data = NetUtil.readInputStreamToString(
+ inputStream, inputStream.available());
+ // expand json file back to original contents.
+ var re = new RegExp(
+ "[freelib]".replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'),
+ 'g'
+ );
+ raw_data = raw_data.replace(re, AUTHOR_REASON);
+ //console.debug("raw_data is ", raw_data);
+ // The file data is contained within inputStream.
+ // You can read it into a string with
+ // get string into json also
+ that.data = JSON.parse(raw_data);
+
+ callback(that.data);
+ });
+ } catch (e) {
+ that.initialWrite();
}
-
- var raw_data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
- // expand json file back to original contents.
- var re = new RegExp("[freelib]".replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
- raw_data = raw_data.replace(re, AUTHOR_REASON);
- console.debug("raw_data is ", raw_data);
- // The file data is contained within inputStream.
- // You can read it into a string with
- // get string into json also
- that.data = JSON.parse(raw_data);
-
- callback(that.data);
- });
- } catch (e) {
- that.initialWrite();
- }
- },
+ },
- initialWrite: function (callback) {
- console.debug("About to write free libraries");
- // our file is not populated with default contents.
- // use free_libraries.js to populate.
- require("script_entries/free_libraries").init();
- this.writeCacheToDB(callback);
- },
- /**
- * writes the contents of scriptsCached to the persistent
- * JSON file.
- */
- writeCacheToDB: function (callback) {
- console.debug("writing to db");
- data = scriptsCached.getCacheForWriting();
- json = JSON.stringify(data);
+ initialWrite: function (callback) {
+ console.debug("About to write free libraries");
+ // our file is not populated with default contents.
+ // use free_libraries.js to populate.
+ require("script_entries/free_libraries").init();
+ this.writeCacheToDB(callback);
+ },
- // make json file smaller.
- var re = new RegExp(AUTHOR_REASON.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
- json = json.replace(re, "[freelib]");
-
- var rc = JSON.stringify(relationChecker());
- re = new RegExp(rc.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
- json = json.replace(re, "\"[rl]\"");
- console.debug("this.data is now", this.data);
- this.write(callback, json);
- },
- generateCacheFromDB: function (callback) {
- if (callback === undefined) {
- callback = function () {
- // nothing to do.
- };
- }
- this.read(function (data) {
- scriptsCached.bulkImportCache(data);
- });
- },
- write: function (onDataWritten, json) {
+ /**
+ * writes the contents of scriptsCached to the persistent
+ * JSON file.
+ */
+ writeCacheToDB: function (callback) {
+ console.debug("writing to db");
+ data = scriptsCached.getCacheForWriting();
+ json = JSON.stringify(data);
- this.init();
- var str;
- if (json === undefined) {
- str = JSON.stringify(this.data);
- } else {
- // we are passing json already formatted.
- str = json;
- }
- var ostream = FileUtils.openSafeFileOutputStream(this.file);
- var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
- converter.charset = "UTF-8";
- var istream = converter.convertToInputStream(str);
- // The last argument (the callback) is optional.
- NetUtil.asyncCopy(istream, ostream, function(status) {
- if (!components.isSuccessCode(status)) {
- // Handle error!
- return;
- }
- if (!onDataWritten) {
- console.debug("onDataWritten is not defined");
- onDataWritten = function () {
- console.debug("onDataWritten dummy callback triggered");
- };
- }
- // Data has been written to the file.
- onDataWritten();
- });
- },
+ // make json file smaller.
+ var re = new RegExp(
+ AUTHOR_REASON.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
+ json = json.replace(re, "[freelib]");
+
+ var rc = JSON.stringify(relationChecker());
+ re = new RegExp(rc.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g');
+ json = json.replace(re, "\"[rl]\"");
+ //console.debug("this.data is now", this.data);
+ this.write(callback, json);
+ },
+ generateCacheFromDB: function (callback) {
+ if (typeof callback === 'undefined') {
+ callback = function () {
+ // nothing to do.
+ };
+ }
+ this.read(function (data) {
+ scriptsCached.bulkImportCache(data);
+ });
+ },
+ write: function (onDataWritten, json) {
- /**
- * getEntry -- Returns a storage entry if it is present.
- */
- getEntry: function (hash) {
- var entry = this.data[hash];
- if (entry) {
- if (entry.result == "[freelib]") {
- entry.result = { "type": 4, "reason": "this script has been tagged as free software by LibreJS authors" };
- }
- entry.relationChecker = rc;
- return entry;
+ this.init();
+ var str;
+ if (typeof json === 'undefined') {
+ str = JSON.stringify(this.data);
+ } else {
+ // we are passing json already formatted.
+ str = json;
+ }
+ var ostream = FileUtils.openSafeFileOutputStream(this.file);
+ var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
+ .createInstance(Ci.nsIScriptableUnicodeConverter);
+ converter.charset = "UTF-8";
+ var istream = converter.convertToInputStream(str);
+ // The last argument (the callback) is optional.
+ NetUtil.asyncCopy(istream, ostream, function(status) {
+ if (!components.isSuccessCode(status)) {
+ // Handle error!
+ return;
+ }
+ if (!onDataWritten) {
+ console.debug("onDataWritten is not defined");
+ onDataWritten = function () {
+ console.debug("onDataWritten dummy callback triggered");
+ };
+ }
+ // Data has been written to the file.
+ onDataWritten();
+ });
+ },
+
+ /**
+ * getEntry -- Returns a storage entry if it is present.
+ */
+ getEntry: function (hash) {
+ var entry = this.data[hash];
+ if (entry) {
+ if (entry.result === '[freelib]') {
+ entry.result = {
+ 'type': 4,
+ 'reason': 'This script has been tagged as free ' +
+ 'software by LibreJS authors.'
+ };
+ }
+ entry.relationChecker = rc;
+ return entry;
+ }
+ return false;
}
- return false;
- }
};
exports.librejsStorage = librejsStorage;
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui.js
new file mode 100644
index 0000000..e135f57
--- /dev/null
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui.js
@@ -0,0 +1,188 @@
+/**
+ * GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
+ * *
+ * Copyright (C) 2015 Nik Nyby
+ *
+ * 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.
+ *
+ * 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 GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+let data = require("sdk/self").data;
+let panel = require('sdk/panel');
+let tabs = require("sdk/tabs");
+let {getMostRecentBrowserWindow} = require('sdk/window/utils');
+let {ToggleButton} = require('sdk/ui/button/toggle');
+
+let settings_tab = require('settings/settings_tab');
+let allowedRef = require("http_observer/allowed_referrers").allowedReferrers;
+let urlHandler = require("url_handler/url_handler");
+let removedScripts = require("script_entries/removed_scripts").removedScripts;
+let acceptedScripts = require("script_entries/accepted_scripts")
+ .acceptedScripts;
+let jsLabelsPagesVisited = require('html_script_finder/web_labels/js_web_labels')
+ .jsLabelsPagesVisited;
+let dryRunScripts = require("script_entries/dryrun_scripts").dryRunScripts;
+let types = require("js_checker/constant_types");
+const removeHashCallback = require("js_checker/js_checker").removeHashCallback;
+
+// move to sub-module later
+const scriptsCached = require("script_entries/scripts_cache").scriptsCached;
+
+function generateDataURI (encodedText) {
+ return "data:text/html;charset=UTF-8;base64," + encodedText;
+}
+
+/**
+ * UI
+ *
+ * A singleton that starts the user interface content scripts.
+ */
+let UI = exports.UI = {
+ init: function() {
+ var mainPanel = panel.Panel({
+ contentURL: data.url('display_panel/content/display-panel.html'),
+ width: 800,
+ height: 500,
+ contentScriptFile: [
+ data.url('settings/third-party/jquery/jquery.min.js'),
+ data.url('display_panel/main_panel.js')
+ ],
+ onShow: this.showPanelContent,
+ onHide: function() {
+ toggleButton.state('window', { checked: false });
+ }
+ });
+
+ mainPanel.port.on('hideMainPanel', function () {
+ mainPanel.hide();
+ });
+
+ mainPanel.port.on('allowAllClicked', function (url) {
+ url = urlHandler.removeFragment(url);
+ allowedRef.addPage(url);
+ tabs.activeTab.reload();
+ });
+
+ mainPanel.port.on('disallowAllClicked', function (url) {
+ console.debug('url is', url);
+ url = urlHandler.removeFragment(url);
+ console.debug('before clear, url is in allowedRef',
+ allowedRef.urlInAllowedReferrers(url));
+ allowedRef.clearSinglePageEntry(url);
+ console.debug('after clear, url is in allowedRef',
+ allowedRef.urlInAllowedReferrers(url));
+ mainPanel.hide();
+ tabs.activeTab.reload();
+ });
+
+ mainPanel.port.on('openInTab', function (text) {
+ var str = generateDataURI(text);
+ tabs.open(str);
+ mainPanel.hide();
+ });
+
+ mainPanel.port.on('whitelistByHash', function(
+ hash, url, name, reason
+ ) {
+ console.debug("hash is", hash);
+ url = urlHandler.removeFragment(url);
+ /* var cached_result = scriptsCached.isCached(hash);
+ if (cached_results) {
+ reason = cached_result['reason'];
+ }*/
+ scriptsCached.addEntryByHash(
+ hash, types.whitelisted(reason), {}, true, url);
+ });
+
+ mainPanel.port.on('removeFromWhitelistByHash', function (hash) {
+ scriptsCached.removeEntryByHash(hash);
+ removeHashCallback(hash);
+ });
+
+ mainPanel.port.on('openSesame', function () {
+ // open the settings tab.
+ settings_tab.settingsManager.open();
+ mainPanel.hide();
+ });
+
+ var toggleButton = ToggleButton({
+ id: 'librejs-toggle-switch',
+ label: 'LibreJS',
+ icon: {
+ '16': './widget/images/librejs.png',
+ '32': './widget/images/librejs-32.png',
+ '64': './widget/images/librejs-64.png'
+ },
+ panel: mainPanel,
+ onChange: function(state) {
+ if (state.checked) {
+ mainPanel.show({
+ position: toggleButton
+ });
+ }
+ }
+ });
+
+ var menuitem = require("menuitems").Menuitem({
+ id: 'librejs_settings',
+ menuid: 'menu_ToolsPopup',
+ label: 'LibreJS Whitelist',
+ onCommand: function() {
+ settings_tab.settingsManager.open();
+ },
+ insertBefore: "menu_pageInfo"
+ });
+ },
+
+ showPanelContent: function() {
+ let that = this;
+ var message, externalEntries,
+ externalScripts, urlTabIndex, tabData;
+
+ var worker = tabs.activeTab.attach({
+ contentScriptFile: [
+ data.url('complain/contact_regex.js'),
+ data.url('complain/link_types.js'),
+ data.url('settings/third-party/jquery/jquery.min.js'),
+ data.url('complain/contact_finder.js'),
+ data.url('complain/pagemod_finder.js'),
+ data.url('script_detector/script_detector.js')
+ ],
+ contentScriptWhen: 'ready',
+ onMessage: function(respData) {
+ var url = urlHandler.removeFragment(tabs.activeTab.url);
+
+ if (respData.event === 'scriptsFetched') {
+ var scriptsData = {
+ 'jsLabelsPagesVisited': jsLabelsPagesVisited,
+ 'removed': removedScripts.getScripts(url),
+ 'accepted': acceptedScripts.getScripts(url),
+ 'dryRun': dryRunScripts.getScripts(url)
+ };
+ that.postMessage({
+ 'pageURL': url,
+ 'urlData': scriptsData,
+ 'isAllowed': allowedRef.urlInAllowedReferrers(url)
+ });
+ worker.port.emit('pageUrl', url);
+ } else {
+ that.postMessage(respData);
+ }
+ }
+ });
+ }
+};
+
+UI.init();
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/notification.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/notification.js
index aeb279a..da4b7d5 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/notification.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/notification.js
@@ -2,34 +2,36 @@
* 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/>.
*/
// this module is used to display a notification when LibreJS
// is running to inform the user it is indeed busy working.
const timer = require("sdk/timers");
const self = require("sdk/self");
-const isDisplayNotifications = require("addon_management/prefchange").isDisplayNotifications;
+const isDisplayNotifications = require("addon_management/prefchange")
+ .isDisplayNotifications;
exports.createCriticalNotification = function (text) {
if (text === undefined) {
text = "";
}
var self = require('sdk/self');
- var randomnumber = Math.floor(Math.random()*11);
var notif = require("notification-box").NotificationBox({
'value': 'librejs-critical-notification-js-web-labels',
'label': text,
@@ -53,7 +55,6 @@ exports.createNotification = function (jsValue) {
jsValue = "";
}
var self = require('sdk/self');
- var randomnumber = Math.floor(Math.random()*11);
var notif = require("notification-box").NotificationBox({
'value': 'librejs-message',
'label': 'LibreJS is analyzing: ' + jsValue + " ...",
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/script_panel.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/script_panel.js
index 85c22a4..35b601c 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/script_panel.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/script_panel.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 urlHandler = require("url_handler/url_handler");
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/ui_info.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/ui_info.js
index 5e0c2a8..6df8a09 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/ui_info.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/ui/ui_info.js
@@ -2,35 +2,32 @@
* 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/>.
*/
-
-
// page mod executing content script at every page load.
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
-
var urlHandler = require("url_handler/url_handler");
-
var pageWorker = require("sdk/page-worker");
-
var tabs = require("sdk/tabs");
-var isComplaintTab = require("addon_management/prefchange").isComplaintTab;
+var prefs = require("addon_management/prefchange");
// contain list of recently found contact links or email addresses.
var contactList = {};
@@ -57,40 +54,34 @@ const SNAIL_ADDRESS_FOUND = 'snailAddressFound';
* main pageMod.
* Find blocked script in all pages being opened.
* Launch the scripts that search for a complaint contact.
- *
+ *
*/
pageMod.PageMod({
-
- include: ['file://*','*', 'data:*', 'about:*'],
-
- contentScriptWhen: 'end',
-
- contentScriptFile: [
- data.url('complain/contact_regex.js'),
- data.url('complain/link_types.js'),
- data.url('third_party/jquery-src.js'),
- data.url('third_party/jquery.easing.1.3.js'),
- data.url('complain/contact_finder.js'),
- data.url('complain/pagemod_finder.js'),
- data.url('script_detector/script_detector.js')
- ],
-
- onAttach: function onAttach(worker) {
-
- if (worker.tab !== undefined && isComplaintTab()) {
-
- // this is a tab.
- if (!foundInContactList(worker.url)) {
- // the hostname doesn't appear in the object literal.
- // run script fetching/complaint feature if applicable.
- tabProcess(worker);
- } else {
- worker.postMessage(foundInContactList(worker.url));
- }
- }
-
- }
+ include: ['file://*', '*', 'data:*', 'about:*'],
+ contentScriptWhen: 'end',
+
+ contentScriptFile: [
+ data.url('complain/contact_regex.js'),
+ data.url('complain/link_types.js'),
+ data.url('settings/third-party/jquery/jquery.min.js'),
+ data.url('complain/contact_finder.js'),
+ data.url('complain/pagemod_finder.js'),
+ data.url('script_detector/script_detector.js')
+ ],
+
+ onAttach: function onAttach(worker) {
+ if (worker.tab !== undefined && prefs.isComplaintTab()) {
+ // this is a tab.
+ if (!foundInContactList(worker.url)) {
+ // the hostname doesn't appear in the object literal.
+ // run script fetching/complaint feature if applicable.
+ tabProcess(worker);
+ } else {
+ worker.postMessage(foundInContactList(worker.url));
+ }
+ }
+ }
});
/**
@@ -100,92 +91,81 @@ pageMod.PageMod({
* false.
*/
var foundInContactList = function (url) {
-
- var hostname = urlHandler.getHostname(url);
-
- if (contactList[hostname] !== undefined) {
-
- return contactList[hostname];
-
- } else {
-
- return false;
-
- }
-
+ var hostname = urlHandler.getHostname(url);
+ if (contactList[hostname] !== undefined) {
+ return contactList[hostname];
+ } else {
+ return false;
+ }
};
/**
* tabProcess
* Find blocked/accepted scripts, prepare
- * display panel and complaint panel, ...
- *
+ * display panel and complaint panel.
*/
var tabProcess = function (worker) {
-
- var visitedUrl = {};
-
- // webmaster email is better than a webpage.
- worker.emailFound = false;
- var modUrl = '',
- searchUrl = '';
-
- modUrl = worker.url;
-
- console.debug('pagemod triggered');
-
- // send local path to complain button graphic.
- worker.postMessage({'event': 'assets-uri', 'value': data.url('assets/')});
- worker.postMessage({'event': 'page-url', 'value': modUrl});
-
- worker.on('message', function (respData) {
-
- // console.debug('worker is receiving a message', respData.event);
-
- var pw;
-
- worker.on('detach', function () {
- console.debug('detaching worker');
- if (pw) {
- pw.destroy();
-
- }
- });
- if (respData.contact !== undefined) {
- // pass the message to the complaint display panel.
- worker.postMessage(respData);
- }
-
- else if (respData.event === 'complaintSearch') {
-
- console.debug('complaintSearch triggered');
- console.debug('worker tab url', worker.tab.url);
- if (!(respData.urlSearch.linkValue in visitedUrl)) {
-
- visitedUrl[respData.urlSearch.linkValue] = 1;
-
- respData.urlSearch.linkValue = urlHandler.addFragment(respData.urlSearch.linkValue, 'librejs=true');
- pw = searchSecondLevelPage(this, respData.urlSearch.linkValue, this.url);
-
- }
- // currently not needed.
- /*else {
- console.debug(respData.urlSearch.linkValue, 'already visited');
- }*/
- }
-
-
- });
-
+ var visitedUrl = {};
+
+ // webmaster email is better than a webpage.
+ worker.emailFound = false;
+ var modUrl = '',
+ searchUrl = '';
+
+ modUrl = worker.url;
+ console.debug('pagemod triggered');
+
+ worker.port.emit('prefs', {
+ complaintEmailSubject: prefs.complaintEmailSubject(),
+ complaintEmailBody: prefs.complaintEmailBody()
+ });
+
+ // send local path to complain button graphic.
+ worker.port.emit('assetsUri',
+ {'event': 'assets-uri',
+ 'value': data.url('assets/')});
+ worker.port.emit('pageUrl',
+ {'event': 'page-url',
+ 'value': modUrl});
+
+ worker.on('message', function (respData) {
+ console.debug('worker is receiving a message', respData.event);
+ var pw;
+
+ worker.on('detach', function () {
+ console.debug('detaching worker');
+ if (pw) {
+ pw.destroy();
+ }
+ });
+ if (respData.contact !== undefined) {
+ // pass the message to the complaint display panel.
+ worker.port.emit('complaintLinkFound', respData);
+ } else if (respData.event === 'complaintSearch') {
+ if (worker.tab) {
+ console.debug('worker tab url', worker.tab.url);
+ }
+ if (!(respData.urlSearch.linkValue in visitedUrl)) {
+ visitedUrl[respData.urlSearch.linkValue] = 1;
+ respData.urlSearch.linkValue = urlHandler.addFragment(
+ respData.urlSearch.linkValue, 'librejs=true');
+ pw = searchSecondLevelPage(
+ this, respData.urlSearch.linkValue, this.url);
+ }
+ // currently not needed.
+ /*else {
+ console.debug(respData.urlSearch.linkValue, 'already visited');
+ }*/
+ }
+ });
};
var searchSecondLevelPage = function(
- worker, urlToSearch, originalUrl) {
+ worker, urlToSearch, originalUrl) {
return;
var originalWorker = worker;
- console.debug('url to search is', urlToSearch);
-
+ console.debug('searchSecondLevelPage');
console.debug(urlToSearch, 'and', originalUrl);
if (urlHandler.haveSameHostname(urlToSearch, originalUrl)) {
@@ -194,39 +174,31 @@ var searchSecondLevelPage = function(
contentScriptFile: [
data.url('complain/contact_regex.js'),
data.url('complain/link_types.js'),
- data.url('third_party/jquery-src.js'),
- data.url('third_party/jquery.easing.1.3.js'),
+ data.url('settings/third-party/jquery/jquery.min.js'),
data.url('complain/contact_finder.js'),
data.url('complain/worker_finder.js')
- ],
- contentScriptWhen: "end",
- onMessage: function (respData) {
- console.debug(JSON.stringify(respData));
- console.debug(originalWorker.url);
- originalWorker.postMessage(respData);
-
- if (respData.event === 'destroy') {
- try {
- console.debug('destroying worker', this.contentURL);
- this.destroy();
- } catch (e) {
- console.debug('in worker', e);
- }
- }
- }
+ ],
+ contentScriptWhen: "end",
+ onMessage: function (respData) {
+ console.debug(JSON.stringify(respData));
+ console.debug(originalWorker.url);
+ originalWorker.postMessage(respData);
+
+ if (respData.event === 'destroy') {
+ try {
+ console.debug('destroying worker', this.contentURL);
+ this.destroy();
+ } catch (e) {
+ console.debug('in worker', e);
+ }
+ }
+ }
});
}
};
-
-
-
exports.testModule = {
-
- 'contactList': contactList,
-
- 'foundInContactList': foundInContactList,
-
- 'tabProcess': tabProcess
-
+ 'contactList': contactList,
+ 'foundInContactList': foundInContactList,
+ 'tabProcess': tabProcess
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_punycode.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_punycode.js
index 64d8c61..163923c 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_punycode.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_punycode.js
@@ -1,219 +1,510 @@
-// Copyright (C) 2011 by Ben Noordhuis <info@bnoordhuis.nl>
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-exports.encode = encode;
-exports.decode = decode;
-
-var TMIN = 1;
-var TMAX = 26;
-var BASE = 36;
-var SKEW = 38;
-var DAMP = 700; // initial bias scaler
-var INITIAL_N = 128;
-var INITIAL_BIAS = 72;
-var MAX_INTEGER = Math.pow(2, 53);
-
-function adapt_bias(delta, n_points, is_first) {
- // scale back, then increase delta
- delta /= is_first ? DAMP : 2;
- delta += ~~(delta / n_points);
-
- var s = (BASE - TMIN);
- var t = ~~((s * TMAX) / 2); // threshold=455
-
- for (var k = 0; delta > t; k += BASE) {
- delta = ~~(delta / s);
- }
-
- var a = (BASE - TMIN + 1) * delta;
- var b = (delta + SKEW);
-
- return k + ~~(a / b);
-}
-
-function next_smallest_codepoint(codepoints, n) {
- var m = 0x110000; // unicode upper bound + 1
-
- for (var i = 0, len = codepoints.length; i < len; ++i) {
- var c = codepoints[i];
- if (c >= n && c < m) {
- m = c;
- }
- }
-
- // sanity check - should not happen
- if (m >= 0x110000) {
- throw new Error('Next smallest code point not found.');
- }
-
- return m;
-}
-
-function encode_digit(d) {
- return d + (d < 26 ? 97 : 22);
-}
-
-function decode_digit(d) {
- if (d >= 48 && d <= 57) {
- return d - 22; // 0..9
- }
- if (d >= 65 && d <= 90) {
- return d - 65; // A..Z
- }
- if (d >= 97 && d <= 122) {
- return d - 97; // a..z
- }
- throw new Error('Illegal digit #' + d);
-}
-
-function threshold(k, bias) {
- if (k <= bias + TMIN) {
- return TMIN;
- }
- if (k >= bias + TMAX) {
- return TMAX;
- }
- return k - bias;
-}
-
-function encode_int(bias, delta) {
- var result = [];
-
- for (var k = BASE, q = delta;; k += BASE) {
- var t = threshold(k, bias);
- if (q < t) {
- result.push(encode_digit(q));
- break;
- }
- else {
- result.push(encode_digit(t + ((q - t) % (BASE - t))));
- q = ~~((q - t) / (BASE - t));
- }
- }
-
- return result;
-}
-
-function encode(input) {
- if (typeof input != 'string') {
- throw new Error('Argument must be a string.');
- }
-
- input = input.split('').map(function(c) {
- return c.charCodeAt(0);
- });
-
- var output = [];
- var non_basic = [];
-
- for (var i = 0, len = input.length; i < len; ++i) {
- var c = input[i];
- if (c < 128) {
- output.push(c);
- }
- else {
- non_basic.push(c);
- }
- }
-
- var b, h;
- b = h = output.length;
-
- if (b) {
- output.push(45); // delimiter '-'
- }
-
- var n = INITIAL_N;
- var bias = INITIAL_BIAS;
- var delta = 0;
-
- for (var len = input.length; h < len; ++n, ++delta) {
- var m = next_smallest_codepoint(non_basic, n);
- delta += (m - n) * (h + 1);
- n = m;
-
- for (var i = 0; i < len; ++i) {
- var c = input[i];
- if (c < n) {
- if (++delta == MAX_INTEGER) {
- throw new Error('Delta overflow.');
- }
- }
- else if (c == n) {
- // TODO append in-place?
- // i.e. -> output.push.apply(output, encode_int(bias, delta));
- output = output.concat(encode_int(bias, delta));
- bias = adapt_bias(delta, h + 1, b == h);
- delta = 0;
- h++;
- }
- }
- }
-
- return String.fromCharCode.apply(String, output);
-}
-
-function decode(input) {
- if (typeof input != 'string') {
- throw new Error('Argument must be a string.');
- }
-
- // find basic code points/delta separator
- var b = 1 + input.lastIndexOf('-');
-
- input = input.split('').map(function(c) {
- return c.charCodeAt(0);
- });
-
- // start with a copy of the basic code points
- var output = input.slice(0, b ? (b - 1) : 0);
-
- var n = INITIAL_N;
- var bias = INITIAL_BIAS;
-
- for (var i = 0, len = input.length; b < len; ++i) {
- var org_i = i;
-
- for (var k = BASE, w = 1;; k += BASE) {
- var d = decode_digit(input[b++]);
-
- // TODO overflow check
- i += d * w;
-
- var t = threshold(k, bias);
- if (d < t) {
- break;
- }
-
- // TODO overflow check
- w *= BASE - t;
- }
-
- var x = 1 + output.length;
- bias = adapt_bias(i - org_i, x, org_i == 0);
- // TODO overflow check
- n += ~~(i / x);
- i %= x;
-
- output.splice(i, 0, n);
- }
-
- return String.fromCharCode.apply(String, output);
-}
+/*! http://mths.be/punycode v1.2.0 by @mathias */
+;(function(root) {
+
+ /**
+ * The `punycode` object.
+ * @name punycode
+ * @type Object
+ */
+ var punycode,
+
+ /** Detect free variables `define`, `exports`, `module` and `require` */
+ freeDefine = typeof define == 'function' && typeof define.amd == 'object' &&
+ define.amd && define,
+ freeExports = typeof exports == 'object' && exports,
+ freeModule = typeof module == 'object' && module,
+ freeRequire = typeof require == 'function' && require,
+
+ /** Highest positive signed 32-bit float value */
+ maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
+
+ /** Bootstring parameters */
+ base = 36,
+ tMin = 1,
+ tMax = 26,
+ skew = 38,
+ damp = 700,
+ initialBias = 72,
+ initialN = 128, // 0x80
+ delimiter = '-', // '\x2D'
+
+ /** Regular expressions */
+ regexPunycode = /^xn--/,
+ regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars
+ regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators
+
+ /** Error messages */
+ errors = {
+ 'overflow': 'Overflow: input needs wider integers to process',
+ 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
+ 'invalid-input': 'Invalid input'
+ },
+
+ /** Convenience shortcuts */
+ baseMinusTMin = base - tMin,
+ floor = Math.floor,
+ stringFromCharCode = String.fromCharCode,
+
+ /** Temporary variable */
+ key;
+
+ /*--------------------------------------------------------------------------*/
+
+ /**
+ * A generic error utility function.
+ * @private
+ * @param {String} type The error type.
+ * @returns {Error} Throws a `RangeError` with the applicable error message.
+ */
+ function error(type) {
+ throw RangeError(errors[type]);
+ }
+
+ /**
+ * A generic `Array#map` utility function.
+ * @private
+ * @param {Array} array The array to iterate over.
+ * @param {Function} callback The function that gets called for every array
+ * item.
+ * @returns {Array} A new array of values returned by the callback function.
+ */
+ function map(array, fn) {
+ var length = array.length;
+ while (length--) {
+ array[length] = fn(array[length]);
+ }
+ return array;
+ }
+
+ /**
+ * A simple `Array#map`-like wrapper to work with domain name strings.
+ * @private
+ * @param {String} domain The domain name.
+ * @param {Function} callback The function that gets called for every
+ * character.
+ * @returns {Array} A new string of characters returned by the callback
+ * function.
+ */
+ function mapDomain(string, fn) {
+ return map(string.split(regexSeparators), fn).join('.');
+ }
+
+ /**
+ * Creates an array containing the decimal code points of each Unicode
+ * character in the string. While JavaScript uses UCS-2 internally,
+ * this function will convert a pair of surrogate halves (each of which
+ * UCS-2 exposes as separate characters) into a single code point,
+ * matching UTF-16.
+ * @see `punycode.ucs2.encode`
+ * @see <http://mathiasbynens.be/notes/javascript-encoding>
+ * @memberOf punycode.ucs2
+ * @name decode
+ * @param {String} string The Unicode input string (UCS-2).
+ * @returns {Array} The new array of code points.
+ */
+ function ucs2decode(string) {
+ var output = [],
+ counter = 0,
+ length = string.length,
+ value,
+ extra;
+ while (counter < length) {
+ value = string.charCodeAt(counter++);
+ if ((value & 0xF800) == 0xD800 && counter < length) {
+ // high surrogate, and there is a next character
+ extra = string.charCodeAt(counter++);
+ if ((extra & 0xFC00) == 0xDC00) { // low surrogate
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
+ } else {
+ output.push(value, extra);
+ }
+ } else {
+ output.push(value);
+ }
+ }
+ return output;
+ }
+
+ /**
+ * Creates a string based on an array of decimal code points.
+ * @see `punycode.ucs2.decode`
+ * @memberOf punycode.ucs2
+ * @name encode
+ * @param {Array} codePoints The array of decimal code points.
+ * @returns {String} The new Unicode string (UCS-2).
+ */
+ function ucs2encode(array) {
+ return map(array, function(value) {
+ var output = '';
+ if (value > 0xFFFF) {
+ value -= 0x10000;
+ output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
+ value = 0xDC00 | value & 0x3FF;
+ }
+ output += stringFromCharCode(value);
+ return output;
+ }).join('');
+ }
+
+ /**
+ * Converts a basic code point into a digit/integer.
+ * @see `digitToBasic()`
+ * @private
+ * @param {Number} codePoint The basic (decimal) code point.
+ * @returns {Number} The numeric value of a basic code point (for use in
+ * representing integers) in the range `0` to `base - 1`, or `base` if
+ * the code point does not represent a value.
+ */
+ function basicToDigit(codePoint) {
+ return codePoint - 48 < 10
+ ? codePoint - 22
+ : codePoint - 65 < 26
+ ? codePoint - 65
+ : codePoint - 97 < 26
+ ? codePoint - 97
+ : base;
+ }
+
+ /**
+ * Converts a digit/integer into a basic code point.
+ * @see `basicToDigit()`
+ * @private
+ * @param {Number} digit The numeric value of a basic code point.
+ * @returns {Number} The basic code point whose value (when used for
+ * representing integers) is `digit`, which needs to be in the range
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
+ * used; else, the lowercase form is used. The behavior is undefined
+ * if flag is non-zero and `digit` has no uppercase form.
+ */
+ function digitToBasic(digit, flag) {
+ // 0..25 map to ASCII a..z or A..Z
+ // 26..35 map to ASCII 0..9
+ return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
+ }
+
+ /**
+ * Bias adaptation function as per section 3.4 of RFC 3492.
+ * http://tools.ietf.org/html/rfc3492#section-3.4
+ * @private
+ */
+ function adapt(delta, numPoints, firstTime) {
+ var k = 0;
+ delta = firstTime ? floor(delta / damp) : delta >> 1;
+ delta += floor(delta / numPoints);
+ for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
+ delta = floor(delta / baseMinusTMin);
+ }
+ return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
+ }
+
+ /**
+ * Converts a basic code point to lowercase if `flag` is falsy, or to
+ * uppercase if `flag` is truthy. The code point is unchanged if it's
+ * caseless. The behavior is undefined if `codePoint` is not a basic code
+ * point.
+ * @private
+ * @param {Number} codePoint The numeric value of a basic code point.
+ * @returns {Number} The resulting basic code point.
+ */
+ function encodeBasic(codePoint, flag) {
+ codePoint -= (codePoint - 97 < 26) << 5;
+ return codePoint + (!flag && codePoint - 65 < 26) << 5;
+ }
+
+ /**
+ * Converts a Punycode string of ASCII code points to a string of Unicode
+ * code points.
+ * @memberOf punycode
+ * @param {String} input The Punycode string of ASCII code points.
+ * @returns {String} The resulting string of Unicode code points.
+ */
+ function decode(input) {
+ // Don't use UCS-2
+ var output = [],
+ inputLength = input.length,
+ out,
+ i = 0,
+ n = initialN,
+ bias = initialBias,
+ basic,
+ j,
+ index,
+ oldi,
+ w,
+ k,
+ digit,
+ t,
+ length,
+ /** Cached calculation results */
+ baseMinusT;
+
+ // Handle the basic code points: let `basic` be the number of input code
+ // points before the last delimiter, or `0` if there is none, then copy
+ // the first basic code points to the output.
+
+ basic = input.lastIndexOf(delimiter);
+ if (basic < 0) {
+ basic = 0;
+ }
+
+ for (j = 0; j < basic; ++j) {
+ // if it's not a basic code point
+ if (input.charCodeAt(j) >= 0x80) {
+ error('not-basic');
+ }
+ output.push(input.charCodeAt(j));
+ }
+
+ // Main decoding loop: start just after the last delimiter if any basic code
+ // points were copied; start at the beginning otherwise.
+
+ for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
+
+ // `index` is the index of the next character to be consumed.
+ // Decode a generalized variable-length integer into `delta`,
+ // which gets added to `i`. The overflow checking is easier
+ // if we increase `i` as we go, then subtract off its starting
+ // value at the end to obtain `delta`.
+ for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
+
+ if (index >= inputLength) {
+ error('invalid-input');
+ }
+
+ digit = basicToDigit(input.charCodeAt(index++));
+
+ if (digit >= base || digit > floor((maxInt - i) / w)) {
+ error('overflow');
+ }
+
+ i += digit * w;
+ t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
+
+ if (digit < t) {
+ break;
+ }
+
+ baseMinusT = base - t;
+ if (w > floor(maxInt / baseMinusT)) {
+ error('overflow');
+ }
+
+ w *= baseMinusT;
+
+ }
+
+ out = output.length + 1;
+ bias = adapt(i - oldi, out, oldi == 0);
+
+ // `i` was supposed to wrap around from `out` to `0`,
+ // incrementing `n` each time, so we'll fix that now:
+ if (floor(i / out) > maxInt - n) {
+ error('overflow');
+ }
+
+ n += floor(i / out);
+ i %= out;
+
+ // Insert `n` at position `i` of the output
+ output.splice(i++, 0, n);
+
+ }
+
+ return ucs2encode(output);
+ }
+
+ /**
+ * Converts a string of Unicode code points to a Punycode string of ASCII
+ * code points.
+ * @memberOf punycode
+ * @param {String} input The string of Unicode code points.
+ * @returns {String} The resulting Punycode string of ASCII code points.
+ */
+ function encode(input) {
+ var n,
+ delta,
+ handledCPCount,
+ basicLength,
+ bias,
+ j,
+ m,
+ q,
+ k,
+ t,
+ currentValue,
+ output = [],
+ /** `inputLength` will hold the number of code points in `input`. */
+ inputLength,
+ /** Cached calculation results */
+ handledCPCountPlusOne,
+ baseMinusT,
+ qMinusT;
+
+ // Convert the input in UCS-2 to Unicode
+ input = ucs2decode(input);
+
+ // Cache the length
+ inputLength = input.length;
+
+ // Initialize the state
+ n = initialN;
+ delta = 0;
+ bias = initialBias;
+
+ // Handle the basic code points
+ for (j = 0; j < inputLength; ++j) {
+ currentValue = input[j];
+ if (currentValue < 0x80) {
+ output.push(stringFromCharCode(currentValue));
+ }
+ }
+
+ handledCPCount = basicLength = output.length;
+
+ // `handledCPCount` is the number of code points that have been handled;
+ // `basicLength` is the number of basic code points.
+
+ // Finish the basic string - if it is not empty - with a delimiter
+ if (basicLength) {
+ output.push(delimiter);
+ }
+
+ // Main encoding loop:
+ while (handledCPCount < inputLength) {
+
+ // All non-basic code points < n have been handled already. Find the next
+ // larger one:
+ for (m = maxInt, j = 0; j < inputLength; ++j) {
+ currentValue = input[j];
+ if (currentValue >= n && currentValue < m) {
+ m = currentValue;
+ }
+ }
+
+ // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
+ // but guard against overflow
+ handledCPCountPlusOne = handledCPCount + 1;
+ if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
+ error('overflow');
+ }
+
+ delta += (m - n) * handledCPCountPlusOne;
+ n = m;
+
+ for (j = 0; j < inputLength; ++j) {
+ currentValue = input[j];
+
+ if (currentValue < n && ++delta > maxInt) {
+ error('overflow');
+ }
+
+ if (currentValue == n) {
+ // Represent delta as a generalized variable-length integer
+ for (q = delta, k = base; /* no condition */; k += base) {
+ t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
+ if (q < t) {
+ break;
+ }
+ qMinusT = q - t;
+ baseMinusT = base - t;
+ output.push(
+ stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
+ );
+ q = floor(qMinusT / baseMinusT);
+ }
+
+ output.push(stringFromCharCode(digitToBasic(q, 0)));
+ bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
+ delta = 0;
+ ++handledCPCount;
+ }
+ }
+
+ ++delta;
+ ++n;
+
+ }
+ return output.join('');
+ }
+
+ /**
+ * Converts a Punycode string representing a domain name to Unicode. Only the
+ * Punycoded parts of the domain name will be converted, i.e. it doesn't
+ * matter if you call it on a string that has already been converted to
+ * Unicode.
+ * @memberOf punycode
+ * @param {String} domain The Punycode domain name to convert to Unicode.
+ * @returns {String} The Unicode representation of the given Punycode
+ * string.
+ */
+ function toUnicode(domain) {
+ return mapDomain(domain, function(string) {
+ return regexPunycode.test(string)
+ ? decode(string.slice(4).toLowerCase())
+ : string;
+ });
+ }
+
+ /**
+ * Converts a Unicode string representing a domain name to Punycode. Only the
+ * non-ASCII parts of the domain name will be converted, i.e. it doesn't
+ * matter if you call it with a domain that's already in ASCII.
+ * @memberOf punycode
+ * @param {String} domain The domain name to convert, as a Unicode string.
+ * @returns {String} The Punycode representation of the given domain name.
+ */
+ function toASCII(domain) {
+ return mapDomain(domain, function(string) {
+ return regexNonASCII.test(string)
+ ? 'xn--' + encode(string)
+ : string;
+ });
+ }
+
+ /*--------------------------------------------------------------------------*/
+
+ /** Define the public API */
+ punycode = {
+ /**
+ * A string representing the current Punycode.js version number.
+ * @memberOf punycode
+ * @type String
+ */
+ 'version': '1.2.0',
+ /**
+ * An object of methods to convert from JavaScript's internal character
+ * representation (UCS-2) to decimal Unicode code points, and back.
+ * @see <http://mathiasbynens.be/notes/javascript-encoding>
+ * @memberOf punycode
+ * @type Object
+ */
+ 'ucs2': {
+ 'decode': ucs2decode,
+ 'encode': ucs2encode
+ },
+ 'decode': decode,
+ 'encode': encode,
+ 'toASCII': toASCII,
+ 'toUnicode': toUnicode
+ };
+
+ /** Expose `punycode` */
+ if (freeExports) {
+ if (freeModule && freeModule.exports == freeExports) {
+ // in Node.js or Ringo 0.8+
+ freeModule.exports = punycode;
+ } else {
+ // in Narwhal or Ringo 0.7-
+ for (key in punycode) {
+ punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
+ }
+ }
+ } else if (freeDefine) {
+ // via curl.js or RequireJS
+ define('punycode', punycode);
+ } else {
+ // in a browser or Rhino
+ root.punycode = punycode;
+ }
+
+}(this));
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_querystring.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_querystring.js
index 3314061..f8c7921 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_querystring.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_querystring.js
@@ -22,7 +22,6 @@
// Query String Utilities
var QueryString = exports;
-//var urlDecode = process.binding('http_parser').urlDecode;
// If obj.hasOwnProperty has been overridden, then calling
@@ -47,55 +46,55 @@ QueryString.unescapeBuffer = function(s, decodeSpaces) {
for (var inIndex = 0, outIndex = 0; inIndex <= s.length; inIndex++) {
var c = s.charCodeAt(inIndex);
switch (state) {
- case 'CHAR':
- switch (c) {
- case charCode('%'):
- n = 0;
- m = 0;
- state = 'HEX0';
+ case 'CHAR':
+ switch (c) {
+ case charCode('%'):
+ n = 0;
+ m = 0;
+ state = 'HEX0';
+ break;
+ case charCode('+'):
+ if (decodeSpaces) c = charCode(' ');
+ // pass thru
+ default:
+ out[outIndex++] = c;
+ break;
+ }
break;
- case charCode('+'):
- if (decodeSpaces) c = charCode(' ');
- // pass thru
- default:
- out[outIndex++] = c;
+
+ case 'HEX0':
+ state = 'HEX1';
+ hexchar = c;
+ if (charCode('0') <= c && c <= charCode('9')) {
+ n = c - charCode('0');
+ } else if (charCode('a') <= c && c <= charCode('f')) {
+ n = c - charCode('a') + 10;
+ } else if (charCode('A') <= c && c <= charCode('F')) {
+ n = c - charCode('A') + 10;
+ } else {
+ out[outIndex++] = charCode('%');
+ out[outIndex++] = c;
+ state = 'CHAR';
+ break;
+ }
break;
- }
- break;
-
- case 'HEX0':
- state = 'HEX1';
- hexchar = c;
- if (charCode('0') <= c && c <= charCode('9')) {
- n = c - charCode('0');
- } else if (charCode('a') <= c && c <= charCode('f')) {
- n = c - charCode('a') + 10;
- } else if (charCode('A') <= c && c <= charCode('F')) {
- n = c - charCode('A') + 10;
- } else {
- out[outIndex++] = charCode('%');
- out[outIndex++] = c;
+
+ case 'HEX1':
state = 'CHAR';
+ if (charCode('0') <= c && c <= charCode('9')) {
+ m = c - charCode('0');
+ } else if (charCode('a') <= c && c <= charCode('f')) {
+ m = c - charCode('a') + 10;
+ } else if (charCode('A') <= c && c <= charCode('F')) {
+ m = c - charCode('A') + 10;
+ } else {
+ out[outIndex++] = charCode('%');
+ out[outIndex++] = hexchar;
+ out[outIndex++] = c;
+ break;
+ }
+ out[outIndex++] = 16 * n + m;
break;
- }
- break;
-
- case 'HEX1':
- state = 'CHAR';
- if (charCode('0') <= c && c <= charCode('9')) {
- m = c - charCode('0');
- } else if (charCode('a') <= c && c <= charCode('f')) {
- m = c - charCode('a') + 10;
- } else if (charCode('A') <= c && c <= charCode('F')) {
- m = c - charCode('A') + 10;
- } else {
- out[outIndex++] = charCode('%');
- out[outIndex++] = hexchar;
- out[outIndex++] = c;
- break;
- }
- out[outIndex++] = 16 * n + m;
- break;
}
}
@@ -106,7 +105,11 @@ QueryString.unescapeBuffer = function(s, decodeSpaces) {
QueryString.unescape = function(s, decodeSpaces) {
- return QueryString.unescapeBuffer(s, decodeSpaces).toString();
+ try {
+ return decodeURIComponent(s);
+ } catch (e) {
+ return QueryString.unescapeBuffer(s, decodeSpaces).toString();
+ }
};
@@ -116,17 +119,17 @@ QueryString.escape = function(str) {
var stringifyPrimitive = function(v) {
switch (typeof v) {
- case 'string':
- return v;
+ case 'string':
+ return v;
- case 'boolean':
- return v ? 'true' : 'false';
+ case 'boolean':
+ return v ? 'true' : 'false';
- case 'number':
- return isFinite(v) ? v : '';
+ case 'number':
+ return isFinite(v) ? v : '';
- default:
- return '';
+ default:
+ return '';
}
};
@@ -134,33 +137,31 @@ var stringifyPrimitive = function(v) {
QueryString.stringify = QueryString.encode = function(obj, sep, eq, name) {
sep = sep || '&';
eq = eq || '=';
- obj = (obj === null) ? undefined : obj;
+ if (obj === null) {
+ obj = undefined;
+ }
- switch (typeof obj) {
- case 'object':
+ if (typeof obj === 'object') {
return Object.keys(obj).map(function(k) {
+ var ks = QueryString.escape(stringifyPrimitive(k)) + eq;
if (Array.isArray(obj[k])) {
return obj[k].map(function(v) {
- return QueryString.escape(stringifyPrimitive(k)) +
- eq +
- QueryString.escape(stringifyPrimitive(v));
+ return ks + QueryString.escape(stringifyPrimitive(v));
}).join(sep);
} else {
- return QueryString.escape(stringifyPrimitive(k)) +
- eq +
- QueryString.escape(stringifyPrimitive(obj[k]));
+ return ks + QueryString.escape(stringifyPrimitive(obj[k]));
}
}).join(sep);
- default:
- if (!name) return '';
- return QueryString.escape(stringifyPrimitive(name)) + eq +
- QueryString.escape(stringifyPrimitive(obj));
}
+
+ if (!name) return '';
+ return QueryString.escape(stringifyPrimitive(name)) + eq +
+ QueryString.escape(stringifyPrimitive(obj));
};
// Parse a key=val string.
-QueryString.parse = QueryString.decode = function(qs, sep, eq) {
+QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
sep = sep || '&';
eq = eq || '=';
var obj = {};
@@ -169,19 +170,44 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq) {
return obj;
}
- qs.split(sep).forEach(function(kvp) {
- var x = kvp.split(eq);
- var k = QueryString.unescape(x[0], true);
- var v = QueryString.unescape(x.slice(1).join(eq), true);
+ var regexp = /\+/g;
+ qs = qs.split(sep);
+
+ var maxKeys = 1000;
+ if (options && typeof options.maxKeys === 'number') {
+ maxKeys = options.maxKeys;
+ }
+
+ var len = qs.length;
+ // maxKeys <= 0 means that we should not limit keys count
+ if (maxKeys > 0 && len > maxKeys) {
+ len = maxKeys;
+ }
+
+ for (var i = 0; i < len; ++i) {
+ var x = qs[i].replace(regexp, '%20'),
+ idx = x.indexOf(eq),
+ kstr, vstr, k, v;
+
+ if (idx >= 0) {
+ kstr = x.substr(0, idx);
+ vstr = x.substr(idx + 1);
+ } else {
+ kstr = x;
+ vstr = '';
+ }
+
+ k = QueryString.unescape(kstr, true);
+ v = QueryString.unescape(vstr, true);
if (!hasOwnProperty(obj, k)) {
obj[k] = v;
- } else if (!Array.isArray(obj[k])) {
- obj[k] = [obj[k], v];
- } else {
+ } else if (Array.isArray(obj[k])) {
obj[k].push(v);
+ } else {
+ obj[k] = [obj[k], v];
}
- });
+ }
return obj;
};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_url.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_url.js
index 6b4940f..71d31a6 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_url.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/node_url.js
@@ -26,28 +26,49 @@ exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
+exports.Url = Url;
+
+function Url() {
+ this.protocol = null;
+ this.slashes = null;
+ this.auth = null;
+ this.host = null;
+ this.port = null;
+ this.hostname = null;
+ this.hash = null;
+ this.search = null;
+ this.query = null;
+ this.pathname = null;
+ this.path = null;
+ this.href = null;
+}
+
// Reference: RFC 3986, RFC 1808, RFC 2396
// define these here so at least they only have to be
// compiled once on the first module load.
var protocolPattern = /^([a-z0-9.+-]+:)/i,
- portPattern = /:[0-9]+$/,
+ portPattern = /:[0-9]*$/,
+
// RFC 2396: characters reserved for delimiting URLs.
+ // We actually just auto-escape these.
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
+
// RFC 2396: characters not allowed for various reasons.
- unwise = ['{', '}', '|', '\\', '^', '~', '[', ']', '`'].concat(delims),
+ unwise = ['{', '}', '|', '\\', '^', '~', '`'].concat(delims),
+
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
- autoEscape = ['\''],
+ autoEscape = ['\''].concat(delims),
// Characters that are never ever allowed in a hostname.
// Note that any invalid chars are also handled, but these
// are the ones that are *expected* to be seen, so we fast-path
// them.
nonHostChars = ['%', '/', '?', ';', '#']
.concat(unwise).concat(autoEscape),
- nonAuthChars = ['/', '@', '?', '#'].concat(delims),
+ hostEndingChars = ['/', '?', '#'],
hostnameMaxLen = 255,
- hostnamePartPattern = /^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,
- hostnamePartStart = /^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,
+ hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/,
+ hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/,
// protocols that can allow "unsafe" and "unwise" chars.
unsafeProtocol = {
'javascript': true,
@@ -58,18 +79,6 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
'javascript': true,
'javascript:': true
},
- // protocols that always have a path component.
- pathedProtocol = {
- 'http': true,
- 'https': true,
- 'ftp': true,
- 'gopher': true,
- 'file': true,
- 'http:': true,
- 'ftp:': true,
- 'gopher:': true,
- 'file:': true
- },
// protocols that always contain a // bit.
slashedProtocol = {
'http': true,
@@ -86,28 +95,35 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
querystring = require('url_handler/node_querystring');
function urlParse(url, parseQueryString, slashesDenoteHost) {
- if (url && typeof(url) === 'object' && url.href) return url;
+ if (url && typeof(url) === 'object' && url instanceof Url) return url;
+
+ var u = new Url;
+ u.parse(url, parseQueryString, slashesDenoteHost);
+ return u;
+}
+Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
if (typeof url !== 'string') {
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
}
- var out = {},
- rest = url;
- out.href = "";
- // cut off any delimiters.
- // This is to support parse stuff like "<http://foo.com>"
- for (var i = 0, l = rest.length; i < l; i++) {
- if (delims.indexOf(rest.charAt(i)) === -1) break;
- }
- if (i !== 0) rest = rest.substr(i);
+ // Copy chrome, IE, opera backslash-handling behavior.
+ // See: https://code.google.com/p/chromium/issues/detail?id=25916
+ var hashSplit = url.split('#');
+ hashSplit[0] = hashSplit[0].replace(/\\/g, '/');
+ url = hashSplit.join('#');
+ var rest = url;
+
+ // trim before proceeding.
+ // This is to support parse stuff like " http://foo.com \n"
+ rest = rest.trim();
var proto = protocolPattern.exec(rest);
if (proto) {
proto = proto[0];
var lowerProto = proto.toLowerCase();
- out.protocol = lowerProto;
+ this.protocol = lowerProto;
rest = rest.substr(proto.length);
}
@@ -119,71 +135,85 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
var slashes = rest.substr(0, 2) === '//';
if (slashes && !(proto && hostlessProtocol[proto])) {
rest = rest.substr(2);
- out.slashes = true;
+ this.slashes = true;
}
}
if (!hostlessProtocol[proto] &&
(slashes || (proto && !slashedProtocol[proto]))) {
+
// there's a hostname.
// the first instance of /, ?, ;, or # ends the host.
- // don't enforce full RFC correctness, just be unstupid about it.
-
+ //
// If there is an @ in the hostname, then non-host chars *are* allowed
- // to the left of the first @ sign, unless some non-auth character
+ // to the left of the last @ sign, unless some host-ending character
// comes *before* the @-sign.
// URLs are obnoxious.
- var atSign = rest.indexOf('@');
- if (atSign !== -1) {
- // there *may be* an auth
- var hasAuth = true;
- for (var i = 0, l = nonAuthChars.length; i < l; i++) {
- var index = rest.indexOf(nonAuthChars[i]);
- if (index !== -1 && index < atSign) {
- // not a valid auth. Something like http://foo.com/bar@baz/
- hasAuth = false;
- break;
- }
- }
- if (hasAuth) {
- // pluck off the auth portion.
- out.auth = rest.substr(0, atSign);
- rest = rest.substr(atSign + 1);
- }
+ //
+ // ex:
+ // http://a@b@c/ => user:a@b host:c
+ // http://a@b?@c => user:a host:c path:/?@c
+
+ // v0.12 TODO(isaacs): This is not quite how Chrome does things.
+ // Review our test case against browsers more comprehensively.
+
+ // find the first instance of any hostEndingChars
+ var hostEnd = -1;
+ for (var i = 0; i < hostEndingChars.length; i++) {
+ var hec = rest.indexOf(hostEndingChars[i]);
+ if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
+ hostEnd = hec;
}
- var firstNonHost = -1;
- for (var i = 0, l = nonHostChars.length; i < l; i++) {
- var index = rest.indexOf(nonHostChars[i]);
- if (index !== -1 &&
- (firstNonHost < 0 || index < firstNonHost)) firstNonHost = index;
+ // at this point, either we have an explicit point where the
+ // auth portion cannot go past, or the last @ char is the decider.
+ var auth, atSign;
+ if (hostEnd === -1) {
+ // atSign can be anywhere.
+ atSign = rest.lastIndexOf('@');
+ } else {
+ // atSign must be in auth portion.
+ // http://a@b/c@d => host:b auth:a path:/c@d
+ atSign = rest.lastIndexOf('@', hostEnd);
}
- if (firstNonHost !== -1) {
- out.host = rest.substr(0, firstNonHost);
- rest = rest.substr(firstNonHost);
- } else {
- out.host = rest;
- rest = '';
+ // Now we have a portion which is definitely the auth.
+ // Pull that off.
+ if (atSign !== -1) {
+ auth = rest.slice(0, atSign);
+ rest = rest.slice(atSign + 1);
+ this.auth = decodeURIComponent(auth);
}
- // pull out port.
- var p = parseHost(out.host);
- var keys = Object.keys(p);
- for (var i = 0, l = keys.length; i < l; i++) {
- var key = keys[i];
- out[key] = p[key];
+ // the host is the remaining to the left of the first non-host char
+ hostEnd = -1;
+ for (var i = 0; i < nonHostChars.length; i++) {
+ var hec = rest.indexOf(nonHostChars[i]);
+ if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
+ hostEnd = hec;
}
+ // if we still have not hit it, then the entire thing is a host.
+ if (hostEnd === -1)
+ hostEnd = rest.length;
+
+ this.host = rest.slice(0, hostEnd);
+ rest = rest.slice(hostEnd);
+
+ // pull out port.
+ this.parseHost();
// we've indicated that there is a hostname,
// so even if it's empty, it has to be present.
- out.hostname = out.hostname || '';
+ this.hostname = this.hostname || '';
+
+ // if hostname begins with [ and ends with ]
+ // assume that it's an IPv6 address.
+ var ipv6Hostname = this.hostname[0] === '[' &&
+ this.hostname[this.hostname.length - 1] === ']';
// validate a little.
- if (out.hostname.length > hostnameMaxLen) {
- out.hostname = '';
- } else {
- var hostparts = out.hostname.split(/\./);
+ if (!ipv6Hostname) {
+ var hostparts = this.hostname.split(/\./);
for (var i = 0, l = hostparts.length; i < l; i++) {
var part = hostparts[i];
if (!part) continue;
@@ -211,32 +241,41 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
if (notHost.length) {
rest = '/' + notHost.join('.') + rest;
}
- out.hostname = validParts.join('.');
+ this.hostname = validParts.join('.');
break;
}
}
}
}
- // hostnames are always lower case.
- out.hostname = out.hostname.toLowerCase();
-
- // IDNA Support: Returns a puny coded representation of "domain".
- // It only converts the part of the domain name that
- // has non ASCII characters. I.e. it dosent matter if
- // you call it with a domain that already is in ASCII.
- var domainArray = out.hostname.split('.');
- var newOut = [];
- for (var i = 0; i < domainArray.length; ++i) {
- var s = domainArray[i];
- newOut.push(s.match(/[^A-Za-z0-9_-]/) ?
- 'xn--' + punycode.encode(s) : s);
+ if (this.hostname.length > hostnameMaxLen) {
+ this.hostname = '';
+ } else {
+ // hostnames are always lower case.
+ this.hostname = this.hostname.toLowerCase();
+ }
+
+ if (!ipv6Hostname) {
+ // IDNA Support: Returns a punycoded representation of "domain".
+ // It only converts parts of the domain name that
+ // have non-ASCII characters, i.e. it doesn't matter if
+ // you call it with a domain that already is ASCII-only.
+ this.hostname = punycode.toASCII(this.hostname);
}
- out.hostname = newOut.join('.');
- out.host = (out.hostname || '') +
- ((out.port) ? ':' + out.port : '');
- out.href += out.host;
+ var p = this.port ? ':' + this.port : '';
+ var h = this.hostname || '';
+ this.host = h + p;
+ this.href += this.host;
+
+ // strip [ and ] from the hostname
+ // the host field still retains them, though
+ if (ipv6Hostname) {
+ this.hostname = this.hostname.substr(1, this.hostname.length - 2);
+ if (rest[0] !== '/') {
+ rest = '/' + rest;
+ }
+ }
}
// now rest is set to the post-host stuff.
@@ -254,16 +293,6 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
}
rest = rest.split(ae).join(esc);
}
-
- // Now make sure that delims never appear in a url.
- var chop = rest.length;
- for (var i = 0, l = delims.length; i < l; i++) {
- var c = rest.indexOf(delims[i]);
- if (c !== -1) {
- chop = Math.min(c, chop);
- }
- }
- rest = rest.substr(0, chop);
}
@@ -271,38 +300,39 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
var hash = rest.indexOf('#');
if (hash !== -1) {
// got a fragment string.
- out.hash = rest.substr(hash);
+ this.hash = rest.substr(hash);
rest = rest.slice(0, hash);
}
var qm = rest.indexOf('?');
if (qm !== -1) {
- out.search = rest.substr(qm);
- out.query = rest.substr(qm + 1);
+ this.search = rest.substr(qm);
+ this.query = rest.substr(qm + 1);
if (parseQueryString) {
- out.query = querystring.parse(out.query);
+ this.query = querystring.parse(this.query);
}
rest = rest.slice(0, qm);
} else if (parseQueryString) {
// no query string, but parseQueryString still requested
- out.search = '';
- out.query = {};
+ this.search = '';
+ this.query = {};
}
- if (rest) out.pathname = rest;
- if (slashedProtocol[proto] &&
- out.hostname && !out.pathname) {
- out.pathname = '/';
+ if (rest) this.pathname = rest;
+ if (slashedProtocol[lowerProto] &&
+ this.hostname && !this.pathname) {
+ this.pathname = '/';
}
//to support http.request
- if (out.pathname || out.search) {
- out.path = (out.pathname ? out.pathname : '') +
- (out.search ? out.search : '');
+ if (this.pathname || this.search) {
+ var p = this.pathname || '';
+ var s = this.search || '';
+ this.path = p + s;
}
// finally, reconstruct the href based on what has been validated.
- out.href = urlFormat(out);
- return out;
-}
+ this.href = this.format();
+ return this;
+};
// format a parsed object into a url string
function urlFormat(obj) {
@@ -311,38 +341,47 @@ function urlFormat(obj) {
// this way, you can call url_format() on strings
// to clean up potentially wonky urls.
if (typeof(obj) === 'string') obj = urlParse(obj);
+ if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
+ return obj.format();
+}
- var auth = obj.auth || '';
+Url.prototype.format = function() {
+ var auth = this.auth || '';
if (auth) {
- auth = auth.split('@').join('%40');
- for (var i = 0, l = nonAuthChars.length; i < l; i++) {
- var nAC = nonAuthChars[i];
- auth = auth.split(nAC).join(encodeURIComponent(nAC));
- }
+ auth = encodeURIComponent(auth);
+ auth = auth.replace(/%3A/i, ':');
auth += '@';
}
- var protocol = obj.protocol || '',
- host = (obj.host !== undefined) ? auth + obj.host :
- obj.hostname !== undefined ? (
- auth + obj.hostname +
- (obj.port ? ':' + obj.port : '')
- ) :
- false,
- pathname = obj.pathname || '',
- query = obj.query &&
- ((typeof obj.query === 'object' &&
- Object.keys(obj.query).length) ?
- querystring.stringify(obj.query) :
- '') || '',
- search = obj.search || (query && ('?' + query)) || '',
- hash = obj.hash || '';
+ var protocol = this.protocol || '',
+ pathname = this.pathname || '',
+ hash = this.hash || '',
+ host = false,
+ query = '';
+
+ if (this.host) {
+ host = auth + this.host;
+ } else if (this.hostname) {
+ host = auth + (this.hostname.indexOf(':') === -1 ?
+ this.hostname :
+ '[' + this.hostname + ']');
+ if (this.port) {
+ host += ':' + this.port;
+ }
+ }
+
+ if (this.query && typeof this.query === 'object' &&
+ Object.keys(this.query).length) {
+ query = querystring.stringify(this.query);
+ }
+
+ var search = this.search || (query && ('?' + query)) || '';
if (protocol && protocol.substr(-1) !== ':') protocol += ':';
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
// unless they had them to begin with.
- if (obj.slashes ||
+ if (this.slashes ||
(!protocol || slashedProtocol[protocol]) && host !== false) {
host = '//' + (host || '');
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
@@ -353,40 +392,68 @@ function urlFormat(obj) {
if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
if (search && search.charAt(0) !== '?') search = '?' + search;
+ pathname = pathname.replace(/[?#]/g, function(match) {
+ return encodeURIComponent(match);
+ });
+ search = search.replace('#', '%23');
+
return protocol + host + pathname + search + hash;
-}
+};
function urlResolve(source, relative) {
- return urlFormat(urlResolveObject(source, relative));
+ return urlParse(source, false, true).resolve(relative);
}
+Url.prototype.resolve = function(relative) {
+ return this.resolveObject(urlParse(relative, false, true)).format();
+};
+
function urlResolveObject(source, relative) {
if (!source) return relative;
+ return urlParse(source, false, true).resolveObject(relative);
+}
+
+Url.prototype.resolveObject = function(relative) {
+ if (typeof relative === 'string') {
+ var rel = new Url();
+ rel.parse(relative, false, true);
+ relative = rel;
+ }
- source = urlParse(urlFormat(source), false, true);
- relative = urlParse(urlFormat(relative), false, true);
+ var result = new Url();
+ Object.keys(this).forEach(function(k) {
+ result[k] = this[k];
+ }, this);
// hash is always overridden, no matter what.
- source.hash = relative.hash;
+ // even href="" will remove it.
+ result.hash = relative.hash;
+ // if the relative url is empty, then there's nothing left to do here.
if (relative.href === '') {
- source.href = urlFormat(source);
- return source;
+ result.href = result.format();
+ return result;
}
// hrefs like //foo/bar always cut to the protocol.
if (relative.slashes && !relative.protocol) {
- relative.protocol = source.protocol;
+ // take everything except the protocol from relative
+ Object.keys(relative).forEach(function(k) {
+ if (k !== 'protocol')
+ result[k] = relative[k];
+ });
+
//urlParse appends trailing / to urls like http://www.example.com
- if (slashedProtocol[relative.protocol] &&
- relative.hostname && !relative.pathname) {
- relative.path = relative.pathname = '/';
+ if (slashedProtocol[result.protocol] &&
+ result.hostname && !result.pathname) {
+ result.path = result.pathname = '/';
}
- relative.href = urlFormat(relative);
- return relative;
+
+ result.href = result.format();
+ return result;
}
- if (relative.protocol && relative.protocol !== source.protocol) {
+ if (relative.protocol && relative.protocol !== result.protocol) {
// if it's a known url protocol, then changing
// the protocol does weird things
// first, if it's not file:, then we MUST have a host,
@@ -396,10 +463,14 @@ function urlResolveObject(source, relative) {
// because that's known to be hostless.
// anything else is assumed to be absolute.
if (!slashedProtocol[relative.protocol]) {
- relative.href = urlFormat(relative);
- return relative;
+ Object.keys(relative).forEach(function(k) {
+ result[k] = relative[k];
+ });
+ result.href = result.format();
+ return result;
}
- source.protocol = relative.protocol;
+
+ result.protocol = relative.protocol;
if (!relative.host && !hostlessProtocol[relative.protocol]) {
var relPath = (relative.pathname || '').split('/');
while (relPath.length && !(relative.host = relPath.shift()));
@@ -407,72 +478,72 @@ function urlResolveObject(source, relative) {
if (!relative.hostname) relative.hostname = '';
if (relPath[0] !== '') relPath.unshift('');
if (relPath.length < 2) relPath.unshift('');
- relative.pathname = relPath.join('/');
+ result.pathname = relPath.join('/');
+ } else {
+ result.pathname = relative.pathname;
}
- source.pathname = relative.pathname;
- source.search = relative.search;
- source.query = relative.query;
- source.host = relative.host || '';
- source.auth = relative.auth;
- source.hostname = relative.hostname || relative.host;
- source.port = relative.port;
- //to support http.request
- if (source.pathname !== undefined || source.search !== undefined) {
- source.path = (source.pathname ? source.pathname : '') +
- (source.search ? source.search : '');
+ result.search = relative.search;
+ result.query = relative.query;
+ result.host = relative.host || '';
+ result.auth = relative.auth;
+ result.hostname = relative.hostname || relative.host;
+ result.port = relative.port;
+ // to support http.request
+ if (result.pathname || result.search) {
+ var p = result.pathname || '';
+ var s = result.search || '';
+ result.path = p + s;
}
- source.slashes = source.slashes || relative.slashes;
- source.href = urlFormat(source);
- return source;
+ result.slashes = result.slashes || relative.slashes;
+ result.href = result.format();
+ return result;
}
- var isSourceAbs = (source.pathname && source.pathname.charAt(0) === '/'),
+ var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
isRelAbs = (
- relative.host !== undefined ||
+ relative.host ||
relative.pathname && relative.pathname.charAt(0) === '/'
),
mustEndAbs = (isRelAbs || isSourceAbs ||
- (source.host && relative.pathname)),
+ (result.host && relative.pathname)),
removeAllDots = mustEndAbs,
- srcPath = source.pathname && source.pathname.split('/') || [],
+ srcPath = result.pathname && result.pathname.split('/') || [],
relPath = relative.pathname && relative.pathname.split('/') || [],
- psychotic = source.protocol &&
- !slashedProtocol[source.protocol];
+ psychotic = result.protocol && !slashedProtocol[result.protocol];
// if the url is a non-slashed url, then relative
// links like ../.. should be able
// to crawl up to the hostname, as well. This is strange.
- // source.protocol has already been set by now.
+ // result.protocol has already been set by now.
// Later on, put the first path part into the host field.
if (psychotic) {
-
- delete source.hostname;
- delete source.port;
- if (source.host) {
- if (srcPath[0] === '') srcPath[0] = source.host;
- else srcPath.unshift(source.host);
+ result.hostname = '';
+ result.port = null;
+ if (result.host) {
+ if (srcPath[0] === '') srcPath[0] = result.host;
+ else srcPath.unshift(result.host);
}
- delete source.host;
+ result.host = '';
if (relative.protocol) {
- delete relative.hostname;
- delete relative.port;
+ relative.hostname = null;
+ relative.port = null;
if (relative.host) {
if (relPath[0] === '') relPath[0] = relative.host;
else relPath.unshift(relative.host);
}
- delete relative.host;
+ relative.host = null;
}
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
}
if (isRelAbs) {
// it's absolute.
- source.host = (relative.host || relative.host === '') ?
- relative.host : source.host;
- source.hostname = (relative.hostname || relative.hostname === '') ?
- relative.hostname : source.hostname;
- source.search = relative.search;
- source.query = relative.query;
+ result.host = (relative.host || relative.host === '') ?
+ relative.host : result.host;
+ result.hostname = (relative.hostname || relative.hostname === '') ?
+ relative.hostname : result.hostname;
+ result.search = relative.search;
+ result.query = relative.query;
srcPath = relPath;
// fall through to the dot-handling below.
} else if (relPath.length) {
@@ -481,53 +552,55 @@ function urlResolveObject(source, relative) {
if (!srcPath) srcPath = [];
srcPath.pop();
srcPath = srcPath.concat(relPath);
- source.search = relative.search;
- source.query = relative.query;
- } else if ('search' in relative) {
+ result.search = relative.search;
+ result.query = relative.query;
+ } else if (relative.search !== null && relative.search !== undefined) {
// just pull out the search.
// like href='?foo'.
// Put this after the other two cases because it simplifies the booleans
if (psychotic) {
- source.hostname = source.host = srcPath.shift();
+ result.hostname = result.host = srcPath.shift();
//occationaly the auth can get stuck only in host
//this especialy happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
- var authInHost = source.host && source.host.indexOf('@') > 0 ?
- source.host.split('@') : false;
+ var authInHost = result.host && result.host.indexOf('@') > 0 ?
+ result.host.split('@') : false;
if (authInHost) {
- source.auth = authInHost.shift();
- source.host = source.hostname = authInHost.shift();
+ result.auth = authInHost.shift();
+ result.host = result.hostname = authInHost.shift();
}
}
- source.search = relative.search;
- source.query = relative.query;
+ result.search = relative.search;
+ result.query = relative.query;
//to support http.request
- if (source.pathname !== undefined || source.search !== undefined) {
- source.path = (source.pathname ? source.pathname : '') +
- (source.search ? source.search : '');
+ if (result.pathname !== null || result.search !== null) {
+ result.path = (result.pathname ? result.pathname : '') +
+ (result.search ? result.search : '');
}
- source.href = urlFormat(source);
- return source;
+ result.href = result.format();
+ return result;
}
+
if (!srcPath.length) {
// no path at all. easy.
// we've already handled the other stuff above.
- delete source.pathname;
+ result.pathname = null;
//to support http.request
- if (!source.search) {
- source.path = '/' + source.search;
+ if (result.search) {
+ result.path = '/' + result.search;
} else {
- delete source.path;
+ result.path = null;
}
- source.href = urlFormat(source);
- return source;
+ result.href = result.format();
+ return result;
}
+
// if a url ENDs in . or .., then it must get a trailing slash.
// however, if it ends in anything else non-slashy,
// then it must NOT get a trailing slash.
var last = srcPath.slice(-1)[0];
var hasTrailingSlash = (
- (source.host || relative.host) && (last === '.' || last === '..') ||
+ (result.host || relative.host) && (last === '.' || last === '..') ||
last === '');
// strip single dots, resolve double dots to parent dir
@@ -563,49 +636,56 @@ function urlResolveObject(source, relative) {
}
var isAbsolute = srcPath[0] === '' ||
- (srcPath[0] && srcPath[0].charAt(0) === '/');
+ (srcPath[0] && srcPath[0].charAt(0) === '/');
// put the host back
if (psychotic) {
- source.hostname = source.host = isAbsolute ? '' :
- srcPath.length ? srcPath.shift() : '';
+ result.hostname = result.host = isAbsolute ? '' :
+ srcPath.length ? srcPath.shift() : '';
//occationaly the auth can get stuck only in host
//this especialy happens in cases like
//url.resolveObject('mailto:local1@domain1', 'local2@domain2')
- var authInHost = source.host && source.host.indexOf('@') > 0 ?
- source.host.split('@') : false;
+ var authInHost = result.host && result.host.indexOf('@') > 0 ?
+ result.host.split('@') : false;
if (authInHost) {
- source.auth = authInHost.shift();
- source.host = source.hostname = authInHost.shift();
+ result.auth = authInHost.shift();
+ result.host = result.hostname = authInHost.shift();
}
}
- mustEndAbs = mustEndAbs || (source.host && srcPath.length);
+ mustEndAbs = mustEndAbs || (result.host && srcPath.length);
if (mustEndAbs && !isAbsolute) {
srcPath.unshift('');
}
- source.pathname = srcPath.join('/');
- //to support request.http
- if (source.pathname !== undefined || source.search !== undefined) {
- source.path = (source.pathname ? source.pathname : '') +
- (source.search ? source.search : '');
+ if (!srcPath.length) {
+ result.pathname = null;
+ result.path = null;
+ } else {
+ result.pathname = srcPath.join('/');
}
- source.auth = relative.auth || source.auth;
- source.slashes = source.slashes || relative.slashes;
- source.href = urlFormat(source);
- return source;
-}
-function parseHost(host) {
- var out = {};
+ //to support request.http
+ if (result.pathname !== null || result.search !== null) {
+ result.path = (result.pathname ? result.pathname : '') +
+ (result.search ? result.search : '');
+ }
+ result.auth = relative.auth || result.auth;
+ result.slashes = result.slashes || relative.slashes;
+ result.href = result.format();
+ return result;
+};
+
+Url.prototype.parseHost = function() {
+ var host = this.host;
var port = portPattern.exec(host);
if (port) {
port = port[0];
- out.port = port.substr(1);
+ if (port !== ':') {
+ this.port = port.substr(1);
+ }
host = host.substr(0, host.length - port.length);
}
- if (host) out.hostname = host;
- return out;
-} \ No newline at end of file
+ if (host) this.hostname = host;
+};
diff --git a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/url_handler.js b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/url_handler.js
index 41ec82e..5117190 100644
--- a/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/url_handler.js
+++ b/data/extensions/jid1-KtlZuoiikVfFew@jetpack/resources/librejs/lib/url_handler/url_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/>.
*/
/**
@@ -25,86 +27,80 @@
*
*/
-// 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 nodeJsUrl = require("url_handler/node_url");
var urlUtils = {
-
- getFragment: function (url) {
- var parse = nodeJsUrl.parse(url);
- if (parse.hash !== undefined) {
- return(parse.hash);
- }
- },
-
- removeFragment: function (url) {
- var parse = nodeJsUrl.parse(url);
- if (parse.hash !== undefined) {
- // Amazon track package bug fix.
- // when url has query string and fragment
- // the add-on wouldn't remove cache entry
- // properly.
- delete parse.hash;
- }
- return nodeJsUrl.format(parse);
- },
-
- addFragment: function (url, query) {
- var parse = nodeJsUrl.parse(url);
-
- // replace hash if it exists.
- parse.hash = '#' + query;
-
- return nodeJsUrl.format(parse);
- },
-
- addQuery: function (url, query) {
- var parse = nodeJsUrl.parse(url);
- console.debug('my parse search', parse.search);
- if (parse.search === undefined) {
- parse.search = '?' + query;
- } else {
- parse.search = parse.search + '&' + query;
- console.debug('parse search is now' + parse.search);
- }
- return nodeJsUrl.format(parse);
- },
-
- getHostname: function (url) {
- return nodeJsUrl.parse(url).hostname;
- },
-
- /**
- * remove www from hostname.
- */
- removeWWW: function (str) {
- if (str !== undefined) {
- return str.replace("www.", "", 'i');
+ getFragment: function (url) {
+ var parse = nodeJsUrl.parse(url);
+ if (parse.hash !== undefined) {
+ return(parse.hash);
+ }
+ },
+
+ removeFragment: function (url) {
+ var parse = nodeJsUrl.parse(url);
+ if (parse.hash !== undefined) {
+ // Amazon track package bug fix.
+ // when url has query string and fragment
+ // the add-on wouldn't remove cache entry
+ // properly.
+ delete parse.hash;
+ }
+ return nodeJsUrl.format(parse);
+ },
+
+ addFragment: function (url, query) {
+ var parse = nodeJsUrl.parse(url);
+
+ // replace hash if it exists.
+ parse.hash = '#' + query;
+
+ return nodeJsUrl.format(parse);
+ },
+
+ addQuery: function (url, query) {
+ var parse = nodeJsUrl.parse(url);
+ console.debug('my parse search', parse.search);
+ if (parse.search === undefined) {
+ parse.search = '?' + query;
+ } else {
+ parse.search = parse.search + '&' + query;
+ console.debug('parse search is now' + parse.search);
+ }
+ return nodeJsUrl.format(parse);
+ },
+
+ getHostname: function (url) {
+ return nodeJsUrl.parse(url).hostname;
+ },
+
+ /**
+ * remove www from hostname.
+ */
+ removeWWW: function (str) {
+ if (str !== undefined) {
+ return str.replace("www.", "", 'i');
+ }
+ return "";
+ },
+
+ /**
+ *
+ * haveSameHostname
+ * Compare that two urls have the same hostname.
+ *
+ */
+ haveSameHostname: function (url1, url2) {
+ try {
+ var host1 = this.removeWWW(this.getHostname(url1)).toLowerCase();
+ var host2 = this.removeWWW(this.getHostname(url2)).toLowerCase();
+ return host1 === host2;
+ } catch (x) {
+ console.debug('error with url_handler', x, x.fileName, x.lineNumber);
+ }
}
- return "";
- },
-
- /**
- *
- * haveSameHostname
- * Compare that two urls have the same hostname.
- *
- */
- haveSameHostname: function (url1, url2) {
-
- try {
-
- var host1 = this.removeWWW(this.getHostname(url1)).toLowerCase();
- var host2 = this.removeWWW(this.getHostname(url2)).toLowerCase();
- return host1 === host2;
-
- } catch (x) {
-
- console.debug('error with url_handler', x, x.fileName, x.lineNumber);
-
- }
- }
};
exports.parse = nodeJsUrl.parse;