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

Delta Between Two Patch Sets: include.preload.js

Issue 29331619: Issue 2397 - Integrate CSS property filters into adblockpluschrome (Closed)
Left Patch Set: Adjust code now that CSSPropertyFilters is a class Created Nov. 30, 2015, 5:37 p.m.
Right Patch Set: Updated adblockplus dependency again Created Dec. 12, 2015, 12:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « dependencies ('k') | metadata.common » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 279
280 return result; 280 return result;
281 } 281 }
282 282
283 function init(document) 283 function init(document)
284 { 284 {
285 var shadow = null; 285 var shadow = null;
286 var style = null; 286 var style = null;
287 var observer = null; 287 var observer = null;
288 var propertyFilters = new CSSPropertyFilters(window, addElemHideSelectors);
288 289
289 // Use Shadow DOM if available to don't mess with web pages that rely on 290 // Use Shadow DOM if available to don't mess with web pages that rely on
290 // the order of their own <style> tags (#309). 291 // the order of their own <style> tags (#309).
291 // 292 //
292 // However, creating a shadow root breaks running CSS transitions. So we 293 // However, creating a shadow root breaks running CSS transitions. So we
293 // have to create the shadow root before transistions might start (#452). 294 // have to create the shadow root before transistions might start (#452).
294 // 295 //
295 // Also, using shadow DOM causes issues on some Google websites, 296 // Also, using shadow DOM causes issues on some Google websites,
296 // including Google Docs and Gmail (#1770, #2602). 297 // including Google Docs and Gmail (#1770, #2602).
297 if ("createShadowRoot" in document.documentElement && !/\.google\.com$/.test(d ocument.domain)) 298 if ("createShadowRoot" in document.documentElement && !/\.google\.com$/.test(d ocument.domain))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 333
333 // WebKit (and Blink?) apparently chokes when the selector list in a 334 // WebKit (and Blink?) apparently chokes when the selector list in a
334 // CSS rule is huge. So we split the elemhide selectors into groups. 335 // CSS rule is huge. So we split the elemhide selectors into groups.
335 while (selectors.length > 0) 336 while (selectors.length > 0)
336 { 337 {
337 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", "); 338 var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", ");
338 style.sheet.addRule(selector, "display: none !important;"); 339 style.sheet.addRule(selector, "display: none !important;");
339 } 340 }
340 }; 341 };
341 342
342 var updateStylesheet = function(propertyFilters) 343 var updateStylesheet = function()
kzar 2015/11/30 17:57:32 I deliberately added a typo in the propertFilters
kzar 2015/12/01 10:46:04 OK I think I understand now, this function is only
343 { 344 {
344 var selectors = null; 345 var selectors = null;
345 var CSSPropertyFiltersLoaded = false; 346 var CSSPropertyFiltersLoaded = false;
346 347
347 var checkLoaded = function() 348 var checkLoaded = function()
348 { 349 {
349 if (!selectors || !CSSPropertyFiltersLoaded) 350 if (!selectors || !CSSPropertyFiltersLoaded)
350 return; 351 return;
351 352
352 if (observer) 353 if (observer)
(...skipping 14 matching lines...) Expand all
367 checkLoaded(); 368 checkLoaded();
368 }); 369 });
369 370
370 propertyFilters.load(function() 371 propertyFilters.load(function()
371 { 372 {
372 CSSPropertyFiltersLoaded = true; 373 CSSPropertyFiltersLoaded = true;
373 checkLoaded(); 374 checkLoaded();
374 }); 375 });
375 }; 376 };
376 377
377 ext.backgroundPage.sendMessage({type: "get-selectors"}, addElemHideSelectors); 378 updateStylesheet();
Sebastian Noack 2015/12/10 10:30:49 Any reason we use different logic on initilization
kzar 2015/12/10 15:16:20 No reason that I know of, Done.
378 379
379 document.addEventListener("error", function(event) 380 document.addEventListener("error", function(event)
380 { 381 {
381 checkCollapse(event.target); 382 checkCollapse(event.target);
382 }, true); 383 }, true);
383 384
384 document.addEventListener("load", function(event) 385 document.addEventListener("load", function(event)
385 { 386 {
386 var element = event.target; 387 var element = event.target;
387 388
(...skipping 19 matching lines...) Expand all
407 // Moreover, "load" and "error" events aren't dispatched for elements 408 // Moreover, "load" and "error" events aren't dispatched for elements
408 // in dynamically created frames due to https://crbug.com/442107. 409 // in dynamically created frames due to https://crbug.com/442107.
409 // So we also have to apply element collpasing from the parent frame. 410 // So we also have to apply element collpasing from the parent frame.
410 if (!contentWindow.collapsing) 411 if (!contentWindow.collapsing)
411 [].forEach.call(contentDocument.querySelectorAll(Object.keys(typeMap ).join(",")), checkCollapse); 412 [].forEach.call(contentDocument.querySelectorAll(Object.keys(typeMap ).join(",")), checkCollapse);
412 } 413 }
413 } 414 }
414 } 415 }
415 }, true); 416 }, true);
416 417
417 if (window.document == document) 418 return updateStylesheet;
Sebastian Noack 2015/12/10 10:30:49 Why don't you just put this code below, outside th
kzar 2015/12/10 15:16:20 Done.
418 {
419 window.updateStylesheet = updateStylesheet.bind(
420 null, new CSSPropertyFilters(window, addElemHideSelectors)
421 );
422 }
423 } 419 }
424 420
425 if (document instanceof HTMLDocument) 421 if (document instanceof HTMLDocument)
426 { 422 {
427 checkSitekey(); 423 checkSitekey();
428 init(document); 424 window.updateStylesheet = init(document);
429 } 425 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld