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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 if (require("info").platform == "chromium") | 18 /** @module popupBlocker */ |
19 { | |
20 var logRequest = require("devtools").logRequest; | |
21 var tabsLoading = {}; | |
22 | 19 |
23 chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details) | 20 "use strict"; |
24 { | |
25 var sourcePage = new ext.Page({id: details.sourceTabId}); | |
26 var sourceFrame = ext.getFrame(details.sourceTabId, details.sourceFrameId); | |
27 | 21 |
28 if (checkWhitelisted(sourcePage, sourceFrame)) | 22 let {defaultMatcher} = require("matcher"); |
29 return; | 23 let {BlockingFilter} = require("filterClasses"); |
| 24 let {stringifyURL, isThirdParty, extractHostFromFrame} = require("url"); |
| 25 let {checkWhitelisted} = require("whitelisting"); |
| 26 let {logRequest} = require("devtools"); |
30 | 27 |
31 var documentHost = extractHostFromFrame(sourceFrame); | 28 let tabsLoading = {}; |
32 if (!documentHost) | |
33 return; | |
34 | |
35 var specificOnly = checkWhitelisted(sourcePage, sourceFrame, | |
36 RegExpFilter.typeMap.GENERICBLOCK); | |
37 | |
38 tabsLoading[details.tabId] = { | |
39 page: sourcePage, | |
40 documentHost: documentHost, | |
41 specificOnly: specificOnly | |
42 }; | |
43 checkPotentialPopup(details.tabId, details.url, sourcePage, documentHost, sp
ecificOnly); | |
44 }); | |
45 | |
46 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) | |
47 { | |
48 if (!(tabId in tabsLoading)) | |
49 { | |
50 // Not a pop-up we've previously seen | |
51 return; | |
52 } | |
53 | |
54 if ("url" in changeInfo) | |
55 { | |
56 var source = tabsLoading[tabId]; | |
57 checkPotentialPopup(tabId, tab.url, source.page, | |
58 source.documentHost, | |
59 source.specificOnly); | |
60 } | |
61 | |
62 if ("status" in changeInfo && changeInfo.status == "complete" && tab.url !=
"about:blank") | |
63 delete tabsLoading[tabId]; | |
64 }); | |
65 } | |
66 | 29 |
67 function checkPotentialPopup(tabId, url, sourcePage, documentHost, specificOnly) | 30 function checkPotentialPopup(tabId, url, sourcePage, documentHost, specificOnly) |
68 { | 31 { |
69 var urlObj = new URL(url || "about:blank"); | 32 let urlObj = new URL(url || "about:blank"); |
70 var urlString = stringifyURL(urlObj); | 33 let urlString = stringifyURL(urlObj); |
71 var thirdParty = isThirdParty(urlObj, documentHost); | 34 let thirdParty = isThirdParty(urlObj, documentHost); |
72 | 35 |
73 var filter = defaultMatcher.matchesAny( | 36 let filter = defaultMatcher.matchesAny( |
74 urlString, RegExpFilter.typeMap.POPUP, | 37 urlString, RegExpFilter.typeMap.POPUP, |
75 documentHost, thirdParty, null, specificOnly | 38 documentHost, thirdParty, null, specificOnly |
76 ); | 39 ); |
77 | 40 |
78 if (filter instanceof BlockingFilter) | 41 if (filter instanceof BlockingFilter) |
79 chrome.tabs.remove(tabId); | 42 chrome.tabs.remove(tabId); |
80 | 43 |
81 logRequest( | 44 logRequest( |
82 sourcePage, urlString, "POPUP", documentHost, | 45 sourcePage, urlString, "POPUP", documentHost, |
83 thirdParty, null, specificOnly, filter | 46 thirdParty, null, specificOnly, filter |
84 ); | 47 ); |
85 } | 48 } |
| 49 |
| 50 chrome.webNavigation.onCreatedNavigationTarget.addListener(details => |
| 51 { |
| 52 let sourcePage = new ext.Page({id: details.sourceTabId}); |
| 53 let sourceFrame = ext.getFrame(details.sourceTabId, details.sourceFrameId); |
| 54 |
| 55 if (checkWhitelisted(sourcePage, sourceFrame)) |
| 56 return; |
| 57 |
| 58 let documentHost = extractHostFromFrame(sourceFrame); |
| 59 if (!documentHost) |
| 60 return; |
| 61 |
| 62 let specificOnly = checkWhitelisted(sourcePage, sourceFrame, |
| 63 RegExpFilter.typeMap.GENERICBLOCK); |
| 64 |
| 65 tabsLoading[details.tabId] = { |
| 66 page: sourcePage, |
| 67 documentHost: documentHost, |
| 68 specificOnly: specificOnly |
| 69 }; |
| 70 checkPotentialPopup(details.tabId, details.url, sourcePage, documentHost, spec
ificOnly); |
| 71 }); |
| 72 |
| 73 chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => |
| 74 { |
| 75 if (!(tabId in tabsLoading)) |
| 76 return; |
| 77 |
| 78 if ("url" in changeInfo) |
| 79 { |
| 80 let source = tabsLoading[tabId]; |
| 81 checkPotentialPopup(tabId, tab.url, source.page, |
| 82 source.documentHost, |
| 83 source.specificOnly); |
| 84 } |
| 85 |
| 86 if ("status" in changeInfo && changeInfo.status == "complete" && tab.url != "a
bout:blank") |
| 87 delete tabsLoading[tabId]; |
| 88 }); |
OLD | NEW |