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

Delta Between Two Patch Sets: lib/popupBlocker.js

Issue 29374674: Issue 4864 - Start using ESLint for adblockpluschrome (Closed)
Left Patch Set: Created Feb. 7, 2017, 4:49 p.m.
Right Patch Set: Use .includes again Created March 31, 2017, 8:37 a.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/notificationHelper.js ('k') | lib/prefs.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-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 *
(...skipping 17 matching lines...) Expand all
31 { 31 {
32 return Object.keys(loadingPopups).length > 0; 32 return Object.keys(loadingPopups).length > 0;
33 } 33 }
34 34
35 function forgetPopup(tabId) 35 function forgetPopup(tabId)
36 { 36 {
37 delete loadingPopups[tabId]; 37 delete loadingPopups[tabId];
38 38
39 if (!hasLoadingPopups()) 39 if (!hasLoadingPopups())
40 { 40 {
41 chrome.webRequest.onBeforeRequest.removeListener(onBeforeRequest); 41 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged);
42 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged);
42 chrome.webNavigation.onCompleted.removeListener(onCompleted); 43 chrome.webNavigation.onCompleted.removeListener(onCompleted);
43 chrome.tabs.onRemoved.removeListener(forgetPopup); 44 chrome.tabs.onRemoved.removeListener(forgetPopup);
44 } 45 }
45 } 46 }
46 47
47 function checkPotentialPopup(tabId, popup) 48 function checkPotentialPopup(tabId, popup)
48 { 49 {
49 let urlObj = new URL(popup.url || "about:blank"); 50 let urlObj = new URL(popup.url || "about:blank");
50 let urlString = stringifyURL(urlObj); 51 let urlString = stringifyURL(urlObj);
51 let documentHost = extractHostFromFrame(popup.sourceFrame); 52 let documentHost = extractHostFromFrame(popup.sourceFrame);
(...skipping 12 matching lines...) Expand all
64 if (filter instanceof BlockingFilter) 65 if (filter instanceof BlockingFilter)
65 chrome.tabs.remove(tabId); 66 chrome.tabs.remove(tabId);
66 67
67 logRequest( 68 logRequest(
68 popup.sourcePage, urlString, "POPUP", 69 popup.sourcePage, urlString, "POPUP",
69 documentHost, thirdParty, null, 70 documentHost, thirdParty, null,
70 specificOnly, filter 71 specificOnly, filter
71 ); 72 );
72 } 73 }
73 74
74 function onBeforeRequest(details) 75 function onPopupURLChanged(details)
75 { 76 {
77 // Ignore frames inside the popup window.
78 if (details.frameId != 0)
79 return;
80
76 let popup = loadingPopups[details.tabId]; 81 let popup = loadingPopups[details.tabId];
77 if (popup) 82 if (popup)
78 { 83 {
79 popup.url = details.url; 84 popup.url = details.url;
80 if (popup.sourceFrame) 85 if (popup.sourceFrame)
81 checkPotentialPopup(details.tabId, popup); 86 checkPotentialPopup(details.tabId, popup);
82 } 87 }
83 } 88 }
84 89
85 function onCompleted(details) 90 function onCompleted(details)
86 { 91 {
87 if (details.frameId == 0 && details.url != "about:blank") 92 if (details.frameId == 0 && details.url != "about:blank")
88 forgetPopup(details.tabId); 93 forgetPopup(details.tabId);
89 } 94 }
90 95
91 chrome.webNavigation.onCreatedNavigationTarget.addListener(details => 96 chrome.webNavigation.onCreatedNavigationTarget.addListener(details =>
92 { 97 {
93 if (!hasLoadingPopups()) 98 if (!hasLoadingPopups())
94 { 99 {
95 chrome.webRequest.onBeforeRequest.addListener( 100 chrome.webRequest.onBeforeRequest.addListener(
96 onBeforeRequest, 101 onPopupURLChanged,
97 { 102 {
98 urls: ["<all_urls>"], 103 urls: ["<all_urls>"],
99 types: ["main_frame"] 104 types: ["main_frame"]
100 } 105 }
101 ); 106 );
102 107 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged);
103 chrome.webNavigation.onCompleted.addListener(onCompleted); 108 chrome.webNavigation.onCompleted.addListener(onCompleted);
104 chrome.tabs.onRemoved.addListener(forgetPopup); 109 chrome.tabs.onRemoved.addListener(forgetPopup);
105 } 110 }
106 111
107 let {tabId} = details; 112 let {tabId} = details;
108 let popup = loadingPopups[tabId] = { 113 let popup = loadingPopups[tabId] = {
109 url: details.url, 114 url: details.url,
110 sourcePage: new ext.Page({id: details.sourceTabId}), 115 sourcePage: new ext.Page({id: details.sourceTabId}),
111 sourceFrame: null 116 sourceFrame: null
112 }; 117 };
113 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); 118 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId);
114 119
115 if (checkWhitelisted(popup.sourcePage, frame)) 120 if (checkWhitelisted(popup.sourcePage, frame))
116 { 121 {
117 forgetPopup(tabId); 122 forgetPopup(tabId);
118 } 123 }
119 else 124 else
120 { 125 {
121 popup.sourceFrame = frame; 126 popup.sourceFrame = frame;
122 checkPotentialPopup(tabId, popup); 127 checkPotentialPopup(tabId, popup);
123 } 128 }
124 }); 129 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld