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

Unified Diff: lib/child/elemHide.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
« no previous file with comments | « no previous file | lib/child/main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/child/elemHide.js
===================================================================
--- a/lib/child/elemHide.js
+++ b/lib/child/elemHide.js
@@ -28,18 +28,21 @@ try
delete proto.Components;
}
catch (e)
{
Cu.reportError(e);
}
let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
+let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
let {shouldAllowAsync} = require("child/contentPolicy");
+let {getFrames, isPrivate} = require("child/utils");
+let {RequestNotifier} = require("child/requestNotifier");
let {port} = require("messaging");
let {Utils} = require("utils");
// The allowXBL binding below won't have any effect on the element. For elements
// that should be hidden however we don't return any binding at all, this makes
// Gecko stop constructing the node - it cannot be shown.
const allowXBL = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dummy' bindToUntrustedContent='true'/></bindings>";
const hideXBL = "<bindings xmlns='http://www.mozilla.org/xbl'/>";
@@ -288,8 +291,67 @@ HitRegistrationChannel.prototype = {
let window = Utils.getRequestWindow(this);
shouldAllowAsync(window, window.document, "ELEMHIDE", this.key, allow =>
{
resolve(allow ? allowXBL : hideXBL);
});
});
}
};
+
+let observer = {
+ QueryInterface: XPCOMUtils.generateQI([
+ Ci.nsIObserver, Ci.nsISupportsWeakReference
+ ]),
+
+ topic: "content-document-global-created",
+ styleURL: Utils.makeURI("about:abp-elemhide?css"),
+ sheet: null,
+
+ init: function()
+ {
+ Services.obs.addObserver(this, this.topic, true);
+ onShutdown.add(() =>
+ {
+ Services.obs.removeObserver(this, this.topic);
+ });
+
+ port.on("elemhideupdate", () =>
+ {
+ this.sheet = null;
Thomas Greiner 2016/06/23 14:12:42 If I understand this correctly, we no longer apply
Wladimir Palant 2016/06/29 16:18:21 Yes, this is very much desirable and indeed listed
+ });
+ },
+
+ observe: function(subject, topic, data)
+ {
+ if (topic != this.topic)
+ return;
+
+ port.emitWithResponse("elemhideEnabled", {
+ frames: getFrames(subject),
+ isPrivate: isPrivate(subject)
+ }).then(({
+ enabled, contentType, docDomain, thirdParty, location, filter,
+ filterType
+ }) =>
+ {
+ if (enabled)
+ {
+ if (!this.sheet)
+ {
+ this.sheet = Utils.styleService.preloadSheet(this.styleURL,
+ Ci.nsIStyleSheetService.USER_SHEET);
+ }
+
+ let utils = subject.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
+ utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET);
+ }
+ else if (filter)
+ {
+ RequestNotifier.addNodeData(subject.document, subject.top, {
+ contentType, docDomain, thirdParty, location, filter, filterType
+ });
+ }
+ });
+ }
+};
+observer.init();
« no previous file with comments | « no previous file | lib/child/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld