mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-24 21:41:33 +01:00
[PM-5189] Implementing a set threshold for the maximum depth for which we are willing to calculate sub frame offsets
This commit is contained in:
parent
d94d85e201
commit
6754afb6d6
@ -38,6 +38,7 @@ import { BrowserPlatformUtilsService } from "../../platform/services/platform-ut
|
|||||||
import {
|
import {
|
||||||
AutofillOverlayElement,
|
AutofillOverlayElement,
|
||||||
AutofillOverlayPort,
|
AutofillOverlayPort,
|
||||||
|
MAX_SUB_FRAME_DEPTH,
|
||||||
RedirectFocusDirection,
|
RedirectFocusDirection,
|
||||||
} from "../enums/autofill-overlay.enum";
|
} from "../enums/autofill-overlay.enum";
|
||||||
import { AutofillService } from "../services/abstractions/autofill.service";
|
import { AutofillService } from "../services/abstractions/autofill.service";
|
||||||
@ -217,6 +218,25 @@ describe("OverlayBackground", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("triggers a destruction of the inline menu listeners if the max frame depth is exceeded ", async () => {
|
||||||
|
getFrameCounter = MAX_SUB_FRAME_DEPTH + 1;
|
||||||
|
const tab = createChromeTabMock({ id: tabId });
|
||||||
|
sendMockExtensionMessage(
|
||||||
|
{ command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() },
|
||||||
|
mock<chrome.runtime.MessageSender>({
|
||||||
|
tab,
|
||||||
|
frameId: 1,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await flushPromises();
|
||||||
|
|
||||||
|
expect(tabsSendMessageSpy).toHaveBeenCalledWith(
|
||||||
|
tab,
|
||||||
|
{ command: "destroyAutofillInlineMenuListeners" },
|
||||||
|
{ frameId: 1 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("builds the offset values for a sub frame within the tab", async () => {
|
it("builds the offset values for a sub frame within the tab", async () => {
|
||||||
sendMockExtensionMessage(
|
sendMockExtensionMessage(
|
||||||
{ command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() },
|
{ command: "collectPageDetailsResponse", details: createAutofillPageDetailsMock() },
|
||||||
|
@ -314,10 +314,14 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
const subFrameData: SubFrameOffsetData = { url, top: 0, left: 0, parentFrameIds: [] };
|
const subFrameData: SubFrameOffsetData = { url, top: 0, left: 0, parentFrameIds: [] };
|
||||||
let frameDetails = await BrowserApi.getFrameDetails({ tabId, frameId });
|
let frameDetails = await BrowserApi.getFrameDetails({ tabId, frameId });
|
||||||
|
|
||||||
while (
|
while (frameDetails && frameDetails.parentFrameId > -1) {
|
||||||
(frameDetails && frameDetails.parentFrameId > -1) ||
|
subFrameDepth++;
|
||||||
subFrameDepth > MAX_SUB_FRAME_DEPTH
|
if (subFrameDepth >= MAX_SUB_FRAME_DEPTH) {
|
||||||
) {
|
subFrameOffsetsForTab.set(frameId, null);
|
||||||
|
this.triggerDestroyInlineMenuListeners(tab, frameId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const subFrameOffset: SubFrameOffsetData = await BrowserApi.tabSendMessage(
|
const subFrameOffset: SubFrameOffsetData = await BrowserApi.tabSendMessage(
|
||||||
tab,
|
tab,
|
||||||
{
|
{
|
||||||
@ -346,13 +350,6 @@ export class OverlayBackground implements OverlayBackgroundInterface {
|
|||||||
tabId,
|
tabId,
|
||||||
frameId: frameDetails.parentFrameId,
|
frameId: frameDetails.parentFrameId,
|
||||||
});
|
});
|
||||||
subFrameDepth++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subFrameDepth > MAX_SUB_FRAME_DEPTH) {
|
|
||||||
subFrameOffsetsForTab.set(frameId, null);
|
|
||||||
this.triggerDestroyInlineMenuListeners(tab, frameId);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subFrameOffsetsForTab.set(frameId, subFrameData);
|
subFrameOffsetsForTab.set(frameId, subFrameData);
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
} from "../enums/autofill-overlay.enum";
|
} from "../enums/autofill-overlay.enum";
|
||||||
import AutofillField from "../models/autofill-field";
|
import AutofillField from "../models/autofill-field";
|
||||||
import { createAutofillFieldMock } from "../spec/autofill-mocks";
|
import { createAutofillFieldMock } from "../spec/autofill-mocks";
|
||||||
import { flushPromises, sendMockExtensionMessage } from "../spec/testing-utils";
|
import { flushPromises, postWindowMessage, sendMockExtensionMessage } from "../spec/testing-utils";
|
||||||
import { ElementWithOpId, FillableFormFieldElement, FormFieldElement } from "../types";
|
import { ElementWithOpId, FillableFormFieldElement, FormFieldElement } from "../types";
|
||||||
|
|
||||||
import { AutoFillConstants } from "./autofill-constants";
|
import { AutoFillConstants } from "./autofill-constants";
|
||||||
@ -1526,13 +1526,13 @@ describe("AutofillOverlayContentService", () => {
|
|||||||
parentFrameIds: [1, 2, 3],
|
parentFrameIds: [1, 2, 3],
|
||||||
subFrameDepth: MAX_SUB_FRAME_DEPTH,
|
subFrameDepth: MAX_SUB_FRAME_DEPTH,
|
||||||
};
|
};
|
||||||
const event = mock<MessageEvent>();
|
|
||||||
// @ts-expect-error - Need to mock the source to be the iframe content window
|
|
||||||
event.source = iframe.contentWindow;
|
|
||||||
event.data.subFrameData = subFrameData;
|
|
||||||
sendExtensionMessageSpy.mockResolvedValue(4);
|
sendExtensionMessageSpy.mockResolvedValue(4);
|
||||||
|
|
||||||
await autofillOverlayContentService["calculateSubFramePositioning"](event);
|
postWindowMessage(
|
||||||
|
{ command: "calculateSubFramePositioning", subFrameData },
|
||||||
|
"*",
|
||||||
|
iframe.contentWindow as any,
|
||||||
|
);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
expect(globalThis.parent.postMessage).not.toHaveBeenCalled();
|
expect(globalThis.parent.postMessage).not.toHaveBeenCalled();
|
||||||
@ -1553,13 +1553,12 @@ describe("AutofillOverlayContentService", () => {
|
|||||||
parentFrameIds: [1, 2, 3],
|
parentFrameIds: [1, 2, 3],
|
||||||
subFrameDepth: 0,
|
subFrameDepth: 0,
|
||||||
};
|
};
|
||||||
const event = mock<MessageEvent>();
|
|
||||||
// @ts-expect-error - Need to mock the source to be the iframe content window
|
|
||||||
event.source = iframe.contentWindow;
|
|
||||||
event.data.subFrameData = subFrameData;
|
|
||||||
sendExtensionMessageSpy.mockResolvedValue(4);
|
|
||||||
|
|
||||||
await autofillOverlayContentService["calculateSubFramePositioning"](event);
|
postWindowMessage(
|
||||||
|
{ command: "calculateSubFramePositioning", subFrameData },
|
||||||
|
"*",
|
||||||
|
iframe.contentWindow as any,
|
||||||
|
);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
expect(globalThis.parent.postMessage).toHaveBeenCalledWith(
|
expect(globalThis.parent.postMessage).toHaveBeenCalledWith(
|
||||||
@ -1567,11 +1566,11 @@ describe("AutofillOverlayContentService", () => {
|
|||||||
command: "calculateSubFramePositioning",
|
command: "calculateSubFramePositioning",
|
||||||
subFrameData: {
|
subFrameData: {
|
||||||
frameId: 10,
|
frameId: 10,
|
||||||
left: 2,
|
left: 20,
|
||||||
parentFrameIds: [1, 2, 3, 4],
|
parentFrameIds: [1, 2, 3],
|
||||||
top: 2,
|
top: 20,
|
||||||
url: "https://example.com/",
|
url: "https://example.com/",
|
||||||
subFrameDepth: 1,
|
subFrameDepth: expect.any(Number),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"*",
|
"*",
|
||||||
@ -1587,24 +1586,24 @@ describe("AutofillOverlayContentService", () => {
|
|||||||
left: 0,
|
left: 0,
|
||||||
top: 0,
|
top: 0,
|
||||||
parentFrameIds: [1, 2, 3],
|
parentFrameIds: [1, 2, 3],
|
||||||
subFrameDepth: 1,
|
subFrameDepth: expect.any(Number),
|
||||||
};
|
};
|
||||||
const event = mock<MessageEvent>();
|
|
||||||
// @ts-expect-error - Need to mock the source to be the iframe content window
|
|
||||||
event.source = iframe.contentWindow;
|
|
||||||
event.data.subFrameData = subFrameData;
|
|
||||||
|
|
||||||
await autofillOverlayContentService["calculateSubFramePositioning"](event);
|
postWindowMessage(
|
||||||
|
{ command: "calculateSubFramePositioning", subFrameData },
|
||||||
|
"*",
|
||||||
|
iframe.contentWindow as any,
|
||||||
|
);
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateSubFrameData", {
|
expect(sendExtensionMessageSpy).toHaveBeenCalledWith("updateSubFrameData", {
|
||||||
subFrameData: {
|
subFrameData: {
|
||||||
frameId: 10,
|
frameId: 10,
|
||||||
left: 2,
|
left: 168,
|
||||||
top: 2,
|
top: 168,
|
||||||
url: "https://example.com/",
|
url: "https://example.com/",
|
||||||
parentFrameIds: [1, 2, 3],
|
parentFrameIds: [1, 2, 3, 4],
|
||||||
subFrameDepth: 2,
|
subFrameDepth: expect.any(Number),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user