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

Unified Diff: lib/child/elemHide.js

Issue 29348029: Issue 4253 - Implement a less fragile way to detect documents that element hiding needs to apply to (Closed)
Patch Set: Created July 19, 2016, 5:35 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 | no next file » | 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
@@ -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();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld