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

Delta Between Two Patch Sets: lib/popupBlocker.js

Issue 29417597: Issue 5161 - Use maps and sets where appropriate (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Left Patch Set: Created April 19, 2017, 4:33 p.m.
Right Patch Set: Minor unrelated changes Created May 21, 2017, 10:15 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/devtools.js ('k') | lib/whitelisting.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module popupBlocker */ 18 /** @module popupBlocker */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {defaultMatcher} = require("matcher"); 22 const {defaultMatcher} = require("matcher");
23 const {BlockingFilter, RegExpFilter} = require("filterClasses"); 23 const {BlockingFilter, RegExpFilter} = require("filterClasses");
24 const {stringifyURL, isThirdParty, extractHostFromFrame} = require("url"); 24 const {stringifyURL, isThirdParty, extractHostFromFrame} = require("url");
25 const {checkWhitelisted} = require("whitelisting"); 25 const {checkWhitelisted} = require("whitelisting");
26 const {logRequest} = require("devtools"); 26 const {logRequest} = require("devtools");
27 27
28 let loadingPopups = new Map(); 28 let loadingPopups = new Map();
29 29
30 function hasLoadingPopups()
31 {
32 return loadingPopups.size > 0;
33 }
34
35 function forgetPopup(tabId) 30 function forgetPopup(tabId)
36 { 31 {
37 loadingPopups.delete(tabId); 32 loadingPopups.delete(tabId);
38 33
39 if (!hasLoadingPopups()) 34 if (loadingPopups.size == 0)
40 { 35 {
41 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged); 36 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged);
42 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged); 37 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged);
43 chrome.webNavigation.onCompleted.removeListener(onCompleted); 38 chrome.webNavigation.onCompleted.removeListener(onCompleted);
44 chrome.tabs.onRemoved.removeListener(forgetPopup); 39 chrome.tabs.onRemoved.removeListener(forgetPopup);
45 } 40 }
46 } 41 }
47 42
48 function checkPotentialPopup(tabId, popup) 43 function checkPotentialPopup(tabId, popup)
49 { 44 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 83 }
89 84
90 function onCompleted(details) 85 function onCompleted(details)
91 { 86 {
92 if (details.frameId == 0 && details.url != "about:blank") 87 if (details.frameId == 0 && details.url != "about:blank")
93 forgetPopup(details.tabId); 88 forgetPopup(details.tabId);
94 } 89 }
95 90
96 chrome.webNavigation.onCreatedNavigationTarget.addListener(details => 91 chrome.webNavigation.onCreatedNavigationTarget.addListener(details =>
97 { 92 {
98 if (!hasLoadingPopups()) 93 if (loadingPopups.size == 0)
99 { 94 {
100 chrome.webRequest.onBeforeRequest.addListener( 95 chrome.webRequest.onBeforeRequest.addListener(
101 onPopupURLChanged, 96 onPopupURLChanged,
102 { 97 {
103 urls: ["<all_urls>"], 98 urls: ["http://*/*", "https://*/*"],
104 types: ["main_frame"] 99 types: ["main_frame"]
105 } 100 }
106 ); 101 );
107 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged); 102 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged);
108 chrome.webNavigation.onCompleted.addListener(onCompleted); 103 chrome.webNavigation.onCompleted.addListener(onCompleted);
109 chrome.tabs.onRemoved.addListener(forgetPopup); 104 chrome.tabs.onRemoved.addListener(forgetPopup);
110 } 105 }
111 106
112 let {tabId} = details; 107 let popup = {
108 url: details.url,
109 sourcePage: new ext.Page({id: details.sourceTabId}),
110 sourceFrame: null
111 };
113 112
114 let popup = Object.create(null); 113 loadingPopups.set(details.tabId, popup);
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.
115 popup.url = details.url;
116 popup.sourcePage = new ext.Page({id: details.sourceTabId});
117 popup.sourceFrame = null;
118
119 loadingPopups.set(tabId, popup);
120 114
121 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); 115 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
122 116
123 if (checkWhitelisted(popup.sourcePage, frame)) 117 if (checkWhitelisted(popup.sourcePage, frame))
124 { 118 {
125 forgetPopup(tabId); 119 forgetPopup(details.tabId);
126 } 120 }
127 else 121 else
128 { 122 {
129 popup.sourceFrame = frame; 123 popup.sourceFrame = frame;
130 checkPotentialPopup(tabId, popup); 124 checkPotentialPopup(details.tabId, popup);
131 } 125 }
132 }); 126 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld