diff --git a/platform/firefox/bootstrap.js b/platform/firefox/bootstrap.js
deleted file mode 100644
index c11454041..000000000
--- a/platform/firefox/bootstrap.js
+++ /dev/null
@@ -1,250 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2017 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/* global ADDON_UNINSTALL, APP_SHUTDOWN */
-/* exported startup, shutdown, install, uninstall */
-
-'use strict';
-
-/******************************************************************************/
-
-const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-
-// Accessing the context of the background page:
-// var win = Services.appShell.hiddenDOMWindow.document.querySelector('iframe[src*=ublock0]').contentWindow;
-
-let windowlessBrowser = null;
-let windowlessBrowserPL = null;
-let bgProcess = null;
-let version;
-const hostName = 'ublock0';
-const restartListener = {
- get messageManager() {
- return Cc['@mozilla.org/parentprocessmessagemanager;1']
- .getService(Ci.nsIMessageListenerManager);
- },
-
- receiveMessage: function() {
- shutdown();
- startup();
- }
-};
-
-/******************************************************************************/
-
-function startup(data/*, reason*/) {
- if ( data !== undefined ) {
- version = data.version;
- }
-
- // Already started?
- if ( bgProcess !== null ) {
- return;
- }
-
- waitForHiddenWindow();
-}
-
-function createBgProcess(parentDocument) {
- bgProcess = parentDocument.documentElement.appendChild(
- parentDocument.createElementNS('http://www.w3.org/1999/xhtml', 'iframe')
- );
- bgProcess.setAttribute(
- 'src',
- 'chrome://' + hostName + '/content/background.html#' + version
- );
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListenerManager#addMessageListener%28%29
- // "If the same listener registers twice for the same message, the
- // "second registration is ignored."
- restartListener.messageManager.addMessageListener(
- hostName + '-restart',
- restartListener
- );
-}
-
-function getWindowlessBrowserFrame(appShell) {
- windowlessBrowser = appShell.createWindowlessBrowser(true);
- windowlessBrowser.QueryInterface(Ci.nsIInterfaceRequestor);
- let webProgress = windowlessBrowser.getInterface(Ci.nsIWebProgress);
- let XPCOMUtils = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null).XPCOMUtils;
- windowlessBrowserPL = {
- QueryInterface: XPCOMUtils.generateQI([
- Ci.nsIWebProgressListener,
- Ci.nsIWebProgressListener2,
- Ci.nsISupportsWeakReference
- ]),
- onStateChange: function(wbp, request, stateFlags/*, status*/) {
- if ( !request ) { return; }
- if ( stateFlags & Ci.nsIWebProgressListener.STATE_STOP ) {
- webProgress.removeProgressListener(windowlessBrowserPL);
- windowlessBrowserPL = null;
- createBgProcess(windowlessBrowser.document);
- }
- }
- };
- webProgress.addProgressListener(windowlessBrowserPL, Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
- windowlessBrowser.document.location = "data:application/vnd.mozilla.xul+xml;charset=utf-8,";
-}
-
-function waitForHiddenWindow() {
- let appShell = Cc['@mozilla.org/appshell/appShellService;1']
- .getService(Ci.nsIAppShellService);
-
- let isReady = function() {
- var hiddenDoc;
-
- try {
- hiddenDoc = appShell.hiddenDOMWindow &&
- appShell.hiddenDOMWindow.document;
- } catch (ex) {
- }
-
- // Do not test against `loading`: it does appear `readyState` could be
- // undefined if looked up too early.
- if ( !hiddenDoc || hiddenDoc.readyState !== 'complete' ) {
- return false;
- }
-
- // In theory, it should be possible to create a windowless browser
- // immediately, without waiting for the hidden window to have loaded
- // completely. However, in practice, on Windows this seems to lead
- // to a broken Firefox appearance. To avoid this, we only create the
- // windowless browser here. We'll use that rather than the hidden
- // window for the actual background page (windowless browsers are
- // also what the webextension implementation in Firefox uses for
- // background pages).
- let { Services } = Cu.import('resource://gre/modules/Services.jsm', null);
- if ( Services.vc.compare(Services.appinfo.platformVersion, '27') >= 0 ) {
- getWindowlessBrowserFrame(appShell);
- } else {
- createBgProcess(hiddenDoc);
- }
- return true;
- };
-
- if ( isReady() ) {
- return;
- }
-
- // https://github.com/gorhill/uBlock/issues/749
- // Poll until the proper environment is set up -- or give up eventually.
- // We poll frequently early on but relax poll delay as time pass.
-
- let tryDelay = 5;
- let trySum = 0;
- // https://trac.torproject.org/projects/tor/ticket/19438
- // Try for a longer period.
- let tryMax = 600011;
- let timer = Cc['@mozilla.org/timer;1']
- .createInstance(Ci.nsITimer);
-
- let checkLater = function() {
- trySum += tryDelay;
- if ( trySum >= tryMax ) {
- timer = null;
- return;
- }
- timer.init(timerObserver, tryDelay, timer.TYPE_ONE_SHOT);
- tryDelay *= 2;
- if ( tryDelay > 503 ) {
- tryDelay = 503;
- }
- };
-
- var timerObserver = {
- observe: function() {
- timer.cancel();
- if ( isReady() ) {
- timer = null;
- } else {
- checkLater();
- }
- }
- };
-
- checkLater();
-}
-
-/******************************************************************************/
-
-function shutdown(data, reason) {
- if ( reason === APP_SHUTDOWN ) {
- return;
- }
-
- if ( bgProcess !== null ) {
- bgProcess.parentNode.removeChild(bgProcess);
- bgProcess = null;
- }
-
- if ( windowlessBrowser !== null ) {
- // close() does not exist for older versions of Firefox.
- if ( typeof windowlessBrowser.close === 'function' ) {
- windowlessBrowser.close();
- }
- windowlessBrowser = null;
- windowlessBrowserPL = null;
- }
-
- if ( data === undefined ) {
- return;
- }
-
- // Remove the restartObserver only when the extension is being disabled
- restartListener.messageManager.removeMessageListener(
- hostName + '-restart',
- restartListener
- );
-}
-
-/******************************************************************************/
-
-function install(/*aData, aReason*/) {
- // https://bugzil.la/719376
- Cc['@mozilla.org/intl/stringbundle;1']
- .getService(Ci.nsIStringBundleService)
- .flushBundles();
-}
-
-/******************************************************************************/
-
-// https://developer.mozilla.org/en-US/Add-ons/Bootstrapped_extensions#uninstall
-// "if you have code in uninstall it will not run, you MUST run some code
-// "in the install function, at the least you must set arguments on the
-// "install function so like: function install(aData, aReason) {} then
-// "uninstall WILL WORK."
-
-function uninstall(aData, aReason) {
- if ( aReason !== ADDON_UNINSTALL ) {
- return;
- }
- // https://github.com/gorhill/uBlock/issues/84
- // "Add cleanup task to remove local storage settings when uninstalling"
- // To cleanup vAPI.localStorage in vapi-common.js
- // As I get more familiar with FF API, will find out whetehr there was
- // a better way to do this.
- Cu.import('resource://gre/modules/Services.jsm', null)
- .Services.prefs.getBranch('extensions.' + hostName + '.')
- .deleteBranch('');
-}
-
-/******************************************************************************/
diff --git a/platform/firefox/chrome.manifest b/platform/firefox/chrome.manifest
deleted file mode 100644
index 75781cd6f..000000000
--- a/platform/firefox/chrome.manifest
+++ /dev/null
@@ -1 +0,0 @@
-content ublock0 ./
diff --git a/platform/firefox/css/legacy-toolbar-button.css b/platform/firefox/css/legacy-toolbar-button.css
deleted file mode 100644
index c4e22522d..000000000
--- a/platform/firefox/css/legacy-toolbar-button.css
+++ /dev/null
@@ -1,46 +0,0 @@
-#uBlock0-legacy-button {
- list-style-image: url('../img/browsericons/icon24.svg');
-}
-#uBlock0-legacy-button.off {
- list-style-image: url('../img/browsericons/icon24-off.svg');
-}
-
-toolbar[iconsize="small"] #uBlock0-legacy-button {
- list-style-image: url('../img/browsericons/icon16.svg');
-}
-toolbar[iconsize="small"] #uBlock0-legacy-button.off {
- list-style-image: url('../img/browsericons/icon16-off.svg');
-}
-#uBlock0-legacy-button[badge]::before {
- background: #555;
- color: #fff;
- content: attr(badge);
- font: bold 10px sans-serif;
- margin-top: -2px;
- padding: 0 2px;
- position: fixed;
-}
-/* This hack required because if the before content changes it de-pops the
- popup (without firing any events). So just hide it instead. Note, can't
- actually *hide* it, or the same thing happens.
-**/
-#uBlock0-legacy-button[badge=""]::before {
- padding: 0;
-}
-
-/* Override off state when in palette */
-toolbarpaletteitem #uBlock0-legacy-button.off {
- list-style-image: url('../img/browsericons/icon24.svg');
-}
-
-/* Override badge when in palette */
-toolbarpaletteitem #uBlock0-legacy-button[badge]::before {
- content: none;
-}
-
-/* Prevent pale moon from showing the arrow underneath the button */
-/* https://github.com/chrisaljoudi/uBlock/issues/1449#issuecomment-112112761 */
-#uBlock0-legacy-button .toolbarbutton-menu-dropmarker {
- display: none;
- -moz-box-orient: horizontal;
-}
diff --git a/platform/firefox/frameModule.js b/platform/firefox/frameModule.js
deleted file mode 100644
index 03ef0bebd..000000000
--- a/platform/firefox/frameModule.js
+++ /dev/null
@@ -1,623 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2017 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/* exported processObserver */
-
-'use strict';
-
-/******************************************************************************/
-
-// https://github.com/gorhill/uBlock/issues/800
-this.EXPORTED_SYMBOLS = [
- 'contentObserver',
- 'processObserver',
- 'LocationChangeListener'
-];
-
-const {interfaces: Ci, utils: Cu} = Components;
-const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
-const {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null);
-
-const hostName = Services.io.newURI(Components.stack.filename, null, null).host;
-const rpcEmitterName = hostName + ':child-process-message';
-
-//Cu.import('resource://gre/modules/Console.jsm'); // Firefox >= 44
-//Cu.import('resource://gre/modules/devtools/Console.jsm'); // Firefox < 44
-
-/******************************************************************************/
-
-const getMessageManager = function(win) {
- let iface = win
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDocShell)
- .sameTypeRootTreeItem
- .QueryInterface(Ci.nsIDocShell)
- .QueryInterface(Ci.nsIInterfaceRequestor);
-
- try {
- return iface.getInterface(Ci.nsIContentFrameMessageManager);
- } catch (ex) {
- // This can throw. It appears `shouldLoad` can be called *after* a
- // tab has been closed. For example, a case where this happens all
- // the time (FF38):
- // - Open twitter.com (assuming you have an account and are logged in)
- // - Close twitter.com
- // There will be an exception raised when `shouldLoad` is called
- // to process a XMLHttpRequest with URL `https://twitter.com/i/jot`
- // fired from `https://twitter.com/`, *after* the tab is closed.
- // In such case, `win` is `about:blank`.
- }
- return null;
-};
-
-/******************************************************************************/
-
-// https://github.com/gorhill/uBlock/issues/2014
-// Have a dictionary of hostnames for which there are script tag filters. This
-// allow for coarse-testing before firing a synchronous message to the
-// parent process. Script tag filters are not very common, so this allows
-// to skip the blocking of the child process most of the time.
-
-var scriptTagFilterer = (function() {
- var scriptTagHostnames;
-
- var getCpmm = function() {
- var svc = Services;
- if ( !svc ) { return; }
- var cpmm = svc.cpmm;
- if ( cpmm ) { return cpmm; }
- cpmm = Components.classes['@mozilla.org/childprocessmessagemanager;1'];
- if ( cpmm ) { return cpmm.getService(Ci.nsISyncMessageSender); }
- };
-
- var getScriptTagHostnames = function() {
- if ( scriptTagHostnames ) {
- return scriptTagHostnames;
- }
- var cpmm = getCpmm();
- if ( !cpmm ) { return; }
- var r = cpmm.sendSyncMessage(rpcEmitterName, { fnName: 'getScriptTagHostnames' });
- if ( Array.isArray(r) && Array.isArray(r[0]) ) {
- scriptTagHostnames = new Set(r[0]);
- }
- return scriptTagHostnames;
- };
-
- var getScriptTagFilters = function(details) {
- let cpmm = getCpmm();
- if ( !cpmm ) { return; }
- let r = cpmm.sendSyncMessage(rpcEmitterName, {
- fnName: 'getScriptTagFilters',
- rootURL: details.rootURL,
- frameURL: details.frameURL,
- frameHostname: details.frameHostname
- });
- if ( Array.isArray(r) ) {
- return r[0];
- }
- };
-
- var regexFromHostname = function(details) {
- // If target hostname has no script tag filter, no point querying
- // chrome process.
- var hostnames = getScriptTagHostnames();
- if ( !hostnames ) { return; }
- var hn = details.frameHostname, pos, entity;
- for (;;) {
- if ( hostnames.has(hn) ) {
- return getScriptTagFilters(details);
- }
- pos = hn.indexOf('.');
- if ( pos === -1 ) { break; }
- entity = hn.slice(0, pos) + '.*';
- if ( hostnames.has(entity) ) {
- return getScriptTagFilters(details);
- }
- hn = hn.slice(pos + 1);
- if ( hn === '' ) { break; }
- }
- };
-
- var reset = function() {
- scriptTagHostnames = undefined;
- };
-
- return {
- get: regexFromHostname,
- reset: reset
- };
-})();
-
-/******************************************************************************/
-
-var contentObserver = {
- classDescription: 'content-policy for ' + hostName,
- classID: Components.ID('{7afbd130-cbaf-46c2-b944-f5d24305f484}'),
- contractID: '@' + hostName + '/content-policy;1',
- ACCEPT: Ci.nsIContentPolicy.ACCEPT,
- REJECT: Ci.nsIContentPolicy.REJECT_REQUEST,
- MAIN_FRAME: Ci.nsIContentPolicy.TYPE_DOCUMENT,
- SUB_FRAME: Ci.nsIContentPolicy.TYPE_SUBDOCUMENT,
- contentBaseURI: 'chrome://' + hostName + '/content/js/',
- cpMessageName: hostName + ':shouldLoad',
- popupMessageName: hostName + ':shouldLoadPopup',
- ignoredPopups: new WeakMap(),
- uniquePopupEventId: 1,
- uniqueSandboxId: 1,
- modernFirefox: Services.vc.compare(Services.appinfo.platformVersion, '44') > 0,
-
- get componentRegistrar() {
- return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
- },
-
- get categoryManager() {
- return Components.classes['@mozilla.org/categorymanager;1']
- .getService(Ci.nsICategoryManager);
- },
-
- QueryInterface: XPCOMUtils.generateQI([
- Ci.nsIFactory,
- Ci.nsIObserver,
- Ci.nsIContentPolicy,
- Ci.nsISupportsWeakReference
- ]),
-
- createInstance: function(outer, iid) {
- if ( outer ) {
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- }
-
- return this.QueryInterface(iid);
- },
-
- register: function() {
- Services.obs.addObserver(this, 'document-element-inserted', true);
- Services.obs.addObserver(this, 'content-document-global-created', true);
-
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1232354
- // For modern versions of Firefox, the frameId/parentFrameId
- // information can be found in channel.loadInfo of the HTTP observer.
- if ( this.modernFirefox !== true ) {
- this.componentRegistrar.registerFactory(
- this.classID,
- this.classDescription,
- this.contractID,
- this
- );
- this.categoryManager.addCategoryEntry(
- 'content-policy',
- this.contractID,
- this.contractID,
- false,
- true
- );
- }
- },
-
- unregister: function() {
- Services.obs.removeObserver(this, 'document-element-inserted');
- Services.obs.removeObserver(this, 'content-document-global-created');
-
- if ( this.modernFirefox !== true ) {
- this.componentRegistrar.unregisterFactory(this.classID, this);
- this.categoryManager.deleteCategoryEntry(
- 'content-policy',
- this.contractID,
- false
- );
- }
- },
-
- getFrameId: function(win) {
- return win
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils)
- .outerWindowID;
- },
-
- // https://bugzil.la/612921
- shouldLoad: function(type, location, origin, context) {
- // For whatever reason, sometimes the global scope is completely
- // uninitialized at this point. Repro steps:
- // - Launch FF with uBlock enabled
- // - Disable uBlock
- // - Enable uBlock
- // - Services and all other global variables are undefined
- // Hopefully will eventually understand why this happens.
- if ( Services === undefined || !context ) {
- return this.ACCEPT;
- }
-
- if ( !location.schemeIs('http') && !location.schemeIs('https') ) {
- return this.ACCEPT;
- }
-
- if ( type === this.MAIN_FRAME ) {
- context = context.contentWindow || context;
- } else if ( type === this.SUB_FRAME ) {
- context = context.contentWindow;
- } else {
- context = (context.ownerDocument || context).defaultView;
- }
-
- // https://github.com/gorhill/uBlock/issues/1893
- // I don't know why this happens. I observed that when it occurred, the
- // resource was not seen by the HTTP observer, as if it was a spurious
- // call to shouldLoad().
- if ( !context ) {
- return this.ACCEPT;
- }
-
- // The context for the toolbar popup is an iframe element here,
- // so check context.top instead of context
- if ( !context.top || !context.location ) {
- return this.ACCEPT;
- }
-
- let messageManager = getMessageManager(context);
- if ( messageManager === null ) {
- return this.ACCEPT;
- }
-
- let isTopContext = context === context.top;
- var parentFrameId;
- if ( isTopContext ) {
- parentFrameId = -1;
- } else if ( context.parent === context.top ) {
- parentFrameId = 0;
- } else {
- parentFrameId = this.getFrameId(context.parent);
- }
-
- let rpcData = this.rpcData;
- rpcData.frameId = isTopContext ? 0 : this.getFrameId(context);
- rpcData.pFrameId = parentFrameId;
- rpcData.type = type;
- rpcData.url = location.spec;
-
- //console.log('shouldLoad: type=' + type + ' url=' + location.spec);
- if ( typeof messageManager.sendRpcMessage === 'function' ) {
- // https://bugzil.la/1092216
- messageManager.sendRpcMessage(this.cpMessageName, rpcData);
- } else {
- // Compatibility for older versions
- messageManager.sendSyncMessage(this.cpMessageName, rpcData);
- }
-
- return this.ACCEPT;
- },
-
- // Reuse object to avoid repeated memory allocation.
- rpcData: { frameId: 0, pFrameId: -1, type: 0, url: '' },
-
- initContentScripts: function(win, create) {
- let messager = getMessageManager(win);
- let sandboxId = hostName + ':sb:' + this.uniqueSandboxId++;
- let sandbox;
-
- if ( create ) {
- let sandboxName = [
- win.location.href.slice(0, 100),
- win.document.title.slice(0, 100)
- ].join(' | ');
-
- // https://github.com/gorhill/uMatrix/issues/325
- // "Pass sameZoneAs to sandbox constructor to make GCs cheaper"
- sandbox = Cu.Sandbox([win], {
- sameZoneAs: win.top,
- sandboxName: sandboxId + '[' + sandboxName + ']',
- sandboxPrototype: win,
- wantComponents: false,
- wantXHRConstructor: false
- });
-
- sandbox.getScriptTagFilters = function(details) {
- return scriptTagFilterer.get(details);
- };
-
- sandbox.injectScript = function(script) {
- let svc = Services;
- // Sandbox appears void.
- // I've seen this happens, need to investigate why.
- if ( svc === undefined ) { return; }
- svc.scriptloader.loadSubScript(script, sandbox);
- };
-
- let canUserStyles = (function() {
- try {
- return win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils)
- .loadSheetUsingURIString instanceof Function;
- } catch(ex) {
- }
- return false;
- })();
-
- if ( canUserStyles ) {
- sandbox.injectCSS = function(sheetURI) {
- try {
- let wu = win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils);
- wu.loadSheetUsingURIString(sheetURI, wu.USER_SHEET);
- } catch(ex) {
- }
- };
- sandbox.removeCSS = function(sheetURI) {
- try {
- let wu = win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils);
- wu.removeSheetUsingURIString(sheetURI, wu.USER_SHEET);
- } catch (ex) {
- }
- };
- }
-
- sandbox.topContentScript = win === win.top;
-
- // https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_loading_and_lifetime#Unloading_frame_scripts
- // The goal is to have content scripts removed from web pages. This
- // helps remove traces of uBlock from memory when disabling/removing
- // the addon.
- // For example, this takes care of:
- // https://github.com/gorhill/uBlock/commit/ea4faff383789053f423498c1f1165c403fde7c7#commitcomment-11964137
- // > "gets the whole selected tab flashing"
- sandbox.outerShutdown = function() {
- sandbox.removeMessageListener();
- sandbox.addMessageListener =
- sandbox.getScriptTagFilters =
- sandbox.injectCSS =
- sandbox.injectScript =
- sandbox.outerShutdown =
- sandbox.removeCSS =
- sandbox.removeMessageListener =
- sandbox.sendAsyncMessage = function(){};
- sandbox.vAPI = {};
- messager = null;
- };
- }
- else {
- sandbox = win;
- }
-
- sandbox._sandboxId_ = sandboxId;
- sandbox.sendAsyncMessage = messager.sendAsyncMessage;
-
- sandbox.addMessageListener = function(callback) {
- if ( sandbox._messageListener_ ) {
- sandbox.removeMessageListener();
- }
-
- sandbox._messageListener_ = function(message) {
- callback(message.data);
- };
-
- sandbox._broadcastListener_ = function(message) {
- // https://github.com/gorhill/uBlock/issues/2014
- if ( sandbox.topContentScript ) {
- let details;
- try { details = JSON.parse(message.data); } catch (ex) {}
- let msg = details && details.msg || {};
- if ( msg.what === 'staticFilteringDataChanged' ) {
- if ( scriptTagFilterer ) {
- scriptTagFilterer.reset();
- }
- }
- }
- callback(message.data);
- };
-
- messager.addMessageListener(
- sandbox._sandboxId_,
- sandbox._messageListener_
- );
- messager.addMessageListener(
- hostName + ':broadcast',
- sandbox._broadcastListener_
- );
- };
-
- sandbox.removeMessageListener = function() {
- if ( !sandbox._messageListener_ ) {
- return;
- }
- // It throws sometimes, mostly when the popup closes
- try {
- messager.removeMessageListener(
- sandbox._sandboxId_,
- sandbox._messageListener_
- );
- } catch (ex) {
- }
- try {
- messager.removeMessageListener(
- hostName + ':broadcast',
- sandbox._broadcastListener_
- );
- } catch (ex) {
- }
-
- sandbox._messageListener_ = sandbox._broadcastListener_ = null;
- };
-
- return sandbox;
- },
-
- injectOtherContentScripts: function(doc, sandbox) {
- let docReady = (e) => {
- let doc = e.target;
- doc.removeEventListener(e.type, docReady, true);
- if ( doc.querySelector('a[href^="abp:"],a[href^="https://subscribe.adblockplus.org/?"]') ) {
- Services.scriptloader.loadSubScript(this.contentBaseURI + 'scriptlets/subscriber.js', sandbox);
- }
- };
- if ( doc.readyState === 'loading') {
- doc.addEventListener('DOMContentLoaded', docReady, true);
- } else {
- docReady({ target: doc, type: 'DOMContentLoaded' });
- }
- },
-
- ignorePopup: function(e) {
- if ( e.isTrusted === false ) { return; }
- let contObs = contentObserver;
- contObs.ignoredPopups.set(this, true);
- this.removeEventListener('keydown', contObs.ignorePopup, true);
- this.removeEventListener('mousedown', contObs.ignorePopup, true);
- },
-
- lookupPopupOpener: function(popup) {
- for (;;) {
- let opener = popup.opener;
- if ( !opener ) { return; }
- if ( opener.top ) { opener = opener.top; }
- if ( opener === popup ) { return; }
- if ( !opener.location ) { return; }
- if ( this.reValidPopups.test(opener.location.protocol) ) {
- return opener;
- }
- // https://github.com/uBlockOrigin/uAssets/issues/255
- // - Mind chained about:blank popups.
- if ( opener.location.href !== 'about:blank' ) { return; }
- popup = opener;
- }
- },
-
- reValidPopups: /^(?:blob|data|https?|javascript):/,
- reMustInjectScript: /^(?:file|https?):/,
-
- observe: function(subject, topic) {
- // For whatever reason, sometimes the global scope is completely
- // uninitialized at this point. Repro steps:
- // - Launch FF with uBlock enabled
- // - Disable uBlock
- // - Enable uBlock
- // - Services and all other global variables are undefined
- // Hopefully will eventually understand why this happens.
- if ( Services === undefined ) { return; }
-
- // https://github.com/gorhill/uBlock/issues/2290
- if ( topic === 'content-document-global-created' ) {
- if ( subject !== subject.top || !subject.opener ) { return; }
- if ( this.ignoredPopups.has(subject) ) { return; }
- let opener = this.lookupPopupOpener(subject);
- if ( !opener ) { return; }
- subject.addEventListener('keydown', this.ignorePopup, true);
- subject.addEventListener('mousedown', this.ignorePopup, true);
- let popupMessager = getMessageManager(subject);
- if ( !popupMessager ) { return; }
- let openerMessager = getMessageManager(opener);
- if ( !openerMessager ) { return; }
- popupMessager.sendAsyncMessage(this.popupMessageName, {
- id: this.uniquePopupEventId,
- popup: true
- });
- openerMessager.sendAsyncMessage(this.popupMessageName, {
- id: this.uniquePopupEventId,
- opener: true
- });
- this.uniquePopupEventId += 1;
- return;
- }
-
- // topic === 'document-element-inserted'
-
- let doc = subject;
- let win = doc.defaultView || null;
- if ( win === null ) { return; }
-
- // https://github.com/gorhill/uBlock/issues/260
- // https://developer.mozilla.org/en-US/docs/Web/API/Document/contentType
- // "Non-standard, only supported by Gecko. To be used in
- // "chrome code (i.e. Extensions and XUL applications)."
- // TODO: We may have to exclude more types, for now let's be
- // conservative and focus only on the one issue reported, i.e. let's
- // not test against 'text/html'.
- if ( doc.contentType.startsWith('image/') ) { return; }
-
- let loc = win.location;
- if ( this.reMustInjectScript.test(loc.protocol) === false ) {
- if ( loc.protocol === 'chrome:' && loc.host === hostName ) {
- this.initContentScripts(win);
- }
- // What about data: and about:blank?
- return;
- }
-
- // Content scripts injection.
- let lss = Services.scriptloader.loadSubScript;
- let sandbox = this.initContentScripts(win, true);
- try {
- lss(this.contentBaseURI + 'vapi-client.js', sandbox);
- lss(this.contentBaseURI + 'contentscript.js', sandbox);
- } catch (ex) {
- //console.exception(ex.msg, ex.stack);
- return;
- }
- // The remaining scripts are worth injecting only on a top-level window
- // and at document_idle time.
- if ( win === win.top ) {
- this.injectOtherContentScripts(doc, sandbox);
- }
- }
-};
-
-/******************************************************************************/
-
-var processObserver = {
- start: function() {
- scriptTagFilterer.reset();
- }
-};
-
-/******************************************************************************/
-
-var LocationChangeListener = function(docShell, webProgress) {
- var mm = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIContentFrameMessageManager);
- if ( !mm || typeof mm.sendAsyncMessage !== 'function' ) {
- return;
- }
- this.messageManager = mm;
- webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_LOCATION);
-};
-
-LocationChangeListener.prototype.messageName = hostName + ':locationChanged';
-
-LocationChangeListener.prototype.QueryInterface = XPCOMUtils.generateQI([
- 'nsIWebProgressListener',
- 'nsISupportsWeakReference'
-]);
-
-LocationChangeListener.prototype.onLocationChange = function(webProgress, request, location, flags) {
- if ( !webProgress.isTopLevel ) {
- return;
- }
- this.messageManager.sendAsyncMessage(this.messageName, {
- url: location.asciiSpec,
- flags: flags
- });
-};
-
-/******************************************************************************/
-
-contentObserver.register();
-
-/******************************************************************************/
diff --git a/platform/firefox/frameScript.js b/platform/firefox/frameScript.js
deleted file mode 100644
index 260f05557..000000000
--- a/platform/firefox/frameScript.js
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2016 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/******************************************************************************/
-
-// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment
-
-(function(context) {
- 'use strict';
-
- if ( !context.docShell ) {
- return;
- }
-
- let webProgress = context.docShell
- .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
- .getInterface(Components.interfaces.nsIWebProgress);
- if ( !webProgress ) {
- return;
- }
-
- // https://github.com/gorhill/uBlock/issues/1514
- // Fix?
- let domWindow = webProgress.DOMWindow;
- if ( domWindow !== domWindow.top ) {
- return;
- }
-
- let {LocationChangeListener} = Components.utils.import(
- Components.stack.filename.replace('Script', 'Module'),
- null
- );
-
- // https://github.com/gorhill/uBlock/issues/1444
- // Apparently, on older versions of Firefox (31 and less), the same context
- // is used for all frame scripts, hence we must use a unique variable name
- // to ensure no collision.
- context.ublock0LocationChangeListener = new LocationChangeListener(
- context.docShell,
- webProgress
- );
-})(this);
-
-/******************************************************************************/
diff --git a/platform/firefox/frameScript0.js b/platform/firefox/frameScript0.js
deleted file mode 100644
index 38acce2ec..000000000
--- a/platform/firefox/frameScript0.js
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2016 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/******************************************************************************/
-
-// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_environment
-
-(function(context) {
-
- 'use strict';
-
- if ( !context.content ) {
- return;
- }
-
- let {contentObserver} = Components.utils.import(
- Components.stack.filename.replace('Script0', 'Module'),
- null
- );
-
- let injectContentScripts = function(win) {
- if ( !win || !win.document ) {
- return;
- }
-
- contentObserver.observe(win.document);
-
- if ( win.frames && win.frames.length ) {
- let i = win.frames.length;
- while ( i-- ) {
- injectContentScripts(win.frames[i]);
- }
- }
- };
-
- injectContentScripts(context.content);
-
-})(this);
-
-/******************************************************************************/
diff --git a/platform/firefox/img/browsericons/icon16-off.svg b/platform/firefox/img/browsericons/icon16-off.svg
deleted file mode 100644
index f0f68be23..000000000
--- a/platform/firefox/img/browsericons/icon16-off.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/platform/firefox/img/browsericons/icon16.svg b/platform/firefox/img/browsericons/icon16.svg
deleted file mode 100644
index d36d9d232..000000000
--- a/platform/firefox/img/browsericons/icon16.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/platform/firefox/img/browsericons/icon24-off.svg b/platform/firefox/img/browsericons/icon24-off.svg
deleted file mode 100644
index 0856eef34..000000000
--- a/platform/firefox/img/browsericons/icon24-off.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/platform/firefox/img/browsericons/icon24.svg b/platform/firefox/img/browsericons/icon24.svg
deleted file mode 100644
index 28f75a726..000000000
--- a/platform/firefox/img/browsericons/icon24.svg
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/platform/firefox/install.rdf b/platform/firefox/install.rdf
deleted file mode 100644
index e9b39263a..000000000
--- a/platform/firefox/install.rdf
+++ /dev/null
@@ -1,64 +0,0 @@
-
-
-
- uBlock0@raymondhill.net
- {version}
- {name}
- {description}
- {homepage}
- {author}
- Deathamns
- Alex Vallat
- Manuel Reimer
- 2
- true
- true
- 2
-{localized}
-
-
-
-
- {{ec8030f7-c20a-464f-9b0e-13a3a9e97384}}
- 32.0
- 56.0a1
-
-
-
-
-
-
- {{aa3c5121-dab2-40e2-81ca-7ea25febc110}}
- 32.0
- 56.0a1
-
-
-
-
-
-
- {{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}}
- 2.24
- *
-
-
-
-
-
-
- {{8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4}}
- 27.0
- 27.*
-
-
-
-
-
-
- {{3550f703-e582-4d05-9a08-453d09bdfdc6}}
- 31.0
- 45.*
-
-
-
-
diff --git a/platform/firefox/options.xul b/platform/firefox/options.xul
deleted file mode 100644
index aee6f7c00..000000000
--- a/platform/firefox/options.xul
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/platform/firefox/polyfill.js b/platform/firefox/polyfill.js
deleted file mode 100644
index 6b03d565b..000000000
--- a/platform/firefox/polyfill.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2016-2017 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-// For background page or non-background pages
-
-/* exported objectAssign */
-
-'use strict';
-
-/******************************************************************************/
-/******************************************************************************/
-
-// As per MDN, Object.assign appeared first in Firefox 34.
-// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility
-
-var objectAssign = Object.assign || function(target, source) {
- var keys = Object.keys(source);
- for ( var i = 0, n = keys.length, key; i < n; i++ ) {
- key = keys[i];
- target[key] = source[key];
- }
- return target;
-};
-
-/******************************************************************************/
diff --git a/platform/firefox/processScript.js b/platform/firefox/processScript.js
deleted file mode 100644
index f0ea54f35..000000000
--- a/platform/firefox/processScript.js
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2016 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/******************************************************************************/
-
-// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIProcessScriptLoader
-
-// Some module tasks need to run once per-content process. This is the purpose
-// of this content process script.
-
-(function() {
- 'use strict';
-
- let {processObserver} = Components.utils.import(
- Components.stack.filename.replace('processScript.js', 'frameModule.js'),
- null
- );
-
- // https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Frame_script_loading_and_lifetime#Unloading_frame_scripts
- // There is no way to unload a frame script, so when the extension will
- // update, it may happen `processObserver` is not available because of
- // trying to import from an older module version.
- // TODO: remove the test once everybody is updated to 1.9.10+.
- if ( processObserver ) {
- processObserver.start();
- }
-})();
-
-/******************************************************************************/
diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js
deleted file mode 100644
index 39b46065d..000000000
--- a/platform/firefox/vapi-background.js
+++ /dev/null
@@ -1,3678 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2018 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/* jshint esnext: true, bitwise: false */
-/* global punycode */
-
-// For background page
-
-'use strict';
-
-/******************************************************************************/
-
-(function() {
-
-/******************************************************************************/
-
-const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
-const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
-
-/******************************************************************************/
-
-var vAPI = self.vAPI = self.vAPI || {};
-vAPI.firefox = true;
-vAPI.fennec = Services.appinfo.ID === '{aa3c5121-dab2-40e2-81ca-7ea25febc110}';
-vAPI.thunderbird = Services.appinfo.ID === '{3550f703-e582-4d05-9a08-453d09bdfdc6}';
-
-if ( vAPI.fennec ) {
- vAPI.battery = true;
-}
-
-/******************************************************************************/
-
-var deferUntil = function(testFn, mainFn, details) {
- if ( typeof details !== 'object' ) {
- details = {};
- }
-
- var now = 0,
- next = details.next || 200,
- until = details.until || 12800;
-
- var check = function() {
- if ( testFn() === true || now >= until ) {
- mainFn();
- return;
- }
- now += next;
- vAPI.setTimeout(check, next);
- };
-
- if ( 'sync' in details && details.sync === true ) {
- check();
- } else {
- vAPI.setTimeout(check, details.first || 1);
- }
-};
-
-/******************************************************************************/
-
-vAPI.app = {
- name: 'uBlock Origin',
- version: location.hash.slice(1)
-};
-
-/******************************************************************************/
-
-vAPI.app.restart = function() {
- // Listening in bootstrap.js
- Cc['@mozilla.org/childprocessmessagemanager;1']
- .getService(Ci.nsIMessageSender)
- .sendAsyncMessage(location.host + '-restart');
-};
-
-/******************************************************************************/
-
-// Set default preferences for user to find in about:config
-vAPI.localStorage.setDefaultBool('forceLegacyToolbarButton', false);
-
-/******************************************************************************/
-
-// List of things that needs to be destroyed when disabling the extension
-// Only functions should be added to it
-
-var cleanupTasks = [];
-
-// This must be updated manually, every time a new task is added/removed
-var expectedNumberOfCleanups = 9;
-
-window.addEventListener('unload', function() {
- if ( typeof vAPI.app.onShutdown === 'function' ) {
- vAPI.app.onShutdown();
- }
-
- // IMPORTANT: cleanup tasks must be executed using LIFO order.
- var i = cleanupTasks.length;
- while ( i-- ) {
- cleanupTasks[i]();
- }
-
- if ( cleanupTasks.length < expectedNumberOfCleanups ) {
- console.error(
- 'uBlock> Cleanup tasks performed: %s (out of %s)',
- cleanupTasks.length,
- expectedNumberOfCleanups
- );
- }
-
- // frameModule needs to be cleared too
- var frameModuleURL = vAPI.getURL('frameModule.js');
- var frameModule = {};
-
- // https://github.com/gorhill/uBlock/issues/1004
- // For whatever reason, `Cu.import` can throw -- at least this was
- // reported as happening for Pale Moon 25.8.
- try {
- Cu.import(frameModuleURL, frameModule);
- frameModule.contentObserver.unregister();
- Cu.unload(frameModuleURL);
- } catch (ex) {
- }
-});
-
-/******************************************************************************/
-
-// For now, only booleans.
-
-vAPI.browserSettings = {
- originalValues: {},
-
- rememberOriginalValue: function(path, setting) {
- var key = path + '.' + setting;
- if ( this.originalValues.hasOwnProperty(key) ) {
- return;
- }
- var hasUserValue;
- var branch = Services.prefs.getBranch(path + '.');
- try {
- hasUserValue = branch.prefHasUserValue(setting);
- } catch (ex) {
- }
- if ( hasUserValue !== undefined ) {
- this.originalValues[key] = hasUserValue ? this.getValue(path, setting) : undefined;
- }
- },
-
- clear: function(path, setting) {
- var key = path + '.' + setting;
-
- // Value was not overriden -- nothing to restore
- if ( this.originalValues.hasOwnProperty(key) === false ) {
- return;
- }
-
- var value = this.originalValues[key];
- // https://github.com/gorhill/uBlock/issues/292#issuecomment-109621979
- // Forget the value immediately, it may change outside of
- // uBlock control.
- delete this.originalValues[key];
-
- // Original value was a default one
- if ( value === undefined ) {
- try {
- Services.prefs.getBranch(path + '.').clearUserPref(setting);
- } catch (ex) {
- }
- return;
- }
-
- // Reset to original value
- this.setValue(path, setting, value);
- },
-
- getValue: function(path, setting) {
- var branch = Services.prefs.getBranch(path + '.');
- var getMethod;
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIPrefBranch#getPrefType%28%29
- switch ( branch.getPrefType(setting) ) {
- case 64: // PREF_INT
- getMethod = 'getIntPref';
- break;
- case 128: // PREF_BOOL
- getMethod = 'getBoolPref';
- break;
- default: // not supported
- return;
- }
-
- try {
- return branch[getMethod](setting);
- } catch (ex) {
- }
- },
-
- setValue: function(path, setting, value) {
- var setMethod;
- switch ( typeof value ) {
- case 'number':
- setMethod = 'setIntPref';
- break;
- case 'boolean':
- setMethod = 'setBoolPref';
- break;
- default: // not supported
- return;
- }
-
- try {
- Services.prefs.getBranch(path + '.')[setMethod](setting, value);
- } catch (ex) {
- }
- },
-
- set: function(details) {
- var settingVal;
- var prefName, prefVal;
- for ( var setting in details ) {
- if ( details.hasOwnProperty(setting) === false ) {
- continue;
- }
- settingVal = !!details[setting];
- switch ( setting ) {
- case 'prefetching':
- this.rememberOriginalValue('network', 'prefetch-next');
- // http://betanews.com/2015/08/15/firefox-stealthily-loads-webpages-when-you-hover-over-links-heres-how-to-stop-it/
- // https://bugzilla.mozilla.org/show_bug.cgi?id=814169
- // Sigh.
- this.rememberOriginalValue('network.http', 'speculative-parallel-limit');
- this.rememberOriginalValue('network.dns', 'disablePrefetch');
- // https://github.com/gorhill/uBlock/issues/292
- // "true" means "do not disable", i.e. leave entry alone
- if ( settingVal ) {
- this.clear('network', 'prefetch-next');
- this.clear('network.http', 'speculative-parallel-limit');
- this.clear('network.dns', 'disablePrefetch');
- } else {
- this.setValue('network', 'prefetch-next', false);
- this.setValue('network.http', 'speculative-parallel-limit', 0);
- this.setValue('network.dns', 'disablePrefetch', true);
- }
- break;
-
- case 'hyperlinkAuditing':
- this.rememberOriginalValue('browser', 'send_pings');
- // https://github.com/gorhill/uBlock/issues/292
- // "true" means "do not disable", i.e. leave entry alone
- if ( settingVal ) {
- this.clear('browser', 'send_pings');
- } else {
- this.setValue('browser', 'send_pings', false);
- }
- break;
-
- // https://github.com/gorhill/uBlock/issues/894
- // Do not disable completely WebRTC if it can be avoided. FF42+
- // has a `media.peerconnection.ice.default_address_only` pref which
- // purpose is to prevent local IP address leakage.
- case 'webrtcIPAddress':
- // https://github.com/gorhill/uBlock/issues/2337
- if ( this.getValue('media.peerconnection', 'ice.no_host') !== undefined ) {
- prefName = 'ice.no_host';
- prefVal = true;
- } else if ( this.getValue('media.peerconnection', 'ice.default_address_only') !== undefined ) {
- prefName = 'ice.default_address_only';
- prefVal = true;
- } else {
- prefName = 'enabled';
- prefVal = false;
- }
-
- this.rememberOriginalValue('media.peerconnection', prefName);
- if ( settingVal ) {
- this.clear('media.peerconnection', prefName);
- } else {
- this.setValue('media.peerconnection', prefName, prefVal);
- }
- break;
-
- default:
- break;
- }
- }
- },
-
- restoreAll: function() {
- var pos;
- for ( var key in this.originalValues ) {
- if ( this.originalValues.hasOwnProperty(key) === false ) {
- continue;
- }
- pos = key.lastIndexOf('.');
- this.clear(key.slice(0, pos), key.slice(pos + 1));
- }
- }
-};
-
-cleanupTasks.push(vAPI.browserSettings.restoreAll.bind(vAPI.browserSettings));
-
-/******************************************************************************/
-
-// API matches that of chrome.storage.local:
-// https://developer.chrome.com/extensions/storage
-
-vAPI.storage = (function() {
- var db = null;
- var vacuumTimer = null;
- var dbOpenError = '';
-
- var close = function(now) {
- if ( vacuumTimer !== null ) {
- clearTimeout(vacuumTimer);
- vacuumTimer = null;
- }
- if ( db === null ) {
- return;
- }
- if ( now ) {
- db.close();
- } else {
- db.asyncClose();
- }
- db = null;
- };
-
- var open = function() {
- if ( db !== null ) {
- return db;
- }
-
- // Create path
- var path = Services.dirsvc.get('ProfD', Ci.nsIFile);
- path.append('extension-data');
- if ( !path.exists() ) {
- path.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0774', 8));
- }
- if ( !path.isDirectory() ) {
- throw Error('Should be a directory...');
- }
- path.append(location.host + '.sqlite');
-
- // Open database.
- // https://github.com/gorhill/uBlock/issues/1768
- // If the SQL file is found to be corrupted at launch time, nuke
- // existing SQL file so that a new one can be created.
- try {
- db = Services.storage.openDatabase(path);
- if ( db.connectionReady === false ) {
- db.asyncClose();
- db = null;
- }
- } catch (ex) {
- if ( dbOpenError === '' ) {
- console.error('vAPI.storage/open() error: ', ex.message);
- dbOpenError = ex.name;
- if ( ex.name === 'NS_ERROR_FILE_CORRUPTED' ) {
- nuke();
- }
- }
- }
-
- if ( db === null ) {
- return null;
- }
-
- // Since database could be opened successfully, reset error flag (its
- // purpose is to avoid spamming console with error messages).
- dbOpenError = '';
-
- // Database was opened, register cleanup task
- cleanupTasks.push(close);
-
- // Setup database
- db.createAsyncStatement('CREATE TABLE IF NOT EXISTS "settings" ("name" TEXT PRIMARY KEY NOT NULL, "value" TEXT);')
- .executeAsync();
-
- if ( vacuum !== null ) {
- vacuumTimer = vAPI.setTimeout(vacuum, 60000);
- }
-
- return db;
- };
-
- var nuke = function() {
- var removeDB = function() {
- close(true);
- var path = Services.dirsvc.get('ProfD', Ci.nsIFile);
- path.append('extension-data');
- if ( !path.exists() || !path.isDirectory() ) {
- return;
- }
- path.append(location.host + '.sqlite');
- if ( path.exists() ) {
- path.remove(false);
- }
- };
- vAPI.setTimeout(removeDB, 1);
- };
-
- // https://developer.mozilla.org/en-US/docs/Storage/Performance#Vacuuming_and_zero-fill
- // Vacuum only once, and only while idle
- var vacuum = function() {
- vacuumTimer = null;
- if ( db === null ) {
- return;
- }
- var idleSvc = Cc['@mozilla.org/widget/idleservice;1']
- .getService(Ci.nsIIdleService);
- if ( idleSvc.idleTime < 60000 ) {
- vacuumTimer = vAPI.setTimeout(vacuum, 60000);
- return;
- }
- db.createAsyncStatement('VACUUM').executeAsync();
- vacuum = null;
- };
-
- // Execute a query
- var runStatement = function(stmt, callback) {
- var result = {};
-
- stmt.executeAsync({
- handleResult: function(rows) {
- if ( !rows || typeof callback !== 'function' ) {
- return;
- }
-
- var row;
-
- while ( (row = rows.getNextRow()) ) {
- // we assume that there will be two columns, since we're
- // using it only for preferences
- result[row.getResultByIndex(0)] = row.getResultByIndex(1);
- }
- },
- handleCompletion: function(reason) {
- if ( typeof callback === 'function' && reason === 0 ) {
- callback(result);
- }
- result = null;
- },
- handleError: function(error) {
- console.error('SQLite error ', error.result, error.message);
- // Caller expects an answer regardless of failure.
- if ( typeof callback === 'function' ) {
- callback({});
- }
- result = null;
- // https://github.com/gorhill/uBlock/issues/1768
- // Error cases which warrant a removal of the SQL file, so far:
- // - SQLLite error 11 database disk image is malformed
- // Can't find doc on MDN about the type of error.result, so I
- // force a string comparison.
- if ( error.result.toString() === '11' ) {
- nuke();
- }
- }
- });
- };
-
- var bindNames = function(stmt, names) {
- if ( Array.isArray(names) === false || names.length === 0 ) {
- return;
- }
- var params = stmt.newBindingParamsArray();
- var i = names.length, bp;
- while ( i-- ) {
- bp = params.newBindingParams();
- bp.bindByName('name', names[i]);
- params.addParams(bp);
- }
- stmt.bindParameters(params);
- };
-
- var clear = function(callback) {
- if ( open() === null ) {
- if ( typeof callback === 'function' ) {
- callback();
- }
- return;
- }
- runStatement(db.createAsyncStatement('DELETE FROM "settings";'), callback);
- };
-
- var getBytesInUse = function(keys, callback) {
- if ( typeof callback !== 'function' ) {
- return;
- }
-
- if ( open() === null ) {
- callback(0);
- return;
- }
-
- var stmt;
- if ( Array.isArray(keys) ) {
- stmt = db.createAsyncStatement('SELECT "size" AS "size", SUM(LENGTH("value")) FROM "settings" WHERE "name" = :name');
- bindNames(keys);
- } else {
- stmt = db.createAsyncStatement('SELECT "size" AS "size", SUM(LENGTH("value")) FROM "settings"');
- }
-
- runStatement(stmt, function(result) {
- callback(result.size || 0);
- });
- };
-
- var read = function(details, callback) {
- if ( typeof callback !== 'function' ) {
- return;
- }
-
- var prepareResult = function(result) {
- var key;
- for ( key in result ) {
- if ( result.hasOwnProperty(key) === false ) {
- continue;
- }
- result[key] = JSON.parse(result[key]);
- }
- if ( typeof details === 'object' && details !== null ) {
- for ( key in details ) {
- if ( result.hasOwnProperty(key) === false ) {
- result[key] = details[key];
- }
- }
- }
- callback(result);
- };
-
- if ( open() === null ) {
- prepareResult({});
- return;
- }
-
- var names = [];
- if ( details !== null ) {
- if ( Array.isArray(details) ) {
- names = details;
- } else if ( typeof details === 'object' ) {
- names = Object.keys(details);
- } else {
- names = [details.toString()];
- }
- }
-
- var stmt;
- if ( names.length === 0 ) {
- stmt = db.createAsyncStatement('SELECT * FROM "settings"');
- } else {
- stmt = db.createAsyncStatement('SELECT * FROM "settings" WHERE "name" = :name');
- bindNames(stmt, names);
- }
-
- runStatement(stmt, prepareResult);
- };
-
- var remove = function(keys, callback) {
- if ( open() === null ) {
- if ( typeof callback === 'function' ) {
- callback();
- }
- return;
- }
- var stmt = db.createAsyncStatement('DELETE FROM "settings" WHERE "name" = :name');
- bindNames(stmt, typeof keys === 'string' ? [keys] : keys);
- runStatement(stmt, callback);
- };
-
- var write = function(details, callback) {
- if ( open() === null ) {
- if ( typeof callback === 'function' ) {
- callback();
- }
- return;
- }
-
- var stmt = db.createAsyncStatement('INSERT OR REPLACE INTO "settings" ("name", "value") VALUES(:name, :value)');
- var params = stmt.newBindingParamsArray(), bp;
- for ( var key in details ) {
- if ( details.hasOwnProperty(key) === false ) {
- continue;
- }
- bp = params.newBindingParams();
- bp.bindByName('name', key);
- bp.bindByName('value', JSON.stringify(details[key]));
- params.addParams(bp);
- }
- if ( params.length === 0 ) {
- return;
- }
-
- stmt.bindParameters(params);
- runStatement(stmt, callback);
- };
-
- // Export API
- var api = {
- QUOTA_BYTES: 100 * 1024 * 1024,
- clear: clear,
- get: read,
- getBytesInUse: getBytesInUse,
- remove: remove,
- set: write
- };
- return api;
-})();
-
-vAPI.cacheStorage = vAPI.storage;
-
-/******************************************************************************/
-
-// This must be executed/setup early.
-
-var winWatcher = (function() {
- var windowToIdMap = new Map();
- var windowIdGenerator = 1;
- var api = {
- onOpenWindow: null,
- onCloseWindow: null
- };
-
- // https://github.com/gorhill/uMatrix/issues/586
- // This is necessary hack because on SeaMonkey 2.40, for unknown reasons
- // private windows do not have the attribute `windowtype` set to
- // `navigator:browser`. As a fallback, the code here will also test whether
- // the id attribute is `main-window`.
- api.toBrowserWindow = function(win) {
- var docElement = win && win.document && win.document.documentElement;
- if ( !docElement ) {
- return null;
- }
- if ( vAPI.thunderbird ) {
- return docElement.getAttribute('windowtype') === 'mail:3pane' ? win : null;
- }
- return docElement.getAttribute('windowtype') === 'navigator:browser' ||
- docElement.getAttribute('id') === 'main-window' ?
- win : null;
- };
-
- api.getWindows = function() {
- return windowToIdMap.keys();
- };
-
- api.idFromWindow = function(win) {
- return windowToIdMap.get(win) || 0;
- };
-
- api.getCurrentWindow = function() {
- return this.toBrowserWindow(Services.wm.getMostRecentWindow(null));
- };
-
- var addWindow = function(win) {
- if ( !win || windowToIdMap.has(win) ) {
- return;
- }
- windowToIdMap.set(win, windowIdGenerator++);
- if ( typeof api.onOpenWindow === 'function' ) {
- api.onOpenWindow(win);
- }
- };
-
- var removeWindow = function(win) {
- if ( !win || windowToIdMap.delete(win) !== true ) {
- return;
- }
- // https://github.com/uBlockOrigin/uAssets/issues/567
- // We need to cleanup if and only if the window being closed is
- // the actual top window.
- if ( win.gBrowser && win.gBrowser.ownerGlobal !== win ) {
- return;
- }
- if ( typeof api.onCloseWindow === 'function' ) {
- api.onCloseWindow(win);
- }
- };
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowWatcher
- // https://github.com/gorhill/uMatrix/issues/357
- // Use nsIWindowMediator for being notified of opened/closed windows.
- var listeners = {
- onOpenWindow: function(aWindow) {
- var win;
- try {
- win = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
- } catch (ex) {
- }
- addWindow(win);
- },
-
- onCloseWindow: function(aWindow) {
- var win;
- try {
- win = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
- } catch (ex) {
- }
- removeWindow(win);
- },
-
- observe: function(aSubject, topic) {
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowWatcher#registerNotification%28%29
- // "aSubject - the window being opened or closed, sent as an
- // "nsISupports which can be ... QueryInterfaced to an
- // "nsIDOMWindow."
- var win;
- try {
- win = aSubject.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
- } catch (ex) {
- }
- if ( !win ) { return; }
- if ( topic === 'domwindowopened' ) {
- addWindow(win);
- return;
- }
- if ( topic === 'domwindowclosed' ) {
- removeWindow(win);
- return;
- }
- }
- };
-
- (function() {
- var winumerator, win;
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator#getEnumerator%28%29
- winumerator = Services.wm.getEnumerator(null);
- while ( winumerator.hasMoreElements() ) {
- win = winumerator.getNext();
- if ( !win.closed ) {
- windowToIdMap.set(win, windowIdGenerator++);
- }
- }
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowWatcher#getWindowEnumerator%28%29
- winumerator = Services.ww.getWindowEnumerator();
- while ( winumerator.hasMoreElements() ) {
- win = winumerator.getNext()
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindow);
- if ( !win.closed ) {
- windowToIdMap.set(win, windowIdGenerator++);
- }
- }
-
- Services.wm.addListener(listeners);
- Services.ww.registerNotification(listeners);
- })();
-
- cleanupTasks.push(function() {
- Services.wm.removeListener(listeners);
- Services.ww.unregisterNotification(listeners);
- windowToIdMap.clear();
- });
-
- return api;
-})();
-
-/******************************************************************************/
-
-var getTabBrowser = (function() {
- if ( vAPI.fennec ) {
- return function(win) {
- return win.BrowserApp || null;
- };
- }
-
- if ( vAPI.thunderbird ) {
- return function(win) {
- return win.document.getElementById('tabmail') || null;
- };
- }
-
- // https://github.com/gorhill/uBlock/issues/1004
- // Merely READING the `gBrowser` property causes the issue -- no
- // need to even use its returned value... This really should be fixed
- // in the browser.
- // Meanwhile, the workaround is to check whether the document is
- // ready. This is hacky, as the code below has to make assumption
- // about the browser's inner working -- specifically that the `gBrowser`
- // property should NOT be accessed before the document of the window is
- // in its ready state.
-
- return function(win) {
- if ( win ) {
- var doc = win.document;
- if ( doc && doc.readyState === 'complete' ) {
- return win.gBrowser || null;
- }
- }
- return null;
- };
-})();
-
-/******************************************************************************/
-
-var getOwnerWindow = function(target) {
- if ( target.ownerDocument ) {
- return target.ownerDocument.defaultView;
- }
-
- // Fennec
- for ( var win of winWatcher.getWindows() ) {
- for ( var tab of win.BrowserApp.tabs) {
- if ( tab === target || tab.window === target ) {
- return win;
- }
- }
- }
-
- return null;
-};
-
-/******************************************************************************/
-
-vAPI.isBehindTheSceneTabId = function(tabId) {
- return tabId < 0;
-};
-
-vAPI.noTabId = -1;
-vAPI.anyTabId = -2;
-
-/******************************************************************************/
-
-vAPI.tabs = {};
-
-/******************************************************************************/
-
-vAPI.tabs.registerListeners = function() {
- tabWatcher.start();
-};
-
-/******************************************************************************/
-
-// Firefox:
-// https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Tabbed_browser
-//
-// browser --> ownerDocument --> defaultView --> gBrowser --> browsers --+
-// ^ |
-// | |
-// +-------------------------------------------------------------------
-//
-// browser (browser)
-// contentTitle
-// currentURI
-// ownerDocument (XULDocument)
-// defaultView (ChromeWindow)
-// gBrowser (tabbrowser OR browser)
-// browsers (browser)
-// selectedBrowser
-// selectedTab
-// tabs (tab.tabbrowser-tab)
-//
-// Fennec: (what I figured so far)
-//
-// tab --> browser windows --> window --> BrowserApp --> tabs --+
-// ^ window |
-// | |
-// +---------------------------------------------------------------+
-//
-// tab
-// browser
-// [manual search to go back to tab from list of windows]
-
-vAPI.tabs.get = function(tabId, callback) {
- var browser;
-
- if ( tabId === null ) {
- browser = tabWatcher.currentBrowser();
- tabId = tabWatcher.tabIdFromTarget(browser);
- } else {
- browser = tabWatcher.browserFromTabId(tabId);
- }
-
- // For internal use
- if ( typeof callback !== 'function' ) {
- return browser;
- }
-
- if ( !browser || !browser.currentURI ) {
- callback();
- return;
- }
-
- var win = getOwnerWindow(browser);
- var tabBrowser = getTabBrowser(win);
-
- // https://github.com/gorhill/uMatrix/issues/540
- // The `index` property is nowhere used by uBlock at this point, so we
- // will refrain from returning this information for the time being.
-
- callback({
- id: tabId,
- index: undefined,
- windowId: winWatcher.idFromWindow(win),
- active: tabBrowser !== null && browser === tabBrowser.selectedBrowser,
- url: browser.currentURI.asciiSpec,
- title: browser.contentTitle
- });
-};
-
-/******************************************************************************/
-
-vAPI.tabs.getAll = function(window) {
- var win, tab;
- var tabs = [];
-
- for ( win of winWatcher.getWindows() ) {
- if ( window && window !== win ) {
- continue;
- }
-
- var tabBrowser = getTabBrowser(win);
- if ( tabBrowser === null ) {
- continue;
- }
-
- // This can happens if a tab-less window is currently opened.
- // Example of a tab-less window: one opened from clicking
- // "View Page Source".
- if ( !tabBrowser.tabs ) {
- continue;
- }
-
- for ( tab of tabBrowser.tabs ) {
- tabs.push(tab);
- }
- }
-
- return tabs;
-};
-
-/******************************************************************************/
-
-// properties of the details object:
-// url: 'URL', // the address that will be opened
-// tabId: 1, // the tab is used if set, instead of creating a new one
-// index: -1, // undefined: end of the list, -1: following tab, or after index
-// active: false, // opens the tab in background - true and undefined: foreground
-// select: true // if a tab is already opened with that url, then select it instead of opening a new one
-
-vAPI.tabs.open = function(details) {
- if ( !details.url ) {
- return null;
- }
- // extension pages
- if ( /^[\w-]{2,}:/.test(details.url) === false ) {
- details.url = vAPI.getURL(details.url);
- }
-
- var tab;
-
- if ( details.select ) {
- var URI = Services.io.newURI(details.url, null, null);
-
- for ( tab of this.getAll() ) {
- var browser = tabWatcher.browserFromTarget(tab);
- // https://github.com/gorhill/uBlock/issues/2558
- if ( browser === null ) { continue; }
-
- // Or simply .equals if we care about the fragment
- if ( URI.equalsExceptRef(browser.currentURI) === false ) {
- continue;
- }
-
- this.select(tab);
-
- // Update URL if fragment is different
- if ( URI.equals(browser.currentURI) === false ) {
- browser.loadURI(URI.asciiSpec);
- }
- return;
- }
- }
-
- if ( details.active === undefined ) {
- details.active = true;
- }
-
- if ( details.tabId ) {
- tab = tabWatcher.browserFromTabId(details.tabId);
- if ( tab ) {
- tabWatcher.browserFromTarget(tab).loadURI(details.url);
- return;
- }
- }
-
- var win = winWatcher.getCurrentWindow();
- var tabBrowser = getTabBrowser(win);
- if ( tabBrowser === null ) {
- return;
- }
-
- if ( vAPI.fennec ) {
- tabBrowser.addTab(details.url, {
- selected: details.active !== false,
- parentId: tabBrowser.selectedTab.id
- });
- // Note that it's impossible to move tabs on Fennec, so don't bother
- return;
- }
-
- // Open in a standalone window
- if ( details.popup === true ) {
- Services.ww.openWindow(
- win,
- details.url,
- 'uBO-logger',
- 'location=1,menubar=1,personalbar=1,resizable=1,toolbar=1',
- null
- );
- return;
- }
-
- if ( vAPI.thunderbird ) {
- tabBrowser.openTab('contentTab', {
- contentPage: details.url,
- background: !details.active
- });
- // TODO: Should be possible to move tabs on Thunderbird
- return;
- }
-
- if ( details.index === -1 ) {
- details.index = tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1;
- }
-
- tab = tabBrowser.loadOneTab(details.url, { inBackground: !details.active });
-
- if ( details.index !== undefined ) {
- tabBrowser.moveTabTo(tab, details.index);
- }
-};
-
-/******************************************************************************/
-
-// Replace the URL of a tab. Noop if the tab does not exist.
-
-vAPI.tabs.replace = function(tabId, url) {
- var targetURL = url;
-
- // extension pages
- if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
- targetURL = vAPI.getURL(targetURL);
- }
-
- var browser = tabWatcher.browserFromTabId(tabId);
- if ( browser ) {
- browser.loadURI(targetURL);
- }
-};
-
-/******************************************************************************/
-
-vAPI.tabs._remove = (function() {
- if ( vAPI.fennec || vAPI.thunderbird ) {
- return function(tab, tabBrowser) {
- tabBrowser.closeTab(tab);
- };
- }
- return function(tab, tabBrowser) {
- if ( !tabBrowser ) { return; }
- tabBrowser.removeTab(tab);
- };
-})();
-
-/******************************************************************************/
-
-// https://bugzilla.mozilla.org/show_bug.cgi?id=1317173
-// Work around FF45 (and earlier) timing issue by delaying the closing
-// of tabs. The picked delay is just what seemed to work for the test case
-// reported in the issue above.
-
-vAPI.tabs.remove = (function() {
- var timer = null,
- queue = [];
-
- var remove = function() {
- timer = null;
- var tabId, browser, tab;
- while ( (tabId = queue.pop()) ) {
- browser = tabWatcher.browserFromTabId(tabId);
- if ( !browser ) { continue; }
- tab = tabWatcher.tabFromBrowser(browser);
- if ( !tab ) { continue; }
- this._remove(tab, getTabBrowser(getOwnerWindow(browser)));
- }
- };
-
- // Do this asynchronously
- return function(tabId, delay) {
- queue.push(tabId);
- if ( timer !== null ) {
- if ( !delay ) { return; }
- clearTimeout(timer);
- }
- timer = vAPI.setTimeout(remove.bind(this), delay ? 250 : 25);
- };
-})();
-
-/******************************************************************************/
-
-vAPI.tabs.reload = function(tabId) {
- var browser = tabWatcher.browserFromTabId(tabId);
- if ( !browser ) {
- return;
- }
-
- browser.webNavigation.reload(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
-};
-
-/******************************************************************************/
-
-vAPI.tabs.select = function(tab) {
- if ( typeof tab !== 'object' ) {
- tab = tabWatcher.tabFromBrowser(tabWatcher.browserFromTabId(tab));
- }
- if ( !tab ) {
- return;
- }
-
- var win = getOwnerWindow(tab);
- var tabBrowser = getTabBrowser(win);
- if ( tabBrowser === null ) {
- return;
- }
-
- // https://github.com/gorhill/uBlock/issues/470
- win.focus();
-
- if ( vAPI.fennec ) {
- tabBrowser.selectTab(tab);
- } else {
- tabBrowser.selectedTab = tab;
- }
-};
-
-/******************************************************************************/
-
-vAPI.tabs.injectScript = function(tabId, details, callback) {
- var browser = tabWatcher.browserFromTabId(tabId);
- if ( !browser ) {
- return;
- }
-
- if ( typeof details.file !== 'string' ) {
- return;
- }
-
- details.file = vAPI.getURL(details.file);
- browser.messageManager.sendAsyncMessage(
- location.host + ':broadcast',
- JSON.stringify({
- broadcast: true,
- channelName: 'vAPI',
- msg: {
- cmd: 'injectScript',
- details: details
- }
- })
- );
-
- if ( typeof callback === 'function' ) {
- vAPI.setTimeout(callback, 13);
- }
-};
-
-/******************************************************************************/
-
-var tabWatcher = (function() {
- // https://github.com/gorhill/uMatrix/issues/540
- // Use only weak references to hold onto browser references.
- var browserToTabIdMap = new WeakMap();
- var tabIdToBrowserMap = new Map();
- var tabIdGenerator = 1;
-
- var indexFromBrowser = function(browser) {
- if ( !browser ) {
- return -1;
- }
- // TODO: Add support for this
- if ( vAPI.thunderbird ) {
- return -1;
- }
- var win = getOwnerWindow(browser);
- if ( !win ) {
- return -1;
- }
- var tabbrowser = getTabBrowser(win);
- if ( tabbrowser === null ) {
- return -1;
- }
- // This can happen, for example, the `view-source:` window, there is
- // no tabbrowser object, the browser object sits directly in the
- // window.
- if ( tabbrowser === browser ) {
- return 0;
- }
- // Fennec
- // https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/BrowserApp
- if ( vAPI.fennec ) {
- return tabbrowser.tabs.indexOf(tabbrowser.getTabForBrowser(browser));
- }
- return tabbrowser.browsers.indexOf(browser);
- };
-
- var indexFromTarget = function(target) {
- return indexFromBrowser(browserFromTarget(target));
- };
-
- var tabFromBrowser = function(browser) {
- var i = indexFromBrowser(browser);
- if ( i === -1 ) {
- return null;
- }
- var win = getOwnerWindow(browser);
- if ( !win ) {
- return null;
- }
- var tabbrowser = getTabBrowser(win);
- if ( tabbrowser === null ) {
- return null;
- }
- if ( !tabbrowser.tabs || i >= tabbrowser.tabs.length ) {
- return null;
- }
- return tabbrowser.tabs[i];
- };
-
- var browserFromTarget = (function() {
- if ( vAPI.fennec ) {
- return function(target) {
- if ( !target ) { return null; }
- if ( target.browser ) { // target is a tab
- target = target.browser;
- }
- return target.localName === 'browser' ? target : null;
- };
- }
- if ( vAPI.thunderbird ) {
- return function(target) {
- if ( !target ) { return null; }
- if ( target.mode ) { // target is object with tab info
- var browserFunc = target.mode.getBrowser || target.mode.tabType.getBrowser;
- if ( browserFunc ) {
- return browserFunc.call(target.mode.tabType, target);
- }
- }
- return target.localName === 'browser' ? target : null;
- };
- }
- return function(target) {
- if ( !target ) { return null; }
- if ( target.linkedPanel ) { // target is a tab
- target = target.linkedBrowser;
- }
- return target.localName === 'browser' ? target : null;
- };
- })();
-
- var tabIdFromTarget = function(target) {
- var browser = browserFromTarget(target);
- if ( browser === null ) {
- return vAPI.noTabId;
- }
- var tabId = browserToTabIdMap.get(browser);
- if ( tabId === undefined ) {
- tabId = tabIdGenerator++;
- browserToTabIdMap.set(browser, tabId);
- tabIdToBrowserMap.set(tabId, Cu.getWeakReference(browser));
- }
- return tabId;
- };
-
- var browserFromTabId = function(tabId) {
- var weakref = tabIdToBrowserMap.get(tabId);
- return weakref && weakref.get() || null;
- };
-
- var currentBrowser = function() {
- var win = winWatcher.getCurrentWindow();
- // https://github.com/gorhill/uBlock/issues/399
- // getTabBrowser() can return null at browser launch time.
- var tabBrowser = getTabBrowser(win);
- if ( tabBrowser === null ) {
- return null;
- }
- if ( vAPI.thunderbird ) {
- // Directly at startup the first tab may not be initialized
- if ( tabBrowser.tabInfo.length === 0 ) {
- return null;
- }
- return tabBrowser.getBrowserForSelectedTab() || null;
- }
- return browserFromTarget(tabBrowser.selectedTab);
- };
-
- var removeBrowserEntry = function(tabId, browser) {
- if ( tabId && tabId !== vAPI.noTabId ) {
- vAPI.tabs.onClosed(tabId);
- vAPI.toolbarButton.tabs.delete(tabId);
- tabIdToBrowserMap.delete(tabId);
- }
- if ( browser ) {
- browserToTabIdMap.delete(browser);
- }
- };
-
- var removeTarget = function(target) {
- onClose({ target: target });
- };
-
- var getAllBrowsers = function() {
- var browsers = [], browser;
- for ( var weakref of tabIdToBrowserMap.values() ) {
- browser = weakref.get();
- // TODO:
- // Maybe call removeBrowserEntry() if the browser no longer exists?
- if ( browser ) {
- browsers.push(browser);
- }
- }
- return browsers;
- };
-
- // https://developer.mozilla.org/en-US/docs/Web/Events/TabShow
- var onShow = function({target}) {
- tabIdFromTarget(target);
- };
-
- // https://developer.mozilla.org/en-US/docs/Web/Events/TabClose
- var onClose = function({target}) {
- // target is tab in Firefox, browser in Fennec
- var browser = browserFromTarget(target);
- var tabId = browserToTabIdMap.get(browser);
- removeBrowserEntry(tabId, browser);
- };
-
- // https://developer.mozilla.org/en-US/docs/Web/Events/TabSelect
- var onSelect = function({target}) {
- vAPI.setIcon(tabIdFromTarget(target), getOwnerWindow(target));
- };
-
- var attachToTabBrowser = function(window) {
- if ( typeof vAPI.toolbarButton.attachToNewWindow === 'function' ) {
- vAPI.toolbarButton.attachToNewWindow(window);
- }
-
- var tabBrowser = getTabBrowser(window);
- if ( tabBrowser === null ) {
- return;
- }
-
- var tabContainer;
- if ( tabBrowser.deck ) { // Fennec
- tabContainer = tabBrowser.deck;
- } else if ( tabBrowser.tabContainer ) { // Firefox
- tabContainer = tabBrowser.tabContainer;
- vAPI.contextMenu.register(window);
- vAPI.commands.register(window);
- }
-
- // https://github.com/gorhill/uBlock/issues/697
- // Ignore `TabShow` events: unfortunately the `pending` attribute is
- // not set when a tab is opened as a result of session restore -- it is
- // set *after* the event is fired in such case.
- if ( tabContainer ) {
- tabContainer.addEventListener('TabShow', onShow);
- tabContainer.addEventListener('TabClose', onClose);
- // when new window is opened TabSelect doesn't run on the selected tab?
- tabContainer.addEventListener('TabSelect', onSelect);
- }
- };
-
- // https://github.com/gorhill/uBlock/issues/906
- // Ensure the environment is ready before trying to attaching.
- var canAttachToTabBrowser = function(window) {
- var document = window && window.document;
- if ( !document || document.readyState !== 'complete' ) {
- return false;
- }
-
- // On some platforms, the tab browser isn't immediately available,
- // try waiting a bit if this happens.
- // https://github.com/gorhill/uBlock/issues/763
- // Not getting a tab browser should not prevent from attaching ourself
- // to the window.
- var tabBrowser = getTabBrowser(window);
- if ( tabBrowser === null ) {
- return false;
- }
-
- return winWatcher.toBrowserWindow(window) !== null;
- };
-
- var onWindowLoad = function(win) {
- deferUntil(
- canAttachToTabBrowser.bind(null, win),
- attachToTabBrowser.bind(null, win)
- );
- };
-
- var onWindowUnload = function(win) {
- vAPI.contextMenu.unregister(win);
- vAPI.commands.unregister(win);
-
- var tabBrowser = getTabBrowser(win);
- if ( tabBrowser === null ) {
- return;
- }
-
- var tabContainer;
- if ( tabBrowser.deck ) { // Fennec
- tabContainer = tabBrowser.deck;
- } else if ( tabBrowser.tabContainer ) { // Firefox
- tabContainer = tabBrowser.tabContainer;
- }
- if ( tabContainer ) {
- tabContainer.removeEventListener('TabShow', onShow);
- tabContainer.removeEventListener('TabClose', onClose);
- tabContainer.removeEventListener('TabSelect', onSelect);
- }
-
- // https://github.com/gorhill/uBlock/issues/574
- // To keep in mind: not all windows are tab containers,
- // sometimes the window IS the tab.
- var tabs;
- if ( vAPI.thunderbird ) {
- tabs = tabBrowser.tabInfo;
- } else if ( tabBrowser.tabs ) {
- tabs = tabBrowser.tabs;
- } else if ( tabBrowser.localName === 'browser' ) {
- tabs = [tabBrowser];
- } else {
- tabs = [];
- }
-
- var browser, tabId;
- var tabindex = tabs.length, tab;
- while ( tabindex-- ) {
- tab = tabs[tabindex];
- browser = browserFromTarget(tab);
- if ( browser === null ) {
- continue;
- }
- tabId = browserToTabIdMap.get(browser);
- if ( tabId !== undefined ) {
- removeBrowserEntry(tabId, browser);
- tabIdToBrowserMap.delete(tabId);
- }
- browserToTabIdMap.delete(browser);
- }
- };
-
- // Initialize map with existing active tabs
- var start = function() {
- var tabBrowser, tabs, tab;
- for ( var win of winWatcher.getWindows() ) {
- onWindowLoad(win);
- tabBrowser = getTabBrowser(win);
- if ( tabBrowser === null ) {
- continue;
- }
- // `tabBrowser.tabs` may not exist (Thunderbird).
- tabs = tabBrowser.tabs;
- if ( !tabs ) {
- continue;
- }
- for ( tab of tabs ) {
- if ( vAPI.fennec || !tab.hasAttribute('pending') ) {
- tabIdFromTarget(tab);
- }
- }
- }
-
- winWatcher.onOpenWindow = onWindowLoad;
- winWatcher.onCloseWindow = onWindowUnload;
- };
-
- var stop = function() {
- winWatcher.onOpenWindow = null;
- winWatcher.onCloseWindow = null;
-
- for ( var win of winWatcher.getWindows() ) {
- onWindowUnload(win);
- }
- browserToTabIdMap = new WeakMap();
- tabIdToBrowserMap.clear();
- };
-
- cleanupTasks.push(stop);
-
- return {
- browsers: getAllBrowsers,
- browserFromTabId: browserFromTabId,
- browserFromTarget: browserFromTarget,
- currentBrowser: currentBrowser,
- indexFromTarget: indexFromTarget,
- removeTarget: removeTarget,
- start: start,
- tabFromBrowser: tabFromBrowser,
- tabIdFromTarget: tabIdFromTarget
- };
-})();
-
-/******************************************************************************/
-
-vAPI.setIcon = function(tabId, iconStatus, badge) {
- // If badge is undefined, then setIcon was called from the TabSelect event
- var win = badge === undefined
- ? iconStatus
- : winWatcher.getCurrentWindow();
- var curTabId;
- var tabBrowser = getTabBrowser(win);
- if ( tabBrowser !== null ) {
- curTabId = tabWatcher.tabIdFromTarget(tabBrowser.selectedTab);
- }
- var tb = vAPI.toolbarButton;
-
- // from 'TabSelect' event
- if ( tabId === undefined ) {
- tabId = curTabId;
- } else if ( badge !== undefined ) {
- tb.tabs.set(tabId, { badge: badge, img: iconStatus === 'on' });
- }
-
- if ( curTabId && tabId === curTabId ) {
- tb.updateState(win, tabId);
- vAPI.contextMenu.onMustUpdate(tabId);
- }
-};
-
-/******************************************************************************/
-
-vAPI.messaging = {
- get globalMessageManager() {
- return Cc['@mozilla.org/globalmessagemanager;1']
- .getService(Ci.nsIMessageListenerManager);
- },
- frameScriptURL: vAPI.getURL('frameScript.js'),
- listeners: {},
- defaultHandler: null,
- NOOPFUNC: function(){},
- UNHANDLED: 'vAPI.messaging.notHandled'
-};
-
-/******************************************************************************/
-
-vAPI.messaging.listen = function(listenerName, callback) {
- this.listeners[listenerName] = callback;
-};
-
-/******************************************************************************/
-
-vAPI.messaging.onMessage = (function() {
- var messaging = vAPI.messaging;
-
- // Use a wrapper to avoid closure and to allow reuse.
- var CallbackWrapper = function(messageManager, listenerId, channelName, auxProcessId) {
- this.callback = this.proxy.bind(this); // bind once
- this.init(messageManager, listenerId, channelName, auxProcessId);
- };
-
- CallbackWrapper.prototype.init = function(messageManager, listenerId, channelName, auxProcessId) {
- this.messageManager = messageManager;
- this.listenerId = listenerId;
- this.channelName = channelName;
- this.auxProcessId = auxProcessId;
- return this;
- };
-
- CallbackWrapper.prototype.proxy = function(response) {
- var message = JSON.stringify({
- auxProcessId: this.auxProcessId,
- channelName: this.channelName,
- msg: response !== undefined ? response : null
- });
-
- if ( this.messageManager.sendAsyncMessage ) {
- this.messageManager.sendAsyncMessage(this.listenerId, message);
- } else {
- this.messageManager.broadcastAsyncMessage(this.listenerId, message);
- }
-
- // Mark for reuse
- this.messageManager =
- this.listenerId =
- this.channelName =
- this.auxProcessId = null;
- callbackWrapperJunkyard.push(this);
- };
-
- var callbackWrapperJunkyard = [];
-
- var callbackWrapperFactory = function(messageManager, listenerId, channelName, auxProcessId) {
- var wrapper = callbackWrapperJunkyard.pop();
- if ( wrapper ) {
- return wrapper.init(messageManager, listenerId, channelName, auxProcessId);
- }
- return new CallbackWrapper(messageManager, listenerId, channelName, auxProcessId);
- };
-
- return function({target, data}) {
- // Auxiliary process to main process
- var messageManager = target.messageManager;
-
- // Message came from a popup, and its message manager is not usable.
- // So instead we broadcast to the parent window.
- if ( !messageManager ) {
- messageManager = getOwnerWindow(
- target.webNavigation.QueryInterface(Ci.nsIDocShell).chromeEventHandler
- ).messageManager;
- }
-
- var channelNameRaw = data.channelName;
- var pos = channelNameRaw.indexOf('|');
- var channelName = channelNameRaw.slice(pos + 1);
-
- // Auxiliary process to main process: prepare response
- var callback = messaging.NOOPFUNC;
- if ( data.auxProcessId !== undefined ) {
- callback = callbackWrapperFactory(
- messageManager,
- channelNameRaw.slice(0, pos),
- channelName,
- data.auxProcessId
- ).callback;
- }
-
- var sender = {
- tab: {
- id: tabWatcher.tabIdFromTarget(target)
- }
- };
-
- // Auxiliary process to main process: specific handler
- var r = messaging.UNHANDLED;
- var listener = messaging.listeners[channelName];
- if ( typeof listener === 'function' ) {
- r = listener(data.msg, sender, callback);
- }
- if ( r !== messaging.UNHANDLED ) { return; }
-
- // Auxiliary process to main process: default handler
- r = messaging.defaultHandler(data.msg, sender, callback);
- if ( r !== messaging.UNHANDLED ) { return; }
-
- // Auxiliary process to main process: no handler
- console.error('uBlock> messaging > unknown request: %o', data);
-
- // Need to callback anyways in case caller expected an answer, or
- // else there is a memory leak on caller's side
- callback();
- };
-})();
-
-/******************************************************************************/
-
-vAPI.messaging.setup = function(defaultHandler) {
- // Already setup?
- if ( this.defaultHandler !== null ) {
- return;
- }
-
- if ( typeof defaultHandler !== 'function' ) {
- defaultHandler = function(){ return vAPI.messaging.UNHANDLED; };
- }
- this.defaultHandler = defaultHandler;
-
- var gmm = this.globalMessageManager;
- gmm.addMessageListener(
- location.host + ':background',
- this.onMessage
- );
- gmm.loadFrameScript(this.frameScriptURL, true);
-
- cleanupTasks.push(function() {
- var gmm = vAPI.messaging.globalMessageManager;
- gmm.broadcastAsyncMessage(
- location.host + ':broadcast',
- JSON.stringify({
- broadcast: true,
- channelName: 'vAPI',
- msg: { cmd: 'shutdownSandbox' }
- })
- );
- gmm.removeDelayedFrameScript(vAPI.messaging.frameScriptURL);
- gmm.removeMessageListener(
- location.host + ':background',
- vAPI.messaging.onMessage
- );
- vAPI.messaging.defaultHandler = null;
- });
-};
-
-/******************************************************************************/
-
-vAPI.messaging.broadcast = function(message) {
- this.globalMessageManager.broadcastAsyncMessage(
- location.host + ':broadcast',
- JSON.stringify({broadcast: true, msg: message})
- );
-};
-
-/******************************************************************************/
-/******************************************************************************/
-
-// Synchronous messaging: Firefox allows this. Chromium does not allow this.
-
-// Sometimes there is no way around synchronous messaging, as long as:
-// - the code at the other end execute fast and return quickly.
-// - it's not abused.
-// Original rationale is .
-// Synchronous messaging is a good solution for this case because:
-// - It's done only *once* per page load. (Keep in mind there is already a
-// sync message sent for each single network request on a page and it's not
-// an issue, because the code executed is trivial, which is the key -- see
-// shouldLoadListener below).
-// - The code at the other end is fast.
-// Though vAPI.rpcReceiver was brought forth because of this one case, I
-// generalized the concept for whatever future need for synchronous messaging
-// which might arise.
-
-// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview#Content_frame_message_manager
-
-vAPI.rpcReceiver = (function() {
- var calls = Object.create(null),
- childProcessMessageName = location.host + ':child-process-message',
- processScriptURL = vAPI.getURL('processScript.js');
-
- var onChildProcessMessage = function(ev) {
- var msg = ev.data;
- if ( !msg ) { return; }
- var fn = calls[msg.fnName];
- if ( typeof fn === 'function' ) {
- return fn(msg);
- }
- };
-
- var ppmm = Services.ppmm;
- if ( !ppmm ) {
- ppmm = Cc['@mozilla.org/parentprocessmessagemanager;1'];
- if ( ppmm ) {
- ppmm = ppmm.getService(Ci.nsIMessageListenerManager);
- }
- if ( !ppmm ) {
- return calls;
- }
- }
-
- // https://github.com/gorhill/uBlock/issues/2014
- // Not supported on older versions of Firefox.
- if ( ppmm.loadProcessScript instanceof Function ) {
- ppmm.loadProcessScript(processScriptURL, true);
- }
-
- ppmm.addMessageListener(
- childProcessMessageName,
- onChildProcessMessage
- );
-
- cleanupTasks.push(function() {
- if ( ppmm.removeDelayedProcessScript instanceof Function ) {
- ppmm.removeDelayedProcessScript(processScriptURL);
- }
-
- ppmm.removeMessageListener(
- childProcessMessageName,
- onChildProcessMessage
- );
- });
-
- return calls;
-})();
-
-/******************************************************************************/
-/******************************************************************************/
-
-var httpObserver = {
- classDescription: 'net-channel-event-sinks for ' + location.host,
- classID: Components.ID('{dc8d6319-5f6e-4438-999e-53722db99e84}'),
- contractID: '@' + location.host + '/net-channel-event-sinks;1',
- REQDATAKEY: location.host + 'reqdata',
- ABORT: Components.results.NS_BINDING_ABORTED,
- ACCEPT: Components.results.NS_SUCCEEDED,
- // Request types:
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIContentPolicy#Constants
- typeMap: {
- 1: 'other',
- 2: 'script',
- 3: 'image',
- 4: 'stylesheet',
- 5: 'object',
- 6: 'main_frame',
- 7: 'sub_frame',
- 10: 'ping',
- 11: 'xmlhttprequest',
- 12: 'object',
- 14: 'font',
- 15: 'media',
- 16: 'websocket',
- 17: 'csp_report',
- 19: 'beacon',
- 20: 'xmlhttprequest',
- 21: 'image'
- },
- onBeforeRequest: function(){},
- onBeforeRequestTypes: null,
- onHeadersReceived: function(){},
- onHeadersReceivedTypes: null,
-
- get componentRegistrar() {
- return Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
- },
-
- get categoryManager() {
- return Cc['@mozilla.org/categorymanager;1']
- .getService(Ci.nsICategoryManager);
- },
-
- QueryInterface: (function() {
- var {XPCOMUtils} = Cu.import('resource://gre/modules/XPCOMUtils.jsm', null);
-
- return XPCOMUtils.generateQI([
- Ci.nsIFactory,
- Ci.nsIObserver,
- Ci.nsIChannelEventSink,
- Ci.nsISupportsWeakReference
- ]);
- })(),
-
- createInstance: function(outer, iid) {
- if ( outer ) {
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- }
-
- return this.QueryInterface(iid);
- },
-
- register: function() {
- this.pendingRingBufferInit();
-
- Services.obs.addObserver(this, 'http-on-modify-request', true);
- Services.obs.addObserver(this, 'http-on-examine-response', true);
-
- // Guard against stale instances not having been unregistered
- if ( this.componentRegistrar.isCIDRegistered(this.classID) ) {
- try {
- this.componentRegistrar.unregisterFactory(this.classID, Components.manager.getClassObject(this.classID, Ci.nsIFactory));
- } catch (ex) {
- console.error('uBlock> httpObserver > unable to unregister stale instance: ', ex);
- }
- }
-
- this.componentRegistrar.registerFactory(
- this.classID,
- this.classDescription,
- this.contractID,
- this
- );
- this.categoryManager.addCategoryEntry(
- 'net-channel-event-sinks',
- this.contractID,
- this.contractID,
- false,
- true
- );
- },
-
- unregister: function() {
- Services.obs.removeObserver(this, 'http-on-modify-request');
- Services.obs.removeObserver(this, 'http-on-examine-response');
-
- this.componentRegistrar.unregisterFactory(this.classID, this);
- this.categoryManager.deleteCategoryEntry(
- 'net-channel-event-sinks',
- this.contractID,
- false
- );
- },
-
- PendingRequest: function() {
- this.frameId = 0;
- this.parentFrameId = 0;
- this.rawtype = 0;
- this.tabId = 0;
- this._key = ''; // key is url, from URI.spec
- },
-
- // If all work fine, this map should not grow indefinitely. It can have
- // stale items in it, but these will be taken care of when entries in
- // the ring buffer are overwritten.
- pendingURLToIndex: new Map(),
- pendingWritePointer: 0,
- pendingRingBuffer: new Array(256),
- pendingRingBufferInit: function() {
- // Use and reuse pre-allocated PendingRequest objects = less memory
- // churning.
- var i = this.pendingRingBuffer.length;
- while ( i-- ) {
- this.pendingRingBuffer[i] = new this.PendingRequest();
- }
- },
-
- // Pending request ring buffer:
- // +-------+-------+-------+-------+-------+-------+-------
- // |0 |1 |2 |3 |4 |5 |...
- // +-------+-------+-------+-------+-------+-------+-------
- //
- // URL to ring buffer index map:
- // { k = URL, s = ring buffer indices }
- //
- // s is a string which character codes map to ring buffer indices -- for
- // when the same URL is received multiple times by shouldLoadListener()
- // before the existing one is serviced by the network request observer.
- // I believe the use of a string in lieu of an array reduces memory
- // churning.
-
- createPendingRequest: function(url) {
- var bucket;
- var i = this.pendingWritePointer;
- this.pendingWritePointer = i + 1 & 255;
- var preq = this.pendingRingBuffer[i];
- var si = String.fromCharCode(i);
- // Cleanup unserviced pending request
- if ( preq._key !== '' ) {
- bucket = this.pendingURLToIndex.get(preq._key);
- if ( bucket.length === 1 ) {
- this.pendingURLToIndex.delete(preq._key);
- } else {
- var pos = bucket.indexOf(si);
- this.pendingURLToIndex.set(preq._key, bucket.slice(0, pos) + bucket.slice(pos + 1));
- }
- }
- bucket = this.pendingURLToIndex.get(url);
- this.pendingURLToIndex.set(url, bucket === undefined ? si : si + bucket);
- preq._key = url;
- return preq;
- },
-
- lookupPendingRequest: function(url) {
- var bucket = this.pendingURLToIndex.get(url);
- if ( bucket === undefined ) {
- return null;
- }
- var i = bucket.charCodeAt(0);
- if ( bucket.length === 1 ) {
- this.pendingURLToIndex.delete(url);
- } else {
- this.pendingURLToIndex.set(url, bucket.slice(1));
- }
- var preq = this.pendingRingBuffer[i];
- preq._key = ''; // mark as "serviced"
- return preq;
- },
-
- // https://github.com/gorhill/uMatrix/issues/165
- // https://developer.mozilla.org/en-US/Firefox/Releases/3.5/Updating_extensions#Getting_a_load_context_from_a_request
- // Not sure `umatrix:shouldLoad` is still needed, uMatrix does not
- // care about embedded frames topography.
- // Also:
- // https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Limitations_of_chrome_scripts
- tabIdFromChannel: function(channel) {
- var lc;
- try {
- lc = channel.notificationCallbacks.getInterface(Ci.nsILoadContext);
- } catch(ex) {
- }
- if ( !lc ) {
- try {
- lc = channel.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
- } catch(ex) {
- }
- if ( !lc ) {
- return vAPI.noTabId;
- }
- }
- if ( lc.topFrameElement ) {
- return tabWatcher.tabIdFromTarget(lc.topFrameElement);
- }
- var win;
- try {
- win = lc.associatedWindow;
- } catch (ex) { }
- if ( !win ) {
- return vAPI.noTabId;
- }
- if ( win.top ) {
- win = win.top;
- }
- var tabBrowser;
- try {
- tabBrowser = getTabBrowser(
- win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsIDocShell).rootTreeItem
- .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow)
- );
- } catch (ex) { }
- if ( !tabBrowser ) {
- return vAPI.noTabId;
- }
- if ( tabBrowser.getBrowserForContentWindow ) {
- return tabWatcher.tabIdFromTarget(tabBrowser.getBrowserForContentWindow(win));
- }
- // Falling back onto _getTabForContentWindow to ensure older versions
- // of Firefox work well.
- return tabBrowser._getTabForContentWindow ?
- tabWatcher.tabIdFromTarget(tabBrowser._getTabForContentWindow(win)) :
- vAPI.noTabId;
- },
-
- // https://github.com/gorhill/uBlock/issues/959
- syntheticPendingRequest: { frameId: 0, parentFrameId: -1, tabId: 0, rawtype: 1 },
-
- handleRequest: function(channel, URI, details) {
- var type = this.typeMap[details.rawtype] || 'other';
- if ( this.onBeforeRequestTypes && this.onBeforeRequestTypes.has(type) === false ) {
- return false;
- }
-
- // https://github.com/uBlockOrigin/uAssets/issues/123#issuecomment-244055243
- // Need special handling for websocket requests: http-based websocket
- // requests will be evaluated as ws-based websocket requests.
- if ( details.rawtype === 16 && URI.asciiSpec.startsWith('http') ) {
- URI = Services.io.newURI(URI.asciiSpec.replace(/^http(s)?:/, 'ws$1:'), null, null);
- }
-
- var result = this.onBeforeRequest({
- frameId: details.frameId,
- parentFrameId: details.parentFrameId,
- tabId: details.tabId,
- type: type,
- url: URI.asciiSpec
- });
-
- if ( result && typeof result === 'object' ) {
- if ( 'cancel' in result && result.cancel === true ) {
- channel.cancel(this.ABORT);
- return true;
- }
- if ( 'redirectUrl' in result ) {
- channel.redirectionLimit = 1;
- channel.redirectTo(Services.io.newURI(result.redirectUrl, null, null));
- return true;
- }
- }
-
- return false;
- },
-
- getResponseHeader: function(channel, name) {
- var value;
- try {
- value = channel.getResponseHeader(name);
- } catch (ex) {
- }
- return value;
- },
-
- handleResponseHeaders: function(channel, URI, channelData) {
- var requestType = this.typeMap[channelData[3]] || 'other';
- if ( this.onHeadersReceivedTypes && this.onHeadersReceivedTypes.has(requestType) === false ) {
- return;
- }
-
- // 'Content-Security-Policy' MUST come last in the array. Need to
- // revised this eventually.
- var responseHeaders = [],
- value = channel.contentLength;
- if ( value !== -1 ) {
- responseHeaders.push({ name: 'Content-Length', value: value });
- }
- if ( requestType.endsWith('_frame') ) {
- value = this.getResponseHeader(channel, 'Content-Security-Policy');
- if ( value !== undefined ) {
- responseHeaders.push({ name: 'Content-Security-Policy', value: value });
- }
- }
-
- var result = this.onHeadersReceived({
- parentFrameId: channelData[1],
- responseHeaders: responseHeaders,
- tabId: channelData[2],
- type: requestType,
- url: URI.asciiSpec
- });
-
- if ( !result ) {
- return;
- }
-
- if ( result.cancel ) {
- channel.cancel(this.ABORT);
- return;
- }
-
- if ( result.responseHeaders && result.responseHeaders.length ) {
- channel.setResponseHeader(
- 'Content-Security-Policy',
- result.responseHeaders.pop().value,
- true
- );
- return;
- }
- },
-
- channelDataFromChannel: function(channel) {
- if ( channel instanceof Ci.nsIWritablePropertyBag ) {
- try {
- return channel.getProperty(this.REQDATAKEY) || null;
- } catch (ex) {
- }
- }
- return null;
- },
-
- observe: function(channel, topic) {
- if ( channel instanceof Ci.nsIHttpChannel === false ) {
- return;
- }
-
- var URI = channel.URI;
- var channelData = this.channelDataFromChannel(channel);
-
- if ( topic === 'http-on-examine-response' ) {
- if ( channelData !== null ) {
- this.handleResponseHeaders(channel, URI, channelData);
- }
- return;
- }
-
- // http-on-modify-request
-
- // The channel was previously serviced.
- if ( channelData !== null ) {
- this.handleRequest(channel, URI, {
- frameId: channelData[0],
- parentFrameId: channelData[1],
- tabId: channelData[2],
- rawtype: channelData[3]
- });
- return;
- }
-
- // The channel was never serviced.
- var pendingRequest = this.lookupPendingRequest(URI.spec);
-
- // https://github.com/gorhill/uMatrix/issues/390#issuecomment-155759004
- var loadInfo = channel.loadInfo,
- rawtype = 1,
- frameId = 0,
- parentFrameId = -1;
-
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1232354
- // https://dxr.mozilla.org/mozilla-central/source/toolkit/modules/addons/WebRequest.jsm#537-553
- // For modern Firefox, loadInfo contains the information about the
- // context of the network request.
- if ( loadInfo ) {
- rawtype = loadInfo.externalContentPolicyType !== undefined ?
- loadInfo.externalContentPolicyType :
- loadInfo.contentPolicyType;
- if ( !rawtype ) {
- rawtype = 1;
- }
- frameId = loadInfo.frameOuterWindowID ? loadInfo.frameOuterWindowID : loadInfo.outerWindowID;
- parentFrameId = loadInfo.frameOuterWindowID ? loadInfo.outerWindowID : loadInfo.parentOuterWindowID;
- if ( frameId === parentFrameId ) {
- parentFrameId = -1;
- }
- }
-
- if ( pendingRequest !== null ) {
- // https://github.com/gorhill/uBlock/issues/654
- // Use the request type from the HTTP observer point of view.
- if ( rawtype !== 1 ) {
- pendingRequest.rawtype = rawtype;
- }
- // IMPORTANT:
- // If this is a main frame, ensure that the proper tab id is being
- // used: it can happen that the wrong tab id was looked up at
- // `shouldLoadListener` time. Without this, the popup blocker may
- // not work properly, and also a tab opened from a link may end up
- // being wrongly reported as an embedded element.
- if ( pendingRequest.rawtype === 6 ) {
- var tabId = this.tabIdFromChannel(channel);
- if ( tabId !== vAPI.noTabId ) {
- pendingRequest.tabId = tabId;
- }
- }
- } else { // pendingRequest === null
- // No matching pending request found, synthetize one.
- pendingRequest = this.syntheticPendingRequest;
- pendingRequest.tabId = this.tabIdFromChannel(channel);
- pendingRequest.rawtype = rawtype;
- pendingRequest.frameId = frameId;
- pendingRequest.parentFrameId = parentFrameId;
- }
-
- if ( this.handleRequest(channel, URI, pendingRequest) ) {
- return;
- }
-
- // If request is not handled we may use the data in on-modify-request
- if ( channel instanceof Ci.nsIWritablePropertyBag ) {
- channel.setProperty(this.REQDATAKEY, [
- pendingRequest.frameId,
- pendingRequest.parentFrameId,
- pendingRequest.tabId,
- pendingRequest.rawtype
- ]);
- }
- },
-
- // contentPolicy.shouldLoad doesn't detect redirects, this needs to be used
- asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback) {
- // If error thrown, the redirect will fail
- try {
- var URI = newChannel.URI;
- if ( !URI.schemeIs('http') && !URI.schemeIs('https') ) {
- return;
- }
-
- if (
- oldChannel instanceof Ci.nsIWritablePropertyBag === false ||
- newChannel instanceof Ci.nsIWritablePropertyBag === false
- ) {
- return;
- }
-
- // Carry the data on in case of multiple redirects
- newChannel.setProperty(
- this.REQDATAKEY,
- oldChannel.getProperty(this.REQDATAKEY)
- );
- } catch (ex) {
- // console.error(ex);
- } finally {
- callback.onRedirectVerifyCallback(this.ACCEPT);
- }
- }
-};
-
-/******************************************************************************/
-/******************************************************************************/
-
-vAPI.net = {};
-
-/******************************************************************************/
-
-vAPI.net.registerListeners = function() {
- if ( typeof this.onBeforeRequest.callback === 'function' ) {
- httpObserver.onBeforeRequest = this.onBeforeRequest.callback;
- httpObserver.onBeforeRequestTypes = this.onBeforeRequest.types ?
- new Set(this.onBeforeRequest.types) :
- null;
- }
-
- if ( typeof this.onHeadersReceived.callback === 'function' ) {
- httpObserver.onHeadersReceived = this.onHeadersReceived.callback;
- httpObserver.onHeadersReceivedTypes = this.onHeadersReceived.types ?
- new Set(this.onHeadersReceived.types) :
- null;
- }
-
- var shouldLoadPopupListenerMessageName = location.host + ':shouldLoadPopup';
- var shouldLoadPopupListenerEntries = [];
- var shouldLoadPopupListener = function(e) {
- if ( typeof vAPI.tabs.onPopupCreated !== 'function' ) { return; }
-
- var target = e.target,
- data = e.data,
- now = Date.now(),
- entries = shouldLoadPopupListenerEntries,
- entry;
-
- var i = entries.length;
- while ( i-- ) {
- entry = entries[i];
- if ( entry.id === data.id ) {
- entries.splice(i, 1);
- break;
- }
- if ( entry.expire <= now ) {
- entries.splice(i, 1);
- }
- entry = undefined;
- }
- if ( !entry ) {
- entry = {
- id: data.id,
- popupTabId: undefined,
- openerTabId: undefined,
- expire: now + 10000
- };
- entries.push(entry);
- }
- var tabId = tabWatcher.tabIdFromTarget(target);
- if ( data.popup ) {
- entry.popupTabId = tabId;
- } else /* if ( data.opener ) */ {
- entry.openerTabId = tabId;
- }
- if ( entry.popupTabId && entry.openerTabId ) {
- vAPI.tabs.onPopupCreated(entry.popupTabId, entry.openerTabId);
- }
- };
-
- vAPI.messaging.globalMessageManager.addMessageListener(
- shouldLoadPopupListenerMessageName,
- shouldLoadPopupListener
- );
-
- var shouldLoadListenerMessageName = location.host + ':shouldLoad';
- var shouldLoadListener = function(e) {
- // Non blocking: it is assumed that the http observer is fired after
- // shouldLoad recorded the pending requests. If this is not the case,
- // a request would end up being categorized as a behind-the-scene
- // requests.
- var details = e.data;
-
- // We are being called synchronously from the content process, so we
- // must return ASAP. The code below merely record the details of the
- // request into a ring buffer for later retrieval by the HTTP observer.
- var pendingReq = httpObserver.createPendingRequest(details.url);
- pendingReq.frameId = details.frameId;
- pendingReq.parentFrameId = details.pFrameId;
- pendingReq.rawtype = details.type;
- pendingReq.tabId = tabWatcher.tabIdFromTarget(e.target);
- };
-
- vAPI.messaging.globalMessageManager.addMessageListener(
- shouldLoadListenerMessageName,
- shouldLoadListener
- );
-
- var locationChangedListenerMessageName = location.host + ':locationChanged';
- var locationChangedListener = function(e) {
- var browser = e.target;
-
- // I have seen this happens (at startup time)
- if ( !browser.currentURI ) {
- return;
- }
-
- // https://github.com/gorhill/uBlock/issues/697
- // Dismiss event if the associated tab is pending.
- var tab = tabWatcher.tabFromBrowser(browser);
- if ( !vAPI.fennec && tab && tab.hasAttribute('pending') ) {
- // https://github.com/gorhill/uBlock/issues/820
- // Firefox quirk: it happens the `pending` attribute was not
- // present for certain tabs at startup -- and this can cause
- // unwanted [browser <--> tab id] associations internally.
- // Dispose of these if it is found the `pending` attribute is
- // set.
- tabWatcher.removeTarget(tab);
- return;
- }
-
- var details = e.data;
- var tabId = tabWatcher.tabIdFromTarget(browser);
-
- // Ignore notifications related to our popup
- if ( details.url.startsWith(vAPI.getURL('popup.html')) ) {
- return;
- }
-
- // LOCATION_CHANGE_SAME_DOCUMENT = "did not load a new document"
- if ( details.flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_SAME_DOCUMENT ) {
- vAPI.tabs.onUpdated(tabId, {url: details.url}, {
- frameId: 0,
- tabId: tabId,
- url: browser.currentURI.asciiSpec
- });
- return;
- }
-
- // https://github.com/chrisaljoudi/uBlock/issues/105
- // Allow any kind of pages
- vAPI.tabs.onNavigation({
- frameId: 0,
- tabId: tabId,
- url: details.url
- });
- };
-
- vAPI.messaging.globalMessageManager.addMessageListener(
- locationChangedListenerMessageName,
- locationChangedListener
- );
-
- httpObserver.register();
-
- cleanupTasks.push(function() {
- vAPI.messaging.globalMessageManager.removeMessageListener(
- shouldLoadPopupListenerMessageName,
- shouldLoadPopupListener
- );
-
- vAPI.messaging.globalMessageManager.removeMessageListener(
- shouldLoadListenerMessageName,
- shouldLoadListener
- );
-
- vAPI.messaging.globalMessageManager.removeMessageListener(
- locationChangedListenerMessageName,
- locationChangedListener
- );
-
- httpObserver.unregister();
- });
-};
-
-/******************************************************************************/
-/******************************************************************************/
-
-vAPI.toolbarButton = {
- id: location.host + '-button',
- type: 'view',
- viewId: location.host + '-panel',
- label: vAPI.app.name,
- tooltiptext: vAPI.app.name,
- tabs: new Map(/* tabId: { badge: 0, img: boolean } */),
- init: null,
- codePath: ''
-};
-
-/******************************************************************************/
-
-// Fennec
-
-(function() {
- if ( !vAPI.fennec ) {
- return;
- }
-
- var tbb = vAPI.toolbarButton;
-
- tbb.codePath = 'fennec';
-
- var menuItemIds = new WeakMap();
-
- var shutdown = function() {
- for ( var win of winWatcher.getWindows() ) {
- var id = menuItemIds.get(win);
- if ( !id ) {
- continue;
- }
- win.NativeWindow.menu.remove(id);
- menuItemIds.delete(win);
- }
- };
-
- tbb.getMenuItemLabel = function(tabId) {
- var label = this.label;
- if ( tabId === undefined ) {
- return label;
- }
- var tabDetails = this.tabs.get(tabId);
- if ( tabDetails === undefined ) {
- return label;
- }
- if ( !tabDetails.img ) {
- label += ' (' + vAPI.i18n('fennecMenuItemBlockingOff') + ')';
- } else if ( tabDetails.badge ) {
- label += ' (' + tabDetails.badge + ')';
- }
- return label;
- };
-
- tbb.onClick = function() {
- var win = winWatcher.getCurrentWindow();
- var curTabId = tabWatcher.tabIdFromTarget(getTabBrowser(win).selectedTab);
- vAPI.tabs.open({
- url: 'popup.html?tabId=' + curTabId + '&mobile=1',
- index: -1,
- select: true
- });
- };
-
- tbb.updateState = function(win, tabId) {
- var id = menuItemIds.get(win);
- if ( !id ) {
- return;
- }
- win.NativeWindow.menu.update(id, {
- name: this.getMenuItemLabel(tabId)
- });
- };
-
- // https://github.com/gorhill/uBlock/issues/955
- // Defer until `NativeWindow` is available.
- tbb.initOne = function(win) {
- if ( !win.NativeWindow ) {
- return;
- }
- var label = this.getMenuItemLabel();
- var id = win.NativeWindow.menu.add({
- name: label,
- callback: this.onClick
- });
- menuItemIds.set(win, id);
- };
-
- tbb.canInit = function(win) {
- return !!win.NativeWindow;
- };
-
- tbb.init = function() {
- // Only actually expecting one window under Fennec (note, not tabs, windows)
- for ( var win of winWatcher.getWindows() ) {
- deferUntil(
- this.canInit.bind(this, win),
- this.initOne.bind(this, win)
- );
- }
-
- cleanupTasks.push(shutdown);
- };
-})();
-
-/******************************************************************************/
-
-// Non-Fennec: common code paths.
-
-(function() {
- if ( vAPI.fennec ) {
- return;
- }
-
- var tbb = vAPI.toolbarButton;
-
- tbb.onViewShowing = function({target}) {
- target.firstChild.setAttribute('src', vAPI.getURL('popup.html'));
- };
-
- tbb.onViewHiding = function({target}) {
- target.parentNode.style.maxWidth = '';
- target.firstChild.setAttribute('src', 'about:blank');
- };
-
- tbb.updateState = function(win, tabId) {
- var button = win.document.getElementById(this.id);
-
- if ( !button ) {
- return;
- }
-
- var icon = this.tabs.get(tabId);
-
- button.setAttribute('badge', icon && icon.badge || '');
- button.classList.toggle('off', !icon || !icon.img);
- };
-
- tbb.populatePanel = function(doc, panel) {
- panel.setAttribute('id', this.viewId);
-
- var iframe = doc.createElement('iframe');
- iframe.setAttribute('type', 'content');
-
- panel.appendChild(iframe);
-
- var toPx = function(pixels) {
- return pixels.toString() + 'px';
- };
-
- var resizeTimer = null;
- var resizePopupDelayed = function(attempts) {
- if ( resizeTimer !== null ) {
- return;
- }
-
- // Sanity check
- attempts = (attempts || 0) + 1;
- if ( attempts > 1/*000*/ ) {
- console.error('uBlock0> resizePopupDelayed: giving up after too many attempts');
- return;
- }
-
- resizeTimer = vAPI.setTimeout(resizePopup, 10, attempts);
- };
-
- var resizePopup = function(attempts) {
- resizeTimer = null;
- var body = iframe.contentDocument.body;
- panel.parentNode.style.maxWidth = 'none';
-
- // https://github.com/gorhill/uMatrix/issues/362
- panel.parentNode.style.opacity = '1';
-
- // https://github.com/chrisaljoudi/uBlock/issues/730
- // Voodoo programming: this recipe works
- var clientHeight = body.clientHeight;
- iframe.style.height = toPx(clientHeight);
- panel.style.height = toPx(clientHeight + panel.boxObject.height - panel.clientHeight);
-
- var clientWidth = body.clientWidth;
- iframe.style.width = toPx(clientWidth);
- panel.style.width = toPx(clientWidth + panel.boxObject.width - panel.clientWidth);
-
- if ( iframe.clientHeight !== body.clientHeight || iframe.clientWidth !== body.clientWidth ) {
- resizePopupDelayed(attempts);
- }
- };
-
- var onPopupReady = function() {
- var win = this.contentWindow;
-
- if ( !win || win.location.host !== location.host ) {
- return;
- }
-
- if ( typeof tbb.onBeforePopupReady === 'function' ) {
- tbb.onBeforePopupReady.call(this);
- }
-
- new win.MutationObserver(resizePopupDelayed).observe(win.document.body, {
- attributes: true,
- characterData: true,
- subtree: true
- });
-
- resizePopupDelayed();
- };
-
- iframe.addEventListener('load', onPopupReady, true);
- };
-})();
-
-/******************************************************************************/
-
-// Firefox 35 and less: use legacy toolbar button.
-
-(function() {
- var tbb = vAPI.toolbarButton;
- if ( tbb.init !== null ) {
- return;
- }
- var CustomizableUI = null;
- var forceLegacyToolbarButton = vAPI.localStorage.getBool('forceLegacyToolbarButton');
- if ( !forceLegacyToolbarButton ) {
- try {
- CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
- } catch (ex) {
- }
- }
- if (
- CustomizableUI !== null &&
- Services.vc.compare(Services.appinfo.platformVersion, '36.0') >= 0
- ) {
- return;
- }
-
- tbb.codePath = 'legacy';
- tbb.id = 'uBlock0-legacy-button'; // NOTE: must match legacy-toolbar-button.css
- tbb.viewId = tbb.id + '-panel';
-
- var styleSheetUri = null;
-
- var createToolbarButton = function(window) {
- var document = window.document;
-
- var toolbarButton = document.createElement('toolbarbutton');
- toolbarButton.setAttribute('id', tbb.id);
- // type = panel would be more accurate, but doesn't look as good
- toolbarButton.setAttribute('type', 'menu');
- toolbarButton.setAttribute('removable', 'true');
- toolbarButton.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional');
- toolbarButton.setAttribute('label', tbb.label);
- toolbarButton.setAttribute('tooltiptext', tbb.label);
-
- var toolbarButtonPanel = document.createElement('panel');
- // NOTE: Setting level to parent breaks the popup for PaleMoon under
- // linux (mouse pointer misaligned with content). For some reason.
- // toolbarButtonPanel.setAttribute('level', 'parent');
- tbb.populatePanel(document, toolbarButtonPanel);
- toolbarButtonPanel.addEventListener('popupshowing', tbb.onViewShowing);
- toolbarButtonPanel.addEventListener('popuphiding', tbb.onViewHiding);
- toolbarButton.appendChild(toolbarButtonPanel);
-
- return toolbarButton;
- };
-
- var addLegacyToolbarButton = function(window) {
- // uBO's stylesheet lazily added.
- if ( styleSheetUri === null ) {
- var sss = Cc['@mozilla.org/content/style-sheet-service;1']
- .getService(Ci.nsIStyleSheetService);
- styleSheetUri = Services.io.newURI(vAPI.getURL('css/legacy-toolbar-button.css'), null, null);
-
- // Register global so it works in all windows, including palette
- if ( !sss.sheetRegistered(styleSheetUri, sss.AUTHOR_SHEET) ) {
- sss.loadAndRegisterSheet(styleSheetUri, sss.AUTHOR_SHEET);
- }
- }
-
- var document = window.document;
-
- // https://github.com/gorhill/uMatrix/issues/357
- // Already installed?
- if ( document.getElementById(tbb.id) !== null ) {
- return;
- }
-
- var toolbox = document.getElementById('navigator-toolbox') ||
- document.getElementById('mail-toolbox');
- if ( toolbox === null ) {
- return;
- }
-
- var toolbarButton = createToolbarButton(window);
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/toolbarpalette
- var palette = toolbox.palette;
- if ( palette && palette.querySelector('#' + tbb.id) === null ) {
- palette.appendChild(toolbarButton);
- }
-
- // Find the place to put the button.
- // Pale Moon: `toolbox.externalToolbars` can be undefined. Seen while
- // testing popup test number 3:
- // http://raymondhill.net/ublock/popup.html
- var toolbars = toolbox.externalToolbars ? toolbox.externalToolbars.slice() : [];
- for ( var child of toolbox.children ) {
- if ( child.localName === 'toolbar' ) {
- toolbars.push(child);
- }
- }
-
- for ( var toolbar of toolbars ) {
- var currentsetString = toolbar.getAttribute('currentset');
- if ( !currentsetString ) {
- continue;
- }
- var currentset = currentsetString.split(/\s*,\s*/);
- var index = currentset.indexOf(tbb.id);
- if ( index === -1 ) {
- continue;
- }
- // This can occur with Pale Moon:
- // "TypeError: toolbar.insertItem is not a function"
- if ( typeof toolbar.insertItem !== 'function' ) {
- continue;
- }
- // Found our button on this toolbar - but where on it?
- var before = null;
- for ( var i = index + 1; i < currentset.length; i++ ) {
- before = toolbar.querySelector('[id="' + currentset[i] + '"]');
- if ( before !== null ) {
- break;
- }
- }
- // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Method/insertItem
- toolbar.insertItem(tbb.id, before);
- break;
- }
-
- // https://github.com/gorhill/uBlock/issues/763
- // We are done if our toolbar button is already installed in one of the
- // toolbar.
- if ( palette !== null && toolbarButton.parentElement !== palette ) {
- return;
- }
-
- // No button yet so give it a default location. If forcing the button,
- // just put in in the palette rather than on any specific toolbar (who
- // knows what toolbars will be available or visible!)
- var navbar = document.getElementById('nav-bar');
- if ( navbar !== null && !vAPI.localStorage.getBool('legacyToolbarButtonAdded') ) {
- // https://github.com/gorhill/uBlock/issues/264
- // Find a child customizable palette, if any.
- navbar = navbar.querySelector('.customization-target') || navbar;
- navbar.appendChild(toolbarButton);
- navbar.setAttribute('currentset', navbar.currentSet);
- document.persist(navbar.id, 'currentset');
- vAPI.localStorage.setBool('legacyToolbarButtonAdded', 'true');
- }
- };
-
- var canAddLegacyToolbarButton = function(window) {
- var document = window.document;
- if (
- !document ||
- document.readyState !== 'complete' ||
- document.getElementById('nav-bar') === null
- ) {
- return false;
- }
- var toolbox = document.getElementById('navigator-toolbox') ||
- document.getElementById('mail-toolbox');
- return toolbox !== null && !!toolbox.palette;
- };
-
- var onPopupCloseRequested = function({target}) {
- var document = target.ownerDocument;
- if ( !document ) {
- return;
- }
- var toolbarButtonPanel = document.getElementById(tbb.viewId);
- if ( toolbarButtonPanel === null ) {
- return;
- }
- // `hidePopup` reported as not existing while testing legacy button
- // on FF 41.0.2.
- // https://bugzilla.mozilla.org/show_bug.cgi?id=1151796
- if ( typeof toolbarButtonPanel.hidePopup === 'function' ) {
- toolbarButtonPanel.hidePopup();
- }
- };
-
- var shutdown = function() {
- for ( var win of winWatcher.getWindows() ) {
- var toolbarButton = win.document.getElementById(tbb.id);
- if ( toolbarButton ) {
- toolbarButton.parentNode.removeChild(toolbarButton);
- }
- }
-
- vAPI.messaging.globalMessageManager.removeMessageListener(
- location.host + ':closePopup',
- onPopupCloseRequested
- );
-
- if ( styleSheetUri !== null ) {
- var sss = Cc['@mozilla.org/content/style-sheet-service;1']
- .getService(Ci.nsIStyleSheetService);
- if ( sss.sheetRegistered(styleSheetUri, sss.AUTHOR_SHEET) ) {
- sss.unregisterSheet(styleSheetUri, sss.AUTHOR_SHEET);
- }
- styleSheetUri = null;
- }
- };
-
- tbb.attachToNewWindow = function(win) {
- deferUntil(
- canAddLegacyToolbarButton.bind(null, win),
- addLegacyToolbarButton.bind(null, win)
- );
- };
-
- tbb.init = function() {
- vAPI.messaging.globalMessageManager.addMessageListener(
- location.host + ':closePopup',
- onPopupCloseRequested
- );
-
- cleanupTasks.push(shutdown);
- };
-})();
-
-/******************************************************************************/
-
-// Firefox Australis >= 36.
-
-(function() {
- var tbb = vAPI.toolbarButton;
- if ( tbb.init !== null ) {
- return;
- }
- if ( Services.vc.compare(Services.appinfo.platformVersion, '36.0') < 0 ) {
- return null;
- }
- if ( vAPI.localStorage.getBool('forceLegacyToolbarButton') ) {
- return null;
- }
- var CustomizableUI = null;
- try {
- CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
- } catch (ex) {
- }
- if ( CustomizableUI === null ) {
- return null;
- }
- tbb.codePath = 'australis';
- tbb.CustomizableUI = CustomizableUI;
- tbb.defaultArea = CustomizableUI.AREA_NAVBAR;
-
- var CUIEvents = {};
-
- var badgeCSSRules = [
- 'background: #666',
- 'color: #fff'
- ].join(';');
-
- var updateBadgeStyle = function() {
- for ( var win of winWatcher.getWindows() ) {
- var button = win.document.getElementById(tbb.id);
- if ( button === null ) {
- continue;
- }
- var badge = button.ownerDocument.getAnonymousElementByAttribute(
- button,
- 'class',
- 'toolbarbutton-badge'
- );
- if ( !badge ) {
- continue;
- }
-
- badge.style.cssText = badgeCSSRules;
- }
- };
-
- var updateBadge = function() {
- var wId = tbb.id;
- var buttonInPanel = CustomizableUI.getWidget(wId).areaType === CustomizableUI.TYPE_MENU_PANEL;
-
- for ( var win of winWatcher.getWindows() ) {
- var button = win.document.getElementById(wId);
- if ( button === null ) {
- continue;
- }
- if ( buttonInPanel ) {
- button.classList.remove('badged-button');
- continue;
- }
- button.classList.add('badged-button');
- }
-
- if ( buttonInPanel ) {
- return;
- }
-
- // Anonymous elements need some time to be reachable
- vAPI.setTimeout(updateBadgeStyle, 250);
- }.bind(CUIEvents);
-
- // https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/CustomizableUI.jsm#Listeners
- CUIEvents.onCustomizeEnd = updateBadge;
- CUIEvents.onWidgetAdded = updateBadge;
- CUIEvents.onWidgetUnderflow = updateBadge;
-
- var onPopupCloseRequested = function({target}) {
- if ( typeof tbb.closePopup === 'function' ) {
- tbb.closePopup(target);
- }
- };
-
- var shutdown = function() {
- for ( var win of winWatcher.getWindows() ) {
- var panel = win.document.getElementById(tbb.viewId);
- if ( panel !== null && panel.parentNode !== null ) {
- panel.parentNode.removeChild(panel);
- }
- win.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils)
- .removeSheet(styleURI, 1);
- }
-
- CustomizableUI.removeListener(CUIEvents);
- CustomizableUI.destroyWidget(tbb.id);
-
- vAPI.messaging.globalMessageManager.removeMessageListener(
- location.host + ':closePopup',
- onPopupCloseRequested
- );
- };
-
- var styleURI = null;
-
- tbb.onBeforeCreated = function(doc) {
- var panel = doc.createElement('panelview');
-
- this.populatePanel(doc, panel);
-
- doc.getElementById('PanelUI-multiView').appendChild(panel);
-
- doc.defaultView.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDOMWindowUtils)
- .loadSheet(styleURI, 1);
- };
-
- tbb.onCreated = function(button) {
- button.setAttribute('badge', '');
- vAPI.setTimeout(updateBadge, 250);
- };
-
- tbb.onBeforePopupReady = function() {
- // https://github.com/gorhill/uBlock/issues/83
- // Add `portrait` class if width is constrained.
- try {
- this.contentDocument.body.classList.toggle(
- 'portrait',
- CustomizableUI.getWidget(tbb.id).areaType === CustomizableUI.TYPE_MENU_PANEL
- );
- } catch (ex) {
- /* noop */
- }
- };
-
- tbb.closePopup = function(tabBrowser) {
- CustomizableUI.hidePanelForNode(
- tabBrowser.ownerDocument.getElementById(tbb.viewId)
- );
- };
-
- tbb.init = function() {
- vAPI.messaging.globalMessageManager.addMessageListener(
- location.host + ':closePopup',
- onPopupCloseRequested
- );
-
- CustomizableUI.addListener(CUIEvents);
-
- // https://github.com/gorhill/uBlock/issues/2696
- // https://github.com/gorhill/uBlock/issues/2709
-
- var style = [
- '#' + this.id + '.off {',
- 'list-style-image: url(',
- vAPI.getURL('img/browsericons/icon16-off.svg'),
- ');',
- '}',
- '#' + this.id + ' {',
- 'list-style-image: url(',
- vAPI.getURL('img/browsericons/icon16.svg'),
- ');',
- '}',
- '#' + this.viewId + ',',
- '#' + this.viewId + ' > iframe {',
- 'height: 290px;',
- 'max-width: none !important;',
- 'min-width: 0 !important;',
- 'overflow: hidden !important;',
- 'padding: 0 !important;',
- 'width: 160px;',
- '}'
- ];
-
- styleURI = Services.io.newURI(
- 'data:text/css,' + encodeURIComponent(style.join('')),
- null,
- null
- );
-
- CustomizableUI.createWidget(this);
-
- cleanupTasks.push(shutdown);
- };
-})();
-
-/******************************************************************************/
-
-// No toolbar button.
-
-(function() {
- // Just to ensure the number of cleanup tasks is as expected: toolbar
- // button code is one single cleanup task regardless of platform.
- if ( vAPI.toolbarButton.init === null ) {
- cleanupTasks.push(function(){});
- }
-})();
-
-/******************************************************************************/
-
-if ( vAPI.toolbarButton.init !== null ) {
- vAPI.toolbarButton.init();
-}
-
-/******************************************************************************/
-/******************************************************************************/
-
-vAPI.contextMenu = (function() {
- var clientCallback = null;
- var clientEntries = [];
-
- var contextMap = {
- frame: 'inFrame',
- link: 'onLink',
- image: 'onImage',
- audio: 'onAudio',
- video: 'onVideo',
- editable: 'onEditableArea'
- };
-
- var onCommand = function() {
- var gContextMenu = getOwnerWindow(this).gContextMenu;
- var details = {
- menuItemId: this.id
- };
-
- if ( gContextMenu.inFrame ) {
- details.tagName = 'iframe';
- // Probably won't work with e10s
- details.frameUrl = gContextMenu.focusedWindow && gContextMenu.focusedWindow.location.href || '';
- } else if ( gContextMenu.onImage ) {
- details.tagName = 'img';
- details.srcUrl = gContextMenu.mediaURL;
- } else if ( gContextMenu.onAudio ) {
- details.tagName = 'audio';
- details.srcUrl = gContextMenu.mediaURL;
- } else if ( gContextMenu.onVideo ) {
- details.tagName = 'video';
- details.srcUrl = gContextMenu.mediaURL;
- } else if ( gContextMenu.onLink ) {
- details.tagName = 'a';
- details.linkUrl = gContextMenu.linkURL;
- }
-
- clientCallback(details, {
- id: tabWatcher.tabIdFromTarget(gContextMenu.browser),
- url: gContextMenu.browser.currentURI.asciiSpec
- });
- };
-
- var menuItemMatchesContext = function(contextMenu, clientEntry) {
- if ( !clientEntry.contexts ) {
- return false;
- }
- for ( var context of clientEntry.contexts ) {
- if ( context === 'all' ) {
- return true;
- }
- if (
- contextMap.hasOwnProperty(context) &&
- contextMenu[contextMap[context]]
- ) {
- return true;
- }
- }
- return false;
- };
-
- var onMenuShowing = function({target}) {
- var doc = target.ownerDocument;
- var gContextMenu = doc.defaultView.gContextMenu;
- if ( !gContextMenu.browser ) {
- return;
- }
-
- // https://github.com/chrisaljoudi/uBlock/issues/105
- // TODO: Should the element picker works on any kind of pages?
- var currentURI = gContextMenu.browser.currentURI,
- isHTTP = currentURI.schemeIs('http') || currentURI.schemeIs('https'),
- layoutChanged = false,
- contextMenu = doc.getElementById('contentAreaContextMenu'),
- newEntries = clientEntries,
- oldMenuitems = contextMenu.querySelectorAll('[data-uBlock0="menuitem"]'),
- newMenuitems = [],
- n = Math.max(clientEntries.length, oldMenuitems.length),
- menuitem, newEntry;
- for ( var i = 0; i < n; i++ ) {
- menuitem = oldMenuitems[i];
- newEntry = newEntries[i];
- if ( menuitem && !newEntry ) {
- menuitem.parentNode.removeChild(menuitem);
- menuitem.removeEventListener('command', onCommand);
- menuitem = null;
- layoutChanged = true;
- } else if ( !menuitem && newEntry ) {
- menuitem = doc.createElement('menuitem');
- menuitem.setAttribute('data-uBlock0', 'menuitem');
- menuitem.addEventListener('command', onCommand);
- }
- if ( !menuitem ) {
- continue;
- }
- if ( menuitem.id !== newEntry.id ) {
- menuitem.setAttribute('id', newEntry.id);
- menuitem.setAttribute('label', newEntry.title);
- layoutChanged = true;
- }
- menuitem.setAttribute('hidden', !isHTTP || !menuItemMatchesContext(gContextMenu, newEntry));
- newMenuitems.push(menuitem);
- }
- // No changes?
- if ( layoutChanged === false ) {
- return;
- }
- // No entry: remove submenu if present.
- var menu = contextMenu.querySelector('[data-uBlock0="menu"]');
- if ( newMenuitems.length === 0 ) {
- if ( menu !== null ) {
- menu.parentNode.removeChild(menuitem);
- }
- return;
- }
- // Only one entry: no need for a submenu.
- if ( newMenuitems.length === 1 ) {
- if ( menu !== null ) {
- menu.parentNode.removeChild(menu);
- }
- menuitem = newMenuitems[0];
- menuitem.setAttribute('class', 'menuitem-iconic');
- menuitem.setAttribute('image', vAPI.getURL('img/browsericons/icon16.svg'));
- contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator'));
- return;
- }
- // More than one entry: we need a submenu.
- if ( menu === null ) {
- menu = doc.createElement('menu');
- menu.setAttribute('label', vAPI.app.name);
- menu.setAttribute('data-uBlock0', 'menu');
- menu.setAttribute('class', 'menu-iconic');
- menu.setAttribute('image', vAPI.getURL('img/browsericons/icon16.svg'));
- contextMenu.insertBefore(menu, doc.getElementById('inspect-separator'));
- }
- var menupopup = contextMenu.querySelector('[data-uBlock0="menupopup"]');
- if ( menupopup === null ) {
- menupopup = doc.createElement('menupopup');
- menupopup.setAttribute('data-uBlock0', 'menupopup');
- menu.appendChild(menupopup);
- }
- for ( i = 0; i < newMenuitems.length; i++ ) {
- menuitem = newMenuitems[i];
- menuitem.setAttribute('class', 'menuitem-non-iconic');
- menuitem.removeAttribute('image');
- menupopup.appendChild(menuitem);
- }
- };
-
- // https://github.com/gorhill/uBlock/issues/906
- // Be sure document.readyState is 'complete': it could happen at launch
- // time that we are called by vAPI.contextMenu.create() directly before
- // the environment is properly initialized.
- var canRegister = function(win) {
- return win && win.document.readyState === 'complete';
- };
-
- var register = function(window) {
- if ( canRegister(window) !== true ) {
- return;
- }
-
- var contextMenu = window.document.getElementById('contentAreaContextMenu');
- if ( contextMenu === null ) {
- return;
- }
- contextMenu.addEventListener('popupshowing', onMenuShowing);
- };
-
- var registerAsync = function(win) {
- // TODO https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/API/NativeWindow/contextmenus/add
- // var nativeWindow = doc.defaultView.NativeWindow;
- // contextId = nativeWindow.contextmenus.add(
- // this.menuLabel,
- // nativeWindow.contextmenus.linkOpenableContext,
- // this.onCommand
- // );
- if ( vAPI.fennec ) {
- return;
- }
- deferUntil(
- canRegister.bind(null, win),
- register.bind(null, win),
- { first: 4000 }
- );
- };
-
- var unregister = function(win) {
- // TODO
- if ( vAPI.fennec ) {
- return;
- }
- var contextMenu = win.document.getElementById('contentAreaContextMenu');
- if ( contextMenu !== null ) {
- contextMenu.removeEventListener('popupshowing', onMenuShowing);
- }
- var menuitems = win.document.querySelectorAll('[data-uBlock0]'),
- menuitem;
- for ( var i = 0; i < menuitems.length; i++ ) {
- menuitem = menuitems[i];
- menuitem.parentNode.removeChild(menuitem);
- menuitem.removeEventListener('command', onCommand);
- }
- };
-
- var setEntries = function(entries, callback) {
- clientEntries = entries || [];
- clientCallback = callback || null;
- };
-
- return {
- onMustUpdate: function() {},
- register: registerAsync,
- unregister: unregister,
- setEntries: setEntries
- };
-})();
-
-/******************************************************************************/
-/******************************************************************************/
-
-// Keyboard shortcuts have to be hardcoded, as they are declaratively created
-// in the manifest.json file on webext API, and only a listener has to be
-// installed with the browser.commands API.
-//
-// Assuming only one client listener is installed.
-
-// Shortcuts can be customized in `about:config` using
-// extensions.ublock0.shortcuts.[command id] => modifier-key
-// To disable a shortcut, set it to `-`:
-// extensions.ublock0.shortcuts.[command id] => -
-
-vAPI.commands = (function() {
- if ( vAPI.fennec || vAPI.thunderbird ) { return; }
-
- var commands = [
- { id: 'launch-element-zapper' },
- { id: 'launch-element-picker' },
- { id: 'launch-logger' }
- ];
- var clientListener;
-
- var commandHandler = function(ev) {
- if ( typeof clientListener !== 'function' ) { return; }
- var match = /^uBlock0Key-([a-z-]+)$/.exec(ev.target.id);
- if ( match === null ) { return; }
- clientListener(match[1]);
- };
-
- var canRegister = function(win) {
- return win && win.document.readyState === 'complete';
- };
-
- var register = function(window) {
- if ( canRegister(window) !== true ) { return; }
-
- var doc = window.document,
- myKeyset = doc.getElementById('uBlock0Keyset');
- // Already registered?
- if ( myKeyset !== null ) { return; }
-
- var mainKeyset = doc.getElementById('mainKeyset'),
- keysetHolder = mainKeyset && mainKeyset.parentNode;
- if ( keysetHolder === null ) { return; }
-
- myKeyset = doc.createElement('keyset');
- myKeyset.setAttribute('id', 'uBlock0Keyset');
-
- var myKey, shortcut, parts, modifiers, key;
- for ( var command of commands ) {
- modifiers = key = '';
- shortcut = vAPI.localStorage.getItem('shortcuts.' + command.id);
- if ( shortcut === null ) {
- vAPI.localStorage.setItem('shortcuts.' + command.id, '');
- } else if ( (parts = /^((?:[a-z]+-){1,})?(\w)$/.exec(shortcut)) !== null ) {
- modifiers = (parts[1] || '').slice(0, -1).replace(/-/g, ',');
- key = parts[2] || '';
- }
- myKey = doc.createElement('key');
- myKey.setAttribute('id', 'uBlock0Key-' + command.id);
- if ( modifiers !== '' ) {
- myKey.setAttribute('modifiers', modifiers);
- }
- myKey.setAttribute('key', key);
- // https://stackoverflow.com/a/16786770
- myKey.setAttribute('oncommand', ';');
- myKeyset.appendChild(myKey);
- }
-
- keysetHolder.addEventListener('command', commandHandler);
- keysetHolder.appendChild(myKeyset);
- };
-
- var registerAsync = function(win) {
- if ( vAPI.fennec ) { return; }
- deferUntil(
- canRegister.bind(null, win),
- register.bind(null, win),
- { first: 4000 }
- );
- };
-
- var unregister = function(window) {
- var doc = window.document,
- myKeyset = doc.getElementById('uBlock0Keyset');
- if ( myKeyset === null ) { return; }
- myKeyset.removeEventListener('command', commandHandler);
- myKeyset.parentNode.removeChild(myKeyset);
- };
-
- var addListener = function(callback) {
- clientListener = callback;
- };
-
- return {
- register: registerAsync,
- unregister: unregister,
- onCommand: {
- addListener: addListener
- }
- };
-})();
-
-/******************************************************************************/
-/******************************************************************************/
-
-var optionsObserver = (function() {
- var addonId = 'uBlock0@raymondhill.net';
-
- var commandHandler = function() {
- switch ( this.id ) {
- case 'showDashboardButton':
- vAPI.tabs.open({ url: 'dashboard.html', index: -1 });
- break;
- case 'showNetworkLogButton':
- vAPI.tabs.open({ url: 'logger-ui.html', index: -1 });
- break;
- default:
- break;
- }
- };
-
- var setupOptionsButton = function(doc, id) {
- var button = doc.getElementById(id);
- if ( button === null ) {
- return;
- }
- button.addEventListener('command', commandHandler);
- button.label = vAPI.i18n(id);
- };
-
- var setupOptionsButtons = function(doc) {
- setupOptionsButton(doc, 'showDashboardButton');
- setupOptionsButton(doc, 'showNetworkLogButton');
- };
-
- var observer = {
- observe: function(doc, topic, id) {
- if ( id !== addonId ) {
- return;
- }
-
- setupOptionsButtons(doc);
- }
- };
-
- // https://github.com/gorhill/uBlock/issues/948
- // Older versions of Firefox can throw here when looking up `currentURI`.
-
- var canInit = function() {
- try {
- var tabBrowser = tabWatcher.currentBrowser();
- return tabBrowser &&
- tabBrowser.currentURI &&
- tabBrowser.currentURI.spec === 'about:addons' &&
- tabBrowser.contentDocument &&
- tabBrowser.contentDocument.readyState === 'complete';
- } catch (ex) {
- }
- };
-
- // Manually add the buttons if the `about:addons` page is already opened.
-
- var init = function() {
- if ( canInit() ) {
- setupOptionsButtons(tabWatcher.currentBrowser().contentDocument);
- }
- };
-
- var unregister = function() {
- Services.obs.removeObserver(observer, 'addon-options-displayed');
- };
-
- var register = function() {
- Services.obs.addObserver(observer, 'addon-options-displayed', false);
- cleanupTasks.push(unregister);
- deferUntil(canInit, init, { first: 4000 });
- };
-
- return {
- register: register,
- unregister: unregister
- };
-})();
-
-optionsObserver.register();
-
-/******************************************************************************/
-/******************************************************************************/
-
-vAPI.lastError = function() {
- return null;
-};
-
-/******************************************************************************/
-
-// This is called only once, when everything has been loaded in memory after
-// the extension was launched. It can be used to inject content scripts
-// in already opened web pages, to remove whatever nuisance could make it to
-// the web pages before uBlock was ready.
-
-vAPI.onLoadAllCompleted = function() {
- // TODO: vAPI shouldn't know about uBlock. Just like in uMatrix, uBlock
- // should collect on its side all the opened tabs whenever it is ready.
- var µb = µBlock;
- for ( var browser of tabWatcher.browsers() ) {
- var tabId = tabWatcher.tabIdFromTarget(browser);
- µb.tabContextManager.commit(tabId, browser.currentURI.asciiSpec);
- µb.bindTabToPageStats(tabId);
- }
- // Inject special frame script, which sole purpose is to inject
- // content scripts into *already* opened tabs. This allows to unclutter
- // the main frame script.
- vAPI.messaging
- .globalMessageManager
- .loadFrameScript(vAPI.getURL('frameScript0.js'), false);
-};
-
-/******************************************************************************/
-/******************************************************************************/
-
-// Likelihood is that we do not have to punycode: given punycode overhead,
-// it's faster to check and skip than do it unconditionally all the time.
-
-var punycodeHostname = punycode.toASCII;
-var isNotASCII = /[^\x21-\x7F]/;
-
-vAPI.punycodeHostname = function(hostname) {
- return isNotASCII.test(hostname) ? punycodeHostname(hostname) : hostname;
-};
-
-vAPI.punycodeURL = function(url) {
- if ( isNotASCII.test(url) ) {
- return Services.io.newURI(url, null, null).asciiSpec;
- }
- return url;
-};
-
-/******************************************************************************/
-/******************************************************************************/
-
-// https://github.com/gorhill/uBlock/issues/531
-// Storage area dedicated to admin settings. Read-only.
-
-vAPI.adminStorage = {
- getItem: function(key, callback) {
- if ( typeof callback !== 'function' ) {
- return;
- }
- callback(vAPI.localStorage.getItem(key));
- }
-};
-
-/******************************************************************************/
-/******************************************************************************/
-
-vAPI.cloud = (function() {
- var extensionBranchPath = 'extensions.' + location.host;
- var cloudBranchPath = extensionBranchPath + '.cloudStorage';
-
- // https://github.com/gorhill/uBlock/issues/80#issuecomment-132081658
- // We must use get/setComplexValue in order to properly handle strings
- // with unicode characters.
- var iss = Ci.nsISupportsString;
- var argstr = Components.classes['@mozilla.org/supports-string;1']
- .createInstance(iss);
-
- var options = {
- defaultDeviceName: '',
- deviceName: ''
- };
-
- // User-supplied device name.
- try {
- options.deviceName = Services.prefs
- .getBranch(extensionBranchPath + '.')
- .getComplexValue('deviceName', iss)
- .data;
- } catch(ex) {
- }
-
- var getDefaultDeviceName = function() {
- var name = '';
- try {
- name = Services.prefs
- .getBranch('services.sync.client.')
- .getComplexValue('name', iss)
- .data;
- } catch(ex) {
- }
-
- return name || window.navigator.platform || window.navigator.oscpu;
- };
-
- var start = function(dataKeys) {
- var extensionBranch = Services.prefs.getBranch(extensionBranchPath + '.');
- var syncBranch = Services.prefs.getBranch('services.sync.prefs.sync.');
-
- // Mark config entries as syncable
- argstr.data = '';
- var dataKey;
- for ( var i = 0; i < dataKeys.length; i++ ) {
- dataKey = dataKeys[i];
- if ( extensionBranch.prefHasUserValue('cloudStorage.' + dataKey) === false ) {
- extensionBranch.setComplexValue('cloudStorage.' + dataKey, iss, argstr);
- }
- syncBranch.setBoolPref(cloudBranchPath + '.' + dataKey, true);
- }
- };
-
- var push = function(datakey, data, callback) {
- var branch = Services.prefs.getBranch(cloudBranchPath + '.');
- var bin = {
- 'source': options.deviceName || getDefaultDeviceName(),
- 'tstamp': Date.now(),
- 'data': data,
- 'size': 0
- };
- bin.size = JSON.stringify(bin).length;
- argstr.data = JSON.stringify(bin);
- branch.setComplexValue(datakey, iss, argstr);
- if ( typeof callback === 'function' ) {
- callback();
- }
- };
-
- var pull = function(datakey, callback) {
- var result = null;
- var branch = Services.prefs.getBranch(cloudBranchPath + '.');
- try {
- var json = branch.getComplexValue(datakey, iss).data;
- if ( typeof json === 'string' ) {
- result = JSON.parse(json);
- }
- } catch(ex) {
- }
- callback(result);
- };
-
- var getOptions = function(callback) {
- if ( typeof callback !== 'function' ) {
- return;
- }
- options.defaultDeviceName = getDefaultDeviceName();
- callback(options);
- };
-
- var setOptions = function(details, callback) {
- if ( typeof details !== 'object' || details === null ) {
- return;
- }
-
- var branch = Services.prefs.getBranch(extensionBranchPath + '.');
-
- if ( typeof details.deviceName === 'string' ) {
- argstr.data = details.deviceName;
- branch.setComplexValue('deviceName', iss, argstr);
- options.deviceName = details.deviceName;
- }
-
- getOptions(callback);
- };
-
- return {
- start: start,
- push: push,
- pull: pull,
- getOptions: getOptions,
- setOptions: setOptions
- };
-})();
-
-/******************************************************************************/
-/******************************************************************************/
-
-})();
-
-/******************************************************************************/
diff --git a/platform/firefox/vapi-client.js b/platform/firefox/vapi-client.js
deleted file mode 100644
index 4cf5e4e6a..000000000
--- a/platform/firefox/vapi-client.js
+++ /dev/null
@@ -1,399 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2017 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/* global HTMLDocument, XMLDocument,
- addMessageListener, removeMessageListener, sendAsyncMessage, outerShutdown
- */
-
-'use strict';
-
-// For non background pages
-
-/******************************************************************************/
-
-(function(self) {
-
-// https://github.com/chrisaljoudi/uBlock/issues/464
-if ( document instanceof HTMLDocument === false ) {
- // https://github.com/chrisaljoudi/uBlock/issues/1528
- // A XMLDocument can be a valid HTML document.
- if (
- document instanceof XMLDocument === false ||
- document.createElement('div') instanceof HTMLDivElement === false
- ) {
- return;
- }
-}
-
-/******************************************************************************/
-
-// https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10
-if ( !self.vAPI || self.vAPI.uBO !== true ) {
- self.vAPI = { uBO: true };
-}
-
-var vAPI = self.vAPI;
-
-/******************************************************************************/
-
-vAPI.firefox = true;
-
-vAPI.randomToken = function() {
- return String.fromCharCode(Date.now() % 26 + 97) +
- Math.floor(Math.random() * 982451653 + 982451653).toString(36);
-};
-
-vAPI.sessionId = vAPI.randomToken();
-
-/******************************************************************************/
-
-vAPI.setTimeout = vAPI.setTimeout || function(callback, delay, extra) {
- return setTimeout(function(a) { callback(a); }, delay, extra);
-};
-
-/******************************************************************************/
-
-vAPI.shutdown = {
- jobs: [],
- add: function(job) {
- this.jobs.push(job);
- },
- exec: function() {
- var job;
- while ( (job = this.jobs.pop()) ) {
- job();
- }
- },
- remove: function(job) {
- var pos;
- while ( (pos = this.jobs.indexOf(job)) !== -1 ) {
- this.jobs.splice(pos, 1);
- }
- }
-};
-
-/******************************************************************************/
-
-(function() {
- if ( !self.getScriptTagFilters ) {
- return;
- }
- var hostname = location.hostname;
- if ( !hostname ) {
- return;
- }
- var filters = self.getScriptTagFilters({
- rootURL: self.location.href,
- frameURL: self.location.href,
- frameHostname: hostname
- });
- if ( typeof filters !== 'string' || filters === '' ) {
- return;
- }
- var reFilters = new RegExp(filters);
- document.addEventListener('beforescriptexecute', function(ev) {
- if ( reFilters.test(ev.target.textContent) ) {
- ev.preventDefault();
- ev.stopPropagation();
- }
- });
-})();
-
-/******************************************************************************/
-
-var insertUserCSS = self.injectCSS || function(){},
- removeUserCSS = self.removeCSS || function(){};
-
-var processUserCSS = function(details, callback) {
- var cssText;
- var aa = details.add;
- if ( Array.isArray(aa) ) {
- for ( cssText of aa ) {
- insertUserCSS(
- 'data:text/css;charset=utf-8,' +
- encodeURIComponent(cssText)
- );
- }
- }
- aa = details.remove;
- if ( Array.isArray(aa) ) {
- for ( cssText of aa ) {
- removeUserCSS(
- 'data:text/css;charset=utf-8,' +
- encodeURIComponent(cssText)
- );
- }
- }
- if ( typeof callback === 'function' ) {
- callback();
- }
-};
-
-/******************************************************************************/
-
-vAPI.messaging = {
- channels: new Map(),
- pending: new Map(),
- auxProcessId: 1,
- connected: false,
-
- messageListener: function(msg) {
- var details = JSON.parse(msg);
- if ( !details ) { return; }
-
- // Sent to all channels
- if ( details.broadcast && !details.channelName ) {
- for ( var channelName of this.channels.keys() ) {
- this.sendToChannelListeners(channelName, details.msg);
- }
- return;
- }
-
- // Response to specific message previously sent
- if ( details.auxProcessId ) {
- var listener = this.pending.get(details.auxProcessId);
- this.pending.delete(details.auxProcessId);
- if ( listener ) {
- listener(details.msg);
- return;
- }
- }
-
- // Sent to a specific channel
- this.sendToChannelListeners(details.channelName, details.msg);
- },
-
- builtinListener: function(msg) {
- if ( msg.cmd === 'injectScript' ) {
- // injectScript is not always present.
- // - See contentObserver.initContentScripts in frameModule.js
- if ( typeof self.injectScript !== 'function' ) { return; }
- var details = msg.details;
- // Whether to inject in all child frames. Default to only top frame.
- var allFrames = details.allFrames || false;
- if ( allFrames !== true && window !== window.top ) { return; }
- // https://github.com/gorhill/uBlock/issues/876
- // Enforce `details.runAt`. Default to `document_end`.
- var runAt = details.runAt || 'document_end';
- if ( runAt === 'document_start' || document.readyState !== 'loading' ) {
- self.injectScript(details.file);
- return;
- }
- var injectScriptDelayed = function() {
- document.removeEventListener('DOMContentLoaded', injectScriptDelayed);
- self.injectScript(details.file);
- };
- document.addEventListener('DOMContentLoaded', injectScriptDelayed);
- return;
- }
- if ( msg.cmd === 'shutdownSandbox' ) {
- vAPI.shutdown.exec();
- vAPI.messaging.stop();
- if ( typeof self.outerShutdown === 'function' ) {
- outerShutdown();
- }
- // https://github.com/gorhill/uBlock/issues/1573
- // Will let uBO's own web pages close themselves. `window.top` is
- // used on the assumption that uBO's own web pages will never be
- // embedded in anything else than its own documents.
- try {
- var top = window.top;
- if ( top.location.href.startsWith(vAPI.getURL('')) ) {
- top.close();
- }
- } catch (ex) {
- }
- return;
- }
- },
-
- toggleListener: function({type, persisted}) {
- if ( type === 'pagehide' && !persisted ) {
- vAPI.shutdown.exec();
- this.stop();
- if ( typeof self.outerShutdown === 'function' ) {
- outerShutdown();
- }
- return;
- }
-
- if ( type === 'pagehide' ) {
- this.disconnect();
- } else /* if ( type === 'pageshow' ) */ {
- this.connect();
- }
- },
- toggleListenerCallback: null,
-
- start: function() {
- this.addChannelListener('vAPI', this.builtinListener);
- if ( this.toggleListenerCallback === null ) {
- this.toggleListenerCallback = this.toggleListener.bind(this);
- }
- window.addEventListener('pagehide', this.toggleListenerCallback, true);
- window.addEventListener('pageshow', this.toggleListenerCallback, true);
- },
-
- stop: function() {
- if ( this.toggleListenerCallback !== null ) {
- window.removeEventListener('pagehide', this.toggleListenerCallback, true);
- window.removeEventListener('pageshow', this.toggleListenerCallback, true);
- }
- this.disconnect();
- this.channels.clear();
- // service pending callbacks
- var pending = this.pending;
- this.pending = new Map();
- for ( var callback of pending.values() ) {
- if ( typeof callback === 'function' ) {
- callback(null);
- }
- }
- },
-
- connect: function() {
- if ( !this.connected ) {
- addMessageListener(this.messageListener.bind(this));
- this.connected = true;
- }
- },
-
- disconnect: function() {
- if ( this.connected ) {
- removeMessageListener();
- this.connected = false;
- }
- },
-
- send: function(channelName, message, callback) {
- // User stylesheets are handled content-side on legacy Firefox.
- if ( channelName === 'vapi' && message.what === 'userCSS' ) {
- return processUserCSS(message, callback);
- }
- if ( !this.connected ) {
- if ( typeof callback === 'function' ) { callback(); }
- return;
- }
- // Too large a gap between the last request and the last response means
- // the main process is no longer reachable: memory leaks and bad
- // performance become a risk -- especially for long-lived, dynamic
- // pages. Guard against this.
- if ( this.pending.size > 25 ) {
- vAPI.shutdown.exec();
- }
- this.connect();
- var auxProcessId;
- if ( callback ) {
- auxProcessId = this.auxProcessId++;
- this.pending.set(auxProcessId, callback);
- }
- sendAsyncMessage('ublock0:background', {
- channelName: self._sandboxId_ + '|' + channelName,
- auxProcessId: auxProcessId,
- msg: message
- });
- },
-
- // TODO: implement as time permits.
- connectTo: function(from, to, handler) {
- handler({
- what: 'connectionRefused',
- from: from,
- to: to
- });
- },
-
- disconnectFrom: function() {
- },
-
- sendTo: function() {
- },
-
- addChannelListener: function(channelName, listener) {
- var listeners = this.channels.get(channelName);
- if ( listeners === undefined ) {
- this.channels.set(channelName, [ listener ]);
- } else if ( listeners.indexOf(listener) === -1 ) {
- listeners.push(listener);
- }
- this.connect();
- },
-
- removeChannelListener: function(channelName, listener) {
- var listeners = this.channels.get(channelName);
- if ( listeners === undefined ) { return; }
- var pos = listeners.indexOf(listener);
- if ( pos === -1 ) { return; }
- listeners.splice(pos, 1);
- if ( listeners.length === 0 ) {
- this.channels.delete(channelName);
- }
- },
-
- removeAllChannelListeners: function(channelName) {
- this.channels.delete(channelName);
- },
-
- sendToChannelListeners: function(channelName, msg) {
- var listeners = this.channels.get(channelName);
- if ( listeners === undefined ) { return; }
- listeners = listeners.slice(0);
- var response;
- for ( var listener of listeners ) {
- response = listener(msg);
- if ( response !== undefined ) { break; }
- }
- return response;
- }
-};
-
-vAPI.messaging.start();
-
-// https://www.youtube.com/watch?v=Cg0cmhjdiLs
-
-/******************************************************************************/
-
-// https://bugzilla.mozilla.org/show_bug.cgi?id=444165
-// https://github.com/gorhill/uBlock/issues/2256
-// Not the prettiest solution, but that's the safest/simplest I can think
-// of at this point. If/when bugzilla issue above is solved, we will need
-// version detection to decide whether the patch needs to be applied.
-
-vAPI.iframeLoadEventPatch = function(target) {
- if ( target.localName === 'iframe' ) {
- target.dispatchEvent(new Event('load'));
- }
-};
-
-/******************************************************************************/
-
-// No need to have vAPI client linger around after shutdown if
-// we are not a top window (because element picker can still
-// be injected in top window).
-if ( window !== window.top ) {
- // Can anything be done?
-}
-
-/******************************************************************************/
-
-})(this);
-
-/******************************************************************************/
diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js
deleted file mode 100644
index d5b0abae3..000000000
--- a/platform/firefox/vapi-common.js
+++ /dev/null
@@ -1,167 +0,0 @@
-/*******************************************************************************
-
- uBlock Origin - a browser extension to block requests.
- Copyright (C) 2014-2017 The uBlock Origin authors
-
- 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/}.
-
- Home: https://github.com/gorhill/uBlock
-*/
-
-/* global sendAsyncMessage */
-
-// For background page or non-background pages
-
-'use strict';
-
-/******************************************************************************/
-
-(function(self) {
-
-/******************************************************************************/
-
-const {Services} = Components.utils.import(
- 'resource://gre/modules/Services.jsm',
- null
-);
-
-// https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10
-if ( !self.vAPI || self.vAPI.uBO !== true ) {
- self.vAPI = { uBO: true };
-}
-
-var vAPI = self.vAPI;
-
-/******************************************************************************/
-
-vAPI.setTimeout = vAPI.setTimeout || function(callback, delay, extra) {
- return setTimeout(function(a) { callback(a); }, delay, extra);
-};
-
-/******************************************************************************/
-
-// http://www.w3.org/International/questions/qa-scripts#directions
-
-var setScriptDirection = function(language) {
- document.body.setAttribute(
- 'dir',
- ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1 ? 'rtl' : 'ltr'
- );
-};
-
-/******************************************************************************/
-
-vAPI.download = function(details) {
- if ( !details.url ) {
- return;
- }
-
- var a = document.createElement('a');
- a.href = details.url;
- a.setAttribute('download', details.filename || '');
- a.dispatchEvent(new MouseEvent('click'));
-};
-
-/******************************************************************************/
-
-vAPI.getURL = function(path) {
- return 'chrome://' + location.host + '/content/' + path.replace(/^\/+/, '');
-};
-
-/******************************************************************************/
-
-vAPI.i18n = (function() {
- var stringBundle = Services.strings.createBundle(
- 'chrome://' + location.host + '/locale/messages.properties'
- );
-
- return function(s) {
- try {
- return stringBundle.GetStringFromName(s);
- } catch (ex) {
- return '';
- }
- };
-})();
-
-setScriptDirection(navigator.language);
-
-/******************************************************************************/
-
-vAPI.closePopup = function() {
- sendAsyncMessage(location.host + ':closePopup');
-};
-
-/******************************************************************************/
-
-// A localStorage-like object which should be accessible from the
-// background page or auxiliary pages.
-// This storage is optional, but it is nice to have, for a more polished user
-// experience.
-
-vAPI.localStorage = {
- pbName: '',
- pb: null,
- str: Components.classes['@mozilla.org/supports-string;1']
- .createInstance(Components.interfaces.nsISupportsString),
- init: function(pbName) {
- this.pbName = pbName;
- this.pb = Services.prefs.getBranch(pbName);
- },
- getItem: function(key) {
- try {
- return this.pb.getComplexValue(
- key,
- Components.interfaces.nsISupportsString
- ).data;
- } catch (ex) {
- return null;
- }
- },
- setItem: function(key, value) {
- this.str.data = value;
- this.pb.setComplexValue(
- key,
- Components.interfaces.nsISupportsString,
- this.str
- );
- },
- getBool: function(key) {
- try {
- return this.pb.getBoolPref(key);
- } catch (ex) {
- return null;
- }
- },
- setBool: function(key, value) {
- this.pb.setBoolPref(key, value);
- },
- setDefaultBool: function(key, defaultValue) {
- Services.prefs.getDefaultBranch(this.pbName).setBoolPref(key, defaultValue);
- },
- removeItem: function(key) {
- this.pb.clearUserPref(key);
- },
- clear: function() {
- this.pb.deleteBranch('');
- }
-};
-
-vAPI.localStorage.init('extensions.' + location.host + '.');
-
-/******************************************************************************/
-
-})(this);
-
-/******************************************************************************/
diff --git a/tools/make-firefox-meta.py b/tools/make-firefox-meta.py
deleted file mode 100644
index efa77013c..000000000
--- a/tools/make-firefox-meta.py
+++ /dev/null
@@ -1,122 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import json
-import re
-import sys
-from io import open
-from shutil import rmtree
-from collections import OrderedDict
-
-if len(sys.argv) == 1 or not sys.argv[1]:
- raise SystemExit('Build dir missing.')
-
-
-def mkdirs(path):
- try:
- os.makedirs(path)
- finally:
- return os.path.exists(path)
-
-pj = os.path.join
-
-# Find path to project root
-proj_dir = os.path.split(os.path.abspath(__file__))[0]
-while not os.path.isdir(os.path.join(proj_dir, '.git')):
- proj_dir = os.path.normpath(os.path.join(proj_dir, '..'))
-
-# Check that found project root is valid
-version_filepath = os.path.join(proj_dir, 'dist', 'version')
-if not os.path.isfile(version_filepath):
- print('Version file not found.')
- exit(1)
-
-build_dir = os.path.abspath(sys.argv[1])
-source_locale_dir = pj(build_dir, '_locales')
-target_locale_dir = pj(build_dir, 'locale')
-language_codes = []
-descriptions = OrderedDict({})
-title_case_strings = ['pickerContextMenuEntry', 'contextMenuTemporarilyAllowLargeMediaElements']
-
-for alpha2 in sorted(os.listdir(source_locale_dir)):
- locale_path = pj(source_locale_dir, alpha2, 'messages.json')
- with open(locale_path, encoding='utf-8') as f:
- strings = json.load(f, object_pairs_hook=OrderedDict)
- alpha2 = alpha2.replace('_', '-')
- descriptions[alpha2] = strings['extShortDesc']['message']
- del strings['extShortDesc']
- language_codes.append(alpha2)
- mkdirs(pj(target_locale_dir, alpha2))
- locale_path = pj(target_locale_dir, alpha2, 'messages.properties')
- with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f:
- for string_name in strings:
- string = strings[string_name]['message']
- if alpha2 == 'en' and string_name in title_case_strings:
- string = string.title()
- f.write(string_name)
- f.write(u'=')
- f.write(string.replace('\n', r'\n'))
- f.write(u'\n')
-
-# generate chrome.manifest file
-chrome_manifest = pj(build_dir, 'chrome.manifest')
-
-with open(chrome_manifest, 'at', encoding='utf-8', newline='\n') as f:
- f.write(u'\nlocale ublock0 en ./locale/en/\n')
- for alpha2 in language_codes:
- if alpha2 == 'en':
- continue
- f.write(u'locale ublock0 ' + alpha2 + ' ./locale/' + alpha2 + '/\n')
-
-rmtree(source_locale_dir)
-
-# update install.rdf
-
-chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json')
-with open(chromium_manifest, encoding='utf-8') as m:
- manifest = json.load(m)
-
-# Fetch extension version
-# https://developer.mozilla.org/en-US/Add-ons/AMO/Policy/Maintenance#How_do_I_submit_a_Beta_add-on.3F
-# "To create a beta channel [...] '(a|alpha|b|beta|pre|rc)\d*$' "
-
-version = ''
-with open(version_filepath) as f:
- version = f.read().strip()
-match = re.search('^(\d+\.\d+\.\d+)(\.\d+)$', version)
-if match:
- buildtype = int(match.group(2)[1:])
- if buildtype < 100:
- builttype = 'b' + str(buildtype)
- else:
- builttype = 'rc' + str(buildtype - 100)
- version = match.group(1) + builttype
-manifest['version'] = version
-
-manifest['homepage'] = 'https://github.com/gorhill/uBlock'
-manifest['description'] = descriptions['en']
-del descriptions['en']
-
-manifest['localized'] = []
-t = ' '
-t3 = 3 * t
-for alpha2 in descriptions:
- if alpha2 == 'en':
- continue
- manifest['localized'].append(
- '\n' + t*2 + '\n' +
- t3 + '' + alpha2 + '\n' +
- t3 + '' + manifest['name'] + '\n' +
- t3 + '' + descriptions[alpha2] + '\n' +
- t3 + '' + manifest['author'] + '\n' +
- # t3 + '' + ??? + '\n' +
- t3 + '' + manifest['homepage'] + '\n' +
- t*2 + ''
- )
-manifest['localized'] = '\n'.join(manifest['localized'])
-
-install_rdf = pj(build_dir, 'install.rdf')
-with open(install_rdf, 'r+t', encoding='utf-8', newline='\n') as f:
- install_rdf = f.read()
- f.seek(0)
- f.write(install_rdf.format(**manifest))
diff --git a/tools/make-firefox.sh b/tools/make-firefox.sh
deleted file mode 100755
index b6f8c8398..000000000
--- a/tools/make-firefox.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/env bash
-#
-# This script assumes a linux environment
-
-echo "*** uBlock0.firefox: Copying files"
-
-DES=dist/build/uBlock0.firefox
-rm -rf $DES
-mkdir -p $DES
-
-bash ./tools/make-assets.sh $DES
-
-cp -R src/css $DES/
-cp -R src/img $DES/
-cp -R src/js $DES/
-cp -R src/lib $DES/
-cp -R src/_locales $DES/
-cp src/*.html $DES/
-
-mv $DES/img/icon_128.png $DES/icon.png
-cp platform/firefox/css/* $DES/css/
-cp platform/firefox/polyfill.js $DES/js/
-cp platform/firefox/vapi-*.js $DES/js/
-cp platform/chromium/vapi-usercss.real.js $DES/js/
-cp platform/webext/vapi-usercss.js $DES/js/
-cp platform/firefox/bootstrap.js $DES/
-cp platform/firefox/processScript.js $DES/
-cp platform/firefox/frame*.js $DES/
-cp -R platform/firefox/img $DES/
-cp platform/firefox/chrome.manifest $DES/
-cp platform/firefox/install.rdf $DES/
-cp platform/firefox/*.xul $DES/
-cp LICENSE.txt $DES/
-
-echo "*** uBlock0.firefox: concatenating content scripts"
-cat $DES/js/vapi-usercss.js > /tmp/contentscript.js
-echo >> /tmp/contentscript.js
-grep -v "^'use strict';$" $DES/js/vapi-usercss.real.js >> /tmp/contentscript.js
-echo >> /tmp/contentscript.js
-grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js
-mv /tmp/contentscript.js $DES/js/contentscript.js
-rm $DES/js/vapi-usercss.js
-rm $DES/js/vapi-usercss.real.js
-
-echo "*** uBlock0.firefox: Generating meta..."
-python tools/make-firefox-meta.py $DES/
-
-if [ "$1" = all ]; then
- set +v
- echo "*** uBlock0.firefox: Creating package..."
- pushd $DES/ > /dev/null
- zip ../uBlock0.firefox.xpi -qr *
- popd > /dev/null
-fi
-
-echo "*** uBlock0.firefox: Package done."