| 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-present eyeo GmbH | 3  * Copyright (C) 2006-present 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("../adblockpluscore/lib/matcher"); | 22 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); | 
| 23 const {BlockingFilter, | 23 const {BlockingFilter, | 
| 24        RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); | 24        RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); | 
| 25 const {isThirdParty} = require("../adblockpluscore/lib/domain"); |  | 
| 26 const {extractHostFromFrame} = require("./url"); | 25 const {extractHostFromFrame} = require("./url"); | 
| 27 const {checkWhitelisted} = require("./whitelisting"); | 26 const {checkWhitelisted} = require("./whitelisting"); | 
| 28 const {logRequest} = require("./hitLogger"); | 27 const {logRequest} = require("./hitLogger"); | 
| 29 | 28 | 
| 30 let loadingPopups = new Map(); | 29 let loadingPopups = new Map(); | 
| 31 | 30 | 
| 32 function forgetPopup(tabId) | 31 function forgetPopup(tabId) | 
| 33 { | 32 { | 
| 34   loadingPopups.delete(tabId); | 33   loadingPopups.delete(tabId); | 
| 35 | 34 | 
| 36   if (loadingPopups.size == 0) | 35   if (loadingPopups.size == 0) | 
| 37   { | 36   { | 
| 38     browser.webRequest.onBeforeRequest.removeListener(onPopupURLChanged); | 37     browser.webRequest.onBeforeRequest.removeListener(onPopupURLChanged); | 
| 39     browser.webNavigation.onCommitted.removeListener(onPopupURLChanged); | 38     browser.webNavigation.onCommitted.removeListener(onPopupURLChanged); | 
| 40     browser.webNavigation.onCompleted.removeListener(onCompleted); | 39     browser.webNavigation.onCompleted.removeListener(onCompleted); | 
| 41     browser.tabs.onRemoved.removeListener(forgetPopup); | 40     browser.tabs.onRemoved.removeListener(forgetPopup); | 
| 42   } | 41   } | 
| 43 } | 42 } | 
| 44 | 43 | 
| 45 function checkPotentialPopup(tabId, popup) | 44 function checkPotentialPopup(tabId, popup) | 
| 46 { | 45 { | 
| 47   let url = popup.url || "about:blank"; | 46   let url = popup.url || "about:blank"; | 
| 48   let documentHost = extractHostFromFrame(popup.sourceFrame); | 47   let documentHost = extractHostFromFrame(popup.sourceFrame); | 
| 49   let thirdParty = isThirdParty(new URL(url), documentHost); |  | 
| 50 | 48 | 
| 51   let specificOnly = !!checkWhitelisted( | 49   let specificOnly = !!checkWhitelisted( | 
| 52     popup.sourcePage, popup.sourceFrame, null, | 50     popup.sourcePage, popup.sourceFrame, null, | 
| 53     RegExpFilter.typeMap.GENERICBLOCK | 51     RegExpFilter.typeMap.GENERICBLOCK | 
| 54   ); | 52   ); | 
| 55 | 53 | 
| 56   let filter = defaultMatcher.matchesAny( | 54   let filter = defaultMatcher.matchesAny( | 
| 57     url, RegExpFilter.typeMap.POPUP, | 55     url, RegExpFilter.typeMap.POPUP, | 
| 58     documentHost, thirdParty, null, specificOnly | 56     documentHost, null, specificOnly | 
| 59   ); | 57   ); | 
| 60 | 58 | 
| 61   if (filter instanceof BlockingFilter) | 59   if (filter instanceof BlockingFilter) | 
| 62     browser.tabs.remove(tabId); | 60     browser.tabs.remove(tabId); | 
| 63 | 61 | 
| 64   logRequest( | 62   logRequest( | 
| 65     [popup.sourcePage.id], | 63     [popup.sourcePage.id], | 
| 66     {url, type: "POPUP", docDomain: documentHost, thirdParty, specificOnly}, | 64     {url, type: "POPUP", docDomain: documentHost, specificOnly}, | 
| 67     filter | 65     filter | 
| 68   ); | 66   ); | 
| 69 } | 67 } | 
| 70 | 68 | 
| 71 function onPopupURLChanged(details) | 69 function onPopupURLChanged(details) | 
| 72 { | 70 { | 
| 73   // Ignore frames inside the popup window. | 71   // Ignore frames inside the popup window. | 
| 74   if (details.frameId != 0) | 72   if (details.frameId != 0) | 
| 75     return; | 73     return; | 
| 76 | 74 | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 124     { | 122     { | 
| 125       forgetPopup(details.tabId); | 123       forgetPopup(details.tabId); | 
| 126     } | 124     } | 
| 127     else | 125     else | 
| 128     { | 126     { | 
| 129       popup.sourceFrame = frame; | 127       popup.sourceFrame = frame; | 
| 130       checkPotentialPopup(details.tabId, popup); | 128       checkPotentialPopup(details.tabId, popup); | 
| 131     } | 129     } | 
| 132   }); | 130   }); | 
| 133 } | 131 } | 
| OLD | NEW | 
|---|