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

Unified Diff: popupBlocker.js

Issue 9496013: Pop-up blocking functionality for Chrome (Closed)
Patch Set: Created March 1, 2013, 3:45 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 | « metadata.chrome ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popupBlocker.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/popupBlocker.js
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the Adblock Plus extension,
+ * Copyright (C) 2006-2012 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+var tabsLoading = {};
+
+chrome.tabs.onCreated.addListener(function(tab)
+{
+ if (!("openerTabId" in tab))
+ {
+ // This isn't a pop-up
+ return;
+ }
+
+ if (isFrameWhitelisted(tab.openerTabId, 0))
+ return false;
Thomas Greiner 2013/03/04 11:28:03 inconsistent with other returns: write |return;| h
+
+ var openerUrl = getFrameUrl(tab.openerTabId, 0);
+ if (!openerUrl)
+ {
+ // We don't know the opener tab
+ return;
+ }
+ tabsLoading[tab.id] = openerUrl;
+
+ checkPotentialPopup(tab, openerUrl);
+});
+
+chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
+{
+ if (!(tabId in tabsLoading))
+ {
+ // Not a pop-up we've previously seen
+ return;
+ }
+
+ if ("url" in changeInfo)
+ checkPotentialPopup(tab, tabsLoading[tabId]);
+
+ if ("status" in changeInfo && changeInfo.status == "complete")
+ delete tabsLoading[tabId];
+});
+
+
+function checkPotentialPopup(tab)
+{
+ var requestHost = extractHostFromURL(tab.url);
+ var documentHost = extractHostFromURL(tabsLoading[tab.id]);
+ var thirdParty = isThirdParty(requestHost, documentHost);
+ var filter = defaultMatcher.matchesAny(tab.url || "about:blank", "POPUP", documentHost, thirdParty);
+ if (filter instanceof BlockingFilter)
+ chrome.tabs.remove(tab.id);
+}
« no previous file with comments | « metadata.chrome ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld