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: Created July 12, 2018, 4:31 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 no-console: "off" */ 19 /* eslint no-console: "off" */
19 20
20 "use strict"; 21 "use strict";
21 22
22 function injectCode(code) 23 function injectCode(code, dependencies = [])
23 { 24 {
25 for (let dependency of dependencies)
26 code += dependency;
27
24 let script = document.createElement("script"); 28 let script = document.createElement("script");
25 29
26 script.type = "application/javascript"; 30 script.type = "application/javascript";
27 script.async = false; 31 script.async = false;
28 32
29 // Firefox 58 only bypasses site CSPs when assigning to 'src', 33 // Firefox 58 only bypasses site CSPs when assigning to 'src',
30 // while Chrome 67 only bypasses site CSPs when using 'textContent'. 34 // while Chrome 67 only bypasses site CSPs when using 'textContent'.
31 if (browser.runtime.getURL("").startsWith("chrome-extension://")) 35 if (browser.runtime.getURL("").startsWith("chrome-extension://"))
32 { 36 {
33 script.textContent = code; 37 script.textContent = code;
34 document.documentElement.appendChild(script); 38 document.documentElement.appendChild(script);
35 } 39 }
36 else 40 else
37 { 41 {
38 let url = URL.createObjectURL(new Blob([code])); 42 let url = URL.createObjectURL(new Blob([code]));
39 script.src = url; 43 script.src = url;
40 document.documentElement.appendChild(script); 44 document.documentElement.appendChild(script);
41 URL.revokeObjectURL(url); 45 URL.revokeObjectURL(url);
42 } 46 }
43 47
44 document.documentElement.removeChild(script); 48 document.documentElement.removeChild(script);
45 } 49 }
46 50
47 function stringifyFunctionCall(func, ...params) 51 function stringifyFunctionCall(func, ...params)
48 { 52 {
49 return `(${func})(${params.map(JSON.stringify).join(",")});`; 53 return `"use strict";(${func})(${params.map(JSON.stringify).join(",")});`;
50 } 54 }
51 55
52 function makeInjector(injectable) 56 function makeInjector(injectable, ...dependencies)
53 { 57 {
54 return (...args) => injectCode(stringifyFunctionCall(injectable, ...args)); 58 return (...args) => injectCode(stringifyFunctionCall(injectable, ...args),
59 dependencies);
55 } 60 }
56 61
57 function log(...args) 62 function log(...args)
58 { 63 {
59 console.log(...args); 64 console.log(...args);
60 } 65 }
61 66
62 exports.log = log; 67 exports.log = log;
63 68
69 function trace(...args)
70 {
71 log(...args);
72 }
73
74 exports.trace = makeInjector(trace, log);
75
76 // This is an implementation of the uabinject-defuser technique used by uBlock
77 // Origin
78 // https://github.com/uBlockOrigin/uAssets/blob/c091f861b63cd2254b8e9e4628f6bdcd 89d43caa/filters/resources.txt#L640
64 function uabinjectDefuser() 79 function uabinjectDefuser()
65 { 80 {
66 window.trckd = window.uabpdl = window.uabInject = window.uabDetect = true; 81 window.trckd = true;
82 window.uabpdl = true;
83 window.uabInject = true;
84 window.uabDetect = true;
67 } 85 }
68 86
69 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