From fc2df27d5768294f22a4d9ad049d45f2d0d52781 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Sat, 22 Jun 2019 00:12:53 +0200 Subject: Remove some cruft --- js/vapi-common.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 6946a9c..f1bc2ca 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -39,8 +39,10 @@ const {Services} = Components.utils.import( ); // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 -if ( self.vAPI === undefined || self.vAPI.eMatrix !== true ) { - self.vAPI = { eMatrix: true }; +// eMatrix: does this apply to us? +// In the meantime, let's remove the useless `eMatrix' property from vAPI +if (self.vAPI === undefined) { + self.vAPI = {}; } var vAPI = self.vAPI; -- cgit v1.2.3 From 9d87f8f864b28d182af9659a3095433adb4b0126 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Thu, 4 Jul 2019 17:33:06 +0200 Subject: Change how modules are imported I can't really find a reason why the returned value is preferred over the normal importing process. Additionally, there's a good chance importing Services.jsm can be done only once at the start of everything, instead of binding each object to a separate closure. --- js/vapi-common.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index f1bc2ca..1bc20bc 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -33,10 +33,7 @@ /******************************************************************************/ -const {Services} = Components.utils.import( - 'resource://gre/modules/Services.jsm', - null -); +Components.utils.import('resource://gre/modules/Services.jsm'); // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 // eMatrix: does this apply to us? -- cgit v1.2.3 From d8950421332a0d5b28cba6df38fc4fe85ff26d9e Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Thu, 4 Jul 2019 18:08:31 +0200 Subject: Remove one more importing --- js/vapi-common.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 1bc20bc..2b4158a 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -33,8 +33,6 @@ /******************************************************************************/ -Components.utils.import('resource://gre/modules/Services.jsm'); - // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 // eMatrix: does this apply to us? // In the meantime, let's remove the useless `eMatrix' property from vAPI -- cgit v1.2.3 From 29943a00d915abd025dc93f7f52b3b03aabf149f Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Thu, 4 Jul 2019 18:20:35 +0200 Subject: Revert "Remove one more importing" This reverts commit d8950421332a0d5b28cba6df38fc4fe85ff26d9e. Followup to the previous reverting. --- js/vapi-common.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 2b4158a..1bc20bc 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -33,6 +33,8 @@ /******************************************************************************/ +Components.utils.import('resource://gre/modules/Services.jsm'); + // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 // eMatrix: does this apply to us? // In the meantime, let's remove the useless `eMatrix' property from vAPI -- cgit v1.2.3 From 6908a6c89f9f44380faa1831ec13cff4042b671a Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Thu, 4 Jul 2019 18:41:18 +0200 Subject: Make vAPI definitely global At least for background.html, it can be defined once at the start of vapi-core and then populated. --- js/vapi-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 1bc20bc..9a322ec 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -42,7 +42,7 @@ if (self.vAPI === undefined) { self.vAPI = {}; } -var vAPI = self.vAPI; +var vAPI = self.vAPI; // This is used also when vapi-core is not available /******************************************************************************/ -- cgit v1.2.3 From 4c1c37a54318d91d572180b45bda9db6d9de0389 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Fri, 5 Jul 2019 13:34:01 +0200 Subject: Style changes --- js/vapi-common.js | 286 +++++++++++++++++++++++++----------------------------- 1 file changed, 133 insertions(+), 153 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 9a322ec..14b1086 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -21,172 +21,152 @@ uMatrix Home: https://github.com/gorhill/uMatrix */ -/* global sendAsyncMessage */ - // For background page or non-background pages 'use strict'; -/******************************************************************************/ - -(function(self) { - -/******************************************************************************/ - -Components.utils.import('resource://gre/modules/Services.jsm'); - -// https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 -// eMatrix: does this apply to us? -// In the meantime, let's remove the useless `eMatrix' property from vAPI -if (self.vAPI === undefined) { - self.vAPI = {}; -} - -var vAPI = self.vAPI; // This is used also when vapi-core is not available - -/******************************************************************************/ - -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' - ); -}; +(function (self) { + const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + Cu.import('resource://gre/modules/Services.jsm'); -/******************************************************************************/ - -vAPI.download = function(details) { - if ( !details.url ) { - return; + // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 + // eMatrix: does this apply to us? + // In the meantime, let's remove the useless `eMatrix' property from vAPI + if (self.vAPI === undefined) { + self.vAPI = {}; } - var a = document.createElement('a'); - a.href = details.url; - a.setAttribute('download', details.filename || ''); - a.dispatchEvent(new MouseEvent('click')); -}; - -/******************************************************************************/ - -vAPI.insertHTML = (function() { - const parser = Components.classes['@mozilla.org/parserutils;1'] - .getService(Components.interfaces.nsIParserUtils); - - // https://github.com/gorhill/uBlock/issues/845 - // Apparently dashboard pages execute with `about:blank` principal. - - return function(node, html) { - while ( node.firstChild ) { - node.removeChild(node.firstChild); - } - - node.appendChild(parser.parseFragment( - html, - parser.SanitizerAllowStyle, - false, - Services.io.newURI('about:blank', null, null), - document.documentElement - )); - }; -})(); - -/******************************************************************************/ + var vAPI = self.vAPI; // This is used also when vapi-core is not available -vAPI.getURL = function(path) { - return 'chrome://' + location.host + '/content/' + path.replace(/^\/+/, ''); -}; + 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) { + let dir = + ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1 + ? 'rtl' + : 'ltr'; + + document.body.setAttribute('dir', dir); + }; -vAPI.i18n = (function() { - var stringBundle = Services.strings.createBundle( - 'chrome://' + location.host + '/locale/messages.properties' - ); + vAPI.download = function (details) { + if (!details.url) { + return; + } - return function(s) { - try { - return stringBundle.GetStringFromName(s); - } catch (ex) { - return ''; - } + var a = document.createElement('a'); + a.href = details.url; + a.setAttribute('download', details.filename || ''); + a.dispatchEvent(new MouseEvent('click')); }; -})(); - -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 + '.'); + vAPI.insertHTML = (function () { + const parser = Cc['@mozilla.org/parserutils;1'] + .getService(Ci.nsIParserUtils); + + // https://github.com/gorhill/uBlock/issues/845 + // Apparently dashboard pages execute with `about:blank` principal. + + return function (node, html) { + while (node.firstChild) { + node.removeChild(node.firstChild); + } + + let parsed = + parser.parseFragment(html, + parser.SanitizerAllowStyle, + false, + Services.io.newURI('about:blank', + null, null), + document.documentElement); + + node.appendChild(parsed); + }; + })(); + + 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: Cc['@mozilla.org/supports-string;1'] + .createInstance(Ci.nsISupportsString), + + init: function (pbName) { + this.pbName = pbName; + this.pb = Services.prefs.getBranch(pbName); + }, + getItem: function (key) { + try { + return this.pb + .getComplexValue(key, + Ci.nsISupportsString).data; + } catch (ex) { + return null; + } + }, + setItem: function (key, value) { + this.str.data = value; + this.pb.setComplexValue(key, + Ci.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); - -/******************************************************************************/ -- cgit v1.2.3 From 1418306606fbf0c06cf1c12e027cf159ce478e02 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Fri, 5 Jul 2019 13:42:53 +0200 Subject: Minor style fixes --- js/vapi-common.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 14b1086..46225b1 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -36,7 +36,7 @@ self.vAPI = {}; } - var vAPI = self.vAPI; // This is used also when vapi-core is not available + let vAPI = self.vAPI; // This is used also when vapi-core is not available vAPI.setTimeout = vAPI.setTimeout || function (callback, delay, extra) { return setTimeout(function (a) { @@ -45,7 +45,7 @@ }; // http://www.w3.org/International/questions/qa-scripts#directions - var setScriptDirection = function(language) { + let setScriptDirection = function(language) { let dir = ['ar', 'he', 'fa', 'ps', 'ur'].indexOf(language) !== -1 ? 'rtl' @@ -59,7 +59,7 @@ return; } - var a = document.createElement('a'); + let a = document.createElement('a'); a.href = details.url; a.setAttribute('download', details.filename || ''); a.dispatchEvent(new MouseEvent('click')); @@ -97,7 +97,7 @@ }; vAPI.i18n = (function () { - var stringBundle = + let stringBundle = Services.strings.createBundle('chrome://' + location.host + '/locale/messages.properties'); -- cgit v1.2.3 From 8c05a1711951f3cc9179eec2c086b0e88d42e5f0 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Fri, 19 Jul 2019 15:54:34 +0200 Subject: Make vAPI definitely global for non-background pages too --- js/vapi-common.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 46225b1..473ad89 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -25,19 +25,12 @@ 'use strict'; +let vAPI = {}; + (function (self) { const {classes: Cc, interfaces: Ci, utils: Cu} = Components; Cu.import('resource://gre/modules/Services.jsm'); - // https://bugs.chromium.org/p/project-zero/issues/detail?id=1225&desc=6#c10 - // eMatrix: does this apply to us? - // In the meantime, let's remove the useless `eMatrix' property from vAPI - if (self.vAPI === undefined) { - self.vAPI = {}; - } - - let vAPI = self.vAPI; // This is used also when vapi-core is not available - vAPI.setTimeout = vAPI.setTimeout || function (callback, delay, extra) { return setTimeout(function (a) { callback(a); -- cgit v1.2.3 From acd097e4733c106a15815c90e21c00d0c545e042 Mon Sep 17 00:00:00 2001 From: Alessio Vanni Date: Fri, 19 Jul 2019 16:00:08 +0200 Subject: Make components and Services.jsm global Once again, but this time it works. --- js/vapi-common.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/vapi-common.js') diff --git a/js/vapi-common.js b/js/vapi-common.js index 473ad89..b7c5635 100644 --- a/js/vapi-common.js +++ b/js/vapi-common.js @@ -27,10 +27,10 @@ let vAPI = {}; -(function (self) { - const {classes: Cc, interfaces: Ci, utils: Cu} = Components; - Cu.import('resource://gre/modules/Services.jsm'); +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; +Cu.import('resource://gre/modules/Services.jsm'); +(function (self) { vAPI.setTimeout = vAPI.setTimeout || function (callback, delay, extra) { return setTimeout(function (a) { callback(a); -- cgit v1.2.3