Skip to content

Commit 3665ffb

Browse files
authored
Ghostery 10: Selective blocking (#1512)
1 parent d254240 commit 3665ffb

File tree

96 files changed

+3569
-1092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3569
-1092
lines changed

extension-manifest-v2/app/panel-android/index.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
import React from 'react';
1919
import ReactDOM from 'react-dom';
20-
import '@ghostery/ui/pages';
2120

2221
import PanelAndroid from './components/PanelAndroid';
22+
import '../panel/elements/onboarding-state';
23+
2324
import '../scss/panel_android.scss';
2425

2526
ReactDOM.render(

extension-manifest-v2/app/panel/components/Summary.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import React from 'react';
1515
import { ReactSVG } from 'react-svg';
1616
import ClassNames from 'classnames';
17-
import '@ghostery/ui/pages';
1817

18+
import '../elements/onboarding-state';
1919
import Tooltip from '../../shared-components/Tooltip';
2020
import DynamicUIPortContext from '../contexts/DynamicUIPortContext';
2121
import { sendMessage } from '../utils/msg';

packages/ui/src/modules/global/components/onboarding-state.js extension-manifest-v2/app/panel/elements/onboarding-state.js

+19-13
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
* file, You can obtain one at http://mozilla.org/MPL/2.0
1010
*/
1111

12-
import { html } from 'hybrids';
12+
import { define, html } from 'hybrids';
1313

14-
export default {
15-
disabled: false,
16-
href: '',
17-
render: ({ disabled, href }) => html`
14+
export default define({
15+
tag: 'ui-onboarding-state',
16+
disabled: false,
17+
href: '',
18+
render: ({ disabled, href }) => html`
1819
<template
1920
layout="column content:center relative"
2021
layout[disabled]="height::120px"
@@ -25,22 +26,21 @@ export default {
2526
id="disabled"
2627
layout="column center gap:2 margin absolute inset layer:1"
2728
>
28-
<ui-text type="label-m" color="error-500" layout="block:center">
29+
<span layout="block:center">
2930
<ui-icon name="warning" layout="block inline"></ui-icon><br />
3031
Additional Permissions Required
31-
</ui-text>
32-
<ui-text class="button" type="label-m" color="white">
32+
</span>
33+
<span class="button">
3334
Enable Ghostery
34-
</ui-text>
35+
</span>
3536
<a layout="absolute inset layer:3" href="${href}" target="_blank"></a>
3637
</section>
3738
`}
3839
<div id="content"><slot></slot></div>
3940
</template>
4041
`.css`
41-
4242
:host([disabled]) {
43-
border: 1px dashed var(--ui-color-error-500);
43+
border: 1px dashed #ff4500;
4444
border-radius: 4px;
4545
}
4646
@@ -57,7 +57,13 @@ export default {
5757
background: rgba(255, 243, 238, 0.8);
5858
}
5959
60-
ui-text.button {
60+
span {
61+
font: 500 14px / 18px Roboto, sans-serif;
62+
color: #ff4500;
63+
}
64+
65+
span.button {
66+
color: white;
6167
background: #00AEF0;
6268
border-radius: 2px;
6369
padding: 8px 12px;
@@ -67,4 +73,4 @@ export default {
6773
z-index: 0;
6874
}
6975
`,
70-
};
76+
});

extension-manifest-v2/app/scss/panel.scss

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
// Import shared helpers
2424
@import 'shared_helper_classes';
2525

26-
// ghostery-ui
27-
// @import "@ghostery/ui/src/styles/pages.css";
28-
2926
html body {
3027
margin: 0px;
3128
font-size: 75%;

extension-manifest-v2/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"foundation-sites": "^6.6.2",
5252
"ghostery-common": "^1.3.12",
5353
"history": "^4.10.1",
54-
"hybrids": "^8.2.14",
54+
"hybrids": "^8.2.22",
5555
"linkedom": "^0.16.11",
5656
"moment": "^2.29.1",
5757
"prop-types": "^15.6.2",

extension-manifest-v3/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
"scripts": {
77
"download-engines": "node scripts/download-engines/index.js",
88
"download-whotracksme-bloomfilter": "node scripts/download-whotracksme-bloomfilter.js",
9-
"download": "npm run download-engines && npm run download-whotracksme-bloomfilter",
10-
"download.staging": "npm run download-engines -- --staging && npm run download-whotracksme-bloomfilter",
119
"build": "node scripts/build.js",
1210
"start": "npm run build -- --watch",
1311
"licenses": "license-report --config=../.license-report-config.json > dist/licenses.html",
1412
"lint": "eslint src/",
15-
"test": "npm run lint",
13+
"test": "node --test && npm run lint",
1614
"locales.ui": "hybrids extract -c --format=chrome.i18n ../node_modules/@ghostery/ui ./src/_locales/en/messages.json",
1715
"locales.src": "hybrids extract -c --format=chrome.i18n ./src ./src/_locales/en/messages.json",
1816
"locales": "npm run locales.ui && npm run locales.src",
@@ -28,8 +26,10 @@
2826
"license": "MPL-2.0",
2927
"devDependencies": {
3028
"shelljs": "^0.8.5",
29+
"sinon-chrome": "^3.0.1",
3130
"vite": "^4.5.2",
32-
"web-ext": "^7.11.0"
31+
"web-ext": "^7.11.0",
32+
"webextension-polyfill": "^0.11.0"
3333
},
3434
"dependencies": {
3535
"@cliqz/adblocker": "^1.27.1",
@@ -40,7 +40,7 @@
4040
"@ghostery/ui": "^1.0.0",
4141
"@github/relative-time-element": "^4.3.0",
4242
"@whotracksme/webextension-packages": "^5.0.11",
43-
"hybrids": "^8.2.14",
43+
"hybrids": "^8.2.22",
4444
"idb": "^7.1.1",
4545
"jwt-decode": "^4.0.0",
4646
"tldts-experimental": "^6.0.19"

extension-manifest-v3/scripts/build.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { resolve, dirname } from 'path';
2-
import { readFileSync, writeFileSync } from 'fs';
1+
import { resolve, dirname, join } from 'path';
2+
import { readFileSync, writeFileSync, readdirSync } from 'fs';
33
import { exec, execSync } from 'child_process';
44
import { build } from 'vite';
55
import shelljs from 'shelljs';
@@ -67,14 +67,16 @@ if (argv.target === 'safari') {
6767
options.assets.push('background/safari');
6868
}
6969

70+
// Download adblocker engines
7071
if (argv.staging) {
71-
execSync('npm run download.staging', { stdio: 'inherit' });
72-
72+
execSync('npm run download-engines -- --staging', { stdio: 'inherit' });
7373
manifest.debug = true;
7474
} else {
75-
execSync('npm run download', { stdio: 'inherit' });
75+
execSync('npm run download-engines', { stdio: 'inherit' });
7676
}
7777

78+
execSync('npm run download-whotracksme-bloomfilter', { stdio: 'inherit' });
79+
7880
const config = {
7981
logLevel: argv.silent ? 'silent' : undefined,
8082
configFile: false,
@@ -114,7 +116,7 @@ options.assets.forEach((path) => {
114116
// copy adblocker engines
115117
shelljs.mkdir('-p', resolve(options.outDir, 'rule_resources'));
116118

117-
const engines = ['ads', 'tracking', 'annoyances'];
119+
const engines = ['ads', 'tracking', 'annoyances', 'fixes'];
118120
const engineType = argv.target === 'firefox' ? '' : '-cosmetics';
119121

120122
engines.forEach((engine) => {
@@ -173,6 +175,10 @@ execSync('npm run licenses', { stdio: 'inherit' });
173175
// set manifest version from package.json
174176
manifest.version = pkg.version;
175177

178+
if (manifest.permissions.includes('declarativeNetRequest') && argv.watch) {
179+
manifest.permissions.push('declarativeNetRequestFeedback');
180+
}
181+
176182
writeFileSync(
177183
resolve(options.outDir, 'manifest.json'),
178184
JSON.stringify(manifest, null, 2),
@@ -191,6 +197,20 @@ if (manifest.browser_action?.default_popup) {
191197
source.push(manifest.browser_action.default_popup);
192198
}
193199

200+
// offscreen documents
201+
if (
202+
manifest.permissions.includes('offscreen') ||
203+
manifest.optional_permissions?.includes('offscreen')
204+
) {
205+
readdirSync(join(options.srcDir, 'pages', 'offscreen'), {
206+
withFileTypes: true,
207+
})
208+
.filter((dirent) => dirent.isDirectory() && !dirent.name.startsWith('.'))
209+
.forEach((dirent) =>
210+
source.push(join('pages', 'offscreen', dirent.name, 'index.html')),
211+
);
212+
}
213+
194214
// options page
195215
if (manifest.options_ui?.page) {
196216
source.push(manifest.options_ui?.page);

extension-manifest-v3/scripts/download-engines/index.js

+10-48
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const ENGINES = {
2727
'dnr-cosmetics-ads': 'ads-cosmetics',
2828
'dnr-cosmetics-tracking': 'tracking-cosmetics',
2929
'dnr-cosmetics-annoyances': 'annoyances-cosmetics',
30+
'dnr-fixes': 'fixes',
31+
'dnr-cosmetics-fixes': 'fixes-cosmetics',
3032
'trackerdbMv3': 'trackerdb',
3133
};
3234

@@ -86,17 +88,14 @@ for (const [name, target] of Object.entries(ENGINES)) {
8688
writeFileSync(outputPath, new Uint8Array(rules));
8789
}
8890

89-
const DNR = staging
90-
? {
91-
'dnr-ads': 'ads',
92-
'dnr-tracking': 'tracking',
93-
'dnr-annoyances': 'annoyances',
94-
}
95-
: {
96-
'dnr-ads-2': 'ads',
97-
'dnr-tracking-2': 'tracking',
98-
'dnr-annoyances-2': 'annoyances',
99-
};
91+
const DNR = {
92+
'dnr-ads': 'ads',
93+
'dnr-tracking': 'tracking',
94+
'dnr-annoyances': 'annoyances',
95+
'dnr-fixes': 'fixes',
96+
'dnr-ios': 'safari',
97+
'dnr-trackerdb': 'trackerdb',
98+
};
10099

101100
for (const [name, target] of Object.entries(DNR)) {
102101
console.log(`Downloading "${name}"...`);
@@ -119,7 +118,6 @@ for (const [name, target] of Object.entries(DNR)) {
119118
const outputPath = `${TARGET_PATH}/dnr-${target}.json`;
120119

121120
if (
122-
staging &&
123121
existsSync(outputPath) &&
124122
checksum(readFileSync(outputPath)) === list.dnr.checksum
125123
) {
@@ -140,39 +138,3 @@ for (const [name, target] of Object.entries(DNR)) {
140138
writeFileSync(outputPath, dnr);
141139
}
142140
}
143-
144-
/* DNR for Safari */
145-
146-
console.log(`Downloading "dnr-ios"...`);
147-
const outputPath = `${TARGET_PATH}/dnr-safari.json`;
148-
149-
const list = await fetch(
150-
`https://staging-cdn.ghostery.com/adblocker/configs/dnr-ios/allowed-lists.json`,
151-
).then((res) => {
152-
if (!res.ok) {
153-
throw new Error(
154-
`Failed to download allowed list for dnr-ios": ${res.status}: ${res.statusText}`,
155-
);
156-
}
157-
158-
return res.json();
159-
});
160-
161-
if (
162-
!existsSync(outputPath) ||
163-
checksum(readFileSync(outputPath)) !== list.dnr.checksum
164-
) {
165-
const dnr = await fetch(list.dnr.url || list.dnr.network).then((res) => {
166-
if (!res.ok) {
167-
throw new Error(
168-
`Failed to fetch DNR rules for "${name}": ${res.status}: ${res.statusText}`,
169-
);
170-
}
171-
172-
return res.text();
173-
});
174-
175-
writeFileSync(outputPath, dnr);
176-
} else {
177-
console.log('Checksum match - skipping download');
178-
}

0 commit comments

Comments
 (0)