Index: lib/elemHideFF.js |
=================================================================== |
rename from lib/elemHideStylesheet.js |
rename to lib/elemHideFF.js |
--- a/lib/elemHideStylesheet.js |
+++ b/lib/elemHideFF.js |
@@ -15,93 +15,36 @@ |
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
*/ |
"use strict"; |
let {port} = require("messaging"); |
let {ElemHide} = require("elemHide"); |
let {FilterNotifier} = require("filterNotifier"); |
+let {FilterStorage} = require("filterStorage"); |
let {Prefs} = require("prefs"); |
-let {Utils} = require("utils"); |
+let {Policy} = require("contentPolicy"); |
-/** |
- * Indicates whether the element hiding stylesheet is currently applied. |
- * @type Boolean |
- */ |
-let applied = false; |
+FilterNotifier.on("elemhideupdate", () => port.emit("elemhideupdate")); |
-/** |
- * Stylesheet URL to be registered |
- * @type nsIURI |
- */ |
-let styleURL = Utils.makeURI("about:abp-elemhide?css"); |
+port.on("getSelectors", () => ElemHide.getSelectors()); |
-function init() |
+port.on("elemhideEnabled", ({frames, isPrivate}) => |
{ |
- port.on("getSelectors", () => ElemHide.getSelectors()); |
+ if (!Prefs.enabled) |
+ return {enabled: false}; |
- apply(); |
- onShutdown.add(unapply); |
- |
- Prefs.addListener(function(name) |
+ let hit = Policy.isFrameWhitelisted(frames, true); |
+ if (hit) |
{ |
- if (name == "enabled") |
- apply(); |
- }); |
- |
- FilterNotifier.on("elemhideupdate", onUpdate); |
-} |
- |
-function onUpdate() |
-{ |
- // Call apply() asynchronously and protect against reentrance - multiple |
- // change events shouldn't result in multiple calls. |
- if (onUpdate.inProgress) |
- return; |
- |
- onUpdate.inProgress = true; |
- Utils.runAsync(() => |
- { |
- onUpdate.inProgress = false; |
- apply(); |
- }); |
-} |
- |
-function apply() |
-{ |
- unapply(); |
- |
- if (!Prefs.enabled) |
- return; |
- |
- try |
- { |
- Utils.styleService.loadAndRegisterSheet(styleURL, |
- Ci.nsIStyleSheetService.USER_SHEET); |
- applied = true; |
+ let [frameIndex, contentType, docDomain, thirdParty, location, filter] = hit; |
+ if (!isPrivate) |
+ FilterStorage.increaseHitCount(filter); |
+ return { |
+ enabled: false, |
+ contentType, docDomain, thirdParty, location, |
+ filter: filter.text, filterType: filter.type |
+ }; |
} |
- catch (e) |
- { |
- Cu.reportError(e); |
- } |
-} |
- |
-function unapply() |
-{ |
- if (applied) |
- { |
- try |
- { |
- Utils.styleService.unregisterSheet(styleURL, |
- Ci.nsIStyleSheetService.USER_SHEET); |
- } |
- catch (e) |
- { |
- Cu.reportError(e); |
- } |
- applied = false; |
- } |
-} |
- |
-// Send dummy message before initializing, this delay makes sure that the child |
-// modules are loaded and our protocol handler registered. |
-port.emitWithResponse("ping").then(init); |
+ else |
+ return {enabled: true}; |
+}); |