mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
[PM-5189] Refactoring and organizing implementation
This commit is contained in:
@@ -126,6 +126,18 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
private themeStateService: ThemeStateService,
|
private themeStateService: ThemeStateService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the extension message listeners and gets the settings for the
|
||||||
|
* overlay's visibility and the user's authentication status.
|
||||||
|
*/
|
||||||
|
async init() {
|
||||||
|
this.setupExtensionMessageListeners();
|
||||||
|
const env = await firstValueFrom(this.environmentService.environment$);
|
||||||
|
this.iconsServerUrl = env.getIconsUrl();
|
||||||
|
await this.getOverlayVisibility();
|
||||||
|
await this.getAuthStatus();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes cached page details for a tab
|
* Removes cached page details for a tab
|
||||||
* based on the passed tabId.
|
* based on the passed tabId.
|
||||||
@@ -148,18 +160,6 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up the extension message listeners and gets the settings for the
|
|
||||||
* overlay's visibility and the user's authentication status.
|
|
||||||
*/
|
|
||||||
async init() {
|
|
||||||
this.setupExtensionMessageListeners();
|
|
||||||
const env = await firstValueFrom(this.environmentService.environment$);
|
|
||||||
this.iconsServerUrl = env.getIconsUrl();
|
|
||||||
await this.getOverlayVisibility();
|
|
||||||
await this.getAuthStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the overlay list's ciphers and sends the updated list to the overlay list iframe.
|
* Updates the overlay list's ciphers and sends the updated list to the overlay list iframe.
|
||||||
* Queries all ciphers for the given url, and sorts them by last used. Will not update the
|
* Queries all ciphers for the given url, and sorts them by last used. Will not update the
|
||||||
@@ -225,6 +225,10 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
message: OverlayBackgroundExtensionMessage,
|
message: OverlayBackgroundExtensionMessage,
|
||||||
sender: chrome.runtime.MessageSender,
|
sender: chrome.runtime.MessageSender,
|
||||||
) {
|
) {
|
||||||
|
if (!this.portKeyForTab[sender.tab.id]) {
|
||||||
|
this.portKeyForTab[sender.tab.id] = generateRandomChars(12);
|
||||||
|
}
|
||||||
|
|
||||||
const pageDetails = {
|
const pageDetails = {
|
||||||
frameId: sender.frameId,
|
frameId: sender.frameId,
|
||||||
tab: sender.tab,
|
tab: sender.tab,
|
||||||
@@ -949,11 +953,6 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabId = port.sender.tab.id;
|
|
||||||
if (!this.portKeyForTab[tabId]) {
|
|
||||||
this.portKeyForTab[tabId] = generateRandomChars(12);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isOverlayListPort) {
|
if (isOverlayListPort) {
|
||||||
this.overlayListPort = port;
|
this.overlayListPort = port;
|
||||||
} else {
|
} else {
|
||||||
@@ -969,7 +968,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
translations: this.getTranslations(),
|
translations: this.getTranslations(),
|
||||||
ciphers: isOverlayListPort ? await this.getOverlayCipherData() : null,
|
ciphers: isOverlayListPort ? await this.getOverlayCipherData() : null,
|
||||||
messageConnectorUrl: chrome.runtime.getURL("overlay/message-connector.html"),
|
messageConnectorUrl: chrome.runtime.getURL("overlay/message-connector.html"),
|
||||||
portKey: this.portKeyForTab[tabId],
|
portKey: this.portKeyForTab[port.sender.tab.id],
|
||||||
});
|
});
|
||||||
void this.updateOverlayPosition(
|
void this.updateOverlayPosition(
|
||||||
{
|
{
|
||||||
@@ -991,8 +990,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
message: OverlayBackgroundExtensionMessage,
|
message: OverlayBackgroundExtensionMessage,
|
||||||
port: chrome.runtime.Port,
|
port: chrome.runtime.Port,
|
||||||
) => {
|
) => {
|
||||||
const tabId = port.sender.tab.id;
|
if (this.portKeyForTab[port.sender.tab.id] !== message?.portKey) {
|
||||||
if (this.portKeyForTab[tabId] !== message?.portKey) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -363,10 +363,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
|
|
||||||
this.storeModifiedFormElement(formFieldElement);
|
this.storeModifiedFormElement(formFieldElement);
|
||||||
|
|
||||||
if (
|
if (await this.hideOverlayListOnFilledField(formFieldElement)) {
|
||||||
formFieldElement.value &&
|
|
||||||
((await this.isInlineMenuCiphersPopulated()) || !this.isUserAuthed())
|
|
||||||
) {
|
|
||||||
void this.sendExtensionMessage("closeAutofillOverlay", {
|
void this.sendExtensionMessage("closeAutofillOverlay", {
|
||||||
overlayElement: AutofillOverlayElement.List,
|
overlayElement: AutofillOverlayElement.List,
|
||||||
forceCloseOverlay: true,
|
forceCloseOverlay: true,
|
||||||
@@ -466,15 +463,12 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (await this.hideOverlayListOnFilledField(formFieldElement as FillableFormFieldElement)) {
|
||||||
!formElementHasValue ||
|
this.updateOverlayButtonPosition();
|
||||||
(!(await this.isInlineMenuCiphersPopulated()) && this.isUserAuthed())
|
|
||||||
) {
|
|
||||||
void this.sendExtensionMessage("openAutofillOverlay");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateOverlayButtonPosition();
|
void this.sendExtensionMessage("openAutofillOverlay");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -758,8 +752,9 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
this.toggleOverlayHidden(false);
|
this.toggleOverlayHidden(false);
|
||||||
if (
|
if (
|
||||||
(this.mostRecentlyFocusedField as HTMLInputElement)?.value &&
|
await this.hideOverlayListOnFilledField(
|
||||||
((await this.isInlineMenuCiphersPopulated()) || !this.isUserAuthed())
|
this.mostRecentlyFocusedField as FillableFormFieldElement,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
void this.sendExtensionMessage("closeAutofillOverlay", {
|
void this.sendExtensionMessage("closeAutofillOverlay", {
|
||||||
overlayElement: AutofillOverlayElement.List,
|
overlayElement: AutofillOverlayElement.List,
|
||||||
@@ -769,10 +764,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
}, 50);
|
}, 50);
|
||||||
this.clearUserInteractionEventTimeout();
|
this.clearUserInteractionEventTimeout();
|
||||||
|
|
||||||
if (
|
if (this.isRepositionedFocusedFieldOutOfBounds()) {
|
||||||
this.focusedFieldData.focusedFieldRects?.top > 0 &&
|
|
||||||
this.focusedFieldData.focusedFieldRects?.top < globalThis.innerHeight + globalThis.scrollY
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -797,6 +789,24 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isRepositionedFocusedFieldOutOfBounds() {
|
||||||
|
const focusedFieldRectsTop = this.focusedFieldData?.focusedFieldRects?.top;
|
||||||
|
return (
|
||||||
|
focusedFieldRectsTop &&
|
||||||
|
focusedFieldRectsTop > 0 &&
|
||||||
|
focusedFieldRectsTop < globalThis.innerHeight + globalThis.scrollY
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async hideOverlayListOnFilledField(
|
||||||
|
formFieldElement?: FillableFormFieldElement,
|
||||||
|
): Promise<boolean> {
|
||||||
|
return (
|
||||||
|
formFieldElement?.value &&
|
||||||
|
((await this.isInlineMenuCiphersPopulated()) || !this.isUserAuthed())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up global event listeners and the mutation
|
* Sets up global event listeners and the mutation
|
||||||
* observer to facilitate required changes to the
|
* observer to facilitate required changes to the
|
||||||
|
|||||||
Reference in New Issue
Block a user