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
This commit is contained in:
Julian Descottes 2024-03-22 13:19:58 +00:00
parent 2127c2b7cf
commit b17c68fc9b
2 changed files with 12 additions and 24 deletions

View file

@ -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;
}

View file

@ -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;
}