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

Side by Side Diff: include.preload.js

Issue 5989914281771008: Use Shadow DOM for element hiding (Closed)
Patch Set: Created April 15, 2014, 9:48 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 | « background.js ('k') | 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 var SELECTOR_GROUP_SIZE = 20; 18 var SELECTOR_GROUP_SIZE = 20;
19 19
20 var elemhideElt = null; 20 var elemhideElt = null;
21 21
22 // Sets the currently used CSS rules for elemhide filters 22 // Sets the currently used CSS rules for elemhide filters
23 function setElemhideCSSRules(selectors) 23 function setElemhideCSSRules(selectors)
24 { 24 {
25 if (elemhideElt && elemhideElt.parentNode) 25 if (elemhideElt && elemhideElt.parentNode)
26 elemhideElt.parentNode.removeChild(elemhideElt); 26 elemhideElt.parentNode.removeChild(elemhideElt);
Sebastian Noack 2014/04/15 09:58:06 Storing the inserted <style> tag into a global var
Wladimir Palant 2014/04/15 13:13:14 I somewhat remember that AdThwart had issues with
27 27
28 if (!selectors) 28 if (selectors.length == 0)
Sebastian Noack 2014/04/15 09:58:06 Skip inserting a style tag, if there are no elemen
Wladimir Palant 2014/04/15 13:13:14 That doesn't make much difference in reality - if
Sebastian Noack 2014/04/15 19:21:54 I am aware that at least when using EASYList there
29 return; 29 return;
30 30
31 elemhideElt = document.createElement("style");
32 elemhideElt.setAttribute("type", "text/css");
33
34 // Try to insert the style into the <head> tag, inserting directly under the 31 // Try to insert the style into the <head> tag, inserting directly under the
35 // document root breaks dev tools functionality: 32 // document root breaks dev tools functionality:
36 // http://code.google.com/p/chromium/issues/detail?id=178109 33 // http://code.google.com/p/chromium/issues/detail?id=178109
37 (document.head || document.documentElement).appendChild(elemhideElt); 34 var container = document.head || document.documentElement;
35
36 // Use Shadow DOM if available to don't mess with web pages
37 // that rely on the order of their own <style> tags (#309)
38 if ("createShadowRoot" in container)
39 container = container.createShadowRoot();
Wladimir Palant 2014/04/15 13:13:14 Given that this standard is still very much in flu
Sebastian Noack 2014/04/15 19:21:54 Done.
40 else if ("webkitCreateShadowRoot" in container)
41 container = container.webkitCreateShadowRoot();
Wladimir Palant 2014/04/15 13:13:14 Please add a <shadow> element to our shadow root t
Sebastian Noack 2014/04/15 19:21:54 Done.
42
43 elemhideElt = document.createElement("style");
44 elemhideElt.setAttribute("type", "text/css");
45 container.appendChild(elemhideElt);
Wladimir Palant 2014/04/15 13:13:14 Will these styles affect the regular elements or o
Sebastian Noack 2014/04/15 19:21:54 You are right, it actually didn't worked with the
38 46
39 var elt = elemhideElt; // Use a local variable to avoid racing conditions 47 var elt = elemhideElt; // Use a local variable to avoid racing conditions
40 function setRules() 48 function setRules()
41 { 49 {
42 if (!elt.sheet) 50 if (!elt.sheet)
Sebastian Noack 2014/04/15 19:21:54 I also got rid of that code. The sheet property is
Wladimir Palant 2014/04/15 21:19:47 I didn't remember but hg blame points to https://a
43 { 51 {
44 // Stylesheet didn't initialize yet, wait a little longer 52 // Stylesheet didn't initialize yet, wait a little longer
45 window.setTimeout(setRules, 0); 53 window.setTimeout(setRules, 0);
46 return; 54 return;
47 } 55 }
48 56
49 // WebKit apparently chokes when the selector list in a CSS rule is huge. 57 // WebKit apparently chokes when the selector list in a CSS rule is huge.
50 // So we split the elemhide selectors into groups. 58 // So we split the elemhide selectors into groups.
51 for (var i = 0, j = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE, j++) 59 for (var i = 0, j = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE, j++)
52 { 60 {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); 122 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr});
115 123
116 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 124 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
117 } 125 }
118 126
119 // In Chrome 18 the document might not be initialized yet 127 // In Chrome 18 the document might not be initialized yet
120 if (document.documentElement) 128 if (document.documentElement)
121 init(); 129 init();
122 else 130 else
123 window.setTimeout(init, 0); 131 window.setTimeout(init, 0);
OLDNEW
« no previous file with comments | « background.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld