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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 150 } |
151 } | 151 } |
152 ); | 152 ); |
153 }); | 153 }); |
154 | 154 |
155 observer.observe(style.parentNode, {childList: true}); | 155 observer.observe(style.parentNode, {childList: true}); |
156 } | 156 } |
157 | 157 |
158 function init(document) | 158 function init(document) |
159 { | 159 { |
160 // prior to Chrome 37, content scripts don't run on about:blank | |
161 // and about:srcdoc. So we have to apply element hiding and collapsing | |
162 // from the parent frame, when inline frames are loaded. | |
163 var match = navigator.userAgent.match(/\bChrome\/(\d+)/); | |
164 var fixInlineFrames = match && parseInt(match[1], 10) < 37; | |
165 | |
166 // use Shadow DOM if available to don't mess with web pages that | 160 // use Shadow DOM if available to don't mess with web pages that |
167 // rely on the order of their own <style> tags (#309). However we | 161 // rely on the order of their own <style> tags (#309). However we |
168 // must not create the shadow root in the response callback passed | 162 // must not create the shadow root in the response callback passed |
169 // to sendMessage(), otherwise Chrome breaks some websites (#450). | 163 // to sendMessage(), otherwise Chrome breaks some websites (#450). |
170 var shadow = null; | 164 var shadow = null; |
171 if ("createShadowRoot" in document.documentElement) | 165 if ("createShadowRoot" in document.documentElement) |
172 { | 166 { |
173 shadow = document.documentElement.createShadowRoot(); | 167 shadow = document.documentElement.createShadowRoot(); |
174 shadow.appendChild(document.createElement("shadow")); | 168 shadow.appendChild(document.createElement("shadow")); |
175 } | 169 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 checkCollapse(event.target); | 220 checkCollapse(event.target); |
227 }, true); | 221 }, true); |
228 | 222 |
229 document.addEventListener("load", function(event) | 223 document.addEventListener("load", function(event) |
230 { | 224 { |
231 var element = event.target; | 225 var element = event.target; |
232 | 226 |
233 if (/^i?frame$/.test(element.localName)) | 227 if (/^i?frame$/.test(element.localName)) |
234 checkCollapse(element); | 228 checkCollapse(element); |
235 | 229 |
236 if (fixInlineFrames && isInlineFrame(element)) | 230 // prior to Chrome 37, content scripts cannot run on about:blank, |
| 231 // about:srcdoc and javascript: URLs. Moreover, as of Chrome 40 |
| 232 // "load" and "error" events aren't dispatched there. So we have |
| 233 // to apply element hiding and collapsing from the parent frame. |
| 234 if (/\bChrome\//.test(navigator.userAgent) && isInlineFrame(element)) |
237 { | 235 { |
238 init(element.contentDocument); | 236 init(element.contentDocument); |
239 | 237 |
240 for (var tagName in typeMap) | 238 for (var tagName in typeMap) |
241 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam
e(tagName), checkCollapse); | 239 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam
e(tagName), checkCollapse); |
242 } | 240 } |
243 }, true); | 241 }, true); |
244 | 242 |
245 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 243 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); |
246 } | 244 } |
247 | 245 |
248 if (document instanceof HTMLDocument) | 246 if (document instanceof HTMLDocument) |
249 { | 247 { |
250 checkSitekey(); | 248 checkSitekey(); |
251 init(document); | 249 init(document); |
252 } | 250 } |
OLD | NEW |