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

Delta Between Two Patch Sets: lib/content/snippets.js

Issue 29828604: Issue 6790 - Implement uabinject-defuser snippet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Add attribution Created July 13, 2018, 12:59 p.m.
Right Patch Set: Rebase on patch #29829569 Created July 13, 2018, 2:34 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 | « no previous file | no next file » | 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-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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* eslint-env webextensions */ 18 /* eslint-env webextensions */
19 /* eslint no-console: "off" */ 19 /* eslint no-console: "off" */
20 20
21 "use strict"; 21 "use strict";
22 22
23 function injectCode(code) 23 function injectCode(code, dependencies = [])
24 { 24 {
25 for (let dependency of dependencies)
26 code += dependency;
27
25 let script = document.createElement("script"); 28 let script = document.createElement("script");
26 29
27 script.type = "application/javascript"; 30 script.type = "application/javascript";
28 script.async = false; 31 script.async = false;
29 32
30 // Firefox 58 only bypasses site CSPs when assigning to 'src', 33 // Firefox 58 only bypasses site CSPs when assigning to 'src',
31 // while Chrome 67 only bypasses site CSPs when using 'textContent'. 34 // while Chrome 67 only bypasses site CSPs when using 'textContent'.
32 if (browser.runtime.getURL("").startsWith("chrome-extension://")) 35 if (browser.runtime.getURL("").startsWith("chrome-extension://"))
33 { 36 {
34 script.textContent = code; 37 script.textContent = code;
35 document.documentElement.appendChild(script); 38 document.documentElement.appendChild(script);
36 } 39 }
37 else 40 else
38 { 41 {
39 let url = URL.createObjectURL(new Blob([code])); 42 let url = URL.createObjectURL(new Blob([code]));
40 script.src = url; 43 script.src = url;
41 document.documentElement.appendChild(script); 44 document.documentElement.appendChild(script);
42 URL.revokeObjectURL(url); 45 URL.revokeObjectURL(url);
43 } 46 }
44 47
45 document.documentElement.removeChild(script); 48 document.documentElement.removeChild(script);
46 } 49 }
47 50
48 function stringifyFunctionCall(func, ...params) 51 function stringifyFunctionCall(func, ...params)
49 { 52 {
50 return `"use strict";(${func})(${params.map(JSON.stringify).join(",")});`; 53 return `"use strict";(${func})(${params.map(JSON.stringify).join(",")});`;
51 } 54 }
52 55
53 function makeInjector(injectable) 56 function makeInjector(injectable, ...dependencies)
54 { 57 {
55 return (...args) => injectCode(stringifyFunctionCall(injectable, ...args)); 58 return (...args) => injectCode(stringifyFunctionCall(injectable, ...args),
59 dependencies);
56 } 60 }
57 61
58 function log(...args) 62 function log(...args)
59 { 63 {
60 console.log(...args); 64 console.log(...args);
61 } 65 }
62 66
63 exports.log = log; 67 exports.log = log;
68
69 function trace(...args)
70 {
71 log(...args);
72 }
73
74 exports.trace = makeInjector(trace, log);
64 75
65 // This is an implementation of the uabinject-defuser technique used by uBlock 76 // This is an implementation of the uabinject-defuser technique used by uBlock
66 // Origin 77 // Origin
67 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd 89d43caa/filters/resources.txt#L640 78 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd 89d43caa/filters/resources.txt#L640
68 function uabinjectDefuser() 79 function uabinjectDefuser()
69 { 80 {
70 window.trckd = true; 81 window.trckd = true;
71 window.uabpdl = true; 82 window.uabpdl = true;
72 window.uabInject = true; 83 window.uabInject = true;
73 window.uabDetect = true; 84 window.uabDetect = true;
74 } 85 }
75 86
76 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser); 87 exports["uabinject-defuser"] = makeInjector(uabinjectDefuser);
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld