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

Side by Side Diff: lib/popupBlocker.js

Issue 29452181: Noissue - Merge current tip to Edge bookmark (Closed)
Patch Set: Created May 30, 2017, 3:49 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/notificationHelper.js ('k') | lib/prefs.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 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} = 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 = Object.create(null); 28 let loadingPopups = new Map();
29
30 function hasLoadingPopups()
31 {
32 return Object.keys(loadingPopups).length > 0;
33 }
34 29
35 function forgetPopup(tabId) 30 function forgetPopup(tabId)
36 { 31 {
37 delete loadingPopups[tabId]; 32 loadingPopups.delete(tabId);
38 33
39 if (!hasLoadingPopups()) 34 if (loadingPopups.size == 0)
40 { 35 {
41 chrome.webRequest.onBeforeRequest.removeListener(onBeforeRequest); 36 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged);
37 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged);
42 chrome.webNavigation.onCompleted.removeListener(onCompleted); 38 chrome.webNavigation.onCompleted.removeListener(onCompleted);
43 chrome.tabs.onRemoved.removeListener(forgetPopup); 39 chrome.tabs.onRemoved.removeListener(forgetPopup);
44 } 40 }
45 } 41 }
46 42
47 function checkPotentialPopup(tabId, popup) 43 function checkPotentialPopup(tabId, popup)
48 { 44 {
49 let urlObj = new URL(popup.url || "about:blank"); 45 let urlObj = new URL(popup.url || "about:blank");
50 let urlString = stringifyURL(urlObj); 46 let urlString = stringifyURL(urlObj);
51 let documentHost = extractHostFromFrame(popup.sourceFrame); 47 let documentHost = extractHostFromFrame(popup.sourceFrame);
(...skipping 12 matching lines...) Expand all
64 if (filter instanceof BlockingFilter) 60 if (filter instanceof BlockingFilter)
65 chrome.tabs.remove(tabId); 61 chrome.tabs.remove(tabId);
66 62
67 logRequest( 63 logRequest(
68 popup.sourcePage, urlString, "POPUP", 64 popup.sourcePage, urlString, "POPUP",
69 documentHost, thirdParty, null, 65 documentHost, thirdParty, null,
70 specificOnly, filter 66 specificOnly, filter
71 ); 67 );
72 } 68 }
73 69
74 function onBeforeRequest(details) 70 function onPopupURLChanged(details)
75 { 71 {
76 let popup = loadingPopups[details.tabId]; 72 // Ignore frames inside the popup window.
73 if (details.frameId != 0)
74 return;
75
76 let popup = loadingPopups.get(details.tabId);
77 if (popup) 77 if (popup)
78 { 78 {
79 popup.url = details.url; 79 popup.url = details.url;
80 if (popup.sourceFrame) 80 if (popup.sourceFrame)
81 checkPotentialPopup(details.tabId, popup); 81 checkPotentialPopup(details.tabId, popup);
82 } 82 }
83 } 83 }
84 84
85 function onCompleted(details) 85 function onCompleted(details)
86 { 86 {
87 if (details.frameId == 0 && details.url != "about:blank") 87 if (details.frameId == 0 && details.url != "about:blank")
88 forgetPopup(details.tabId); 88 forgetPopup(details.tabId);
89 } 89 }
90 90
91 chrome.webNavigation.onCreatedNavigationTarget.addListener(details => 91 chrome.webNavigation.onCreatedNavigationTarget.addListener(details =>
92 { 92 {
93 if (!hasLoadingPopups()) 93 if (loadingPopups.size == 0)
94 { 94 {
95 chrome.webRequest.onBeforeRequest.addListener( 95 chrome.webRequest.onBeforeRequest.addListener(
96 onBeforeRequest, 96 onPopupURLChanged,
97 { 97 {
98 urls: ["<all_urls>"], 98 urls: ["http://*/*", "https://*/*"],
99 types: ["main_frame"] 99 types: ["main_frame"]
100 } 100 }
101 ); 101 );
102 102 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged);
103 chrome.webNavigation.onCompleted.addListener(onCompleted); 103 chrome.webNavigation.onCompleted.addListener(onCompleted);
104 chrome.tabs.onRemoved.addListener(forgetPopup); 104 chrome.tabs.onRemoved.addListener(forgetPopup);
105 } 105 }
106 106
107 let tabId = details.tabId; 107 let popup = {
108 let popup = loadingPopups[tabId] = {
109 url: details.url, 108 url: details.url,
110 sourcePage: new ext.Page({id: details.sourceTabId}), 109 sourcePage: new ext.Page({id: details.sourceTabId}),
111 sourceFrame: null 110 sourceFrame: null
112 }; 111 };
112
113 loadingPopups.set(details.tabId, popup);
114
113 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); 115 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
114 116
115 if (checkWhitelisted(popup.sourcePage, frame)) 117 if (checkWhitelisted(popup.sourcePage, frame))
116 { 118 {
117 forgetPopup(tabId); 119 forgetPopup(details.tabId);
118 } 120 }
119 else 121 else
120 { 122 {
121 popup.sourceFrame = frame; 123 popup.sourceFrame = frame;
122 checkPotentialPopup(tabId, popup); 124 checkPotentialPopup(details.tabId, popup);
123 } 125 }
124 }); 126 });
OLDNEW
« 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