Skip to content

Commit

Permalink
Merge branch 'master' into 5864-use-built-in-linkify-html-types
Browse files Browse the repository at this point in the history
  • Loading branch information
sosnovsky authored Dec 4, 2024
2 parents faf8fc3 + 5278bd5 commit 16f18aa
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 740 deletions.
2 changes: 1 addition & 1 deletion extension/chrome/elements/attachment_preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as pdfjsLib from 'pdfjs';
import { AttachmentPreviewPdf } from '../../js/common/ui/attachment_preview_pdf.js';

// https://github.com/FlowCrypt/flowcrypt-browser/issues/5822#issuecomment-2362529197
// eslint-disable-next-line @typescript-eslint/no-deprecated

pdfjsLib.GlobalWorkerOptions.workerSrc = chrome.runtime.getURL(`lib/pdf.worker.min.mjs`);
type AttachmentType = 'img' | 'txt' | 'pdf';

Expand Down
16 changes: 11 additions & 5 deletions extension/chrome/elements/compose-modules/compose-render-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export class ComposeRenderModule extends ViewModule<ComposeView> {
const thread = await this.view.emailProvider.threadGet(this.view.threadId, 'metadata');
const inReplyToMessage = thread.messages?.find(message => message.id === this.view.replyMsgId);
if (inReplyToMessage) {
this.view.replyParams.inReplyTo = inReplyToMessage.payload?.headers?.find(
header => header.name === 'Message-Id' || header.name === 'Message-ID'
)?.value;
const msgId = inReplyToMessage.payload?.headers?.find(header => header.name === 'Message-Id' || header.name === 'Message-ID')?.value;
const references = inReplyToMessage.payload?.headers?.find(header => header.name === 'References')?.value;
this.setReplyHeaders(msgId, references);
}
this.view.replyParams.subject = `${this.responseMethod === 'reply' ? 'Re' : 'Fwd'}: ${this.view.replyParams.subject}`;
if (this.view.useFullScreenSecureCompose) {
Expand All @@ -117,8 +117,7 @@ export class ComposeRenderModule extends ViewModule<ComposeView> {
);
if (this.view.quoteModule.messageToReplyOrForward) {
const msgId = this.view.quoteModule.messageToReplyOrForward.headers['message-id'];
this.view.sendBtnModule.additionalMsgHeaders['In-Reply-To'] = msgId;
this.view.sendBtnModule.additionalMsgHeaders.References = this.view.quoteModule.messageToReplyOrForward.headers.references + ' ' + msgId;
this.setReplyHeaders(msgId, this.view.quoteModule.messageToReplyOrForward.headers.references);
if (this.view.replyPubkeyMismatch) {
await this.renderReplyMsgAsReplyPubkeyMismatch();
} else if (this.view.quoteModule.messageToReplyOrForward.isOnlySigned) {
Expand Down Expand Up @@ -273,6 +272,13 @@ export class ComposeRenderModule extends ViewModule<ComposeView> {
}
};

private setReplyHeaders = (msgId?: string, references?: string) => {
if (msgId) {
this.view.sendBtnModule.additionalMsgHeaders['In-Reply-To'] = msgId;
this.view.sendBtnModule.additionalMsgHeaders.References = [references, msgId].filter(Boolean).join(' ');
}
};

private initComposeBoxStyles = () => {
if (this.view.isReplyBox) {
this.view.S.cached('body').addClass('reply_box');
Expand Down
1 change: 0 additions & 1 deletion extension/chrome/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ View.run(
}

public render = async () => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const isDevMode = !('update_url' in chrome.runtime.getManifest());
$('#status-row #status_version').text(`v:${VERSION}${isDevMode ? '-dev' : ''}`);
for (const webmailLName of await Env.webmails()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class ConfiguredIdpOAuth extends OAuth {
grant_type: 'refresh_token',
refreshToken,
client_id: authConf.oauth.clientId,
// eslint-disable-next-line @typescript-eslint/no-deprecated

redirect_uri: chrome.identity.getRedirectURL('oauth'),
},
dataType: 'JSON',
Expand All @@ -120,7 +120,7 @@ export class ConfiguredIdpOAuth extends OAuth {
access_type: 'offline',
prompt: 'login',
state,
// eslint-disable-next-line @typescript-eslint/no-deprecated

redirect_uri: chrome.identity.getRedirectURL('oauth'),
scope: this.OAUTH_REQUEST_SCOPES.join(' '),
login_hint: acctEmail,
Expand All @@ -131,9 +131,8 @@ export class ConfiguredIdpOAuth extends OAuth {
private static async getAuthRes({ acctEmail, expectedState, authUrl }: { acctEmail: string; expectedState: string; authUrl: string }): Promise<AuthRes> {
/* eslint-disable @typescript-eslint/naming-convention */
try {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const redirectUri = await chrome.identity.launchWebAuthFlow({ url: authUrl, interactive: true });
// eslint-disable-next-line @typescript-eslint/no-deprecated

if (chrome.runtime.lastError || !redirectUri || redirectUri?.includes('access_denied')) {
return { acctEmail, result: 'Denied', error: `Failed to launch web auth flow`, id_token: undefined };
}
Expand Down Expand Up @@ -207,7 +206,7 @@ export class ConfiguredIdpOAuth extends OAuth {
grant_type: 'authorization_code',
code,
client_id: authConf.oauth.clientId,
// eslint-disable-next-line @typescript-eslint/no-deprecated

redirect_uri: chrome.identity.getRedirectURL('oauth'),
},
dataType: 'JSON',
Expand Down
6 changes: 3 additions & 3 deletions extension/js/common/api/email-provider/sendable-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export class SendableMsg {
public type: MimeEncodeType,
public externalId?: string // for binding a password-protected message
) {
const allEmails = this.getAllRecipients();
if (!allEmails.length && !isDraft) {
const allRecipients = this.getAllRecipients();
if (!allRecipients.length && !isDraft) {
throw new Error('The To:, Cc: and Bcc: fields are empty. Please add recipients and try again');
}
const invalidEmails = allEmails.filter(email => !Str.isEmailValid(email.email));
const invalidEmails = allRecipients.map(recipient => recipient.email).filter(email => !Str.isEmailValid(email));
// todo: distinguish To:, Cc: and Bcc: in error report?
if (invalidEmails.length) {
throw new InvalidRecipientError(`The To: field contains invalid emails: ${invalidEmails.join(', ')}\n\nPlease check recipients and try again.`);
Expand Down
15 changes: 4 additions & 11 deletions extension/js/common/browser/browser-msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface ChildFrame {

export namespace Bm {
export type Dest = string;
// eslint-disable-next-line @typescript-eslint/no-deprecated

export type Sender = chrome.runtime.MessageSender | 'background';
export type Response = unknown;
export type RawResponse = { result: unknown; exception?: Bm.ErrAsJson };
Expand Down Expand Up @@ -415,7 +415,6 @@ export class BrowserMsg {
}

public static listen(dest: Bm.Dest) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.runtime.onMessage.addListener((msg: Bm.Raw, _sender, rawRespond: (rawResponse: Bm.RawResponse) => void) => {
// console.debug(`listener(${dest}) new message: ${msg.name} to ${msg.to} with id ${msg.uid} from`, _sender);
if (msg.to && [dest, 'broadcast'].includes(msg.to)) {
Expand All @@ -432,7 +431,7 @@ export class BrowserMsg {

public static createIntervalAlarm(action: string, periodInMinutes: number) {
const alarmName = `${action}_interval_${Date.now()}`;
// eslint-disable-next-line @typescript-eslint/no-deprecated

void chrome.alarms.create(alarmName, { periodInMinutes });
}

Expand All @@ -441,7 +440,6 @@ export class BrowserMsg {
}

public static bgListen() {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.runtime.onMessage.addListener((msg: Bm.Raw, _sender, rawRespond: (rawRes: Bm.RawResponse) => void) => {
const respondIfPageStillOpen = (response: Bm.RawResponse) => {
try {
Expand Down Expand Up @@ -521,7 +519,7 @@ export class BrowserMsg {
Catch.try(BrowserMsg.INTERVAL_HANDLERS[actionName])();
}
};
// eslint-disable-next-line @typescript-eslint/no-deprecated

chrome.alarms.onAlarm.addListener(alarmListener);
}

Expand Down Expand Up @@ -646,7 +644,7 @@ export class BrowserMsg {
resolve(undefined);
} else if (!r || typeof r !== 'object') {
// r can be null if we sent a message to a non-existent window id
// eslint-disable-next-line @typescript-eslint/no-deprecated

const lastError = chrome.runtime.lastError ? chrome.runtime.lastError.message || '(empty lastError)' : '(no lastError)';
let e: Error;
if (typeof destString === 'undefined' && typeof r === 'undefined') {
Expand Down Expand Up @@ -676,24 +674,19 @@ export class BrowserMsg {
}
};
try {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (chrome.runtime) {
Env.isBackgroundPage()
.then(isBackgroundPage => {
if (isBackgroundPage) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
for (const tab of tabs) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.tabs.sendMessage(Number(tab.id), msg, resolve);
}
});
} else {
if (awaitRes) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.runtime.sendMessage(msg, processRawMsgResponse);
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
void chrome.runtime.sendMessage(msg);
}
}
Expand Down
1 change: 0 additions & 1 deletion extension/js/common/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class Browser {
};

public static openSettingsPage = async (path = 'index.htm', acctEmail?: string, page = '', rawPageUrlParams?: Dict<UrlParam>, addNewAcct = false) => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const basePath = chrome.runtime.getURL(`chrome/settings/${path}`);
const pageUrlParams = rawPageUrlParams ? JSON.stringify(rawPageUrlParams) : undefined;
if (acctEmail || path === 'fatal.htm') {
Expand Down
17 changes: 2 additions & 15 deletions extension/js/common/browser/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ const handleFatalErr = async (reason: 'storage_undefined', error: Error) => {
throw error;
} else if (Env.isContentScript()) {
console.error('Incomplete extension environment in content script', error);
// eslint-disable-next-line @typescript-eslint/no-deprecated
} else if (!chrome.runtime) {
console.error('Chrome.runtime missing, cannot continue', error);
} else {
// extension pages
// eslint-disable-next-line @typescript-eslint/no-deprecated

window.location.href = chrome.runtime.getURL(Url.create(`chrome/settings/fatal.htm`, { reason, stack: error.stack }));
}
} catch (e) {
Expand All @@ -34,12 +33,10 @@ const handleFatalErr = async (reason: 'storage_undefined', error: Error) => {
}
}
};
// eslint-disable-next-line @typescript-eslint/no-deprecated

export const windowsCreate = async (q: chrome.windows.CreateData): Promise<chrome.windows.Window | undefined> => {
return await new Promise(resolve => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof chrome.windows !== 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.windows.create(q, resolve);
} else {
Ui.modal.error('Your platform is not supported: browser does not support extension windows').catch(Catch.reportErr);
Expand All @@ -49,18 +46,14 @@ export const windowsCreate = async (q: chrome.windows.CreateData): Promise<chrom

export const storageGet = async (storageType: ChromeStorageType, keys: string[]): Promise<Dict<unknown>> => {
return await new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof chrome.storage === 'undefined') {
void handleFatalErr('storage_undefined', new Error('storage is undefined'));
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const storage = chrome.storage[storageType];
storage.get(keys, result => {
if (typeof result !== 'undefined') {
resolve(result);
// eslint-disable-next-line @typescript-eslint/no-deprecated
} else if (chrome.runtime.lastError) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
reject(AbstractStore.errCategorize(chrome.runtime.lastError));
} else {
reject(new Error(`storageGet(${storageType}, ${keys.join(',')}) produced undefined result without an error`));
Expand All @@ -72,11 +65,9 @@ export const storageGet = async (storageType: ChromeStorageType, keys: string[])

export const storageGetAll = async (storageType: ChromeStorageType): Promise<{ [key: string]: unknown }> => {
return await new Promise(resolve => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof chrome.storage === 'undefined') {
void handleFatalErr('storage_undefined', new Error('storage is undefined'));
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const storage = chrome.storage[storageType];
storage.get(resolve);
}
Expand All @@ -85,11 +76,9 @@ export const storageGetAll = async (storageType: ChromeStorageType): Promise<{ [

export const storageSet = async (storageType: ChromeStorageType, values: Dict<unknown>): Promise<void> => {
return await new Promise(resolve => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof chrome.storage === 'undefined') {
void handleFatalErr('storage_undefined', new Error('storage is undefined'));
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const storage = chrome.storage[storageType];
storage.set(values, resolve);
}
Expand All @@ -98,11 +87,9 @@ export const storageSet = async (storageType: ChromeStorageType, values: Dict<un

export const storageRemove = async (storageType: ChromeStorageType, keys: string[]): Promise<void> => {
return await new Promise(resolve => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (typeof chrome.storage === 'undefined') {
void handleFatalErr('storage_undefined', new Error('storage is undefined'));
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const storage = chrome.storage[storageType];
storage.remove(keys, resolve);
}
Expand Down
6 changes: 1 addition & 5 deletions extension/js/common/browser/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ export type WebMailVersion = 'generic' | 'gmail2020' | 'gmail2022';

export class Env {
public static runtimeId(orig = false) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (chrome?.runtime?.id) {
if (orig) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return chrome.runtime.id;
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return chrome.runtime.id.replace(/[^a-z0-9]/gi, '');
}
}
return undefined;
}

public static getExtensionOrigin() {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const url = chrome.runtime.getURL('');
return Url.removeTrailingSlash(url);
}
Expand All @@ -32,7 +28,7 @@ export class Env {
if (Env.isExtension()) {
try {
// Attempt to get the URL of an extension resource. This will succeed if we're in an extension context.
// eslint-disable-next-line @typescript-eslint/no-deprecated

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.startsWith(extensionUrl);
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/browser/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class Ui {

public static spinner = (color: string, placeholderCls: 'small_spinner' | 'large_spinner' = 'small_spinner') => {
const path = `/img/svgs/spinner-${color}-small.svg`;
// eslint-disable-next-line @typescript-eslint/no-deprecated

const url = typeof chrome !== 'undefined' && chrome.runtime?.getURL ? chrome.runtime.getURL(path) : path;
return `<i class="${placeholderCls}" data-test="spinner"><img src="${url}" /></i>`;
};
Expand Down
5 changes: 2 additions & 3 deletions extension/js/common/oauth2/oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ export class OAuth2 {
// need to use chrome.runtime.onMessage because BrowserMsg.addListener doesn't work
// In gmail page reconnect auth popup, it sends event to background page (BrowserMsg.send.bg.await.reconnectAcctAuthPopup)
// thefore BrowserMsg.addListener doesn't work
// eslint-disable-next-line @typescript-eslint/no-deprecated

chrome.runtime.onMessage.addListener((message: Bm.Raw) => {
if (message.name === 'auth_window_result') {
// eslint-disable-next-line @typescript-eslint/no-deprecated
void chrome.tabs.remove(tabId!); // eslint-disable-line @typescript-eslint/no-non-null-assertion
resolve(message.data.bm as Bm.AuthWindowResult);
}
});
// eslint-disable-next-line @typescript-eslint/no-deprecated

chrome.tabs.onRemoved.addListener(removedTabId => {
// Only reject error when auth result not successful
if (removedTabId === tabId) {
Expand Down
2 changes: 1 addition & 1 deletion extension/js/common/oauth2/oauth2_inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const win: Window = window;

// Redirect back to the extension itself so that we have priveledged access again
// Need to send BrowserMsg event back to GoogleAuth
// eslint-disable-next-line @typescript-eslint/no-deprecated

const redirect = chrome.runtime.getURL('/chrome/elements/oauth2.htm');

win.location = redirect + win.location.search;
1 change: 0 additions & 1 deletion extension/js/common/platform/xss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ export class Xss {
private static sanitizeHrefRegexp = () => {
if (typeof Xss.HREF_REGEX_CACHE === 'undefined') {
Xss.HREF_REGEX_CACHE = new RegExp(
// eslint-disable-next-line @typescript-eslint/no-deprecated
`^(?:(http|https|cid):|data:image/|${Str.regexEscape(chrome.runtime.getURL('/'))}|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))`,
'i'
);
Expand Down
4 changes: 1 addition & 3 deletions extension/js/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export class Settings {
throw new Error('Filter is empty for account_email"' + acctEmail + '"');
}
await new Promise<void>((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
chrome.storage.local.get(async storage => {
try {
for (const storageIndex of Object.keys(storage)) {
Expand Down Expand Up @@ -440,10 +439,9 @@ export class Settings {
}

public static async loginWithPopupShowModalOnErr(acctEmail: string, isCustomIDP: boolean, then: () => void = () => undefined) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (window !== window.top && !chrome.windows) {
// Firefox, chrome.windows isn't available in iframes
// eslint-disable-next-line @typescript-eslint/no-deprecated

await Browser.openExtensionTab(Url.create(chrome.runtime.getURL(`chrome/settings/index.htm`), { acctEmail }));
await Ui.modal.info(`Reload after logging in.`);
window.location.reload();
Expand Down
1 change: 0 additions & 1 deletion extension/js/common/xss-safe-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ export class XssSafeFactory {
};

private extUrl = (s: string) => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
return chrome.runtime.getURL(s);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class GmailWebmailStartup {

private injectFCVarScript = () => {
const scriptElement = document.createElement('script');
// eslint-disable-next-line @typescript-eslint/no-deprecated

scriptElement.src = chrome.runtime.getURL('/js/common/core/feature-config-injector.js');
(document.head || document.documentElement).appendChild(scriptElement);
};
Expand Down
Loading

0 comments on commit 16f18aa

Please sign in to comment.