Index: lib/popupBlocker.js |
=================================================================== |
--- a/lib/popupBlocker.js |
+++ b/lib/popupBlocker.js |
@@ -20,28 +20,23 @@ |
"use strict"; |
const {defaultMatcher} = require("matcher"); |
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(onPopupURLChanged); |
chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged); |
chrome.webNavigation.onCompleted.removeListener(onCompleted); |
chrome.tabs.onRemoved.removeListener(forgetPopup); |
} |
} |
@@ -73,53 +68,57 @@ |
} |
function onPopupURLChanged(details) |
{ |
// Ignore frames inside the popup window. |
if (details.frameId != 0) |
return; |
- let popup = loadingPopups[details.tabId]; |
+ let popup = loadingPopups.get(details.tabId); |
if (popup) |
{ |
popup.url = details.url; |
if (popup.sourceFrame) |
checkPotentialPopup(details.tabId, popup); |
} |
} |
function onCompleted(details) |
{ |
if (details.frameId == 0 && details.url != "about:blank") |
forgetPopup(details.tabId); |
} |
chrome.webNavigation.onCreatedNavigationTarget.addListener(details => |
{ |
- if (!hasLoadingPopups()) |
+ if (loadingPopups.size == 0) |
{ |
chrome.webRequest.onBeforeRequest.addListener( |
onPopupURLChanged, |
{ |
urls: ["http://*/*", "https://*/*"], |
types: ["main_frame"] |
} |
); |
chrome.webNavigation.onCommitted.addListener(onPopupURLChanged); |
chrome.webNavigation.onCompleted.addListener(onCompleted); |
chrome.tabs.onRemoved.addListener(forgetPopup); |
} |
let {tabId} = details; |
Sebastian Noack
2017/05/21 20:40:38
Perhaps get rid of this variable, and in-line deta
Manish Jethani
2017/05/21 22:17:06
Done.
|
- let popup = loadingPopups[tabId] = { |
+ |
+ let popup = { |
url: details.url, |
sourcePage: new ext.Page({id: details.sourceTabId}), |
sourceFrame: null |
}; |
+ |
+ loadingPopups.set(tabId, popup); |
+ |
let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); |
if (checkWhitelisted(popup.sourcePage, frame)) |
{ |
forgetPopup(tabId); |
} |
else |
{ |