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

Side by Side Diff: include.preload.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Rebased Created Feb. 13, 2015, 4:16 p.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 | « chrome/ext/devtools.js ('k') | lib/devtools.js » ('j') | 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return contentDocument.location.protocol == "about:"; 94 return contentDocument.location.protocol == "about:";
95 } 95 }
96 96
97 function resolveURL(url) 97 function resolveURL(url)
98 { 98 {
99 var a = document.createElement("a"); 99 var a = document.createElement("a");
100 a.href = url; 100 a.href = url;
101 return a.href; 101 return a.href;
102 } 102 }
103 103
104 function traceHiddenElements(document, selectors)
105 {
106 function check(element)
107 {
108 var matchedSelectors = [];
109
110 for (var i = 0; i < selectors.length; i++)
111 {
112 var selector = selectors[i];
113 var elements = document.querySelectorAll(selector);
114
115 for (var j = 0; j < elements.length; j++)
116 {
117 if (getComputedStyle(elements[j]).display == "none")
118 {
119 matchedSelectors.push(selector);
120 break;
121 }
122 }
123 }
124
125 if (matchedSelectors.length > 0)
126 ext.backgroundPage.sendMessage({type: "trace-elemhide", selectors: matched Selectors});
127 }
128
129 function trace()
130 {
131 check();
132
133 new MutationObserver(check).observe(
134 document,
135 {
136 childList: true,
137 attributes: true,
138 subtree: true
139 }
140 );
141 }
142
143 if (document.readyState == "loading")
144 document.addEventListener("DOMContentLoaded", trace);
145 else
146 trace();
147 }
148
104 function reinjectRulesWhenRemoved(document, style) 149 function reinjectRulesWhenRemoved(document, style)
105 { 150 {
106 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve r; 151 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve r;
107 if (!MutationObserver) 152 if (!MutationObserver)
108 return; 153 return;
109 154
110 var observer = new MutationObserver(function(mutations) 155 var observer = new MutationObserver(function(mutations)
111 { 156 {
112 var isStyleRemoved = false; 157 var isStyleRemoved = false;
113 for (var i = 0; i < mutations.length; i++) 158 for (var i = 0; i < mutations.length; i++)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Also, we can't use shadow DOM on Google Docs, since it breaks printing 238 // Also, we can't use shadow DOM on Google Docs, since it breaks printing
194 // there (#1770). 239 // there (#1770).
195 var shadow = null; 240 var shadow = null;
196 if ("createShadowRoot" in document.documentElement && document.domain != "docs .google.com") 241 if ("createShadowRoot" in document.documentElement && document.domain != "docs .google.com")
197 { 242 {
198 shadow = document.documentElement.createShadowRoot(); 243 shadow = document.documentElement.createShadowRoot();
199 shadow.appendChild(document.createElement("shadow")); 244 shadow.appendChild(document.createElement("shadow"));
200 } 245 }
201 246
202 // Sets the currently used CSS rules for elemhide filters 247 // Sets the currently used CSS rules for elemhide filters
203 var setElemhideCSSRules = function(selectors) 248 var setElemhideCSSRules = function(response)
204 { 249 {
205 if (selectors.length == 0) 250 if (response.selectors.length == 0)
206 return; 251 return;
207 252
208 var style = document.createElement("style"); 253 var style = document.createElement("style");
209 style.setAttribute("type", "text/css"); 254 style.setAttribute("type", "text/css");
210 255
256 var selectors = response.selectors;
211 if (shadow) 257 if (shadow)
212 { 258 {
213 shadow.appendChild(style); 259 shadow.appendChild(style);
214 selectors = convertSelectorsForShadowDOM(selectors); 260 selectors = convertSelectorsForShadowDOM(selectors);
215 } 261 }
216 else 262 else
217 { 263 {
218 // Try to insert the style into the <head> tag, inserting directly under t he 264 // Try to insert the style into the <head> tag, inserting directly under t he
219 // document root breaks dev tools functionality: 265 // document root breaks dev tools functionality:
220 // http://code.google.com/p/chromium/issues/detail?id=178109 266 // http://code.google.com/p/chromium/issues/detail?id=178109
(...skipping 10 matching lines...) Expand all
231 return; 277 return;
232 } 278 }
233 279
234 // WebKit apparently chokes when the selector list in a CSS rule is huge. 280 // WebKit apparently chokes when the selector list in a CSS rule is huge.
235 // So we split the elemhide selectors into groups. 281 // So we split the elemhide selectors into groups.
236 for (var i = 0; selectors.length > 0; i++) 282 for (var i = 0; selectors.length > 0; i++)
237 { 283 {
238 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); 284 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", ");
239 style.sheet.insertRule(selector + " { display: none !important; }", i); 285 style.sheet.insertRule(selector + " { display: none !important; }", i);
240 } 286 }
287
288 if (response.trace)
289 traceHiddenElements(document, response.selectors);
241 }; 290 };
242 291
243 setRules(); 292 setRules();
244 reinjectRulesWhenRemoved(document, style); 293 reinjectRulesWhenRemoved(document, style);
245 }; 294 };
246 295
247 document.addEventListener("error", function(event) 296 document.addEventListener("error", function(event)
248 { 297 {
249 checkCollapse(event.target); 298 checkCollapse(event.target);
250 }, true); 299 }, true);
(...skipping 19 matching lines...) Expand all
270 }, true); 319 }, true);
271 320
272 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 321 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
273 } 322 }
274 323
275 if (document instanceof HTMLDocument) 324 if (document instanceof HTMLDocument)
276 { 325 {
277 checkSitekey(); 326 checkSitekey();
278 init(document); 327 init(document);
279 } 328 }
OLDNEW
« no previous file with comments | « chrome/ext/devtools.js ('k') | lib/devtools.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld