LEFT | RIGHT |
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 var onFilterChangeTimeout = null; | 20 var onFilterChangeTimeout = null; |
19 function onFilterChange() | 21 function onFilterChange() |
20 { | 22 { |
21 onFilterChangeTimeout = null; | 23 onFilterChangeTimeout = null; |
22 ext.webRequest.handlerBehaviorChanged(); | 24 ext.webRequest.handlerBehaviorChanged(); |
23 } | 25 } |
24 | 26 |
25 var importantNotifications = { | 27 var importantNotifications = { |
26 'filter.added': true, | 28 'filter.added': true, |
27 'filter.removed': true, | 29 'filter.removed': true, |
28 'filter.disabled': true, | 30 'filter.disabled': true, |
29 'subscription.added': true, | 31 'subscription.added': true, |
30 'subscription.removed': true, | 32 'subscription.removed': true, |
31 'subscription.disabled': true, | 33 'subscription.disabled': true, |
32 'subscription.updated': true, | 34 'subscription.updated': true, |
33 'load': true | 35 'load': true |
34 }; | 36 }; |
35 | 37 |
36 require("filterNotifier").FilterNotifier.addListener(function(action) | 38 FilterNotifier.addListener(function(action) |
37 { | 39 { |
38 if (action in importantNotifications) | 40 if (action in importantNotifications) |
39 { | 41 { |
40 // Execute delayed to prevent multiple executions in a quick succession | 42 // Execute delayed to prevent multiple executions in a quick succession |
41 if (onFilterChangeTimeout != null) | 43 if (onFilterChangeTimeout != null) |
42 window.clearTimeout(onFilterChangeTimeout); | 44 window.clearTimeout(onFilterChangeTimeout); |
43 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000); | 45 onFilterChangeTimeout = window.setTimeout(onFilterChange, 2000); |
44 } | 46 } |
45 }); | 47 }); |
46 | 48 |
47 var frames = new TabMap(); | 49 var frames = new TabMap(); |
48 | 50 |
49 function onBeforeRequest(url, type, tab, frameId, parentFrameId) | 51 function onBeforeRequest(url, type, tab, frameId, parentFrameId) |
50 { | 52 { |
51 if (!tab) | 53 if (!tab) |
52 return true; | 54 return true; |
53 | 55 |
54 // Assume that the first request belongs to the top frame. Chrome may give the | 56 // Assume that the first request belongs to the top frame. Chrome may give the |
55 // top frame the type "object" instead of "main_frame". | 57 // top frame the type "object" instead of "main_frame". |
56 // https://code.google.com/p/chromium/issues/detail?id=281711 | 58 // https://code.google.com/p/chromium/issues/detail?id=281711 |
57 if (frameId == 0 && !frames.has(tab) && type == "object") | 59 if (frameId == 0 && !frames.has(tab) && type == "object") |
58 type = "main_frame"; | 60 type = "main_frame"; |
59 | 61 |
60 if (type == "main_frame" || type == "sub_frame") { | 62 if (type == "main_frame" || type == "sub_frame") |
| 63 { |
61 recordFrame(tab, frameId, parentFrameId, url); | 64 recordFrame(tab, frameId, parentFrameId, url); |
62 | 65 |
63 if (type == "main_frame") | 66 if (type == "main_frame") |
64 return true; | 67 return true; |
65 | 68 |
66 type = "subdocument"; | 69 type = "subdocument"; |
67 frameId = parentFrameId; | 70 frameId = parentFrameId; |
68 } | 71 } |
69 | 72 |
70 return !(checkRequest(type.toUpperCase(), tab, url, frameId) instanceof Blocki
ngFilter); | 73 var filter = checkRequest(type.toUpperCase(), tab, url, frameId); |
| 74 FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, tab); |
| 75 return !(filter instanceof BlockingFilter); |
71 } | 76 } |
72 | 77 |
73 function recordFrame(tab, frameId, parentFrameId, url) | 78 function recordFrame(tab, frameId, parentFrameId, url) |
74 { | 79 { |
75 var framesOfTab = frames.get(tab); | 80 var framesOfTab = frames.get(tab); |
76 | 81 |
77 if (!framesOfTab) | 82 if (!framesOfTab) |
78 frames.set(tab, (framesOfTab = {})); | 83 frames.set(tab, (framesOfTab = {})); |
79 | 84 |
80 framesOfTab[frameId] = {url: url, parent: parentFrameId}; | 85 framesOfTab[frameId] = {url: url, parent: parentFrameId}; |
81 } | 86 } |
82 | 87 |
83 function getFrameData(tab, frameId) | 88 function getFrameData(tab, frameId) |
84 { | 89 { |
85 var framesOfTab = frames.get(tab); | 90 var framesOfTab = frames.get(tab); |
86 | 91 |
87 if (framesOfTab) { | 92 if (framesOfTab) |
| 93 { |
88 if (frameId in framesOfTab) | 94 if (frameId in framesOfTab) |
89 return framesOfTab[frameId]; | 95 return framesOfTab[frameId]; |
90 | 96 |
91 // We don't know anything about javascript: or data: frames, use top frame | 97 // We don't know anything about javascript: or data: frames, use top frame |
92 if (frameId != -1) | 98 if (frameId != -1) |
93 return framesOfTab[0]; | 99 return framesOfTab[0]; |
94 } | 100 } |
95 } | 101 } |
96 | 102 |
97 function getFrameUrl(tab, frameId) | 103 function getFrameUrl(tab, frameId) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 var frameUrl = frameData.url; | 136 var frameUrl = frameData.url; |
131 var parentUrl = (parentData ? parentData.url : frameUrl); | 137 var parentUrl = (parentData ? parentData.url : frameUrl); |
132 if ("keyException" in frameData || isWhitelisted(frameUrl, parentUrl, type)) | 138 if ("keyException" in frameData || isWhitelisted(frameUrl, parentUrl, type)) |
133 return true; | 139 return true; |
134 } | 140 } |
135 return false; | 141 return false; |
136 } | 142 } |
137 | 143 |
138 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest, ["http://*/*", "http
s://*/*"]); | 144 ext.webRequest.onBeforeRequest.addListener(onBeforeRequest, ["http://*/*", "http
s://*/*"]); |
139 | 145 |
140 if (window.chrome) { | 146 if (require("info").platform == "chromium") |
141 function onHeadersReceived(details) { | 147 { |
| 148 function onHeadersReceived(details) |
| 149 { |
142 if (details.tabId == -1) | 150 if (details.tabId == -1) |
143 return; | 151 return; |
144 | 152 |
145 var type = details.type; | 153 var type = details.type; |
146 if (type != "main_frame" && type != "sub_frame") | 154 if (type != "main_frame" && type != "sub_frame") |
147 return; | 155 return; |
148 | 156 |
149 var tab = new Tab({id: details.tabId}); | 157 var tab = new Tab({id: details.tabId}); |
150 var url = getFrameUrl(tab, details.frameId); | 158 var url = getFrameUrl(tab, details.frameId); |
151 if (url != details.url) | 159 if (url != details.url) |
152 return; | 160 return; |
153 | 161 |
154 var key = null; | 162 var key = null; |
155 var signature = null; | 163 var signature = null; |
156 for (var i = 0; i < details.responseHeaders.length; i++) | 164 for (var i = 0; i < details.responseHeaders.length; i++) |
157 { | 165 { |
158 var header = details.responseHeaders[i]; | 166 var header = details.responseHeaders[i]; |
159 if (header.name.toLowerCase() == "x-adblock-key" && header.value) | 167 if (header.name.toLowerCase() == "x-adblock-key" && header.value) |
160 { | 168 { |
161 var index = header.value.indexOf("_"); | 169 var index = header.value.indexOf("_"); |
162 if (index >= 0) | 170 if (index >= 0) |
163 { | 171 { |
164 var key = header.value.substr(0, index); | 172 key = header.value.substr(0, index); |
165 var signature = header.value.substr(index + 1); | 173 signature = header.value.substr(index + 1); |
166 break; | 174 break; |
167 } | 175 } |
168 } | 176 } |
169 } | 177 } |
170 if (!key) | 178 if (!key) |
171 return; | 179 return; |
172 | 180 |
173 var parentUrl = null; | 181 var parentUrl = null; |
174 if (type == "sub_frame") | 182 if (type == "sub_frame") |
175 parentUrl = getFrameUrl(tab, details.parentFrameId); | 183 parentUrl = getFrameUrl(tab, details.parentFrameId); |
(...skipping 12 matching lines...) Expand all Loading... |
188 var params = [ | 196 var params = [ |
189 uri.path.replace(/#.*/, ""), // REQUEST_URI | 197 uri.path.replace(/#.*/, ""), // REQUEST_URI |
190 host, // HTTP_HOST | 198 host, // HTTP_HOST |
191 window.navigator.userAgent // HTTP_USER_AGENT | 199 window.navigator.userAgent // HTTP_USER_AGENT |
192 ]; | 200 ]; |
193 if (verifySignature(key, signature, params.join("\0"))) | 201 if (verifySignature(key, signature, params.join("\0"))) |
194 frames.get(tab)[details.frameId].keyException = true; | 202 frames.get(tab)[details.frameId].keyException = true; |
195 } | 203 } |
196 } | 204 } |
197 | 205 |
198 » chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls
: ["http://*/*", "https://*/*"]}, ["responseHeaders"]); | 206 chrome.webRequest.onHeadersReceived.addListener(onHeadersReceived, {urls: ["ht
tp://*/*", "https://*/*"]}, ["responseHeaders"]); |
199 } | 207 } |
200 | |
LEFT | RIGHT |