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(); |