Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1509 Migrate to Manifest V3 #5607

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2ab84bd
#1509 start manifest v3 migration
sosnovsky Feb 19, 2024
5042b9e
fix
sosnovsky Feb 19, 2024
1377e4a
fix: permissions
ioanmo226 Feb 26, 2024
3abf9f9
feat: use alarms intead of inMemoryStoreGetUntilAvailable
ioanmo226 Feb 26, 2024
e3b3e63
Revert "feat: use alarms intead of inMemoryStoreGetUntilAvailable"
ioanmo226 Feb 26, 2024
03cd8eb
fix: splash screen login issue
ioanmo226 Feb 26, 2024
56b3bdc
feat: (WIP) added custom settimeout and setinterval
ioanmo226 Feb 27, 2024
1049bc3
(WIP) move to settimeout and setinterval to background script
ioanmo226 Feb 28, 2024
05ca615
(WIP) setHandledTimeout and interval
ioanmo226 Feb 28, 2024
02c21fa
fix: CSP issue
ioanmo226 Feb 28, 2024
cb1423a
fix: revert timeout and interval
ioanmo226 Feb 28, 2024
75da801
feat: setinterval
ioanmo226 Feb 29, 2024
cfb4753
temp: disable tap
ioanmo226 Feb 29, 2024
b62bba8
fix: *.google.com manifest issue
ioanmo226 Feb 29, 2024
056d979
fix: oauth2.htm permission issue
ioanmo226 Mar 1, 2024
295c430
fix: trustedTypes error handling
ioanmo226 Mar 4, 2024
52b1004
fix: use openpgp ES module
ioanmo226 Mar 6, 2024
50bd21c
revert: openpgp removal from content script
ioanmo226 Mar 6, 2024
8b2e645
fix: conflicts
ioanmo226 Mar 11, 2024
02b10f5
wip: use webpack to bundle forge
ioanmo226 Mar 12, 2024
2c9bf6f
Merge branch 'master' into 1509-manifest-v3
ioanmo226 Mar 12, 2024
4623cc4
fix: unit test
ioanmo226 Mar 12, 2024
0959d7f
fix: unit test
ioanmo226 Mar 13, 2024
48c31d4
fix: ui test compose - test compose after reconnect account
ioanmo226 Mar 13, 2024
53367ee
feat: added forge mjs
ioanmo226 Mar 15, 2024
3934489
fix: forge
ioanmo226 Mar 18, 2024
df0dc31
fix: network available checK
ioanmo226 Mar 19, 2024
a852f87
fix: google reauth
ioanmo226 Mar 19, 2024
f7cb1cc
fix: replace xmlhttprequest with fetch and wip objurls
ioanmo226 Mar 26, 2024
4262aee
fix: ui test
ioanmo226 Mar 26, 2024
d431fc7
Revert "temp: disable tap"
ioanmo226 Mar 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions extension/chrome/dev/ci_unit_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ContactStore } from '../../js/common/platform/store/contact-store.js';
import { Debug } from '../../js/common/platform/debug.js';
import { Catch } from '../../js/common/platform/catch.js';
import { Url } from '../../js/common/core/common.js';
import * as forge from 'node-forge';
import { Gmail } from '../../js/common/api/email-provider/gmail/gmail.js';
import { PgpHash } from '../../js/common/core/crypto/pgp/pgp-hash.js';
import { PgpArmor } from '../../js/common/core/crypto/pgp/pgp-armor.js';
Expand Down Expand Up @@ -53,5 +52,4 @@ const libs: unknown[] = [
for (const lib of libs) {
(window as any)[(lib as any).name] = lib;
}
(window as any).forge = forge;
/* eslint-enable @typescript-eslint/no-explicit-any */
21 changes: 0 additions & 21 deletions extension/js/background_page/background_page.htm

This file was deleted.

8 changes: 4 additions & 4 deletions extension/js/common/api/email-provider/gmail/gmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class Gmail extends EmailProviderApi implements EmailProviderInterface {
let status: number;
const responsePollInterval = Catch.setHandledInterval(() => {
if (status >= 200 && status <= 299 && (r.responseText.length >= minBytes || treatAs === 'publicKey')) {
window.clearInterval(responsePollInterval);
clearInterval(responsePollInterval);
processChunkAndResolve(r.responseText);
r.abort();
}
Expand All @@ -228,7 +228,7 @@ export class Gmail extends EmailProviderApi implements EmailProviderInterface {
status = r.status;
if (status >= 300) {
reject(AjaxErr.fromXhr({ status, readyState: r.readyState }, { method, url, stack }));
window.clearInterval(responsePollInterval);
clearInterval(responsePollInterval);
r.abort();
}
}
Expand All @@ -237,14 +237,14 @@ export class Gmail extends EmailProviderApi implements EmailProviderInterface {
if (status >= 200 && status <= 299 && (r.responseText.length >= minBytes || treatAs === 'publicKey')) {
// done as a success - resolve in case response_poll didn't catch this yet
processChunkAndResolve(r.responseText);
window.clearInterval(responsePollInterval);
clearInterval(responsePollInterval);
if (r.readyState === 3) {
r.abort();
}
} else {
// done as a fail - reject
reject(AjaxErr.fromXhr({ status, readyState: r.readyState }, { method, url, stack }));
window.clearInterval(responsePollInterval);
clearInterval(responsePollInterval);
}
}
};
Expand Down
43 changes: 38 additions & 5 deletions extension/js/common/browser/browser-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export namespace Bm {
}

type Handler = Bm.AsyncRespondingHandler | Bm.AsyncResponselessHandler;
type IntervalHandler = () => void | Promise<void>;
type Handlers = Dict<Handler>;

export class BgNotReadyErr extends Error {}
Expand Down Expand Up @@ -228,6 +229,7 @@ export class BrowserMsg {
private static readonly processed = new Set<string>(); // or ExpirationCache?
/* eslint-disable @typescript-eslint/naming-convention */
private static HANDLERS_REGISTERED_BACKGROUND: Handlers = {};
private static INTERVAL_HANDLERS: Dict<IntervalHandler> = {};
private static HANDLERS_REGISTERED_FRAME: Handlers = {
set_css: BrowserMsgCommonHandlers.setCss,
add_class: BrowserMsgCommonHandlers.addClass,
Expand All @@ -251,14 +253,14 @@ export class BrowserMsg {
div.style.backgroundColor = '#a44';
div.style.padding = '4px 6px';
const a = document.createElement('a');
a.href = window.location.href.split('#')[0];
a.href = location.href.split('#')[0];
a.textContent = 'RELOAD';
a.style.color = 'white';
a.style.fontWeight = 'bold';
a.style.marginLeft = '12px';
div.appendChild(a);
}
window.document.body.appendChild(div);
document.body.appendChild(div);
}

public static generateTabId(contentScript?: boolean) {
Expand All @@ -285,6 +287,16 @@ export class BrowserMsg {
BrowserMsg.HANDLERS_REGISTERED_BACKGROUND[name] = handler;
}

public static createIntervalAlarm(action: string, ms: number) {
// Create the alarm with delay
const alarmName = `${action}_interval_${Date.now()}_${ms}`;
void chrome.alarms.create(alarmName, { when: Date.now() + ms });
}

public static intervalAddListener(name: string, handler: IntervalHandler) {
BrowserMsg.INTERVAL_HANDLERS[name] = handler;
}

public static bgListen() {
chrome.runtime.onMessage.addListener((msg: Bm.Raw, _sender, rawRespond: (rawRes: Bm.RawResponse) => void) => {
const respondIfPageStillOpen = (response: Bm.RawResponse) => {
Expand Down Expand Up @@ -321,9 +333,30 @@ export class BrowserMsg {
});
}

public static alarmListen() {
const alarmListener = (alarm: { name: string }) => {
const alarmName = alarm.name;
const actionName = alarmName.split('_interval')[0];
if (BrowserMsg.INTERVAL_HANDLERS[actionName]) {
Catch.try(BrowserMsg.INTERVAL_HANDLERS[actionName])();
}
if (alarmName.includes('interval')) {
const splitAry = alarmName.split('_');
const ms = splitAry[splitAry.length - 1];
if (ms) {
// Recreate alarm so that interval can be called again
void chrome.alarms.create(alarmName, { when: Date.now() + parseInt(ms) });
}
}
};

// Listen for the alarm and execute the callback when it triggers, then clear the alarm
chrome.alarms.onAlarm.addListener(alarmListener);
}

protected static listenForWindowMessages(dest: Bm.Dest) {
const extensionOrigin = Env.getExtensionOrigin();
window.addEventListener('message', async e => {
addEventListener('message', async e => {
if (e.origin !== 'https://mail.google.com' && e.origin !== extensionOrigin) return;
const encryptedMsg = e.data as SymEncryptedMessage;
if (BrowserMsg.processed.has(encryptedMsg.uid)) return;
Expand Down Expand Up @@ -438,7 +471,7 @@ export class BrowserMsg {
// todo: can objUrls be deleted by another recipient?
const encryptedMsg = await SymmetricMessageEncryption.encrypt(validMsg);
BrowserMsg.sendToChildren(encryptedMsg);
window.postMessage(encryptedMsg, '*');
postMessage(encryptedMsg, '*');
BrowserMsg.sendUpParentLine(encryptedMsg);
})();
}
Expand Down Expand Up @@ -505,7 +538,7 @@ export class BrowserMsg {
let w: Window = window;
while (w.parent && w.parent !== w) {
w = w.parent;
window.parent.postMessage(encryptedWithPropagationFlag, '*');
parent.postMessage(encryptedWithPropagationFlag, '*');
}
}
/**
Expand Down
20 changes: 18 additions & 2 deletions extension/js/common/browser/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,27 @@ export class Env {
}

public static isContentScript() {
return Env.isExtension() && window.location.href.indexOf(chrome.runtime.getURL('')) === -1; // extension but not on its own url
if (Env.isExtension()) {
try {
// Attempt to get the URL of an extension resource. This will succeed if we're in an extension context.
const extensionUrl = chrome.runtime.getURL('');
// Check if the current page URL is different from the extension's base URL (i.e., it's not an extension page)
return window.location.href.indexOf(extensionUrl) !== 0;
} catch (e) {
// In case of any errors (which shouldn't happen in a proper extension context), assume it's not a content script
return false;
}
}
// chrome.runtime is not available, so it's not running within an extension
return false;
}

// Check if the current context is a Service Worker
public static isBackgroundPage() {
return Boolean(window.location && window.location.href.includes('background_page.htm'));
// 'self.registration' exists in service worker contexts
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
return typeof self.registration !== 'undefined';
}

public static isExtension() {
Expand Down
4 changes: 2 additions & 2 deletions extension/js/common/core/crypto/pgp/pgp-armor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

// todo: move this file level up as it handles both S/MIME and OpenPGP?
import * as forge from 'node-forge';
import type * as Forge from 'node-forge';
import { Buf } from '../../buf.js';
import { ReplaceableMsgBlockType } from '../../msg-block.js';
import { Str } from '../../common.js';
Expand All @@ -20,7 +20,7 @@ export type PreparedForDecrypt =
message: OpenPGP.CleartextMessage | OpenPGP.Message<OpenPGP.Data>;
}
| { isArmored: boolean; isCleartext: false; isPkcs7: false; message: OpenPGP.Message<OpenPGP.Data> }
| { isArmored: boolean; isCleartext: false; isPkcs7: true; message: forge.pkcs7.PkcsEnvelopedData };
| { isArmored: boolean; isCleartext: false; isPkcs7: true; message: Forge.pkcs7.PkcsEnvelopedData };

type CryptoArmorHeaderDefinitions = {
readonly [type in ReplaceableMsgBlockType | 'null' | 'signature']: CryptoArmorHeaderDefinition;
Expand Down
Loading
Loading