| OLD | NEW | 
|---|
| 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 = 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(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 21 matching lines...) Expand all  Loading... | 
| 71     specificOnly, filter | 66     specificOnly, filter | 
| 72   ); | 67   ); | 
| 73 } | 68 } | 
| 74 | 69 | 
| 75 function onPopupURLChanged(details) | 70 function onPopupURLChanged(details) | 
| 76 { | 71 { | 
| 77   // Ignore frames inside the popup window. | 72   // Ignore frames inside the popup window. | 
| 78   if (details.frameId != 0) | 73   if (details.frameId != 0) | 
| 79     return; | 74     return; | 
| 80 | 75 | 
| 81   let popup = loadingPopups[details.tabId]; | 76   let popup = loadingPopups.get(details.tabId); | 
| 82   if (popup) | 77   if (popup) | 
| 83   { | 78   { | 
| 84     popup.url = details.url; | 79     popup.url = details.url; | 
| 85     if (popup.sourceFrame) | 80     if (popup.sourceFrame) | 
| 86       checkPotentialPopup(details.tabId, popup); | 81       checkPotentialPopup(details.tabId, popup); | 
| 87   } | 82   } | 
| 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: ["http://*/*", "https://*/*"], | 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 = { | 
| 113   let popup = loadingPopups[tabId] = { |  | 
| 114     url: details.url, | 108     url: details.url, | 
| 115     sourcePage: new ext.Page({id: details.sourceTabId}), | 109     sourcePage: new ext.Page({id: details.sourceTabId}), | 
| 116     sourceFrame: null | 110     sourceFrame: null | 
| 117   }; | 111   }; | 
|  | 112 | 
|  | 113   loadingPopups.set(details.tabId, popup); | 
|  | 114 | 
| 118   let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); | 115   let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); | 
| 119 | 116 | 
| 120   if (checkWhitelisted(popup.sourcePage, frame)) | 117   if (checkWhitelisted(popup.sourcePage, frame)) | 
| 121   { | 118   { | 
| 122     forgetPopup(tabId); | 119     forgetPopup(details.tabId); | 
| 123   } | 120   } | 
| 124   else | 121   else | 
| 125   { | 122   { | 
| 126     popup.sourceFrame = frame; | 123     popup.sourceFrame = frame; | 
| 127     checkPotentialPopup(tabId, popup); | 124     checkPotentialPopup(details.tabId, popup); | 
| 128   } | 125   } | 
| 129 }); | 126 }); | 
| OLD | NEW | 
|---|