diff --git a/platform/chromium/manifest.json b/platform/chromium/manifest.json index 64e71a22b..7751d358c 100644 --- a/platform/chromium/manifest.json +++ b/platform/chromium/manifest.json @@ -38,7 +38,7 @@ "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], - "js": ["js/vapi-client.js", "js/contentscript.js"], + "js": ["js/vapi.js", "js/vapi-client.js", "js/contentscript.js"], "run_at": "document_start", "all_frames": true }, diff --git a/platform/chromium/options_ui.html b/platform/chromium/options_ui.html index d9e1df5b9..9b1d0e6d7 100644 --- a/platform/chromium/options_ui.html +++ b/platform/chromium/options_ui.html @@ -2,6 +2,7 @@ + diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 2aa60b4ff..4589c8d05 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -28,8 +28,7 @@ (function() { /******************************************************************************/ - -var vAPI = self.vAPI = self.vAPI || {}; +/******************************************************************************/ var chrome = self.chrome; var manifest = chrome.runtime.getManifest(); diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 6fd2d77a4..1cd30146c 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -19,58 +19,21 @@ Home: https://github.com/gorhill/uBlock */ -/* global HTMLDocument, XMLDocument */ +// For non-background page '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://github.com/gorhill/uBlock/issues/1124 -// Looks like `contentType` is on track to be standardized: -// https://dom.spec.whatwg.org/#concept-document-content-type -// https://forums.lanik.us/viewtopic.php?f=64&t=31522 -// Skip text/plain documents. -var contentType = document.contentType || ''; -if ( /^image\/|^text\/plain/.test(contentType) ) { - 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; -var chrome = self.chrome; - // https://github.com/chrisaljoudi/uBlock/issues/456 -// Already injected? -if ( vAPI.sessionId ) { - return; -} +// Skip if already injected. + +if ( typeof vAPI === 'object' && !vAPI.clientScript ) { // >>>>>>>> start of HUGE-IF-BLOCK /******************************************************************************/ +/******************************************************************************/ + +vAPI.clientScript = true; vAPI.randomToken = function() { return String.fromCharCode(Date.now() % 26 + 97) + @@ -102,7 +65,6 @@ vAPI.shutdown = { } }; -/******************************************************************************/ /******************************************************************************/ vAPI.messaging = { @@ -349,6 +311,4 @@ vAPI.shutdown.add(function() { /******************************************************************************/ /******************************************************************************/ -})(this); - -/******************************************************************************/ +} // <<<<<<<< end of HUGE-IF-BLOCK diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 1a196910f..ab814424f 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -28,12 +28,6 @@ (function(self) { -// 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; var chrome = self.chrome; /******************************************************************************/ diff --git a/platform/chromium/vapi.js b/platform/chromium/vapi.js new file mode 100644 index 000000000..57fd75cca --- /dev/null +++ b/platform/chromium/vapi.js @@ -0,0 +1,54 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 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 +*/ + +'use strict'; + +/* global HTMLDocument, XMLDocument */ + +// For background page, auxiliary pages, and content scripts. + +/******************************************************************************/ + +// https://bugzilla.mozilla.org/show_bug.cgi?id=1408996#c9 +var vAPI; // jshint ignore:line + +// https://github.com/chrisaljoudi/uBlock/issues/464 +// https://github.com/chrisaljoudi/uBlock/issues/1528 +// A XMLDocument can be a valid HTML document. + +// https://github.com/gorhill/uBlock/issues/1124 +// Looks like `contentType` is on track to be standardized: +// https://dom.spec.whatwg.org/#concept-document-content-type + +// https://forums.lanik.us/viewtopic.php?f=64&t=31522 +// Skip text/plain documents. + +if ( + (document instanceof HTMLDocument || + document instanceof XMLDocument && + document.createElement('div') instanceof HTMLDivElement + ) && + (/^image\/|^text\/plain/.test(document.contentType || '') === false) +) { + vAPI = vAPI instanceof Object && vAPI.uBO === true ? vAPI : { uBO: true }; +} + +/******************************************************************************/ diff --git a/platform/opera/manifest.json b/platform/opera/manifest.json index 38e4df96a..316e49036 100644 --- a/platform/opera/manifest.json +++ b/platform/opera/manifest.json @@ -25,7 +25,7 @@ "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], - "js": ["js/vapi-client.js", "js/contentscript.js"], + "js": ["js/vapi.js", "js/vapi-client.js", "js/contentscript.js"], "run_at": "document_start", "all_frames": true }, diff --git a/platform/webext/manifest.json b/platform/webext/manifest.json index fe121d7db..0c6b1951d 100644 --- a/platform/webext/manifest.json +++ b/platform/webext/manifest.json @@ -37,6 +37,7 @@ "file://*/*" ], "js":[ + "js/vapi.js", "js/vapi-client.js", "js/contentscript.js" ], diff --git a/src/1p-filters.html b/src/1p-filters.html index b1146a09d..f2da57cb9 100644 --- a/src/1p-filters.html +++ b/src/1p-filters.html @@ -26,6 +26,7 @@

+ diff --git a/src/3p-filters.html b/src/3p-filters.html index 062b24fab..efc2a8cfd 100644 --- a/src/3p-filters.html +++ b/src/3p-filters.html @@ -57,6 +57,7 @@ + diff --git a/src/about.html b/src/about.html index 6e3e2afc6..bd0120a0a 100644 --- a/src/about.html +++ b/src/about.html @@ -25,6 +25,7 @@
  • Font Awesome by Dave Gandy + diff --git a/src/advanced-settings.html b/src/advanced-settings.html index da18ac34a..2f91f68b9 100644 --- a/src/advanced-settings.html +++ b/src/advanced-settings.html @@ -15,6 +15,7 @@

    + diff --git a/src/asset-viewer.html b/src/asset-viewer.html index bfabd8829..95f311da9 100644 --- a/src/asset-viewer.html +++ b/src/asset-viewer.html @@ -14,6 +14,7 @@

    + diff --git a/src/background.html b/src/background.html index 7c1a8f917..edc04ba6e 100644 --- a/src/background.html +++ b/src/background.html @@ -8,6 +8,7 @@ + diff --git a/src/dashboard.html b/src/dashboard.html index 14285be52..45e7083e5 100644 --- a/src/dashboard.html +++ b/src/dashboard.html @@ -24,6 +24,7 @@ + diff --git a/src/document-blocked.html b/src/document-blocked.html index 40c03aa3b..156ea6b15 100644 --- a/src/document-blocked.html +++ b/src/document-blocked.html @@ -166,6 +166,7 @@ body[dir="rtl"] #theURL > p > span { + diff --git a/src/dyna-rules.html b/src/dyna-rules.html index fac16dd28..66eb7b7c9 100644 --- a/src/dyna-rules.html +++ b/src/dyna-rules.html @@ -50,6 +50,7 @@ + diff --git a/src/js/contentscript.js b/src/js/contentscript.js index 996d5ac36..58f7b545e 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -105,7 +105,13 @@ // https://github.com/chrisaljoudi/uBlock/issues/456 // https://github.com/gorhill/uBlock/issues/2029 -if ( typeof vAPI !== 'undefined' ) { // >>>>>>>> start of HUGE-IF-BLOCK +if ( typeof vAPI === 'object' && !vAPI.contentScript ) { // >>>>>>>> start of HUGE-IF-BLOCK + +/******************************************************************************/ +/******************************************************************************/ +/******************************************************************************/ + +vAPI.contentScript = true; /******************************************************************************/ /******************************************************************************/ diff --git a/src/logger-ui.html b/src/logger-ui.html index bcbd83f06..34740fc69 100644 --- a/src/logger-ui.html +++ b/src/logger-ui.html @@ -112,6 +112,7 @@
    + diff --git a/src/popup.html b/src/popup.html index 80f003fc4..ea78d2cd6 100644 --- a/src/popup.html +++ b/src/popup.html @@ -59,6 +59,7 @@ + diff --git a/src/settings.html b/src/settings.html index 1dd741a8b..2c63c40c7 100644 --- a/src/settings.html +++ b/src/settings.html @@ -55,6 +55,7 @@

    + diff --git a/src/whitelist.html b/src/whitelist.html index f8a459052..b2d724fa3 100644 --- a/src/whitelist.html +++ b/src/whitelist.html @@ -28,6 +28,7 @@ +