Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 this.observer.disconnect(); | 337 this.observer.disconnect(); |
338 clearTimeout(this.timeout); | 338 clearTimeout(this.timeout); |
339 } | 339 } |
340 }; | 340 }; |
341 | 341 |
342 function ElemHide() | 342 function ElemHide() |
343 { | 343 { |
344 this.shadow = this.createShadowTree(); | 344 this.shadow = this.createShadowTree(); |
345 this.styles = new Map(); | 345 this.styles = new Map(); |
346 this.tracer = null; | 346 this.tracer = null; |
347 this.inline = true; | 347 this.inline = true; |
kzar
2018/01/24 14:30:53
How come you renamed this one? (I'm not against re
Manish Jethani
2018/01/24 16:37:44
Yeah, this was for clarity [1] since we already us
kzar
2018/01/25 11:52:37
Acknowledged.
| |
348 this.emulatedPatterns = null; | 348 this.emulatedPatterns = null; |
349 | 349 |
350 this.elemHideEmulation = new ElemHideEmulation( | 350 this.elemHideEmulation = new ElemHideEmulation( |
351 this.addSelectors.bind(this), | 351 this.addSelectors.bind(this), |
352 this.hideElements.bind(this) | 352 this.hideElements.bind(this) |
353 ); | 353 ); |
354 } | 354 } |
355 ElemHide.prototype = { | 355 ElemHide.prototype = { |
356 selectorGroupSize: 200, | 356 selectorGroupSize: 200, |
357 | 357 |
(...skipping 14 matching lines...) Expand all Loading... | |
372 // Finally since some users have both AdBlock and Adblock Plus installed we | 372 // Finally since some users have both AdBlock and Adblock Plus installed we |
373 // have to consider how the two extensions interact. For example we want to | 373 // have to consider how the two extensions interact. For example we want to |
374 // avoid creating the shadowRoot twice. | 374 // avoid creating the shadowRoot twice. |
375 let shadow = document.documentElement.shadowRoot || | 375 let shadow = document.documentElement.shadowRoot || |
376 document.documentElement.createShadowRoot(); | 376 document.documentElement.createShadowRoot(); |
377 shadow.appendChild(document.createElement("shadow")); | 377 shadow.appendChild(document.createElement("shadow")); |
378 | 378 |
379 return shadow; | 379 return shadow; |
380 }, | 380 }, |
381 | 381 |
382 addSelectorsInline(selectors, filters, groupName) | 382 addSelectorsInline(selectors, groupName) |
kzar
2018/01/24 14:30:53
Just me or is the `filters` parameter not used?
Manish Jethani
2018/01/24 16:37:44
True, removed.
| |
383 { | 383 { |
384 let style = this.styles.get(groupName); | 384 let style = this.styles.get(groupName); |
385 | 385 |
386 if (style) | 386 if (style) |
387 { | 387 { |
388 while (style.sheet.cssRules.length > 0) | 388 while (style.sheet.cssRules.length > 0) |
389 style.sheet.deleteRule(0); | 389 style.sheet.deleteRule(0); |
390 } | 390 } |
391 | 391 |
392 if (selectors.length == 0) | 392 if (selectors.length == 0) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 { | 451 { |
452 // Insert the style rules inline if we have been instructed by the | 452 // Insert the style rules inline if we have been instructed by the |
453 // background page to do so. This is usually the case, except on platforms | 453 // background page to do so. This is usually the case, except on platforms |
454 // that do support user stylesheets via the browser.tabs.insertCSS API | 454 // that do support user stylesheets via the browser.tabs.insertCSS API |
455 // (Firefox 53 onwards for now and possibly Chrome in the near future). | 455 // (Firefox 53 onwards for now and possibly Chrome in the near future). |
456 // Once all supported platforms have implemented this API, we can remove | 456 // Once all supported platforms have implemented this API, we can remove |
457 // the code below. See issue #5090. | 457 // the code below. See issue #5090. |
458 // Related Chrome and Firefox issues: | 458 // Related Chrome and Firefox issues: |
459 // https://bugs.chromium.org/p/chromium/issues/detail?id=632009 | 459 // https://bugs.chromium.org/p/chromium/issues/detail?id=632009 |
460 // https://bugzilla.mozilla.org/show_bug.cgi?id=1310026 | 460 // https://bugzilla.mozilla.org/show_bug.cgi?id=1310026 |
461 this.addSelectorsInline(selectors, filters, "emulated"); | 461 this.addSelectorsInline(selectors, "emulated"); |
462 } | 462 } |
463 else | 463 else |
464 { | 464 { |
465 browser.runtime.sendMessage({ | 465 browser.runtime.sendMessage({ |
466 type: "elemhide.injectSelectors", | 466 type: "elemhide.injectSelectors", |
467 selectors, | 467 selectors, |
468 groupName: "emulated" | 468 groupName: "emulated" |
469 }); | 469 }); |
470 } | 470 } |
471 | 471 |
(...skipping 23 matching lines...) Expand all Loading... | |
495 if (this.tracer) | 495 if (this.tracer) |
496 this.tracer.disconnect(); | 496 this.tracer.disconnect(); |
497 this.tracer = null; | 497 this.tracer = null; |
498 | 498 |
499 if (response.trace) | 499 if (response.trace) |
500 this.tracer = new ElementHidingTracer(); | 500 this.tracer = new ElementHidingTracer(); |
501 | 501 |
502 this.inline = response.inline; | 502 this.inline = response.inline; |
503 | 503 |
504 if (this.inline) | 504 if (this.inline) |
505 this.addSelectorsInline(response.selectors); | 505 this.addSelectorsInline(response.selectors, "standard"); |
kzar
2018/01/24 14:30:53
Shouldn't we pass the other parameters (well `grou
Manish Jethani
2018/01/24 16:37:44
Yeah so the default group is undefined. We could j
kzar
2018/01/25 11:52:37
Yea, I think making the name here explicit would m
Manish Jethani
2018/01/25 14:29:33
OK, I'm using the name "standard" here since these
| |
506 | 506 |
507 if (this.tracer) | 507 if (this.tracer) |
508 this.tracer.addSelectors(response.selectors); | 508 this.tracer.addSelectors(response.selectors); |
509 | 509 |
510 this.elemHideEmulation.apply(response.emulatedPatterns); | 510 this.elemHideEmulation.apply(response.emulatedPatterns); |
511 }); | 511 }); |
512 } | 512 } |
513 }; | 513 }; |
514 | 514 |
515 if (document instanceof HTMLDocument) | 515 if (document instanceof HTMLDocument) |
516 { | 516 { |
517 checkSitekey(); | 517 checkSitekey(); |
518 | 518 |
519 elemhide = new ElemHide(); | 519 elemhide = new ElemHide(); |
520 elemhide.apply(); | 520 elemhide.apply(); |
521 | 521 |
522 document.addEventListener("error", event => | 522 document.addEventListener("error", event => |
523 { | 523 { |
524 checkCollapse(event.target); | 524 checkCollapse(event.target); |
525 }, true); | 525 }, true); |
526 | 526 |
527 document.addEventListener("load", event => | 527 document.addEventListener("load", event => |
528 { | 528 { |
529 let element = event.target; | 529 let element = event.target; |
530 if (/^i?frame$/.test(element.localName)) | 530 if (/^i?frame$/.test(element.localName)) |
531 checkCollapse(element); | 531 checkCollapse(element); |
532 }, true); | 532 }, true); |
533 } | 533 } |
534 | 534 |
535 module.exports = { | 535 window.checkCollapse = checkCollapse; |
536 checkCollapse, | 536 window.elemhide = elemhide; |
537 elemhide, | 537 window.typeMap = typeMap; |
538 typeMap, | 538 window.getURLsFromElement = getURLsFromElement; |
539 getURLsFromElement | |
540 }; | |
LEFT | RIGHT |