Left: | ||
Right: |
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-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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 function checkExceptionKey() | 61 function checkExceptionKey() |
62 { | 62 { |
63 var attr = document.documentElement.getAttribute("data-adblockkey"); | 63 var attr = document.documentElement.getAttribute("data-adblockkey"); |
64 if (attr) | 64 if (attr) |
65 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); | 65 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); |
66 } | 66 } |
67 | 67 |
68 function hasInlineURL(element, attribute) | 68 function hasInlineURL(element, attribute) |
69 { | 69 { |
70 var value = element.getAttribute(attribute); | 70 var value = element.getAttribute(attribute); |
71 return value == null || /^\s*(javascript:|about:|$)/i.test(value); | 71 return value == null || /^\s*(javascript:|about:|$)/i.test(value); |
Wladimir Palant
2014/06/17 13:00:24
I'm surprised you check for null explicitly rather
Sebastian Noack
2014/06/17 14:13:48
I want to skip regex matching if the attribute is
| |
72 } | 72 } |
73 | 73 |
74 function isInlineFrame(element) | |
75 { | |
76 switch (element.localName) | |
77 { | |
78 case "iframe": | |
79 return hasInlineURL(element, "src") || element.hasAttribute("srcdoc"); | |
80 case "frame": | |
81 return hasInlineURL(element, "src"); | |
82 case "object": | |
83 return hasInlineURL(element, "data") && element.contentDocument; | |
84 default: | |
85 return false; | |
86 } | |
87 } | |
88 | |
74 // Converts relative to absolute URL | 89 // Converts relative to absolute URL |
75 // e.g.: foo.swf on http://example.com/whatever/bar.html | 90 // e.g.: foo.swf on http://example.com/whatever/bar.html |
76 // -> http://example.com/whatever/foo.swf | 91 // -> http://example.com/whatever/foo.swf |
77 function relativeToAbsoluteUrl(url) | 92 function relativeToAbsoluteUrl(url) |
78 { | 93 { |
79 // If URL is already absolute, don't mess with it | 94 // If URL is already absolute, don't mess with it |
80 if (!url || /^[\w\-]+:/i.test(url)) | 95 if (!url || /^[\w\-]+:/i.test(url)) |
81 return url; | 96 return url; |
82 | 97 |
83 // Leading / means absolute path | 98 // Leading / means absolute path |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 }; | 202 }; |
188 | 203 |
189 document.addEventListener("error", function(event) | 204 document.addEventListener("error", function(event) |
190 { | 205 { |
191 checkCollapse(event.target); | 206 checkCollapse(event.target); |
192 }, true); | 207 }, true); |
193 | 208 |
194 document.addEventListener("load", function(event) | 209 document.addEventListener("load", function(event) |
195 { | 210 { |
196 var element = event.target; | 211 var element = event.target; |
197 var isFrame = /^i?frame$/.test(element.localName); | 212 |
198 | 213 if (/^i?frame$/.test(element.localName)) |
199 if (isFrame) | |
200 checkCollapse(element); | 214 checkCollapse(element); |
201 | 215 |
202 if (fixInlineFrames && (isFrame ? hasInlineURL(element, "src") || | 216 if (fixInlineFrames && isInlineFrame(element)) |
203 element.hasAttribute("srcdoc") | |
204 | |
205 : element.localName == "object" && | |
206 hasInlineURL(element, "data") && | |
207 element.documentElement)) | |
Wladimir Palant
2014/06/17 13:00:24
There is at least one more scenario: <embed src=".
Sebastian Noack
2014/06/17 14:13:48
As discussed on IRC, we ignore this case because i
| |
208 { | 217 { |
209 init(element.contentDocument); | 218 init(element.contentDocument); |
210 | 219 |
211 for (var tagName in typeMap) | 220 for (var tagName in typeMap) |
212 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam e(tagName), checkCollapse); | 221 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam e(tagName), checkCollapse); |
213 } | 222 } |
214 }, true); | 223 }, true); |
215 | 224 |
216 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 225 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); |
217 } | 226 } |
218 | 227 |
219 if (document.documentElement instanceof HTMLElement) | 228 if (document.documentElement instanceof HTMLElement) |
220 { | 229 { |
221 checkExceptionKey(); | 230 checkExceptionKey(); |
222 init(document); | 231 init(document); |
223 } | 232 } |
LEFT | RIGHT |