[PM-8833] Refactoring implementation
This commit is contained in:
parent
44d8ca8da3
commit
fa4cd3f23c
|
@ -289,7 +289,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg
|
|||
|
||||
const response = (await BrowserApi.tabSendMessage(
|
||||
tab,
|
||||
{ command: "getFormFieldDataForNotification" },
|
||||
{ command: "getInlineMenuFormFieldData" },
|
||||
{ frameId },
|
||||
)) as OverlayNotificationsExtensionMessage;
|
||||
if (response) {
|
||||
|
|
|
@ -21,6 +21,7 @@ export type AutofillExtensionMessage = {
|
|||
authStatus?: AuthenticationStatus;
|
||||
isOpeningFullInlineMenu?: boolean;
|
||||
addNewCipherType?: CipherType;
|
||||
ignoreFieldFocus?: boolean;
|
||||
data?: {
|
||||
direction?: "previous" | "next" | "current";
|
||||
forceCloseInlineMenu?: boolean;
|
||||
|
|
|
@ -30,7 +30,9 @@ export type AutofillOverlayContentExtensionMessageHandlers = {
|
|||
checkMostRecentlyFocusedFieldHasValue: () => boolean;
|
||||
setupRebuildSubFrameOffsetsListeners: () => void;
|
||||
destroyAutofillInlineMenuListeners: () => void;
|
||||
getFormFieldDataForNotification: () => Promise<NotificationFormFieldData>;
|
||||
getInlineMenuFormFieldData: ({
|
||||
message,
|
||||
}: AutofillExtensionMessageParam) => Promise<NotificationFormFieldData>;
|
||||
};
|
||||
|
||||
export interface AutofillOverlayContentService {
|
||||
|
|
|
@ -2367,14 +2367,14 @@ describe("AutofillOverlayContentService", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("getFormFieldDataForNotification message handler", () => {
|
||||
describe("getInlineMenuFormFieldData message handler", () => {
|
||||
it("returns early if a field is currently focused", async () => {
|
||||
jest
|
||||
.spyOn(autofillOverlayContentService as any, "isFieldCurrentlyFocused")
|
||||
.mockReturnValue(true);
|
||||
|
||||
sendMockExtensionMessage(
|
||||
{ command: "getFormFieldDataForNotification" },
|
||||
{ command: "getInlineMenuFormFieldData" },
|
||||
mock<chrome.runtime.MessageSender>(),
|
||||
sendResponseSpy,
|
||||
);
|
||||
|
@ -2385,7 +2385,7 @@ describe("AutofillOverlayContentService", () => {
|
|||
|
||||
it("returns the form field data for a notification", async () => {
|
||||
sendMockExtensionMessage(
|
||||
{ command: "getFormFieldDataForNotification" },
|
||||
{ command: "getInlineMenuFormFieldData" },
|
||||
mock<chrome.runtime.MessageSender>(),
|
||||
sendResponseSpy,
|
||||
);
|
||||
|
|
|
@ -87,7 +87,8 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
|
|||
checkMostRecentlyFocusedFieldHasValue: () => this.mostRecentlyFocusedFieldHasValue(),
|
||||
setupRebuildSubFrameOffsetsListeners: () => this.setupRebuildSubFrameOffsetsListeners(),
|
||||
destroyAutofillInlineMenuListeners: () => this.destroy(),
|
||||
getFormFieldDataForNotification: () => this.handleGetFormFieldDataForNotificationMessage(),
|
||||
getInlineMenuFormFieldData: ({ message }) =>
|
||||
this.handleGetInlineMenuFormFieldDataMessage(message),
|
||||
};
|
||||
private readonly loginFieldQualifiers: Record<string, CallableFunction> = {
|
||||
[AutofillFieldQualifier.username]: this.inlineMenuFieldQualificationService.isUsernameField,
|
||||
|
@ -575,26 +576,27 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
|
|||
* Handles the repositioning of the autofill overlay when the form is submitted.
|
||||
*/
|
||||
private handleFormFieldSubmitEvent = () => {
|
||||
void this.sendExtensionMessage("formFieldSubmitted", this.getFormFieldDataForNotification());
|
||||
void this.sendExtensionMessage("formFieldSubmitted", this.getFormFieldData());
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles capturing the form field data for a notification message. Is triggered from the
|
||||
* background script when a POST request is encountered. Will not trigger this behavior
|
||||
* in the case where the user is still typing in the field.
|
||||
* Handles capturing the form field data for a notification message. Will not trigger this behavior
|
||||
* in the case where the user is still typing in the field unless the focus is ignored.
|
||||
*/
|
||||
private handleGetFormFieldDataForNotificationMessage = async () => {
|
||||
if (await this.isFieldCurrentlyFocused()) {
|
||||
private handleGetInlineMenuFormFieldDataMessage = async ({
|
||||
ignoreFieldFocus,
|
||||
}: AutofillExtensionMessage) => {
|
||||
if (!ignoreFieldFocus && (await this.isFieldCurrentlyFocused())) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.getFormFieldDataForNotification();
|
||||
return this.getFormFieldData();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the form field data used for add login and change password notifications.
|
||||
*/
|
||||
private getFormFieldDataForNotification = (): NotificationFormFieldData => {
|
||||
private getFormFieldData = (): NotificationFormFieldData => {
|
||||
return {
|
||||
uri: globalThis.document.URL,
|
||||
username: this.userFilledFields["username"]?.value || "",
|
||||
|
|
|
@ -3080,6 +3080,16 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||
return;
|
||||
}
|
||||
|
||||
const inlineMenuPreviouslyDisabled = oldSettingValue === AutofillOverlayVisibility.Off;
|
||||
const inlineMenuCurrentlyDisabled = newSettingValue === AutofillOverlayVisibility.Off;
|
||||
if (
|
||||
typeof newSettingValue !== "boolean" &&
|
||||
!inlineMenuPreviouslyDisabled &&
|
||||
!inlineMenuCurrentlyDisabled
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.reloadAutofillScripts();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue