diff options
Diffstat (limited to 'browser/actors/ScreenshotsComponentChild.sys.mjs')
-rw-r--r-- | browser/actors/ScreenshotsComponentChild.sys.mjs | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/browser/actors/ScreenshotsComponentChild.sys.mjs b/browser/actors/ScreenshotsComponentChild.sys.mjs index 0a4d6d2539..06d7204803 100644 --- a/browser/actors/ScreenshotsComponentChild.sys.mjs +++ b/browser/actors/ScreenshotsComponentChild.sys.mjs @@ -44,11 +44,19 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { return this.getDocumentTitle(); case "Screenshots:GetMethodsUsed": return this.getMethodsUsed(); + case "Screenshots:RemoveEventListeners": + return this.removeEventListeners(); + case "Screenshots:AddEventListeners": + return this.addEventListeners(); } return null; } handleEvent(event) { + if (!event.isTrusted) { + return; + } + switch (event.type) { case "click": case "pointerdown": @@ -80,14 +88,6 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { } this.#scrollTask.arm(); break; - case "visibilitychange": - if ( - event.target.visibilityState === "hidden" && - this.overlay?.state === "crosshairs" - ) { - this.requestCancelScreenshot("navigation"); - } - break; case "Screenshots:Close": this.requestCancelScreenshot(event.detail.reason); break; @@ -97,14 +97,16 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { case "Screenshots:Download": this.requestDownloadScreenshot(event.detail.region); break; - case "Screenshots:OverlaySelection": + case "Screenshots:OverlaySelection": { let { hasSelection } = event.detail; this.sendOverlaySelection({ hasSelection }); break; - case "Screenshots:RecordEvent": + } + case "Screenshots:RecordEvent": { let { eventName, reason, args } = event.detail; this.recordTelemetryEvent(eventName, reason, args); break; + } case "Screenshots:ShowPanel": this.showPanel(); break; @@ -206,6 +208,13 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { }); } + addEventListeners() { + this.contentWindow.addEventListener("beforeunload", this); + this.contentWindow.addEventListener("resize", this); + this.contentWindow.addEventListener("scroll", this); + this.addOverlayEventListeners(); + } + addOverlayEventListeners() { let chromeEventHandler = this.docShell.chromeEventHandler; for (let event of ScreenshotsComponentChild.OVERLAY_EVENTS) { @@ -230,16 +239,19 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { let overlay = this.overlay || (this.#overlay = new lazy.ScreenshotsOverlay(this.document)); - this.document.ownerGlobal.addEventListener("beforeunload", this); - this.contentWindow.addEventListener("resize", this); - this.contentWindow.addEventListener("scroll", this); - this.contentWindow.addEventListener("visibilitychange", this); - this.addOverlayEventListeners(); + this.addEventListeners(); overlay.initialize(); return true; } + removeEventListeners() { + this.contentWindow.removeEventListener("beforeunload", this); + this.contentWindow.removeEventListener("resize", this); + this.contentWindow.removeEventListener("scroll", this); + this.removeOverlayEventListeners(); + } + removeOverlayEventListeners() { let chromeEventHandler = this.docShell.chromeEventHandler; for (let event of ScreenshotsComponentChild.OVERLAY_EVENTS) { @@ -251,11 +263,7 @@ export class ScreenshotsComponentChild extends JSWindowActorChild { * Removes event listeners and the screenshots overlay. */ endScreenshotsOverlay(options = {}) { - this.document.ownerGlobal.removeEventListener("beforeunload", this); - this.contentWindow.removeEventListener("resize", this); - this.contentWindow.removeEventListener("scroll", this); - this.contentWindow.removeEventListener("visibilitychange", this); - this.removeOverlayEventListeners(); + this.removeEventListeners(); this.overlay?.tearDown(options); this.#resizeTask?.disarm(); |