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: Created April 19, 2017, 4:33 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
« lib/devtools.js ('K') | « 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,26 +20,26 @@
"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);
+let loadingPopups = new Map();
function hasLoadingPopups()
{
- return Object.keys(loadingPopups).length > 0;
+ return loadingPopups.size > 0;
}
function forgetPopup(tabId)
{
- delete loadingPopups[tabId];
+ loadingPopups.delete(tabId);
if (!hasLoadingPopups())
{
chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged);
chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged);
chrome.webNavigation.onCompleted.removeListener(onCompleted);
chrome.tabs.onRemoved.removeListener(forgetPopup);
}
@@ -73,17 +73,17 @@
}
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);
}
}
@@ -105,21 +105,24 @@
}
);
chrome.webNavigation.onCommitted.addListener(onPopupURLChanged);
chrome.webNavigation.onCompleted.addListener(onCompleted);
chrome.tabs.onRemoved.addListener(forgetPopup);
}
let {tabId} = details;
- let popup = loadingPopups[tabId] = {
- url: details.url,
- sourcePage: new ext.Page({id: details.sourceTabId}),
- sourceFrame: null
- };
+
+ let popup = Object.create(null);
Sebastian Noack 2017/04/29 22:46:32 As mentioned before in this review, please don't c
Manish Jethani 2017/05/04 14:47:34 Done.
+ popup.url = details.url;
+ popup.sourcePage = new ext.Page({id: details.sourceTabId});
+ popup.sourceFrame = null;
+
+ loadingPopups.set(tabId, popup);
+
let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
if (checkWhitelisted(popup.sourcePage, frame))
{
forgetPopup(tabId);
}
else
{
« lib/devtools.js ('K') | « lib/devtools.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld