Skip to content

Commit a6c8f59

Browse files
authored
#5848 Use Manifest V2 for Thunderbird Port (#5850)
* Use Manifest V2 for Thunderbird Port * remove content_scripts for Gmail * added test for Thunderbird manifest file * revert changes * refactor * test permissions exclusive only for Thunderbird
1 parent 70ee9f3 commit a6c8f59

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

test/source/patterns.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ for (const srcFilePath of getAllFilesInDir('./extension', /\.ts$/)) {
8181
const expectedPermissions: chrome.runtime.ManifestPermissions[] = ['alarms', 'scripting', 'storage', 'tabs', 'unlimitedStorage'];
8282
const expectedConsumerHostPermissions = ['https://*.google.com/*', 'https://www.googleapis.com/*', 'https://flowcrypt.com/*'];
8383
const expectedEnterpriseHostPermissions = ['https://*.google.com/*', 'https://*.googleapis.com/*', 'https://flowcrypt.com/*'];
84-
for (const buildType of ['chrome-consumer', 'chrome-enterprise']) {
84+
for (const buildType of ['chrome-consumer', 'chrome-enterprise', 'thunderbird-consumer', 'firefox-consumer']) {
8585
const manifest = JSON.parse(readFileSync(`./build/${buildType}/manifest.json`).toString()) as chrome.runtime.Manifest;
86+
const isManifestV3Build = buildType.includes('chrome') || buildType.includes('firefox');
8687
const expectedHostPermissions = buildType.includes('consumer') ? expectedConsumerHostPermissions : expectedEnterpriseHostPermissions;
8788
for (const expectedHostPermission of expectedHostPermissions) {
88-
if (!manifest.host_permissions.includes(expectedHostPermission)) {
89+
if (isManifestV3Build && !manifest.host_permissions.includes(expectedHostPermission)) {
8990
console.error(`Missing host permission '${expectedHostPermission}' in ${buildType}/manifest.json`);
9091
errsFound++;
9192
}
@@ -98,9 +99,31 @@ for (const buildType of ['chrome-consumer', 'chrome-enterprise']) {
9899
}
99100
}
100101
}
101-
const gmailCs = manifest.content_scripts?.find(cs => cs.matches?.includes('https://mail.google.com/*'));
102-
if (!gmailCs?.css?.length || !gmailCs.js?.length) {
103-
console.error(`Missing content_scripts declaration for Gmail in ${buildType}/manifest.json`);
102+
if (buildType === 'thunderbird-consumer') {
103+
if (manifest.manifest_version !== 2) {
104+
console.error(`${buildType} - The manifest version is not 2`);
105+
errsFound++;
106+
}
107+
if (!Array.isArray(manifest.web_accessible_resources)) {
108+
console.error(`${buildType} - The web_accessible_resources should be an array`);
109+
errsFound++;
110+
}
111+
if (typeof manifest.content_security_policy !== 'string') {
112+
console.error(`${buildType} - The content_security_policy should be a string`);
113+
errsFound++;
114+
}
115+
const thunderbirdExpectedPermissions = ['compose', 'messagesRead', 'messagesUpdate', 'messagesModify', 'accountsRead'];
116+
const buildHostPermissions = isManifestV3Build ? manifest.host_permissions : manifest.permissions;
117+
for (const expectedHostPermission of thunderbirdExpectedPermissions) {
118+
if (!buildHostPermissions?.includes(expectedHostPermission)) {
119+
console.error(`${buildType} - Missing permission ${expectedHostPermission} in ${buildType}/manifest.json`);
120+
errsFound++;
121+
}
122+
}
123+
}
124+
const extensionContentScript = manifest.content_scripts?.find(cs => cs.matches?.includes('https://mail.google.com/*'));
125+
if (!extensionContentScript?.css?.length || !extensionContentScript.js?.length) {
126+
console.error(`Missing content_scripts declaration for the extension in ${buildType}/manifest.json`);
104127
errsFound++;
105128
}
106129
}

tooling/build-types-and-manifests.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ addManifest('firefox-consumer', manifest => {
4747
addManifest(
4848
'thunderbird-consumer',
4949
manifest => {
50-
(manifest.action as messenger._manifest._WebExtensionManifestAction).default_title = 'FlowCrypt';
50+
// we can continue using Manifest V2 for Thunderbird MailExtension - https://github.com/FlowCrypt/flowcrypt-browser/issues/5848
51+
manifest.manifest_version = 2;
5152
manifest.name = 'FlowCrypt Encryption for Thunderbird';
5253
manifest.description = 'Simple end-to-end encryption to secure email and attachments on Thunderbird';
5354
manifest.permissions = [...(manifest.permissions ?? []), 'compose', 'messagesRead', 'messagesUpdate', 'messagesModify', 'accountsRead'];
55+
const manifestV3 = manifest as chrome.runtime.ManifestV3;
56+
manifest.web_accessible_resources = manifestV3.web_accessible_resources?.[0].resources;
57+
manifest.content_security_policy = manifestV3.content_security_policy?.extension_pages;
58+
manifest.permissions = [...(manifestV3.permissions ?? []), ...(manifestV3.host_permissions ?? [])];
59+
delete manifest.host_permissions;
60+
manifest.browser_action = manifestV3.action;
61+
(manifest.browser_action as messenger._manifest._WebExtensionManifestAction).default_title = 'FlowCrypt';
62+
delete manifest.action;
5463
manifest.compose_action = {
5564
default_title: 'Secure Compose', // eslint-disable-line @typescript-eslint/naming-convention
5665
default_icon: '/img/logo/flowcrypt-logo-64-64.png', // eslint-disable-line @typescript-eslint/naming-convention
@@ -59,6 +68,7 @@ addManifest(
5968
default_title: 'Secure Compose', // eslint-disable-line @typescript-eslint/naming-convention
6069
default_icon: '/img/logo/flowcrypt-logo-64-64.png', // eslint-disable-line @typescript-eslint/naming-convention
6170
};
71+
delete manifest.minimum_chrome_version;
6272
(manifest.browser_specific_settings as messenger._manifest.FirefoxSpecificProperties).strict_min_version = '102.0';
6373
manifest.background = {
6474
type: 'module',

0 commit comments

Comments
 (0)