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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 /** | 18 /** |
19 * @fileOverview Content policy implementation, responsible for blocking things. | 19 * @fileOverview Content policy implementation, responsible for blocking things. |
20 */ | 20 */ |
21 | 21 |
22 "use strict"; | 22 "use strict"; |
23 | 23 |
24 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); | 24 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); |
25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); | 25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
| 26 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt
ils.jsm", {}); |
26 | 27 |
27 let {Utils} = require("utils"); | 28 let {Utils} = require("utils"); |
28 let {Prefs} = require("prefs"); | 29 let {Prefs} = require("prefs"); |
29 let {FilterStorage} = require("filterStorage"); | 30 let {FilterStorage} = require("filterStorage"); |
30 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); | 31 let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses"); |
31 let {defaultMatcher} = require("matcher"); | 32 let {defaultMatcher} = require("matcher"); |
32 let {objectMouseEventHander} = require("objectTabs"); | 33 let {objectMouseEventHander} = require("objectTabs"); |
33 let {RequestNotifier} = require("requestNotifier"); | 34 let {RequestNotifier} = require("requestNotifier"); |
34 let {ElemHide} = require("elemHide"); | 35 let {ElemHide} = require("elemHide"); |
35 | 36 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 function cleanWindowLocation(wnd) | 136 function cleanWindowLocation(wnd) |
136 { | 137 { |
137 let url = getWindowLocation(wnd); | 138 let url = getWindowLocation(wnd); |
138 let index = url.indexOf("#"); | 139 let index = url.indexOf("#"); |
139 if (index >= 0) | 140 if (index >= 0) |
140 url = url.substring(0, index); | 141 url = url.substring(0, index); |
141 | 142 |
142 return url; | 143 return url; |
143 } | 144 } |
144 | 145 |
| 146 function addHit(match) |
| 147 { |
| 148 if (!PrivateBrowsingUtils.isContentWindowPrivate(wnd)) |
| 149 FilterStorage.increaseHitCount(match); |
| 150 } |
| 151 |
145 if (!match && Prefs.enabled) | 152 if (!match && Prefs.enabled) |
146 { | 153 { |
147 let testWnd = wnd; | 154 let testWnd = wnd; |
148 let testSitekey = sitekey; | 155 let testSitekey = sitekey; |
149 let testSitekeyWnd = sitekeyWnd; | 156 let testSitekeyWnd = sitekeyWnd; |
150 let parentWndLocation = cleanWindowLocation(testWnd); | 157 let parentWndLocation = cleanWindowLocation(testWnd); |
151 while (true) | 158 while (true) |
152 { | 159 { |
153 let testWndLocation = parentWndLocation; | 160 let testWndLocation = parentWndLocation; |
154 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : clean
WindowLocation(testWnd.parent)); | 161 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : clean
WindowLocation(testWnd.parent)); |
155 let parentDocDomain = getHostname(parentWndLocation); | 162 let parentDocDomain = getHostname(parentWndLocation); |
156 | 163 |
157 let typeMap = RegExpFilter.typeMap.DOCUMENT; | 164 let typeMap = RegExpFilter.typeMap.DOCUMENT; |
158 if (contentType == "ELEMHIDE") | 165 if (contentType == "ELEMHIDE") |
159 typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE; | 166 typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE; |
160 let whitelistMatch = defaultMatcher.matchesAny(testWndLocation, typeMap,
parentDocDomain, false, sitekey); | 167 let whitelistMatch = defaultMatcher.matchesAny(testWndLocation, typeMap,
parentDocDomain, false, sitekey); |
161 if (whitelistMatch instanceof WhitelistFilter) | 168 if (whitelistMatch instanceof WhitelistFilter) |
162 { | 169 { |
163 FilterStorage.increaseHitCount(whitelistMatch, wnd); | 170 addHit(whitelistMatch); |
164 RequestNotifier.addNodeData(testWnd.document, topWnd, | 171 RequestNotifier.addNodeData(testWnd.document, topWnd, |
165 (whitelistMatch.contentType & RegExpFilter.typeMap.DOCUMENT) ? "DOCU
MENT" : "ELEMHIDE", | 172 (whitelistMatch.contentType & RegExpFilter.typeMap.DOCUMENT) ? "DOCU
MENT" : "ELEMHIDE", |
166 parentDocDomain, false, testWndLocation, whitelistMatch); | 173 parentDocDomain, false, testWndLocation, whitelistMatch); |
167 return true; | 174 return true; |
168 } | 175 } |
169 | 176 |
170 let genericType = (contentType == "ELEMHIDE" ? "GENERICHIDE" : "GENERICB
LOCK"); | 177 let genericType = (contentType == "ELEMHIDE" ? "GENERICHIDE" : "GENERICB
LOCK"); |
171 let nogenericMatch = defaultMatcher.matchesAny(testWndLocation, | 178 let nogenericMatch = defaultMatcher.matchesAny(testWndLocation, |
172 RegExpFilter.typeMap[genericType], parentDocDomain, false, testSitek
ey); | 179 RegExpFilter.typeMap[genericType], parentDocDomain, false, testSitek
ey); |
173 if (nogenericMatch instanceof WhitelistFilter) | 180 if (nogenericMatch instanceof WhitelistFilter) |
174 { | 181 { |
175 nogeneric = true; | 182 nogeneric = true; |
176 | 183 |
177 FilterStorage.increaseHitCount(nogenericMatch, wnd); | 184 addHit(nogenericMatch); |
178 RequestNotifier.addNodeData(testWnd.document, topWnd, genericType, | 185 RequestNotifier.addNodeData(testWnd.document, topWnd, genericType, |
179 parentDocDomain, false, testWndLocation, | 186 parentDocDomain, false, testWndLocation, |
180 nogenericMatch); | 187 nogenericMatch); |
181 } | 188 } |
182 | 189 |
183 if (testWnd.parent == testWnd) | 190 if (testWnd.parent == testWnd) |
184 break; | 191 break; |
185 | 192 |
186 if (testWnd == testSitekeyWnd) | 193 if (testWnd == testSitekeyWnd) |
187 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); | 194 [testSitekey, testSitekeyWnd] = getSitekey(testWnd.parent); |
(...skipping 13 matching lines...) Expand all Loading... |
201 { | 208 { |
202 match = location; | 209 match = location; |
203 location = match.text.replace(/^.*?#/, '#'); | 210 location = match.text.replace(/^.*?#/, '#'); |
204 | 211 |
205 if (!match.isActiveOnDomain(docDomain)) | 212 if (!match.isActiveOnDomain(docDomain)) |
206 return true; | 213 return true; |
207 | 214 |
208 let exception = ElemHide.getException(match, docDomain); | 215 let exception = ElemHide.getException(match, docDomain); |
209 if (exception) | 216 if (exception) |
210 { | 217 { |
211 FilterStorage.increaseHitCount(exception, wnd); | 218 addHit(exception); |
212 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
location, exception); | 219 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false,
location, exception); |
213 return true; | 220 return true; |
214 } | 221 } |
215 | 222 |
216 if (nogeneric && match.isGeneric()) | 223 if (nogeneric && match.isGeneric()) |
217 return true; | 224 return true; |
218 } | 225 } |
219 | 226 |
220 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location,
docDomain)); | 227 let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location,
docDomain)); |
221 | 228 |
(...skipping 12 matching lines...) Expand all Loading... |
234 if (!match && contentType == "OBJECT" && node.nodeType == Ci.nsIDOMNode.EL
EMENT_NODE) | 241 if (!match && contentType == "OBJECT" && node.nodeType == Ci.nsIDOMNode.EL
EMENT_NODE) |
235 { | 242 { |
236 node.addEventListener("mouseover", objectMouseEventHander, true); | 243 node.addEventListener("mouseover", objectMouseEventHander, true); |
237 node.addEventListener("mouseout", objectMouseEventHander, true); | 244 node.addEventListener("mouseout", objectMouseEventHander, true); |
238 } | 245 } |
239 } | 246 } |
240 | 247 |
241 // Store node data | 248 // Store node data |
242 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdParty
, location, match); | 249 RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, thirdParty
, location, match); |
243 if (match) | 250 if (match) |
244 FilterStorage.increaseHitCount(match, wnd); | 251 addHit(match); |
245 | 252 |
246 return !match || match instanceof WhitelistFilter; | 253 return !match || match instanceof WhitelistFilter; |
247 }, | 254 }, |
248 | 255 |
249 /** | 256 /** |
250 * Checks whether the location's scheme is blockable. | 257 * Checks whether the location's scheme is blockable. |
251 * @param location {nsIURI} | 258 * @param location {nsIURI} |
252 * @return {Boolean} | 259 * @return {Boolean} |
253 */ | 260 */ |
254 isBlockableScheme: function(location) | 261 isBlockableScheme: function(location) |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 if (!wnd || wnd.closed) | 678 if (!wnd || wnd.closed) |
672 return; | 679 return; |
673 | 680 |
674 if (entry.type == "OBJECT") | 681 if (entry.type == "OBJECT") |
675 { | 682 { |
676 node.removeEventListener("mouseover", objectMouseEventHander, true); | 683 node.removeEventListener("mouseover", objectMouseEventHander, true); |
677 node.removeEventListener("mouseout", objectMouseEventHander, true); | 684 node.removeEventListener("mouseout", objectMouseEventHander, true); |
678 } | 685 } |
679 Policy.processNode(wnd, node, entry.type, entry.location, true); | 686 Policy.processNode(wnd, node, entry.type, entry.location, true); |
680 } | 687 } |
OLD | NEW |