LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of the Adblock Plus extension, | 2 * This file is part of the Adblock Plus extension, |
3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 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 var tabsLoading = {}; | 18 var tabsLoading = {}; |
19 | 19 |
20 chrome.tabs.onCreated.addListener(function(tab) | 20 chrome.webNavigation.onCreatedNavigationTarget.addListener(function(details) |
21 { | 21 { |
22 if (!("openerTabId" in tab)) | 22 if (isFrameWhitelisted(details.sourceTabId, details.sourceFrameId)) |
23 { | |
24 // This isn't a pop-up | |
25 return; | |
26 } | |
27 | |
28 if (isFrameWhitelisted(tab.openerTabId, 0)) | |
29 return; | 23 return; |
30 | 24 |
31 var openerUrl = getFrameUrl(tab.openerTabId, 0); | 25 var openerUrl = getFrameUrl(details.sourceTabId, details.sourceFrameId); |
32 if (!openerUrl) | 26 if (!openerUrl) |
33 { | 27 { |
34 // We don't know the opener tab | 28 // We don't know the opener tab |
35 return; | 29 return; |
36 } | 30 } |
37 tabsLoading[tab.id] = openerUrl; | 31 tabsLoading[details.tabId] = openerUrl; |
38 | 32 |
39 checkPotentialPopup(tab, openerUrl); | 33 checkPotentialPopup(details.tabId, details.url, openerUrl); |
40 }); | 34 }); |
41 | 35 |
42 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) | 36 chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) |
43 { | 37 { |
44 if (!(tabId in tabsLoading)) | 38 if (!(tabId in tabsLoading)) |
45 { | 39 { |
46 // Not a pop-up we've previously seen | 40 // Not a pop-up we've previously seen |
47 return; | 41 return; |
48 } | 42 } |
49 | 43 |
50 if ("url" in changeInfo) | 44 if ("url" in changeInfo) |
51 checkPotentialPopup(tab, tabsLoading[tabId]); | 45 checkPotentialPopup(tabId, tab.url, tabsLoading[tabId]); |
52 | 46 |
53 if ("status" in changeInfo && changeInfo.status == "complete") | 47 if ("status" in changeInfo && changeInfo.status == "complete") |
54 delete tabsLoading[tabId]; | 48 delete tabsLoading[tabId]; |
55 }); | 49 }); |
56 | 50 |
57 | 51 |
58 function checkPotentialPopup(tab) | 52 function checkPotentialPopup(tabId, url, opener) |
59 { | 53 { |
60 var requestHost = extractHostFromURL(tab.url); | 54 var requestHost = extractHostFromURL(url); |
61 var documentHost = extractHostFromURL(tabsLoading[tab.id]); | 55 var documentHost = extractHostFromURL(opener); |
62 var thirdParty = isThirdParty(requestHost, documentHost); | 56 var thirdParty = isThirdParty(requestHost, documentHost); |
63 var filter = defaultMatcher.matchesAny(tab.url || "about:blank", "POPUP", docu
mentHost, thirdParty); | 57 var filter = defaultMatcher.matchesAny(url || "about:blank", "POPUP", document
Host, thirdParty); |
64 if (filter instanceof BlockingFilter) | 58 if (filter instanceof BlockingFilter) |
65 chrome.tabs.remove(tab.id); | 59 chrome.tabs.remove(tabId); |
66 } | 60 } |
LEFT | RIGHT |