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

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

Issue 29828610: Issue 6791 - Implement abort-current-inline-script snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created July 12, 2018, 5:38 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 exports.log = log; 62 exports.log = log;
63 63
64 function uabinjectDefuser() 64 function uabinjectDefuser()
65 { 65 {
66 window.trckd = window.uabpdl = window.uabInject = window.uabDetect = true; 66 window.trckd = window.uabpdl = window.uabInject = window.uabDetect = true;
67 } 67 }
68 68
69 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); 69 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser);
70
71 function abortCurrentInlineScript(target, needle)
72 {
73 "use strict";
74
75 if (!target)
76 return;
77
78 let reText = ".?";
79
80 if (needle)
81 {
82 reText = /^\/.+\/$/.test(needle) ?
83 needle.slice(1, -1) :
84 needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
85 }
86
87 let re = new RegExp(reText);
88 let chain = target.split(".");
89
90 let owner = window;
91 let property = null;
92
93 while (true)
94 {
95 property = chain.shift();
96 if (chain.length == 0)
97 break;
98
99 owner = owner[property];
100 if (!(owner instanceof Object))
101 return;
102 }
103
104 let descriptor = Object.getOwnPropertyDescriptor(owner, property);
105 if (descriptor && descriptor.get)
106 return;
107
108 let magic = String.fromCharCode(Date.now() % 26 + 97) +
109 Math.floor(Math.random() * 982451653 + 982451653).toString(36);
110 let value = owner[property];
111
112 let validate = () =>
113 {
114 let element = document.currentScript;
115 if (element instanceof HTMLScriptElement &&
116 element.src == "" && re.test(element.textContent))
117 {
118 throw new ReferenceError(magic);
119 }
120 };
121
122 Object.defineProperty(owner, property, {
123 get()
124 {
125 validate();
126 return value;
127 },
128 set(newValue)
129 {
130 validate();
131 value = newValue;
132 }
133 });
134
135 let {onerror} = window;
136 window.onerror = function(message, ...rest)
137 {
138 if (typeof message == "string" && message.indexOf(magic) != -1)
139 return true;
140
141 if (onerror instanceof Function)
142 return onerror.call(this, message, ...rest);
143 };
144 }
145
146 exports["abort-current-inline-script"] = makeInjector(abortCurrentInlineScript);
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