Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 FilterNotifier = require("filterNotifier").FilterNotifier; | |
19 | |
18 chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["http://* /*", "https://*/*"]}, ["blocking"]); | 20 chrome.webRequest.onBeforeRequest.addListener(onBeforeRequest, {urls: ["http://* /*", "https://*/*"]}, ["blocking"]); |
19 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["http ://*/*", "https://*/*"]}, ["responseHeaders"]); | 21 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["http ://*/*", "https://*/*"]}, ["responseHeaders"]); |
20 chrome.tabs.onRemoved.addListener(forgetTab); | 22 chrome.tabs.onRemoved.addListener(forgetTab); |
21 | 23 |
22 var onFilterChangeTimeout = null; | 24 var onFilterChangeTimeout = null; |
23 function onFilterChange() | 25 function onFilterChange() |
24 { | 26 { |
25 onFilterChangeTimeout = null; | 27 onFilterChangeTimeout = null; |
26 chrome.webRequest.handlerBehaviorChanged(); | 28 chrome.webRequest.handlerBehaviorChanged(); |
27 } | 29 } |
28 | 30 |
29 var importantNotifications = { | 31 var importantNotifications = { |
30 'filter.added': true, | 32 'filter.added': true, |
31 'filter.removed': true, | 33 'filter.removed': true, |
32 'filter.disabled': true, | 34 'filter.disabled': true, |
33 'subscription.added': true, | 35 'subscription.added': true, |
34 'subscription.removed': true, | 36 'subscription.removed': true, |
35 'subscription.disabled': true, | 37 'subscription.disabled': true, |
36 'subscription.updated': true, | 38 'subscription.updated': true, |
37 'load': true | 39 'load': true |
38 }; | 40 }; |
39 | 41 |
40 require("filterNotifier").FilterNotifier.addListener(function(action) | 42 FilterNotifier.addListener(function(action) |
41 { | 43 { |
42 if (action in importantNotifications) | 44 if (action in importantNotifications) |
43 { | 45 { |
44 // Execute delayed to prevent multiple executions in a quick succession | 46 // Execute delayed to prevent multiple executions in a quick succession |
45 if (onFilterChangeTimeout != null) | 47 if (onFilterChangeTimeout != null) |
46 window.clearTimeout(onFilterChangeTimeout); | 48 window.clearTimeout(onFilterChangeTimeout); |
47 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000); | 49 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000); |
48 } | 50 } |
49 }); | 51 }); |
50 | 52 |
(...skipping 12 matching lines...) Expand all Loading... | |
63 return {}; | 65 return {}; |
64 | 66 |
65 // Type names match Mozilla's with main_frame and sub_frame being the only exc eptions. | 67 // Type names match Mozilla's with main_frame and sub_frame being the only exc eptions. |
66 if (type == "sub_frame") | 68 if (type == "sub_frame") |
67 type = "SUBDOCUMENT"; | 69 type = "SUBDOCUMENT"; |
68 else | 70 else |
69 type = type.toUpperCase(); | 71 type = type.toUpperCase(); |
70 | 72 |
71 var frame = (type != "SUBDOCUMENT" ? details.frameId : details.parentFrameId); | 73 var frame = (type != "SUBDOCUMENT" ? details.frameId : details.parentFrameId); |
72 var filter = checkRequest(type, details.tabId, details.url, frame); | 74 var filter = checkRequest(type, details.tabId, details.url, frame); |
75 FilterNotifier.triggerListeners("document.stats", filter, details.tabId); | |
Wladimir Palant
2013/09/18 09:44:41
The usual notification is "filter.hitCount". This
Thomas Greiner
2013/09/19 09:42:29
I thought about it before but the arguments differ
Wladimir Palant
2013/09/19 10:56:22
I guess we can introduce an additional application
| |
73 if (filter instanceof BlockingFilter) | 76 if (filter instanceof BlockingFilter) |
74 return {cancel: true}; | 77 return {cancel: true}; |
75 else | 78 else |
76 return {}; | 79 return {}; |
77 } | 80 } |
78 | 81 |
79 function onHeadersReceived(details) | 82 function onHeadersReceived(details) |
80 { | 83 { |
81 if (details.tabId == -1) | 84 if (details.tabId == -1) |
82 return; | 85 return; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 parent = frameData.parent; | 193 parent = frameData.parent; |
191 parentData = getFrameData(tabId, parent); | 194 parentData = getFrameData(tabId, parent); |
192 | 195 |
193 var frameUrl = frameData.url; | 196 var frameUrl = frameData.url; |
194 var parentUrl = (parentData ? parentData.url : frameUrl); | 197 var parentUrl = (parentData ? parentData.url : frameUrl); |
195 if ("keyException" in frameData || isWhitelisted(frameUrl, parentUrl, type)) | 198 if ("keyException" in frameData || isWhitelisted(frameUrl, parentUrl, type)) |
196 return true; | 199 return true; |
197 } | 200 } |
198 return false; | 201 return false; |
199 } | 202 } |
OLD | NEW |