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

Side by Side Diff: lib/content/snippets.js

Issue 29886700: Issue 6969 - Implement abort-on-property-read snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Minor style changes Created Oct. 3, 2018, 10:19 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 | « no previous file | no next file » | 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-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
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 function randomId()
496 {
497 // 2176782336 is 36^6 which mean 6 chars [a-z0-9]
498 // 60466176 is 36^5
499 // 2176782336 - 60466176 = 2116316160. This ensure always 6 chars
500 // for when Math.random() returns 0.0
501 return Math.floor(Math.random() * 2116316160 + 60466176).toString(36);
502 }
503
504 /**
505 * Will patch a property on the window object to abort when read.
506 * It will intercept the onerror callback and block it if tagged.
507 *
508 * @todo handle properties of properties.
509 *
510 * @param {string} prop the name of the property.
511 */
512 function abortOnPropertyRead(prop)
513 {
514 if (!prop)
515 return;
516
517 let rid = randomId();
518
519 function canceller()
520 {
521 throw new ReferenceError(rid);
522 }
523
524 let {onerror} = window;
525 window.onerror = (message, ...rest) =>
526 {
527 if (typeof message == "string" && message.includes(rid))
528 return true;
529 if (onerror && typeof onerror == "function")
530 return onerror(this, message, ...rest);
Manish Jethani 2018/10/23 15:31:24 This needs to be onerror.call
hub 2018/10/23 18:23:17 Done.
531 };
532
533 (function(o, p)
Manish Jethani 2018/10/23 15:31:24 I think this should be a separate function: fun
hub 2018/10/23 18:23:17 Done.
534 {
535 // simple property
536 let d = Object.getOwnPropertyDescriptor(o, p);
537 if (!d || d.get != canceller)
538 Object.defineProperty(o, p, {get: canceller, set() {}});
539 })(window, prop);
540 }
541
542 exports["abort-on-property-read"] = makeInjector(abortOnPropertyRead, randomId);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld