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

Unified Diff: lib/popupBlocker.js

Issue 29417597: Issue 5161 - Use maps and sets where appropriate (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Remove blank line Created May 17, 2017, 9:47 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/devtools.js ('k') | lib/whitelisting.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
@@ -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: ["<all_urls>"],
types: ["main_frame"]
}
);
chrome.webNavigation.onCommitted.addListener(onPopupURLChanged);
chrome.webNavigation.onCompleted.addListener(onCompleted);
chrome.tabs.onRemoved.addListener(forgetPopup);
}
let {tabId} = details;
- 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
{
« no previous file with comments | « lib/devtools.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld