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 March 3, 2015, 3: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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 { 87 {
88 return false; // third-party 88 return false; // third-party
89 } 89 }
90 90
91 if (!contentDocument) 91 if (!contentDocument)
92 return false; // not a frame 92 return false; // not a frame
93 93
94 return contentDocument.location.protocol == "about:"; 94 return contentDocument.location.protocol == "about:";
95 } 95 }
96 96
97 function traceHiddenElements(document, selectors)
98 {
99 function check(element)
100 {
101 var matchedSelectors = [];
102
103 for (var i = 0; i < selectors.length; i++)
104 {
105 var selector = selectors[i];
106 var elements = document.querySelectorAll(selector);
107
108 for (var j = 0; j < elements.length; j++)
109 {
110 if (getComputedStyle(elements[j]).display == "none")
111 {
112 matchedSelectors.push(selector);
113 break;
114 }
115 }
116 }
117
118 if (matchedSelectors.length > 0)
119 ext.backgroundPage.sendMessage({type: "trace-elemhide", selectors: matched Selectors});
120 }
121
122 function trace()
123 {
124 check();
125
126 new MutationObserver(check).observe(
127 document,
128 {
129 childList: true,
130 attributes: true,
131 subtree: true
132 }
133 );
134 }
135
136 if (document.readyState == "loading")
137 document.addEventListener("DOMContentLoaded", trace);
138 else
139 trace();
140 }
141
97 function reinjectRulesWhenRemoved(document, style) 142 function reinjectRulesWhenRemoved(document, style)
98 { 143 {
99 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve r; 144 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve r;
100 if (!MutationObserver) 145 if (!MutationObserver)
101 return; 146 return;
102 147
103 var observer = new MutationObserver(function(mutations) 148 var observer = new MutationObserver(function(mutations)
104 { 149 {
105 var isStyleRemoved = false; 150 var isStyleRemoved = false;
106 for (var i = 0; i < mutations.length; i++) 151 for (var i = 0; i < mutations.length; i++)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // Also, we can't use shadow DOM on Google Docs, since it breaks printing 231 // Also, we can't use shadow DOM on Google Docs, since it breaks printing
187 // there (#1770). 232 // there (#1770).
188 var shadow = null; 233 var shadow = null;
189 if ("createShadowRoot" in document.documentElement && document.domain != "docs .google.com") 234 if ("createShadowRoot" in document.documentElement && document.domain != "docs .google.com")
190 { 235 {
191 shadow = document.documentElement.createShadowRoot(); 236 shadow = document.documentElement.createShadowRoot();
192 shadow.appendChild(document.createElement("shadow")); 237 shadow.appendChild(document.createElement("shadow"));
193 } 238 }
194 239
195 // Sets the currently used CSS rules for elemhide filters 240 // Sets the currently used CSS rules for elemhide filters
196 var setElemhideCSSRules = function(selectors) 241 var setElemhideCSSRules = function(response)
197 { 242 {
198 if (selectors.length == 0) 243 if (response.selectors.length == 0)
199 return; 244 return;
200 245
201 var style = document.createElement("style"); 246 var style = document.createElement("style");
202 style.setAttribute("type", "text/css"); 247 style.setAttribute("type", "text/css");
203 248
249 var selectors = response.selectors;
204 if (shadow) 250 if (shadow)
205 { 251 {
206 shadow.appendChild(style); 252 shadow.appendChild(style);
207 selectors = convertSelectorsForShadowDOM(selectors); 253 selectors = convertSelectorsForShadowDOM(selectors);
208 } 254 }
209 else 255 else
210 { 256 {
211 // Try to insert the style into the <head> tag, inserting directly under t he 257 // Try to insert the style into the <head> tag, inserting directly under t he
212 // document root breaks dev tools functionality: 258 // document root breaks dev tools functionality:
213 // http://code.google.com/p/chromium/issues/detail?id=178109 259 // http://code.google.com/p/chromium/issues/detail?id=178109
(...skipping 10 matching lines...) Expand all
224 return; 270 return;
225 } 271 }
226 272
227 // WebKit apparently chokes when the selector list in a CSS rule is huge. 273 // WebKit apparently chokes when the selector list in a CSS rule is huge.
228 // So we split the elemhide selectors into groups. 274 // So we split the elemhide selectors into groups.
229 for (var i = 0; selectors.length > 0; i++) 275 for (var i = 0; selectors.length > 0; i++)
230 { 276 {
231 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); 277 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", ");
232 style.sheet.insertRule(selector + " { display: none !important; }", i); 278 style.sheet.insertRule(selector + " { display: none !important; }", i);
233 } 279 }
280
281 if (response.trace)
282 traceHiddenElements(document, response.selectors);
234 }; 283 };
235 284
236 setRules(); 285 setRules();
237 reinjectRulesWhenRemoved(document, style); 286 reinjectRulesWhenRemoved(document, style);
238 }; 287 };
239 288
240 document.addEventListener("error", function(event) 289 document.addEventListener("error", function(event)
241 { 290 {
242 checkCollapse(event.target); 291 checkCollapse(event.target);
243 }, true); 292 }, true);
(...skipping 19 matching lines...) Expand all
263 }, true); 312 }, true);
264 313
265 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 314 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
266 } 315 }
267 316
268 if (document instanceof HTMLDocument) 317 if (document instanceof HTMLDocument)
269 { 318 {
270 checkSitekey(); 319 checkSitekey();
271 init(document); 320 init(document);
272 } 321 }
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