1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

[PM-5189] Fixing an issue found with iframe service

This commit is contained in:
Cesar Gonzalez
2024-06-11 14:02:46 -05:00
parent 644dbe251b
commit ae5e73b0ae

View File

@@ -9,7 +9,8 @@ import {
} from "../abstractions/autofill-inline-menu-iframe.service";
export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframeServiceInterface {
private sendExtensionMessage = sendExtensionMessage;
private readonly setElementStyles = setElementStyles;
private readonly sendExtensionMessage = sendExtensionMessage;
private port: chrome.runtime.Port | null = null;
private portKey: string;
private iframeMutationObserver: MutationObserver;
@@ -288,12 +289,42 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
this.unobserveIframe();
setElementStyles(customElement, styles, true);
this.iframeStyles = { ...this.iframeStyles, ...styles };
this.setElementStyles(customElement, styles, true);
if (customElement === this.iframe) {
this.iframeStyles = { ...this.iframeStyles, ...styles };
}
this.observeIframe();
}
/**
* Triggers a forced closure of the autofill inline menu. This is used when the
* mutation observer is triggered excessively.
*/
private forceCloseInlineMenu() {
void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true });
}
/**
* Triggers a delayed closure of the inline menu to ensure that click events are
* caught if focus is programmatically redirected away from the inline menu.
*/
private handleDelayedAutofillInlineMenuClosure() {
if (this.delayedCloseTimeout) {
clearTimeout(this.delayedCloseTimeout);
}
this.updateElementStyles(this.iframe, {
transition: this.fadeOutOpacityTransition,
opacity: "0",
});
this.delayedCloseTimeout = globalThis.setTimeout(() => {
this.updateElementStyles(this.iframe, { transition: this.fadeInOpacityTransition });
this.forceCloseInlineMenu();
}, 100);
}
/**
* Handles mutations to the iframe element. The ensures that the iframe
* element's styles are not modified by a third party source.
@@ -323,34 +354,6 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
}
};
/**
* Triggers a forced closure of the autofill inline menu. This is used when the
* mutation observer is triggered excessively.
*/
private forceCloseInlineMenu() {
void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true });
}
/**
* Triggers a delayed closure of the inline menu to ensure that click events are
* caught if focus is programmatically redirected away from the inline menu.
*/
private handleDelayedAutofillInlineMenuClosure() {
if (this.delayedCloseTimeout) {
clearTimeout(this.delayedCloseTimeout);
}
this.updateElementStyles(this.iframe, {
transition: this.fadeOutOpacityTransition,
opacity: "0",
});
this.delayedCloseTimeout = globalThis.setTimeout(() => {
this.updateElementStyles(this.iframe, { transition: this.fadeInOpacityTransition });
this.forceCloseInlineMenu();
}, 100);
}
/**
* Handles mutations to the iframe element's attributes. This ensures that
* the iframe element's attributes are not modified by a third party source.