[Pkg-mozext-commits] [adblock-plus] 28/98: Issue 4335 - Adblock Plus should forget pop-ups after the initial load
David Prévot
taffit at moszumanska.debian.org
Tue Oct 24 01:30:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit b6d6256021f19c9ec4d88394bfa02474bf7bb9d7
Author: Wladimir Palant <trev at adblockplus.org>
Date: Mon Aug 15 19:54:57 2016 +0200
Issue 4335 - Adblock Plus should forget pop-ups after the initial load
---
lib/child/contentPolicy.js | 62 ++++++++++++++++++++++++++++++++--------------
1 file changed, 43 insertions(+), 19 deletions(-)
diff --git a/lib/child/contentPolicy.js b/lib/child/contentPolicy.js
index b273553..98d1a94 100644
--- a/lib/child/contentPolicy.js
+++ b/lib/child/contentPolicy.js
@@ -247,11 +247,11 @@ var PolicyImplementation =
for (let category of this.xpcom_categories)
catMan.addCategoryEntry(category, this.contractID, this.contractID, false, true);
- Services.obs.addObserver(this, "content-document-global-created", true);
+ Services.obs.addObserver(this, "document-element-inserted", true);
onShutdown.add(() =>
{
- Services.obs.removeObserver(this, "content-document-global-created");
+ Services.obs.removeObserver(this, "document-element-inserted");
for (let category of this.xpcom_categories)
catMan.deleteCategoryEntry(category, this.contractID, false);
@@ -312,23 +312,40 @@ var PolicyImplementation =
// nsIObserver interface implementation
//
_openers: new WeakMap(),
+ _alreadyLoaded: Symbol(),
observe: function(subject, topic, data, uri)
{
switch (topic)
{
- case "content-document-global-created":
+ case "document-element-inserted":
{
- let opener = this._openers.get(subject);
- if (opener && Components.utils.isDeadWrapper(opener))
+ let window = subject.defaultView;
+ if (!window)
+ return;
+
+ let type = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .itemType;
+ if (type != Ci.nsIDocShellTreeItem.typeContent)
+ return;
+
+ let opener = this._openers.get(window);
+ if (opener == this._alreadyLoaded)
+ {
+ // This window has loaded already, ignore it regardless of whether
+ // window.opener is still set.
+ return;
+ }
+
+ if (opener && Cu.isDeadWrapper(opener))
opener = null;
if (!opener)
{
// We don't know the opener for this window yet, try to find it
- if (subject instanceof Ci.nsIDOMWindow)
- opener = subject.opener;
-
+ opener = window.opener;
if (!opener)
return;
@@ -336,15 +353,22 @@ var PolicyImplementation =
while (opener.location == "about:blank" && opener.opener)
opener = opener.opener;
- this._openers.set(subject, opener);
+ this._openers.set(window, opener);
+
+ let forgetPopup = event =>
+ {
+ subject.removeEventListener("DOMContentLoaded", forgetPopup);
+ this._openers.set(window, this._alreadyLoaded);
+ };
+ subject.addEventListener("DOMContentLoaded", forgetPopup);
}
- if (!uri && subject instanceof Ci.nsIDOMWindow)
- uri = subject.location.href;
+ if (!uri)
+ uri = window.location.href;
if (!shouldAllow(opener, opener.document, "POPUP", uri))
{
- subject.stop();
- Utils.runAsync(() => subject.close());
+ window.stop();
+ Utils.runAsync(() => window.close());
}
else if (uri == "about:blank")
{
@@ -352,10 +376,10 @@ var PolicyImplementation =
// initiated asynchronously. Wait for that.
Utils.runAsync(() =>
{
- let channel = subject.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDocShell)
- .QueryInterface(Ci.nsIDocumentLoader)
- .documentChannel;
+ let channel = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDocShell)
+ .QueryInterface(Ci.nsIDocumentLoader)
+ .documentChannel;
if (channel)
this.observe(subject, topic, data, channel.URI.spec);
});
@@ -394,8 +418,8 @@ var PolicyImplementation =
// rather than preventing the redirect. Note that we might not have
// seen the original channel yet because the redirect happened before
// the async code in observe() had a chance to run.
- this.observe(wnd, "content-document-global-created", null, oldChannel.URI.spec);
- this.observe(wnd, "content-document-global-created", null, newChannel.URI.spec);
+ this.observe(wnd.document, "document-element-inserted", null, oldChannel.URI.spec);
+ this.observe(wnd.document, "document-element-inserted", null, newChannel.URI.spec);
}
return;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list