1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-29 17:38:04 +01:00

Pass tab onto cipherAction, no need to look up the current tab

This commit is contained in:
Daniel James Smith 2021-10-19 16:03:39 +02:00
parent fc0c7a04b7
commit 421ab36215
No known key found for this signature in database
GPG Key ID: 03E4BD365FF06726

View File

@ -36,7 +36,7 @@ export default class ContextMenusBackground {
info.parentMenuItemId === 'copy-username' || info.parentMenuItemId === 'copy-username' ||
info.parentMenuItemId === 'copy-password' || info.parentMenuItemId === 'copy-password' ||
info.parentMenuItemId === 'copy-totp') { info.parentMenuItemId === 'copy-totp') {
await this.cipherAction(info); await this.cipherAction(tab, info);
} }
}); });
} }
@ -57,7 +57,7 @@ export default class ContextMenusBackground {
BrowserApi.tabSendMessage(tab, { command: 'getClickedElement' }, { frameId: frameId }); BrowserApi.tabSendMessage(tab, { command: 'getClickedElement' }, { frameId: frameId });
} }
private async cipherAction(info: chrome.contextMenus.OnClickData) { private async cipherAction(tab: chrome.tabs.Tab, info: chrome.contextMenus.OnClickData) {
const id = info.menuItemId.split('_')[1]; const id = info.menuItemId.split('_')[1];
if (id === 'noop') { if (id === 'noop') {
if (chrome.browserAction && (chrome.browserAction as any).openPopup) { if (chrome.browserAction && (chrome.browserAction as any).openPopup) {
@ -77,7 +77,7 @@ export default class ContextMenusBackground {
} }
if (info.parentMenuItemId === 'autofill') { if (info.parentMenuItemId === 'autofill') {
await this.startAutofillPage(cipher); await this.startAutofillPage(tab, cipher);
} else if (info.parentMenuItemId === 'copy-username') { } else if (info.parentMenuItemId === 'copy-username') {
this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window }); this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window });
} else if (info.parentMenuItemId === 'copy-password') { } else if (info.parentMenuItemId === 'copy-password') {
@ -89,9 +89,8 @@ export default class ContextMenusBackground {
} }
} }
private async startAutofillPage(cipher: CipherView) { private async startAutofillPage(tab: chrome.tabs.Tab, cipher: CipherView) {
this.main.loginToAutoFill = cipher; this.main.loginToAutoFill = cipher;
const tab = await BrowserApi.getTabFromCurrentWindow();
if (tab == null) { if (tab == null) {
return; return;
} }