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

Unified Diff: popupBlocker.js

Issue 5203459900964864: Issue 492 - Implemented popup blocking for Safari (Closed)
Patch Set: Created May 16, 2014, 9:46 a.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 | « chrome/ext/background.js ('k') | safari/ext/background.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: popupBlocker.js
===================================================================
--- a/popupBlocker.js
+++ b/popupBlocker.js
@@ -15,51 +15,16 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-if (require("info").platform == "chromium")
+ext.pages.onPopup.addListener(function(page, opener)
{
- var tabsLoading = {};
+ if (isFrameWhitelisted(opener.page, opener.frame))
+ return;
- chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details)
- {
- var sourcePage = new ext.Page({id: details.sourceTabId});
- var sourceFrame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
+ var requestHost = extractHostFromURL(page.url);
+ var documentHost = extractHostFromURL(opener.frame.url);
+ var thirdParty = isThirdParty(requestHost, documentHost);
+ var filter = defaultMatcher.matchesAny(page.url, "POPUP", documentHost, thirdParty);
- if (!sourceFrame || isFrameWhitelisted(sourcePage, sourceFrame))
- return;
-
- var openerUrl = sourceFrame.url;
- if (!openerUrl)
- {
- // We don't know the opener tab
- return;
- }
- tabsLoading[details.tabId] = openerUrl;
-
- checkPotentialPopup(details.tabId, details.url, 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(tabId, tab.url, tabsLoading[tabId]);
-
- if ("status" in changeInfo && changeInfo.status == "complete" && tab.url != "about:blank")
- delete tabsLoading[tabId];
- });
-}
-
-function checkPotentialPopup(tabId, url, opener)
-{
- var requestHost = extractHostFromURL(url);
- var documentHost = extractHostFromURL(opener);
- var thirdParty = isThirdParty(requestHost, documentHost);
- var filter = defaultMatcher.matchesAny(url || "about:blank", "POPUP", documentHost, thirdParty);
if (filter instanceof BlockingFilter)
- chrome.tabs.remove(tabId);
-}
+ page.close();
+});
« no previous file with comments | « chrome/ext/background.js ('k') | safari/ext/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld