Skip to content

Commit

Permalink
code review: preemptively address https://bugzilla.mozilla.org/show_b…
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 27, 2017
1 parent 198f72a commit bbda2a9
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 58 deletions.
2 changes: 1 addition & 1 deletion platform/chromium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
1 change: 1 addition & 0 deletions platform/chromium/options_ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<script src="js/vapi.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/options_ui.js"></script>
<title></title>
Expand Down
3 changes: 1 addition & 2 deletions platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
(function() {

/******************************************************************************/

var vAPI = self.vAPI = self.vAPI || {};
/******************************************************************************/

var chrome = self.chrome;
var manifest = chrome.runtime.getManifest();
Expand Down
54 changes: 7 additions & 47 deletions platform/chromium/vapi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,22 @@
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/456
// Skip if already injected.

// 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;
}
if ( typeof vAPI === 'object' && !vAPI.clientScript ) { // >>>>>>>> start of HUGE-IF-BLOCK

/******************************************************************************/

// 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;
}

/******************************************************************************/

vAPI.clientScript = true;

vAPI.randomToken = function() {
return String.fromCharCode(Date.now() % 26 + 97) +
Math.floor(Math.random() * 982451653 + 982451653).toString(36);
Expand Down Expand Up @@ -102,7 +65,6 @@ vAPI.shutdown = {
}
};

/******************************************************************************/
/******************************************************************************/

vAPI.messaging = {
Expand Down Expand Up @@ -349,6 +311,4 @@ vAPI.shutdown.add(function() {
/******************************************************************************/
/******************************************************************************/

})(this);

/******************************************************************************/
} // <<<<<<<< end of HUGE-IF-BLOCK
6 changes: 0 additions & 6 deletions platform/chromium/vapi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/******************************************************************************/
Expand Down
54 changes: 54 additions & 0 deletions platform/chromium/vapi.js
Original file line number Diff line number Diff line change
@@ -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 };
}

/******************************************************************************/
2 changes: 1 addition & 1 deletion platform/opera/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
1 change: 1 addition & 0 deletions platform/webext/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"file://*/*"
],
"js":[
"js/vapi.js",
"js/vapi-client.js",
"js/contentscript.js"
],
Expand Down
1 change: 1 addition & 0 deletions src/1p-filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<input id="importFilePicker" type="file" accept="text/plain" class="hiddenFileInput">
</p>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/3p-filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</ul>
</div>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<li><a href="http://fontawesome.io" target="_blank">Font Awesome</a> by <a href="https://github.com/davegandy">Dave Gandy</a>
</ul>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/advanced-settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<button id="advancedSettingsApply" class="custom important" type="button" disabled="true" data-i18n="genericApplyChanges"></button>&ensp;
<p><textarea id="advancedSettings" dir="auto" spellcheck="false"></textarea>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/asset-viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<div id="content"></div>


<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="js/polyfill.js"></script>
<script src="lib/punycode.js"></script>
<script src="lib/publicsuffixlist.js"></script>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-background.js"></script>
<script src="js/vapi-webrequest.js"></script><!-- Forks can pick the webext, chromium, or their own implementation -->
Expand Down
1 change: 1 addition & 0 deletions src/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<iframe id="iframe" src=""></iframe>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/udom.js"></script>
<script src="js/i18n.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/document-blocked.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
</span>
</div>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/dyna-rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h2 data-i18n="rulesTemporaryHeader"></h2>
</ul>
</div>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
8 changes: 7 additions & 1 deletion src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/******************************************************************************/
/******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/logger-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<div id="filterFinderDialogSentence1"><span><span></span><code></code><span></span></span></div>
</div>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ <h2 data-i18n="popupHitDomainCountPrompt">&nbsp;</h2>
</div>

<script src="lib/punycode.js"></script>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<p><button class="custom" type="button" id="reset" data-i18n="aboutResetDataButton"></button>
</div>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/whitelist.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<input id="importFilePicker" type="file" accept="text/plain" class="hiddenFileInput">

<script src="lib/punycode.js"></script>
<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
Expand Down

0 comments on commit bbda2a9

Please sign in to comment.