Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.preload.js

Issue 5868615689568256: Issue 1703 - Work around Chrome bug 442107, hiding placeholders in frames with javascript: URL (Closed)
Patch Set: Created Dec. 16, 2014, 8:42 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld