| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 if ((!selector || target.matches(selector)) && | 484 if ((!selector || target.matches(selector)) && |
| 485 (!re || re.test(target.textContent))) | 485 (!re || re.test(target.textContent))) |
| 486 { | 486 { |
| 487 event.preventDefault(); | 487 event.preventDefault(); |
| 488 } | 488 } |
| 489 }, | 489 }, |
| 490 true); | 490 true); |
| 491 } | 491 } |
| 492 | 492 |
| 493 exports["prevent-inline-scripts"] = preventInlineScripts; | 493 exports["prevent-inline-scripts"] = preventInlineScripts; |
| 494 | |
| 495 /** | |
| 496 * Generate an alpha-numeric id 6 chars long, in the range 100000..zzzzzz. | |
|
Manish Jethani
2018/10/24 23:02:10
Some nits:
s/Generate/Generates/
s/an alpha-nume
hub
2018/10/25 14:32:27
Done.
| |
| 497 * | |
| 498 * @returns {string} the random id. | |
| 499 */ | |
| 500 function randomId() | |
| 501 { | |
| 502 // 2176782336 is 36^6 which mean 6 chars [a-z0-9] | |
| 503 // 60466176 is 36^5 | |
| 504 // 2176782336 - 60466176 = 2116316160. This ensure to always have 6 | |
| 505 // chars even if Math.random() returns its minimum value 0.0 | |
| 506 return Math.floor(Math.random() * 2116316160 + 60466176).toString(36); | |
| 507 } | |
| 508 | |
| 509 function wrapPropertyAccess(object, property, descriptor) | |
| 510 { | |
| 511 // simple property | |
|
Manish Jethani
2018/10/24 23:02:10
Do we need this comment? The code is quite straigh
hub
2018/10/25 14:32:28
was carried over from other changes. removed it.
| |
| 512 let currentDescriptor = Object.getOwnPropertyDescriptor(object, property); | |
| 513 if (!currentDescriptor) | |
| 514 currentDescriptor = {}; | |
| 515 if (typeof descriptor.get != "undefined") | |
| 516 { | |
| 517 if (currentDescriptor.get != descriptor.get) | |
|
Manish Jethani
2018/10/24 23:02:10
I'm not seeing the point of this check.
hub
2018/10/25 14:32:28
Done.
| |
| 518 currentDescriptor.get = descriptor.get; | |
| 519 } | |
| 520 if (typeof descriptor.set != "undefined") | |
| 521 { | |
| 522 if (currentDescriptor.set != descriptor.set) | |
| 523 currentDescriptor.set = descriptor.set; | |
| 524 } | |
| 525 Object.defineProperty(object, property, currentDescriptor); | |
| 526 } | |
| 527 | |
| 528 /** | |
| 529 * Will patch a property on the window object to abort when read. | |
| 530 * It will intercept the onerror callback and block it if tagged. | |
| 531 * | |
| 532 * @todo handle properties of properties. | |
| 533 * | |
| 534 * @param {string} property the name of the property. | |
| 535 */ | |
| 536 function abortOnPropertyRead(property) | |
| 537 { | |
| 538 if (!property) | |
| 539 return; | |
| 540 | |
| 541 let rid = randomId(); | |
| 542 | |
| 543 function abort() | |
| 544 { | |
| 545 throw new ReferenceError(rid); | |
| 546 } | |
| 547 | |
| 548 let {onerror} = window; | |
| 549 window.onerror = (message, ...rest) => | |
| 550 { | |
| 551 if (typeof message == "string" && message.includes(rid)) | |
| 552 return true; | |
| 553 if (typeof onerror == "function") | |
| 554 return onerror(message, ...rest); | |
| 555 }; | |
| 556 | |
| 557 wrapPropertyAccess(window, property, {get: abort, set() {}}); | |
| 558 } | |
| 559 | |
| 560 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, | |
| 561 wrapPropertyAccess, | |
| 562 randomId); | |
| OLD | NEW |