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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
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) | |
69 { | |
70 var value = element.getAttribute(attribute); | |
71 return value == null || /^\s*(javascript:|about:|$)/i.test(value); | |
72 } | |
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 | |
68 // Converts relative to absolute URL | 89 // Converts relative to absolute URL |
69 // e.g.: foo.swf on http://example.com/whatever/bar.html | 90 // e.g.: foo.swf on http://example.com/whatever/bar.html |
70 // -> http://example.com/whatever/foo.swf | 91 // -> http://example.com/whatever/foo.swf |
71 function relativeToAbsoluteUrl(url) | 92 function relativeToAbsoluteUrl(url) |
72 { | 93 { |
73 // If URL is already absolute, don't mess with it | 94 // If URL is already absolute, don't mess with it |
74 if (!url || /^[\w\-]+:/i.test(url)) | 95 if (!url || /^[\w\-]+:/i.test(url)) |
75 return url; | 96 return url; |
76 | 97 |
77 // Leading / means absolute path | 98 // Leading / means absolute path |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 document.addEventListener("error", function(event) | 204 document.addEventListener("error", function(event) |
184 { | 205 { |
185 checkCollapse(event.target); | 206 checkCollapse(event.target); |
186 }, true); | 207 }, true); |
187 | 208 |
188 document.addEventListener("load", function(event) | 209 document.addEventListener("load", function(event) |
189 { | 210 { |
190 var element = event.target; | 211 var element = event.target; |
191 | 212 |
192 if (/^i?frame$/.test(element.localName)) | 213 if (/^i?frame$/.test(element.localName)) |
193 { | |
194 checkCollapse(element); | 214 checkCollapse(element); |
195 | 215 |
196 if (fixInlineFrames && (element.hasAttribute("srcdoc") || !element.hasAttr ibute("src") || | 216 if (fixInlineFrames && isInlineFrame(element)) |
197 /^\s*(javascript:|about:|$)/i.test(element.getAttr ibute("src")))) | 217 { |
Wladimir Palant
2014/06/04 14:12:49
What about data: URLs? Note that checking whether
Sebastian Noack
2014/06/04 16:12:30
This check intentionally don't match data: URLs, s
| |
198 { | 218 init(element.contentDocument); |
199 var contentDocument = element.contentDocument; | 219 |
200 init(contentDocument); | 220 for (var tagName in typeMap) |
Wladimir Palant
2014/06/04 14:12:49
Nit: It seems that the contentDocument variable is
Sebastian Noack
2014/06/04 16:12:30
Done.
| |
201 | 221 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam e(tagName), checkCollapse); |
202 for (var tagName in typeMap) | |
203 Array.prototype.forEach.call(contentDocument.getElementsByTagName(tagN ame), checkCollapse); | |
204 } | |
205 } | 222 } |
206 }, true); | 223 }, true); |
207 | 224 |
208 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 225 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); |
209 } | 226 } |
210 | 227 |
211 if (document.documentElement instanceof HTMLElement) | 228 if (document.documentElement instanceof HTMLElement) |
212 { | 229 { |
213 checkExceptionKey(); | 230 checkExceptionKey(); |
214 init(document); | 231 init(document); |
215 } | 232 } |
LEFT | RIGHT |