From 5ae7687e5629a13c5733fd8f26fc2c87c6f41660 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Mon, 16 Mar 2015 08:09:34 +0100 Subject: [PATCH 1/2] Firefox: different kind of vAPI.localStorage --- platform/firefox/vapi-common.js | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index 28b25d6d9..8c461453d 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -120,21 +120,34 @@ vAPI.closePopup = function() { // This storage is optional, but it is nice to have, for a more polished user // experience. -Object.defineProperty(vAPI, 'localStorage', { - get: function() { - if ( this._localStorage ) { - return this._localStorage; +vAPI.localStorage = { + PB: Services.prefs.getBranch('extensions.' + location.host + '.'), + str: Components.classes['@mozilla.org/supports-string;1'] + .createInstance(Components.interfaces.nsISupportsString), + getItem: function(key) { + try { + return this.PB.getComplexValue( + key, Components.interfaces.nsISupportsString + ).data; + } catch (ex) { + return null; } - - this._localStorage = Services.domStorageManager.getLocalStorageForPrincipal( - Services.scriptSecurityManager.getCodebasePrincipal( - Services.io.newURI('http://ublock.raymondhill.net/', null, null) - ), - '' + }, + setItem: function(key, value) { + this.str.data = value; + this.PB.setComplexValue( + key, + Components.interfaces.nsISupportsString, + this.str ); - return this._localStorage; + }, + removeItem: function(key) { + this.PB.clearUserPref(key); + }, + clear: function() { + this.PB.deleteBranch(''); } -}); +}; /******************************************************************************/ From ebf840c35d9b2ca51975f0a0bb5c86816c2301dd Mon Sep 17 00:00:00 2001 From: Deathamns Date: Mon, 16 Mar 2015 10:37:55 +0100 Subject: [PATCH 2/2] abp:subscribe fixes Test a[href^="abp:"], since the protocol probably not used for anything else, also "a", because ABP checks only anchors, and these links are made only for ABP. Also, the event target is not always the link, so at least some parents should be tested as well. --- platform/firefox/vapi-background.js | 4 +--- platform/firefox/vapi-common.js | 3 ++- src/js/subscriber.js | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 2df36486a..c3a1f7456 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -455,11 +455,9 @@ vAPI.tabs.getTabId = function(target) { if ( vAPI.fennec ) { if ( target.browser ) { // target is a tab - return target.browser.loadContext.DOMWindowID; + target = target.browser; } return target.loadContext.DOMWindowID; - - return -1; } if ( target.linkedPanel ) { diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index 8c461453d..c84d2813e 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -127,7 +127,8 @@ vAPI.localStorage = { getItem: function(key) { try { return this.PB.getComplexValue( - key, Components.interfaces.nsISupportsString + key, + Components.interfaces.nsISupportsString ).data; } catch (ex) { return null; diff --git a/src/js/subscriber.js b/src/js/subscriber.js index b98b4f46b..c1c6e61c7 100644 --- a/src/js/subscriber.js +++ b/src/js/subscriber.js @@ -37,7 +37,7 @@ // https://github.com/gorhill/uBlock/issues/464 if ( document instanceof HTMLDocument === false ) { //console.debug('contentscript-start.js > not a HTLMDocument'); - return false; + return; } // Because in case @@ -52,7 +52,7 @@ if ( !vAPI ) { // The links look like this: // abp:subscribe?location=https://easylist-downloads.adblockplus.org/easyprivacy.txt[...] -if ( document.querySelector('[href^="abp:subscribe?"]') === null ) { +if ( document.querySelector('a[href^="abp:"]') === null ) { return; } @@ -66,14 +66,16 @@ var onAbpLinkClicked = function(ev) { if ( ev.button !== 0 ) { return; } - var receiver = ev.target; - if ( receiver === null ) { - return; - } - if ( receiver.tagName.toLowerCase() !== 'a' ) { - return; - } - var href = receiver.getAttribute('href') || ''; + var target = ev.target; + var limit = 3; + var href = ''; + do { + if ( target instanceof HTMLAnchorElement ) { + href = target.href; + break; + } + target = target.parentNode; + } while ( target && --limit ); if ( href === '' ) { return; }