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

Unified Diff: lib/popupBlocker.js

Issue 29452181: Noissue - Merge current tip to Edge bookmark (Closed)
Patch Set: Created May 30, 2017, 3:49 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 | « lib/notificationHelper.js ('k') | lib/prefs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/popupBlocker.js
===================================================================
--- a/lib/popupBlocker.js
+++ b/lib/popupBlocker.js
@@ -1,6 +1,6 @@
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
- * Copyright (C) 2006-2016 Eyeo GmbH
+ * Copyright (C) 2006-2017 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
@@ -20,25 +20,21 @@
"use strict";
const {defaultMatcher} = require("matcher");
-const {BlockingFilter} = require("filterClasses");
+const {BlockingFilter, RegExpFilter} = require("filterClasses");
const {stringifyURL, isThirdParty, extractHostFromFrame} = require("url");
const {checkWhitelisted} = require("whitelisting");
const {logRequest} = require("devtools");
-let loadingPopups = Object.create(null);
-
-function hasLoadingPopups()
-{
- return Object.keys(loadingPopups).length > 0;
-}
+let loadingPopups = new Map();
function forgetPopup(tabId)
{
- delete loadingPopups[tabId];
+ loadingPopups.delete(tabId);
- if (!hasLoadingPopups())
+ if (loadingPopups.size == 0)
{
- chrome.webRequest.onBeforeRequest.removeListener(onBeforeRequest);
+ chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged);
+ chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged);
chrome.webNavigation.onCompleted.removeListener(onCompleted);
chrome.tabs.onRemoved.removeListener(forgetPopup);
}
@@ -71,9 +67,13 @@
);
}
-function onBeforeRequest(details)
+function onPopupURLChanged(details)
{
- let popup = loadingPopups[details.tabId];
+ // Ignore frames inside the popup window.
+ if (details.frameId != 0)
+ return;
+
+ let popup = loadingPopups.get(details.tabId);
if (popup)
{
popup.url = details.url;
@@ -90,35 +90,37 @@
chrome.webNavigation.onCreatedNavigationTarget.addListener(details =>
{
- if (!hasLoadingPopups())
+ if (loadingPopups.size == 0)
{
chrome.webRequest.onBeforeRequest.addListener(
- onBeforeRequest,
+ onPopupURLChanged,
{
- urls: ["<all_urls>"],
+ urls: ["http://*/*", "https://*/*"],
types: ["main_frame"]
}
);
-
+ chrome.webNavigation.onCommitted.addListener(onPopupURLChanged);
chrome.webNavigation.onCompleted.addListener(onCompleted);
chrome.tabs.onRemoved.addListener(forgetPopup);
}
- let tabId = details.tabId;
- let popup = loadingPopups[tabId] = {
+ let popup = {
url: details.url,
sourcePage: new ext.Page({id: details.sourceTabId}),
sourceFrame: null
};
+
+ loadingPopups.set(details.tabId, popup);
+
let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
if (checkWhitelisted(popup.sourcePage, frame))
{
- forgetPopup(tabId);
+ forgetPopup(details.tabId);
}
else
{
popup.sourceFrame = frame;
- checkPotentialPopup(tabId, popup);
+ checkPotentialPopup(details.tabId, popup);
}
});
« no previous file with comments | « lib/notificationHelper.js ('k') | lib/prefs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld