| Index: lib/child/elemHide.js |
| =================================================================== |
| --- a/lib/child/elemHide.js |
| +++ b/lib/child/elemHide.js |
| @@ -297,17 +297,17 @@ HitRegistrationChannel.prototype = { |
| } |
| }; |
| let observer = { |
| QueryInterface: XPCOMUtils.generateQI([ |
| Ci.nsIObserver, Ci.nsISupportsWeakReference |
| ]), |
| - topic: "content-document-global-created", |
| + topic: "document-element-inserted", |
| styleURL: Utils.makeURI("about:abp-elemhide?css"), |
| sheet: null, |
| init: function() |
| { |
| Services.obs.addObserver(this, this.topic, true); |
| onShutdown.add(() => |
| { |
| @@ -320,72 +320,69 @@ let observer = { |
| }); |
| }, |
| observe: function(subject, topic, data) |
| { |
| if (topic != this.topic) |
| return; |
| - if (subject.document.readyState == "uninitialized") |
| + let window = subject.defaultView; |
| + if (!window) |
| { |
| - // It would be nice to listen to the readystatechange event here. However, |
| - // adding event listeners on uninitialized documents isn't possible. So |
| - // we listen for DOMContentLoaded and beforescriptexecute - whichever |
| - // fires first. |
| - let listener = () => |
| - { |
| - subject.removeEventListener("DOMContentLoaded", listener); |
| - subject.removeEventListener("beforescriptexecute", listener); |
| - this.observe(subject, topic, data); |
| - }; |
| - subject.addEventListener("DOMContentLoaded", listener); |
| - subject.addEventListener("beforescriptexecute", listener); |
| + // This is typically XBL bindings and SVG images, but also real |
| + // documents occasionally - probably due to speculative loading? |
| return; |
| } |
| + let type = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| + .getInterface(Ci.nsIWebNavigation) |
| + .QueryInterface(Ci.nsIDocShellTreeItem) |
| + .itemType; |
| + if (type != Ci.nsIDocShellTreeItem.typeContent) |
| + return; |
| port.emitWithResponse("elemhideEnabled", { |
| - frames: getFrames(subject), |
| - isPrivate: isPrivate(subject) |
| + frames: getFrames(window), |
| + isPrivate: isPrivate(window) |
| }).then(({ |
| enabled, contentType, docDomain, thirdParty, location, filter, |
| filterType |
| }) => |
| { |
| - if (Cu.isDeadWrapper(subject)) |
| + if (Cu.isDeadWrapper(window)) |
| { |
| // We are too late, the window is gone already. |
| return; |
| } |
| 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); |
| + let utils = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| + .getInterface(Ci.nsIDOMWindowUtils); |
| try |
| { |
| utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET); |
| } |
| catch (e) |
| { |
| // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to add |
| // the stylesheet multiple times to the same document (the observer |
| // will be notified twice for some documents). |
| if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE) |
| throw e; |
| } |
| } |
| else if (filter) |
| { |
| - RequestNotifier.addNodeData(subject.document, subject.top, { |
| + RequestNotifier.addNodeData(window.document, window.top, { |
| contentType, docDomain, thirdParty, location, filter, filterType |
| }); |
| } |
| }); |
| } |
| }; |
| observer.init(); |