mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 09:43:23 +00:00
[PM-5189] Implementing fixes for how we handle adding to the vault through the inline menu
This commit is contained in:
@@ -377,7 +377,11 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
}: { forceCloseOverlay?: boolean; overlayElement?: string } = {},
|
}: { forceCloseOverlay?: boolean; overlayElement?: string } = {},
|
||||||
) {
|
) {
|
||||||
if (forceCloseOverlay) {
|
if (forceCloseOverlay) {
|
||||||
void BrowserApi.tabSendMessage(sender.tab, { command: "closeInlineMenu" }, { frameId: 0 });
|
void BrowserApi.tabSendMessage(
|
||||||
|
sender.tab,
|
||||||
|
{ command: "closeInlineMenu", overlayElement },
|
||||||
|
{ frameId: 0 },
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -745,9 +749,17 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
* @param sender - The sender of the port message
|
* @param sender - The sender of the port message
|
||||||
*/
|
*/
|
||||||
private getNewVaultItemDetails({ sender }: chrome.runtime.Port) {
|
private getNewVaultItemDetails({ sender }: chrome.runtime.Port) {
|
||||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
if (sender.tab.id !== this.focusedFieldData.tabId) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
return;
|
||||||
BrowserApi.tabSendMessage(sender.tab, { command: "addNewVaultItemFromOverlay" });
|
}
|
||||||
|
|
||||||
|
void BrowserApi.tabSendMessage(
|
||||||
|
sender.tab,
|
||||||
|
{ command: "addNewVaultItemFromOverlay" },
|
||||||
|
{
|
||||||
|
frameId: this.focusedFieldData.frameId || 0,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
private readonly domElementVisibilityService: DomElementVisibilityService;
|
private readonly domElementVisibilityService: DomElementVisibilityService;
|
||||||
private readonly collectAutofillContentService: CollectAutofillContentService;
|
private readonly collectAutofillContentService: CollectAutofillContentService;
|
||||||
private readonly insertAutofillContentService: InsertAutofillContentService;
|
private readonly insertAutofillContentService: InsertAutofillContentService;
|
||||||
|
private sendCollectDetailsMessageTimeout: number | NodeJS.Timeout | undefined;
|
||||||
private readonly extensionMessageHandlers: AutofillExtensionMessageHandlers = {
|
private readonly extensionMessageHandlers: AutofillExtensionMessageHandlers = {
|
||||||
collectPageDetails: ({ message }) => this.collectPageDetails(message),
|
collectPageDetails: ({ message }) => this.collectPageDetails(message),
|
||||||
collectPageDetailsImmediately: ({ message }) => this.collectPageDetails(message, true),
|
collectPageDetailsImmediately: ({ message }) => this.collectPageDetails(message, true),
|
||||||
@@ -89,11 +90,13 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
* to act on the page.
|
* to act on the page.
|
||||||
*/
|
*/
|
||||||
private collectPageDetailsOnLoad() {
|
private collectPageDetailsOnLoad() {
|
||||||
const sendCollectDetailsMessage = () =>
|
const sendCollectDetailsMessage = () => {
|
||||||
setTimeout(
|
this.clearSendCollectDetailsMessageTimeout();
|
||||||
|
this.sendCollectDetailsMessageTimeout = setTimeout(
|
||||||
() => sendExtensionMessage("bgCollectPageDetails", { sender: "autofillInit" }),
|
() => sendExtensionMessage("bgCollectPageDetails", { sender: "autofillInit" }),
|
||||||
250,
|
250,
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if (document.readyState === "complete") {
|
if (document.readyState === "complete") {
|
||||||
sendCollectDetailsMessage();
|
sendCollectDetailsMessage();
|
||||||
@@ -300,6 +303,12 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private clearSendCollectDetailsMessageTimeout() {
|
||||||
|
if (this.sendCollectDetailsMessageTimeout) {
|
||||||
|
clearTimeout(this.sendCollectDetailsMessageTimeout as number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles destroying the autofill init content script. Removes all
|
* Handles destroying the autofill init content script. Removes all
|
||||||
* listeners, timeouts, and object instances to prevent memory leaks.
|
* listeners, timeouts, and object instances to prevent memory leaks.
|
||||||
@@ -308,6 +317,7 @@ class AutofillInit implements AutofillInitInterface {
|
|||||||
chrome.runtime.onMessage.removeListener(this.handleExtensionMessage);
|
chrome.runtime.onMessage.removeListener(this.handleExtensionMessage);
|
||||||
this.collectAutofillContentService.destroy();
|
this.collectAutofillContentService.destroy();
|
||||||
this.autofillOverlayContentService?.destroy();
|
this.autofillOverlayContentService?.destroy();
|
||||||
|
this.clearSendCollectDetailsMessageTimeout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class InlineMenuElements implements InlineMenuElementsInterface {
|
|||||||
zIndex: "2147483647",
|
zIndex: "2147483647",
|
||||||
};
|
};
|
||||||
private readonly _extensionMessageHandlers: InlineMenuExtensionMessageHandlers = {
|
private readonly _extensionMessageHandlers: InlineMenuExtensionMessageHandlers = {
|
||||||
closeInlineMenu: ({ message }) => this.removeInlineMenu(),
|
closeInlineMenu: ({ message }) => this.removeInlineMenu(message),
|
||||||
updateInlineMenuElementsPosition: ({ message }) =>
|
updateInlineMenuElementsPosition: ({ message }) =>
|
||||||
this.updateInlineMenuElementsPosition(message),
|
this.updateInlineMenuElementsPosition(message),
|
||||||
toggleInlineMenuHidden: ({ message }) =>
|
toggleInlineMenuHidden: ({ message }) =>
|
||||||
@@ -67,7 +67,17 @@ export class InlineMenuElements implements InlineMenuElementsInterface {
|
|||||||
* unobserve the body element to ensure the mutation observer no
|
* unobserve the body element to ensure the mutation observer no
|
||||||
* longer triggers.
|
* longer triggers.
|
||||||
*/
|
*/
|
||||||
private removeInlineMenu = () => {
|
private removeInlineMenu = (message: any) => {
|
||||||
|
if (message.overlayElement === AutofillOverlayElement.Button) {
|
||||||
|
this.removeInlineMenuButton();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.overlayElement === AutofillOverlayElement.List) {
|
||||||
|
this.removeInlineMenuList();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.removeBodyElementObserver();
|
this.removeBodyElementObserver();
|
||||||
this.removeInlineMenuButton();
|
this.removeInlineMenuButton();
|
||||||
this.removeInlineMenuList();
|
this.removeInlineMenuList();
|
||||||
@@ -403,7 +413,7 @@ export class InlineMenuElements implements InlineMenuElementsInterface {
|
|||||||
clearTimeout(this.mutationObserverIterationsResetTimeout);
|
clearTimeout(this.mutationObserverIterationsResetTimeout);
|
||||||
this.mutationObserverIterations = 0;
|
this.mutationObserverIterations = 0;
|
||||||
void this.sendExtensionMessage("blurMostRecentOverlayField");
|
void this.sendExtensionMessage("blurMostRecentOverlayField");
|
||||||
this.removeInlineMenu();
|
this.removeInlineMenu({ forceClose: true });
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,7 +364,9 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
const eventCode = event.code;
|
const eventCode = event.code;
|
||||||
if (eventCode === "Escape") {
|
if (eventCode === "Escape") {
|
||||||
// this.removeAutofillOverlay();
|
// this.removeAutofillOverlay();
|
||||||
void this.sendExtensionMessage("closeAutofillOverlay");
|
void this.sendExtensionMessage("closeAutofillOverlay", {
|
||||||
|
forceCloseOverlay: true,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,9 +383,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
void this.focusOverlayList();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
||||||
this.focusOverlayList();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -439,6 +439,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
// this.removeAutofillOverlayList();
|
// this.removeAutofillOverlayList();
|
||||||
void this.sendExtensionMessage("closeAutofillOverlay", {
|
void this.sendExtensionMessage("closeAutofillOverlay", {
|
||||||
overlayElement: AutofillOverlayElement.List,
|
overlayElement: AutofillOverlayElement.List,
|
||||||
|
forceCloseOverlay: true,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -538,6 +539,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
// this.removeAutofillOverlayList();
|
// this.removeAutofillOverlayList();
|
||||||
void this.sendExtensionMessage("closeAutofillOverlay", {
|
void this.sendExtensionMessage("closeAutofillOverlay", {
|
||||||
overlayElement: AutofillOverlayElement.List,
|
overlayElement: AutofillOverlayElement.List,
|
||||||
|
forceCloseOverlay: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user