Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/elemHideFF.js

Issue 29346613: Issue 521 - Inject our stylesheet on per-site basis rather than globally (Closed)
Patch Set: Created June 17, 2016, 2:07 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/child/elemHide.js ('K') | « lib/child/main.js ('k') | lib/main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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};
+});
« lib/child/elemHide.js ('K') | « lib/child/main.js ('k') | lib/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld