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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 onShutdown.add(function() | 137 onShutdown.add(function() |
138 { | 138 { |
139 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService.
USER_SHEET); | 139 Utils.styleService.unregisterSheet(collapseStyle, Ci.nsIStyleSheetService.
USER_SHEET); |
140 }) | 140 }) |
141 TimeLine.log("done registering stylesheet"); | 141 TimeLine.log("done registering stylesheet"); |
142 | 142 |
143 TimeLine.leave("Done initializing content policy"); | 143 TimeLine.leave("Done initializing content policy"); |
144 }, | 144 }, |
145 | 145 |
146 /** | 146 /** |
| 147 * Checks whether a window or its parent is whitelisted or has a valid site-ke
y. |
| 148 * @param wnd {nsIDOMWindow} |
| 149 */ |
| 150 shouldNeverBlockWindow: function(wnd) |
| 151 { |
| 152 let uri = wnd.document.documentURIObject; |
| 153 if (!uri) |
| 154 return true; |
| 155 |
| 156 if (!Policy.isBlockableScheme(uri.scheme)) |
| 157 return true; |
| 158 |
| 159 let topWnd = wnd.top; |
| 160 if (!topWnd || !topWnd.location || !topWnd.location.href) |
| 161 return true; |
| 162 |
| 163 let testWnd = wnd; |
| 164 let parentWndLocation = getWindowLocation(testWnd); |
| 165 while (true) |
| 166 { |
| 167 let testWndLocation = parentWndLocation; |
| 168 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWind
owLocation(testWnd.parent)); |
| 169 |
| 170 let match = Policy.isWhitelisted(testWndLocation, parentWndLocation); |
| 171 |
| 172 if (match == null) |
| 173 { |
| 174 let keydata = (testWnd.document && testWnd.document.documentElement ? te
stWnd.document.documentElement.getAttribute("data-adblockkey") : null); |
| 175 if (keydata && keydata.indexOf("_") >= 0) |
| 176 { |
| 177 let [key, signature] = keydata.split("_", 2); |
| 178 let keyMatch = defaultMatcher.matchesByKey(testWndLocation, key.replac
e(/=/g, ""), docDomain); |
| 179 if (keyMatch && Utils.crypto) |
| 180 { |
| 181 // Website specifies a key that we know but is the signature valid? |
| 182 let uri = Services.io.newURI(testWndLocation, null, null); |
| 183 let params = [ |
| 184 uri.path.replace(/#.*/, ""), // REQUEST_URI |
| 185 uri.asciiHost, // HTTP_HOST |
| 186 Utils.httpProtocol.userAgent // HTTP_USER_AGENT |
| 187 ]; |
| 188 if (Utils.verifySignature(key, signature, params.join("\0"))) |
| 189 match = keyMatch; |
| 190 } |
| 191 } |
| 192 } |
| 193 |
| 194 if (match instanceof WhitelistFilter) |
| 195 { |
| 196 FilterStorage.increaseHitCount(match, wnd); |
| 197 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCUME
NT, getHostname(parentWndLocation), false, testWndLocation, match); |
| 198 return true; |
| 199 } |
| 200 |
| 201 if (testWnd.parent == testWnd) |
| 202 break; |
| 203 else |
| 204 testWnd = testWnd.parent; |
| 205 } |
| 206 |
| 207 return false; |
| 208 }, |
| 209 |
| 210 /** |
147 * Checks whether a node should be blocked, hides it if necessary | 211 * Checks whether a node should be blocked, hides it if necessary |
148 * @param wnd {nsIDOMWindow} | 212 * @param wnd {nsIDOMWindow} |
149 * @param node {nsIDOMElement} | 213 * @param node {nsIDOMElement} |
150 * @param contentType {String} | 214 * @param contentType {String} |
151 * @param location {nsIURI} | 215 * @param location {nsIURI} |
152 * @param collapse {Boolean} true to force hiding of the node | 216 * @param collapse {Boolean} true to force hiding of the node |
153 * @return {Boolean} false if the node should be blocked | 217 * @return {Boolean} false if the node should be blocked |
154 */ | 218 */ |
155 processNode: function(wnd, node, contentType, location, collapse) | 219 processNode: function(wnd, node, contentType, location, collapse) |
156 { | 220 { |
157 let topWnd = wnd.top; | 221 if (Policy.shouldNeverBlockWindow(wnd)) |
158 if (!topWnd || !topWnd.location || !topWnd.location.href) | |
159 return true; | 222 return true; |
160 | 223 |
| 224 let topWnd = wnd.top; |
161 let originWindow = Utils.getOriginWindow(wnd); | 225 let originWindow = Utils.getOriginWindow(wnd); |
162 let wndLocation = originWindow.location.href; | 226 let wndLocation = originWindow.location.href; |
163 let docDomain = getHostname(wndLocation); | 227 let docDomain = getHostname(wndLocation); |
164 let match = null; | |
165 if (!match && Prefs.enabled) | |
166 { | |
167 let testWnd = wnd; | |
168 let parentWndLocation = getWindowLocation(testWnd); | |
169 while (true) | |
170 { | |
171 let testWndLocation = parentWndLocation; | |
172 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); | |
173 match = Policy.isWhitelisted(testWndLocation, parentWndLocation); | |
174 | |
175 if (!(match instanceof WhitelistFilter)) | |
176 { | |
177 let keydata = (testWnd.document && testWnd.document.documentElement ?
testWnd.document.documentElement.getAttribute("data-adblockkey") : null); | |
178 if (keydata && keydata.indexOf("_") >= 0) | |
179 { | |
180 let [key, signature] = keydata.split("_", 2); | |
181 let keyMatch = defaultMatcher.matchesByKey(testWndLocation, key.repl
ace(/=/g, ""), docDomain); | |
182 if (keyMatch && Utils.crypto) | |
183 { | |
184 // Website specifies a key that we know but is the signature valid
? | |
185 let uri = Services.io.newURI(testWndLocation, null, null); | |
186 let params = [ | |
187 uri.path.replace(/#.*/, ""), // REQUEST_URI | |
188 uri.asciiHost, // HTTP_HOST | |
189 Utils.httpProtocol.userAgent // HTTP_USER_AGENT | |
190 ]; | |
191 if (Utils.verifySignature(key, signature, params.join("\0"))) | |
192 match = keyMatch; | |
193 } | |
194 } | |
195 } | |
196 | |
197 if (match instanceof WhitelistFilter) | |
198 { | |
199 FilterStorage.increaseHitCount(match, wnd); | |
200 RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCU
MENT, getHostname(parentWndLocation), false, testWndLocation, match); | |
201 return true; | |
202 } | |
203 | |
204 if (testWnd.parent == testWnd) | |
205 break; | |
206 else | |
207 testWnd = testWnd.parent; | |
208 } | |
209 } | |
210 | 228 |
211 // Data loaded by plugins should be attached to the document | 229 // Data loaded by plugins should be attached to the document |
212 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO
MElement) | 230 if (contentType == Policy.type.OBJECT_SUBREQUEST && node instanceof Ci.nsIDO
MElement) |
213 node = node.ownerDocument; | 231 node = node.ownerDocument; |
214 | 232 |
215 // Fix type for objects misrepresented as frames or images | 233 // Fix type for objects misrepresented as frames or images |
216 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec
tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) | 234 if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjec
tElement || node instanceof Ci.nsIDOMHTMLEmbedElement)) |
217 contentType = Policy.type.OBJECT; | 235 contentType = Policy.type.OBJECT; |
218 | 236 |
219 let locationText = location.spec; | 237 let locationText = location.spec; |
220 if (!match && contentType == Policy.type.ELEMHIDE) | 238 let match = null; |
| 239 if (contentType == Policy.type.ELEMHIDE) |
221 { | 240 { |
222 let testWnd = wnd; | 241 let testWnd = wnd; |
223 let parentWndLocation = getWindowLocation(testWnd); | 242 let parentWndLocation = getWindowLocation(testWnd); |
224 while (true) | 243 while (true) |
225 { | 244 { |
226 let testWndLocation = parentWndLocation; | 245 let testWndLocation = parentWndLocation; |
227 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); | 246 parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWi
ndowLocation(testWnd.parent)); |
228 let parentDocDomain = getHostname(parentWndLocation); | 247 let parentDocDomain = getHostname(parentWndLocation); |
229 match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc
Domain, false); | 248 match = defaultMatcher.matchesAny(testWndLocation, "ELEMHIDE", parentDoc
Domain, false); |
230 if (match instanceof WhitelistFilter) | 249 if (match instanceof WhitelistFilter) |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 if (!wnd || wnd.closed) | 784 if (!wnd || wnd.closed) |
766 return; | 785 return; |
767 | 786 |
768 if (entry.type == Policy.type.OBJECT) | 787 if (entry.type == Policy.type.OBJECT) |
769 { | 788 { |
770 node.removeEventListener("mouseover", objectMouseEventHander, true); | 789 node.removeEventListener("mouseover", objectMouseEventHander, true); |
771 node.removeEventListener("mouseout", objectMouseEventHander, true); | 790 node.removeEventListener("mouseout", objectMouseEventHander, true); |
772 } | 791 } |
773 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
; | 792 Policy.processNode(wnd, node, entry.type, Utils.makeURI(entry.location), true)
; |
774 } | 793 } |
OLD | NEW |