| Left: | ||
| Right: |
| 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 | 29 |
| 30 function hasLoadingPopups() | 30 function hasLoadingPopups() |
| 31 { | 31 { |
| 32 return Object.keys(loadingPopups).length > 0; | 32 return loadingPopups.size > 0; |
| 33 } | 33 } |
| 34 | 34 |
| 35 function forgetPopup(tabId) | 35 function forgetPopup(tabId) |
| 36 { | 36 { |
| 37 delete loadingPopups[tabId]; | 37 loadingPopups.delete(tabId); |
| 38 | 38 |
| 39 if (!hasLoadingPopups()) | 39 if (!hasLoadingPopups()) |
| 40 { | 40 { |
| 41 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged); | 41 chrome.webRequest.onBeforeRequest.removeListener(onPopupURLChanged); |
| 42 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged); | 42 chrome.webNavigation.onCommitted.removeListener(onPopupURLChanged); |
| 43 chrome.webNavigation.onCompleted.removeListener(onCompleted); | 43 chrome.webNavigation.onCompleted.removeListener(onCompleted); |
| 44 chrome.tabs.onRemoved.removeListener(forgetPopup); | 44 chrome.tabs.onRemoved.removeListener(forgetPopup); |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 71 specificOnly, filter | 71 specificOnly, filter |
| 72 ); | 72 ); |
| 73 } | 73 } |
| 74 | 74 |
| 75 function onPopupURLChanged(details) | 75 function onPopupURLChanged(details) |
| 76 { | 76 { |
| 77 // Ignore frames inside the popup window. | 77 // Ignore frames inside the popup window. |
| 78 if (details.frameId != 0) | 78 if (details.frameId != 0) |
| 79 return; | 79 return; |
| 80 | 80 |
| 81 let popup = loadingPopups[details.tabId]; | 81 let popup = loadingPopups.get(details.tabId); |
| 82 if (popup) | 82 if (popup) |
| 83 { | 83 { |
| 84 popup.url = details.url; | 84 popup.url = details.url; |
| 85 if (popup.sourceFrame) | 85 if (popup.sourceFrame) |
| 86 checkPotentialPopup(details.tabId, popup); | 86 checkPotentialPopup(details.tabId, popup); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 function onCompleted(details) | 90 function onCompleted(details) |
| 91 { | 91 { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 103 urls: ["<all_urls>"], | 103 urls: ["<all_urls>"], |
| 104 types: ["main_frame"] | 104 types: ["main_frame"] |
| 105 } | 105 } |
| 106 ); | 106 ); |
| 107 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged); | 107 chrome.webNavigation.onCommitted.addListener(onPopupURLChanged); |
| 108 chrome.webNavigation.onCompleted.addListener(onCompleted); | 108 chrome.webNavigation.onCompleted.addListener(onCompleted); |
| 109 chrome.tabs.onRemoved.addListener(forgetPopup); | 109 chrome.tabs.onRemoved.addListener(forgetPopup); |
| 110 } | 110 } |
| 111 | 111 |
| 112 let {tabId} = details; | 112 let {tabId} = details; |
| 113 let popup = loadingPopups[tabId] = { | 113 |
| 114 url: details.url, | 114 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.
| |
| 115 sourcePage: new ext.Page({id: details.sourceTabId}), | 115 popup.url = details.url; |
| 116 sourceFrame: null | 116 popup.sourcePage = new ext.Page({id: details.sourceTabId}); |
| 117 }; | 117 popup.sourceFrame = null; |
| 118 | |
| 119 loadingPopups.set(tabId, popup); | |
| 120 | |
| 118 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); | 121 let frame = ext.getFrame(details.sourceTabId, details.sourceFrameId); |
| 119 | 122 |
| 120 if (checkWhitelisted(popup.sourcePage, frame)) | 123 if (checkWhitelisted(popup.sourcePage, frame)) |
| 121 { | 124 { |
| 122 forgetPopup(tabId); | 125 forgetPopup(tabId); |
| 123 } | 126 } |
| 124 else | 127 else |
| 125 { | 128 { |
| 126 popup.sourceFrame = frame; | 129 popup.sourceFrame = frame; |
| 127 checkPotentialPopup(tabId, popup); | 130 checkPotentialPopup(tabId, popup); |
| 128 } | 131 } |
| 129 }); | 132 }); |
| OLD | NEW |