Skip to content

Commit 80dcfca

Browse files
authored
Add windows browser specific content scripts (#109)
* Add windows browser specific content scripts * Fix generated windows content scope script * Add windows permission usage script as a feature * Fix line ending of built chrome script
1 parent 50df895 commit 80dcfca

File tree

14 files changed

+6613
-184
lines changed

14 files changed

+6613
-184
lines changed

build/apple/contentScope.js

Lines changed: 1102 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/chrome/inject.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/firefox/inject.js

Lines changed: 380 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/integration/contentScope.js

Lines changed: 380 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/windows/contentScope.js

Lines changed: 4326 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inject/apple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global contentScopeFeatures */
22

3-
import { processConfig } from './../src/apple-utils'
3+
import { processConfig } from './../src/utils'
44

55
function init () {
66
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$)

inject/windows.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* global contentScopeFeatures */
2+
3+
import { processConfig, windowsSpecificFeatures } from './../src/utils'
4+
5+
function init () {
6+
const processedConfig = processConfig($CONTENT_SCOPE$, $USER_UNPROTECTED_DOMAINS$, $USER_PREFERENCES$, windowsSpecificFeatures)
7+
8+
contentScopeFeatures.load()
9+
10+
contentScopeFeatures.init(processedConfig)
11+
12+
// Not supported:
13+
// contentScopeFeatures.update(message)
14+
}
15+
16+
init()

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"postinstall": "npm run copy-sjcl",
66
"copy-sjcl": "node scripts/generateSJCL.js",
77
"bundle-config": "node scripts/bundleConfig.mjs",
8-
"build": "npm run build-firefox && npm run build-chrome && npm run build-apple && npm run build-integration",
8+
"build": "npm run build-firefox && npm run build-chrome && npm run build-apple && npm run build-windows && npm run build-integration",
99
"build-firefox": "mkdir -p build/firefox/ && node scripts/inject.mjs firefox > build/firefox/inject.js",
1010
"build-chrome": "mkdir -p build/chrome/ && node scripts/inject.mjs chrome > build/chrome/inject.js",
1111
"build-apple": "mkdir -p build/apple/ && node scripts/inject.mjs apple > build/apple/contentScope.js",
12+
"build-windows": "mkdir -p build/windows/ && node scripts/inject.mjs windows > build/windows/contentScope.js",
1213
"build-integration": "mkdir -p build/integration/ && node scripts/inject.mjs integration > build/integration/contentScope.js && npm run copy-build-integration",
1314
"copy-build-integration": "cp build/integration/contentScope.js integration-test/extension",
1415
"tsc": "tsc",

scripts/generateSJCL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function init () {
1010
return
1111
}
1212

13-
await exec('cd node_modules/sjcl/ && ./configure --no-export --compress=none --without-all --with-hmac --with-codecHex && make')
13+
await exec('cd node_modules/sjcl/ && perl ./configure --no-export --compress=none --without-all --with-hmac --with-codecHex && make')
1414
const sjclFileContents = await fs.readFile('node_modules/sjcl/sjcl.js')
1515
// Reexport the file as es6 module format
1616
const contents = `// @ts-nocheck

scripts/inject.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ async function init() {
5050
initOther('inject/mozilla.js', process.argv[2]);
5151
} else if (process.argv[2] == "apple") {
5252
initOther('inject/apple.js', process.argv[2]);
53+
} else if (process.argv[2] == "windows") {
54+
initOther('inject/windows.js', process.argv[2]);
5355
} else if (process.argv[2] == "integration") {
5456
initOther('inject/integration.js', process.argv[2]);
5557
} else {
@@ -71,7 +73,8 @@ async function initChrome() {
7173
const injectScript = await readFile(injectScriptPath);
7274
const contentScope = await rollupScript(contentScopePath, contentScopeName);
7375
// Encode in URI format to prevent breakage (we could choose to just escape ` instead)
74-
const encodedString = encodeURI(contentScope.toString());
76+
// NB: .replace(/\r\n/g, "\n") is needed because in Windows rollup generates CRLF line endings
77+
const encodedString = encodeURI(contentScope.toString().replace(/\r\n/g, "\n"));
7578
const outputScript = injectScript.toString().replace(replaceString, '${decodeURI("' + encodedString + '")}');
7679
console.log(outputScript);
7780
}

0 commit comments

Comments
 (0)