From b17c68fc9b9e7d237f001ef2c4642f4f5cf52635 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Fri, 22 Mar 2024 13:19:58 +0000 Subject: [PATCH] Bug 1886821 - [remote] Cleanup Dialog class after removal of old modal implementation r=webdriver-reviewers,whimboo We no longer need the curBrowserFn to build the Dialog instance, so we can simplify the implementation Differential Revision: https://phabricator.services.mozilla.com/D205348 --- remote/shared/Prompt.sys.mjs | 25 ++++++++----------- .../shared/listeners/PromptListener.sys.mjs | 11 ++------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/remote/shared/Prompt.sys.mjs b/remote/shared/Prompt.sys.mjs index 6b7030e59f57..39292d4bfd39 100644 --- a/remote/shared/Prompt.sys.mjs +++ b/remote/shared/Prompt.sys.mjs @@ -42,7 +42,7 @@ modal.findPrompt = function (context) { win.opener === context.window ) { lazy.logger.trace("Found open window modal prompt"); - return new modal.Dialog(() => context, win); + return new modal.Dialog(win); } } @@ -51,7 +51,7 @@ modal.findPrompt = function (context) { if (geckoViewPrompts.length) { lazy.logger.trace("Found open GeckoView prompt"); const prompt = geckoViewPrompts[0]; - return new modal.Dialog(() => context, prompt); + return new modal.Dialog(prompt); } } @@ -65,7 +65,7 @@ modal.findPrompt = function (context) { let dialogs = contentBrowser.tabDialogBox.getTabDialogManager().dialogs; if (dialogs.length) { lazy.logger.trace("Found open tab modal prompt"); - return new modal.Dialog(() => context, dialogs[0].frameContentWindow); + return new modal.Dialog(dialogs[0].frameContentWindow); } dialogs = contentBrowser.tabDialogBox.getContentDialogManager().dialogs; @@ -74,7 +74,7 @@ modal.findPrompt = function (context) { // gets lazily added. If it's not set yet, ignore the dialog for now. if (dialogs.length && dialogs[0].frameContentWindow.Dialog) { lazy.logger.trace("Found open content prompt"); - return new modal.Dialog(() => context, dialogs[0].frameContentWindow); + return new modal.Dialog(dialogs[0].frameContentWindow); } } return null; @@ -83,15 +83,14 @@ modal.findPrompt = function (context) { /** * Represents a modal dialog. * - * @param {function(): browser.Context} curBrowserFn - * Function that returns the current |browser.Context|. * @param {DOMWindow} dialog * DOMWindow of the dialog. */ modal.Dialog = class { - constructor(curBrowserFn, dialog) { - this.curBrowserFn_ = curBrowserFn; - this.win_ = Cu.getWeakReference(dialog); + #win; + + constructor(dialog) { + this.#win = Cu.getWeakReference(dialog); } get args() { @@ -102,10 +101,6 @@ modal.Dialog = class { return tm ? tm.args : null; } - get curBrowser_() { - return this.curBrowserFn_(); - } - get isOpen() { if (lazy.AppInfo.isAndroid) { return this.window !== null; @@ -148,8 +143,8 @@ modal.Dialog = class { * it is currently attached to the DOM. */ get window() { - if (this.win_) { - let win = this.win_.get(); + if (this.#win) { + let win = this.#win.get(); if (win && (lazy.AppInfo.isAndroid || win.parent)) { return win; } diff --git a/remote/shared/listeners/PromptListener.sys.mjs b/remote/shared/listeners/PromptListener.sys.mjs index e04c7669707d..0e1440905123 100644 --- a/remote/shared/listeners/PromptListener.sys.mjs +++ b/remote/shared/listeners/PromptListener.sys.mjs @@ -172,7 +172,7 @@ export class PromptListener { } this.emit("opened", { contentBrowser: curBrowser.contentBrowser, - prompt: new lazy.modal.Dialog(() => curBrowser, subject), + prompt: new lazy.modal.Dialog(subject), }); break; @@ -190,7 +190,6 @@ export class PromptListener { // the selected tab. const tab = tabBrowser.selectedTab; const contentBrowser = lazy.TabManager.getBrowserForTab(tab); - const window = lazy.TabManager.getWindowForTab(tab); // Do not send the event if the curBrowser is specified, // and it's different from prompt browser. @@ -200,13 +199,7 @@ export class PromptListener { this.emit("opened", { contentBrowser, - prompt: new lazy.modal.Dialog( - () => ({ - contentBrowser, - window, - }), - prompt - ), + prompt: new lazy.modal.Dialog(prompt), }); return; }