Left: | ||
Right: |
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 107 |
108 // Remove filename and add relative URL to it | 108 // Remove filename and add relative URL to it |
109 var base = document.baseURI.match(/.+\//); | 109 var base = document.baseURI.match(/.+\//); |
110 if (!base) | 110 if (!base) |
111 return document.baseURI + "/" + url; | 111 return document.baseURI + "/" + url; |
112 return base[0] + url; | 112 return base[0] + url; |
113 } | 113 } |
114 | 114 |
115 function init(document) | 115 function init(document) |
116 { | 116 { |
117 var canUseShadow = "webkitCreateShadowRoot" in document.documentElement; | 117 // prior to Chrome 37, content scripts don't run on about:blank |
118 var fixInlineFrames = false; | 118 // and about:srcdoc. So we have to apply element hiding and collapsing |
119 | 119 // from the parent frame, when inline frames are loaded. |
120 var match = navigator.userAgent.match(/\bChrome\/(\d+)/); | 120 var match = navigator.userAgent.match(/\bChrome\/(\d+)/); |
121 if (match) | 121 var fixInlineFrames = match && parseInt(match[1]) < 37); |
122 { | |
123 var chromeVersion = parseInt(match[1]); | |
124 | |
125 // the <shadow> element is ignored in Chrome 32 (#309). Also Chrome 31-33 | |
126 // crashes in some situations on some pages when using shadow DOM (#498). | |
127 // So we must not use Shadow DOM on those versions of Chrome. | |
128 if (chromeVersion >= 31 && chromeVersion <= 33) | |
129 canUseShadow = false; | |
130 | |
131 // prior to Chrome 37, content scripts don't run on about:blank | |
132 // and about:srcdoc. So we have to apply element hiding and collapsing | |
133 // from the parent frame, when inline frames are loaded. | |
134 if (chromeVersion < 37) | |
135 fixInlineFrames = true; | |
136 } | |
137 | 122 |
138 // use Shadow DOM if available to don't mess with web pages that | 123 // use Shadow DOM if available to don't mess with web pages that |
139 // rely on the order of their own <style> tags (#309). However we | 124 // rely on the order of their own <style> tags (#309). However we |
140 // must not create the shadow root in the response callback passed | 125 // must not create the shadow root in the response callback passed |
141 // to sendMessage(), otherwise Chrome breaks some websites (#450). | 126 // to sendMessage(), otherwise Chrome breaks some websites (#450). |
127 var canUseShadow = "createShadowRoot" in document.documentElement; | |
142 if (canUseShadow) | 128 if (canUseShadow) |
143 { | 129 { |
144 var shadow = document.documentElement.webkitCreateShadowRoot(); | 130 var shadow = document.documentElement.createShadowRoot(); |
Wladimir Palant
2014/08/29 20:49:51
I apparently missed that in the previous review -
Sebastian Noack
2014/08/29 22:19:29
Done.
| |
145 shadow.appendChild(document.createElement("shadow")); | 131 shadow.appendChild(document.createElement("shadow")); |
146 } | 132 } |
147 | 133 |
148 // Sets the currently used CSS rules for elemhide filters | 134 // Sets the currently used CSS rules for elemhide filters |
149 var setElemhideCSSRules = function(selectors) | 135 var setElemhideCSSRules = function(selectors) |
150 { | 136 { |
151 if (selectors.length == 0) | 137 if (selectors.length == 0) |
152 return; | 138 return; |
153 | 139 |
154 var style = document.createElement("style"); | 140 var style = document.createElement("style"); |
155 style.setAttribute("type", "text/css"); | 141 style.setAttribute("type", "text/css"); |
156 | 142 |
157 if (canUseShadow) | 143 if (canUseShadow) |
158 { | 144 { |
159 shadow.appendChild(style); | 145 shadow.appendChild(style); |
160 | 146 |
161 try | 147 for (var i = 0; i < selectors.length; i++) |
162 { | 148 selectors[i] = "::content " + selectors[i]; |
163 document.querySelector("::content"); | |
164 | |
165 for (var i = 0; i < selectors.length; i++) | |
166 selectors[i] = "::content " + selectors[i]; | |
167 } | |
168 catch (e) | |
169 { | |
170 for (var i = 0; i < selectors.length; i++) | |
171 selectors[i] = "::-webkit-distributed(" + selectors[i] + ")"; | |
172 } | |
173 } | 149 } |
174 else | 150 else |
175 { | 151 { |
176 // Try to insert the style into the <head> tag, inserting directly under t he | 152 // Try to insert the style into the <head> tag, inserting directly under t he |
177 // document root breaks dev tools functionality: | 153 // document root breaks dev tools functionality: |
178 // http://code.google.com/p/chromium/issues/detail?id=178109 | 154 // http://code.google.com/p/chromium/issues/detail?id=178109 |
179 (document.head || document.documentElement).appendChild(style); | 155 (document.head || document.documentElement).appendChild(style); |
180 } | 156 } |
181 | 157 |
182 var setRules = function() | 158 var setRules = function() |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 }, true); | 199 }, true); |
224 | 200 |
225 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 201 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); |
226 } | 202 } |
227 | 203 |
228 if (document instanceof HTMLDocument) | 204 if (document instanceof HTMLDocument) |
229 { | 205 { |
230 checkExceptionKey(); | 206 checkExceptionKey(); |
231 init(document); | 207 init(document); |
232 } | 208 } |
OLD | NEW |