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

updates related to #1509 #5330

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5520fe0
use chrome.runtime broadcast sends with custom generated tabId
Jul 26, 2023
2a252a6
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Jul 28, 2023
4c1ab6a
postMessage as backup (wip)
Jul 28, 2023
f76d041
simplify, removed background relay (wip)
Jul 29, 2023
df8cf42
fix broadcast propagation
Jul 30, 2023
3cfce61
fix parent propagation
Jul 31, 2023
640c60b
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Jul 31, 2023
3c57a7a
fetch() instead of BrowserMsg.ajax (wip)
Aug 7, 2023
eb7fed8
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 7, 2023
7405ae3
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 8, 2023
ada3139
better custom reponseText handling for 400 Bad request and test robus…
Aug 8, 2023
1f73b14
proper network error handling
Aug 10, 2023
cc22d8b
Update mock for token substitution
Aug 10, 2023
b4d4fbc
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 16, 2023
5a55e51
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 16, 2023
bab1c82
download progress and timeout implementation with fetch()
Aug 17, 2023
7a75e96
convert 'Failed to fetch' error to AjaxErr
Aug 17, 2023
9a613c5
Merge remote-tracking branch 'origin/master' into issue-5329-broadcas…
Aug 18, 2023
6769139
HTTP/2 support in mock
Aug 18, 2023
cc3e0b0
Status texts from dictionary for HTTP/2
Aug 18, 2023
058849c
fix HTTP/2 Authority check in mock
Aug 19, 2023
bacb346
safer message handling
Aug 19, 2023
cf079e3
trying to fix decryption
Aug 19, 2023
8902ef6
trying to fix decryption (verbosity)
Aug 19, 2023
c0165f5
trying to fix decryption (moved some code out of async)
Aug 20, 2023
3c506d6
send messages in a safer order
Aug 20, 2023
9924b21
don't send passphrase_entry to self
Aug 20, 2023
da31ca1
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Nov 15, 2023
096e437
fix background ajax
sosnovsky Nov 15, 2023
192be2e
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Nov 29, 2023
fd01bf8
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Dec 14, 2023
685f178
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Dec 18, 2023
27f5e2e
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Dec 19, 2023
ea9dbcb
wip
sosnovsky Dec 19, 2023
154006b
wip
sosnovsky Dec 19, 2023
1aa3fc1
wip
sosnovsky Dec 20, 2023
0049ead
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Jan 31, 2024
21ffb95
fix tests
sosnovsky Feb 1, 2024
ebbb987
Merge branch 'master' into issue-5329-broadcast-live-test
sosnovsky Jul 19, 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
5 changes: 2 additions & 3 deletions extension/chrome/elements/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class AttachmentDownloadView extends View {
private originalButtonHTML: string | undefined;
private canClickOnAttachment = false;
private downloadInProgress = false;
private tabId!: string;
private readonly tabId = BrowserMsg.generateTabId();

public constructor() {
super();
Expand Down Expand Up @@ -89,7 +89,6 @@ export class AttachmentDownloadView extends View {
};

public render = async () => {
this.tabId = await BrowserMsg.requiredTabId();
const storage = await AcctStore.get(this.acctEmail, ['setup_done', 'email_provider', 'fesUrl']);
this.fesUrl = storage.fesUrl;
try {
Expand Down Expand Up @@ -320,7 +319,7 @@ export class AttachmentDownloadView extends View {
errorDetailsOpened,
this.frameId
);
BrowserMsg.send.showAttachmentPreview(this.parentTabId, { iframeUrl });
BrowserMsg.send.showAttachmentPreview(this, { iframeUrl });
};

private decryptAndSaveAttachmentToDownloads = async () => {
Expand Down
3 changes: 1 addition & 2 deletions extension/chrome/elements/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ComposeView extends View {
public threadId = '';
public ppChangedPromiseCancellation: PromiseCancellation = { cancel: false };

public tabId!: string;
public readonly tabId = BrowserMsg.generateTabId();
public factory!: XssSafeFactory;
public replyParams: ReplyParams | undefined;
public emailProvider: EmailProviderInterface;
Expand Down Expand Up @@ -170,7 +170,6 @@ export class ComposeView extends View {
opgp.config.showVersion = false;
}
this.pubLookup = new PubLookup(this.clientConfiguration);
this.tabId = await BrowserMsg.requiredTabId();
this.factory = new XssSafeFactory(this.acctEmail, this.tabId);
this.draftModule = new ComposeDraftModule(this);
this.quoteModule = new ComposeQuoteModule(this);
Expand Down
6 changes: 3 additions & 3 deletions extension/chrome/elements/pgp_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PgpBlockView extends View {
public readonly errorModule: PgpBlockViewErrorModule;
public readonly renderModule: PgpBlockViewRenderModule;
public readonly printModule = new PgpBlockViewPrintModule();
private tabId!: string;
private readonly tabId = BrowserMsg.generateTabId();

public constructor() {
super();
Expand All @@ -49,7 +49,7 @@ export class PgpBlockView extends View {
};

public render = async () => {
this.tabId = await BrowserMsg.requiredTabId();
//
};

public setHandlers = () => {
Expand All @@ -62,7 +62,7 @@ export class PgpBlockView extends View {
});
BrowserMsg.addListener('confirmation_result', CommonHandlers.createAsyncResultHandler());
BrowserMsg.listen(this.tabId);
BrowserMsg.send.pgpBlockReady({ frameId: this.frameId, messageSender: this.tabId });
BrowserMsg.send.pgpBlockReady(this, { frameId: this.frameId, messageSender: this.tabId });
};

private processMessage = (data: RenderMessage) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class PgpBlockViewAttachmentsModule {
private previewAttachmentClickedHandler = async (attachment: Attachment) => {
const factory = new XssSafeFactory(this.view.acctEmail, this.view.parentTabId);
const iframeUrl = factory.srcPgpAttachmentIframe(attachment, false, undefined, 'chrome/elements/attachment_preview.htm');
BrowserMsg.send.showAttachmentPreview(this.view.parentTabId, { iframeUrl });
BrowserMsg.send.showAttachmentPreview(this.view, { iframeUrl });
};

private decryptAndSaveAttachmentToDownloads = async (encrypted: Attachment) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class PgpBlockViewRenderModule {
public renderSignatureOffline = () => {
this.renderSignatureStatus('error verifying signature: offline, click to retry').on(
'click',
this.view.setHandler(() => BrowserMsg.send.pgpBlockRetry({ frameId: this.view.frameId, messageSender: this.view.getDest() }))
this.view.setHandler(() => BrowserMsg.send.pgpBlockRetry(this.view, { frameId: this.view.frameId, messageSender: this.view.getDest() }))
);
};
}
4 changes: 1 addition & 3 deletions extension/chrome/settings/inbox/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class InboxView extends View {
public messageRenderer!: MessageRenderer;
public factory!: XssSafeFactory;
public picture?: string;
public tabId!: string;
public readonly tabId = BrowserMsg.generateTabId();
public relayManager!: RelayManager;

public constructor() {
Expand All @@ -64,7 +64,6 @@ export class InboxView extends View {
}

public render = async () => {
this.tabId = await BrowserMsg.requiredTabId();
this.relayManager = new RelayManager(this.debug);
this.factory = new XssSafeFactory(this.acctEmail, this.tabId);
this.injector = new Injector('settings', undefined, this.factory);
Expand Down Expand Up @@ -101,7 +100,6 @@ export class InboxView extends View {
// BrowserMsg.addPgpListeners(); // todo - re-allow when https://github.com/FlowCrypt/flowcrypt-browser/issues/2560 fixed
this.addBrowserMsgListeners();
BrowserMsg.listen(this.tabId);
BrowserMsg.listenForWindowMessages(); // listen for direct messages from child iframes
Catch.setHandledInterval(this.webmailCommon.addOrRemoveEndSessionBtnIfNeeded, 30000);
$('.action_open_settings').on(
'click',
Expand Down
3 changes: 1 addition & 2 deletions extension/chrome/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ View.run(
private readonly advanced: boolean;

private readonly gmail: Gmail | undefined;
private tabId!: string;
private readonly tabId = BrowserMsg.generateTabId();
private notifications!: Notifications;
private clientConfiguration: ClientConfiguration | undefined;
private acctServer: AccountServer | undefined;
Expand Down Expand Up @@ -74,7 +74,6 @@ View.run(
for (const webmailLName of await Env.webmails()) {
$('.signin_button.' + webmailLName).css('display', 'inline-block');
}
this.tabId = await BrowserMsg.requiredTabId();
this.notifications = new Notifications();
await this.acctServer?.initialize();
if (this.acctEmail) {
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/settings/modules/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ View.run(
}

public render = async () => {
const tabId = await BrowserMsg.requiredTabId();
const tabId = BrowserMsg.generateTabId();
BrowserMsg.listen(tabId); // set_css
const storage = await AcctStore.get(this.acctEmail, ['fesUrl']);
this.fesUrl = storage.fesUrl;
Expand Down
2 changes: 1 addition & 1 deletion extension/chrome/settings/modules/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ View.run(
}

public render = async () => {
const tabId = await BrowserMsg.requiredTabId();
const tabId = BrowserMsg.generateTabId();
this.factory = new XssSafeFactory(this.acctEmail, tabId);
BrowserMsg.addListener('close_dialog', async () => {
$('.passphrase_dialog').text('');
Expand Down
8 changes: 2 additions & 6 deletions extension/chrome/settings/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class SetupView extends View {
public readonly setupWithEmailKeyManager: SetupWithEmailKeyManagerModule;
public readonly backupUi: BackupUi;

public tabId!: string;
public readonly tabId = BrowserMsg.generateTabId();
public storage!: AcctStoreDict;
public clientConfiguration!: ClientConfiguration;
public pubLookup!: PubLookup;
Expand Down Expand Up @@ -159,7 +159,6 @@ export class SetupView extends View {
$('.input_backup_inbox').prop('checked', false).prop('disabled', true);
$('.remove_if_backup_not_allowed').remove();
}
this.tabId = await BrowserMsg.requiredTabId();
await this.setupRender.renderInitial();
};

Expand All @@ -174,10 +173,7 @@ export class SetupView extends View {
$('.action_send').attr('href', Google.webmailUrl(this.acctEmail));
$('.action_show_help').on(
'click',
this.setHandler(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
async () => await Settings.renderSubPage(this.acctEmail, this.tabId!, '/chrome/settings/modules/help.htm')
)
this.setHandler(async () => await Settings.renderSubPage(this.acctEmail, this.tabId, '/chrome/settings/modules/help.htm'))
);
$('#button-go-back')
.off()
Expand Down
3 changes: 1 addition & 2 deletions extension/js/background_page/background_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ console.info('background_process.js starting');
BrowserMsg.bgAddListener('update_uninstall_url', BgHandlers.updateUninstallUrl);
BrowserMsg.bgAddListener('get_active_tab_info', BgHandlers.getActiveTabInfo);
BrowserMsg.bgAddListener('reconnect_acct_auth_popup', (r: Bm.ReconnectAcctAuthPopup) => GoogleAuth.newAuthPopup(r));
BrowserMsg.bgAddListener('_tab_', BgHandlers.respondWithSenderTabId);
BrowserMsg.bgListen();

await BgHandlers.updateUninstallUrl({}, {});
await BgHandlers.updateUninstallUrl({});
injectFcIntoWebmail();
})().catch(Catch.reportErr);
42 changes: 7 additions & 35 deletions extension/js/background_page/bg-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,15 @@ export class BgHandlers {
return await dbFunc(db, ...request.args);
};

public static ajaxHandler = async (r: Bm.Ajax, sender: Bm.Sender): Promise<Bm.Res.Ajax> => {
public static ajaxHandler = async (r: Bm.Ajax): Promise<Bm.Res.Ajax> => {
if (r.req.context?.operationId) {
// progress updates were requested via messages
let dest = r.req.context.tabId;
if (typeof dest === 'undefined') {
// detect tabId from sender
if (sender !== 'background') {
if (typeof sender?.tab?.id !== 'undefined') {
dest = `${sender.tab.id}:0`;
}
}
}
if (typeof dest !== 'undefined') {
const destination = dest;
const operationId = r.req.context.operationId;
const expectedTransferSize = r.req.context.expectedTransferSize;
r.req.xhr = Api.getAjaxProgressXhrFactory({
download: (percent, loaded, total) => BrowserMsg.send.ajaxProgress(destination, { percent, loaded, total, expectedTransferSize, operationId }),
});
}
const destination = r.req.context.tabId;
const operationId = r.req.context.operationId;
const expectedTransferSize = r.req.context.expectedTransferSize;
r.req.xhr = Api.getAjaxProgressXhrFactory({
download: (percent, loaded, total) => BrowserMsg.send.ajaxProgress(destination, { percent, loaded, total, expectedTransferSize, operationId }),
});
}
return await Api.ajax(r.req, r.stack);
};
Expand Down Expand Up @@ -90,21 +79,4 @@ export class BgHandlers {
}
});
});

public static respondWithSenderTabId = async (r: Bm._tab_, sender: Bm.Sender): Promise<Bm.Res._tab_> => {
if (sender === 'background') {
return { tabId: null }; // eslint-disable-line no-null/no-null
} else if (typeof sender.tab?.id === 'number' && sender.tab.id > 0) {
const tabId = `${sender.tab.id}:${sender.frameId}`;
if (r.contentScript) {
BrowserMsg.contentScriptsRegistry.add(tabId);
}
return { tabId };
} else {
// sender.tab: "This property will only be present when the connection was opened from a tab (including content scripts)"
// https://developers.chrome.com/extensions/runtime#type-MessageSender
// MDN says the same - thus this is most likely a background script, through browser message passing
return { tabId: null }; // eslint-disable-line no-null/no-null
}
};
}
2 changes: 1 addition & 1 deletion extension/js/common/api/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type RawAjaxErr = {
status?: number;
statusText?: string;
};
export type ProgressDestFrame = { operationId: string; expectedTransferSize: number; tabId?: string };
export type ProgressDestFrame = { operationId: string; expectedTransferSize: number; tabId: string };
export type ApiCallContext = ProgressDestFrame | undefined;

export type ChunkedCb = (r: ProviderContactsResults) => Promise<void>;
Expand Down
Loading