Skip to content

Commit

Permalink
[PM-8833] Fixing an issue with attempting to generate a password with…
Browse files Browse the repository at this point in the history
…out being authenticated
  • Loading branch information
cagonzalezcs committed Sep 20, 2024
1 parent 55b0934 commit eb4ccf3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
53 changes: 32 additions & 21 deletions apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,16 +1099,18 @@ export class OverlayBackground implements OverlayBackgroundInterface {
sender: chrome.runtime.MessageSender,
{ forceCloseInlineMenu, overlayElement }: CloseInlineMenuMessage = {},
) {
this.generatedPassword = null;

const command = "closeAutofillInlineMenu";
const sendOptions = { frameId: 0 };
this.generatedPassword = null;

if (forceCloseInlineMenu) {
BrowserApi.tabSendMessage(sender.tab, { command, overlayElement }, sendOptions).catch(
(error) => this.logService.error(error),
);
this.isInlineMenuButtonVisible = false;
this.isInlineMenuListVisible = false;
BrowserApi.tabSendMessage(
sender.tab,
{ command: "closeAutofillInlineMenu", overlayElement },
{ frameId: 0 },
).catch((error) => this.logService.error(error));
this.updateClosedInlineMenuVisibleStatus(overlayElement);

return;
}

Expand All @@ -1126,22 +1128,26 @@ export class OverlayBackground implements OverlayBackgroundInterface {
return;
}

if (overlayElement === AutofillOverlayElement.Button) {
this.isInlineMenuButtonVisible = false;
}
this.updateClosedInlineMenuVisibleStatus(overlayElement);
BrowserApi.tabSendMessage(sender.tab, { command, overlayElement }, sendOptions).catch((error) =>
this.logService.error(error),
);
}

if (overlayElement === AutofillOverlayElement.List) {
private updateClosedInlineMenuVisibleStatus(overlayElement: string) {
if (!overlayElement) {
this.isInlineMenuButtonVisible = false;
this.isInlineMenuListVisible = false;
return;
}

if (!overlayElement) {
if (overlayElement === AutofillOverlayElement.Button) {
this.isInlineMenuButtonVisible = false;
this.isInlineMenuListVisible = false;
}

BrowserApi.tabSendMessage(sender.tab, { command, overlayElement }, sendOptions).catch((error) =>
this.logService.error(error),
);
if (overlayElement === AutofillOverlayElement.List) {
this.isInlineMenuListVisible = false;
}
}

/**
Expand Down Expand Up @@ -2330,7 +2336,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
* Triggers a closure of the inline menu during a reposition event.
*
* @param sender - The sender of the message
| */
| */
private async closeInlineMenuAfterReposition(sender: chrome.runtime.MessageSender) {
await this.toggleInlineMenuHidden(
{ isInlineMenuHidden: false, setTransparentInlineMenu: true },
Expand Down Expand Up @@ -2432,12 +2438,17 @@ export class OverlayBackground implements OverlayBackgroundInterface {
this.portKeyForTab[port.sender.tab.id] = generateRandomChars(12);
}

const authStatus = await this.getAuthStatus();
const showInlineMenuAccountCreation = this.showInlineMenuAccountCreation();
const showInlineMenuPasswordGenerator = this.showInlineMenuPasswordGenerator(
isInlineMenuListPort,
showInlineMenuAccountCreation,
);
if (showInlineMenuPasswordGenerator && !this.generatedPassword) {
if (
authStatus === AuthenticationStatus.Unlocked &&
showInlineMenuPasswordGenerator &&
!this.generatedPassword
) {
await this.generatePassword();
}

Expand All @@ -2452,7 +2463,6 @@ export class OverlayBackground implements OverlayBackgroundInterface {
pageTitle: chrome.i18n.getMessage(
isInlineMenuListPort ? "bitwardenVault" : "bitwardenOverlayButton",
),
authStatus: await this.getAuthStatus(),
styleSheetUrl: chrome.runtime.getURL(
`overlay/menu-${isInlineMenuListPort ? "list" : "button"}.css`,
),
Expand All @@ -2464,9 +2474,10 @@ export class OverlayBackground implements OverlayBackgroundInterface {
? AutofillOverlayPort.ListMessageConnector
: AutofillOverlayPort.ButtonMessageConnector,
inlineMenuFillType: this.focusedFieldData?.inlineMenuFillType,
showInlineMenuAccountCreation,
showPasskeysLabels: this.showPasskeysLabelsWithinInlineMenu,
generatedPassword: showInlineMenuPasswordGenerator ? this.generatedPassword : null,
showInlineMenuAccountCreation,
authStatus,
});
this.updateInlineMenuPosition(
{
Expand All @@ -2482,7 +2493,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
* Stores the connected overlay port and sets up any existing ports to be disconnected.
*
* @param port - The port to store
| */
| */
private storeOverlayPort(port: chrome.runtime.Port) {
if (port.name === AutofillOverlayPort.List) {
this.storeExpiredOverlayPort(this.inlineMenuListPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,11 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
return;
}

if (await this.isInlineMenuButtonVisible()) {
this.updateInlineMenuListPosition();
return;
}

this.openInlineMenu();
}

Expand Down Expand Up @@ -1293,7 +1298,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
private async hideInlineMenuListOnFilledField(
formFieldElement?: FillableFormFieldElement,
): Promise<boolean> {
return (
return !!(
formFieldElement?.value &&
((await this.isInlineMenuCiphersPopulated()) || !this.isUserAuthed())
);
Expand Down

0 comments on commit eb4ccf3

Please sign in to comment.