Bug 1666247 - Part 2: Return dialog from tabDialogBox.open r=pbz

Depends on D102356

Differential Revision: https://phabricator.services.mozilla.com/D103525
This commit is contained in:
Mark Striemer
2021-07-08 03:54:19 +00:00
parent aefaad96af
commit 52ee5d15ce
7 changed files with 61 additions and 60 deletions

View File

@@ -330,7 +330,7 @@ class PromptParent extends JSWindowActorParent {
allowFocusCheckbox: args.allowFocusCheckbox,
},
bag
);
).closedPromise;
} else {
// Ensure we set the correct modal type at this point.
// If we use window prompts as a fallback it may not be set.

View File

@@ -8942,7 +8942,9 @@ class TabDialogBox {
* Set to true to keep the dialog open for same origin navigation.
* @param {Number} [aOptions.modalType] - The modal type to create the dialog for.
* By default, we show the dialog for tab prompts.
* @returns {Promise} - Resolves once the dialog has been closed.
* @returns {Object} [result] Returns an object { closedPromise, dialog }.
* @returns {Promise} [result.closedPromise] Resolves once the dialog has been closed.
* @returns {SubDialog} [result.dialog] A reference to the opened SubDialog.
*/
open(
aURL,
@@ -8956,54 +8958,55 @@ class TabDialogBox {
} = {},
...aParams
) {
return new Promise(resolve => {
// Get the dialog manager to open the prompt with.
let dialogManager =
modalType === Ci.nsIPrompt.MODAL_TYPE_CONTENT
? this.getContentDialogManager()
: this._tabDialogManager;
let hasDialogs =
this._tabDialogManager.hasDialogs ||
this._contentDialogManager?.hasDialogs;
let resolveClosed;
let closedPromise = new Promise(resolve => (resolveClosed = resolve));
// Get the dialog manager to open the prompt with.
let dialogManager =
modalType === Ci.nsIPrompt.MODAL_TYPE_CONTENT
? this.getContentDialogManager()
: this._tabDialogManager;
let hasDialogs =
this._tabDialogManager.hasDialogs ||
this._contentDialogManager?.hasDialogs;
if (!hasDialogs) {
this._onFirstDialogOpen();
}
let closingCallback = event => {
if (!hasDialogs) {
this._onFirstDialogOpen();
this._onLastDialogClose();
}
let closingCallback = event => {
if (!hasDialogs) {
this._onLastDialogClose();
}
if (allowFocusCheckbox && !event.detail?.abort) {
this.maybeSetAllowTabSwitchPermission(event.target);
}
};
if (modalType == Ci.nsIPrompt.MODAL_TYPE_CONTENT) {
sizeTo = "limitheight";
if (allowFocusCheckbox && !event.detail?.abort) {
this.maybeSetAllowTabSwitchPermission(event.target);
}
};
// Open dialog and resolve once it has been closed
let dialog = dialogManager.open(
aURL,
{
features,
allowDuplicateDialogs,
sizeTo,
closingCallback,
closedCallback: resolve,
},
...aParams
);
if (modalType == Ci.nsIPrompt.MODAL_TYPE_CONTENT) {
sizeTo = "limitheight";
}
// Marking the dialog externally, instead of passing it as an option.
// The SubDialog(Manager) does not care about navigation.
// dialog can be null here if allowDuplicateDialogs = false.
if (dialog) {
dialog._keepOpenSameOriginNav = keepOpenSameOriginNav;
}
});
// Open dialog and resolve once it has been closed
let dialog = dialogManager.open(
aURL,
{
features,
allowDuplicateDialogs,
sizeTo,
closingCallback,
closedCallback: resolveClosed,
},
...aParams
);
// Marking the dialog externally, instead of passing it as an option.
// The SubDialog(Manager) does not care about navigation.
// dialog can be null here if allowDuplicateDialogs = false.
if (dialog) {
dialog._keepOpenSameOriginNav = keepOpenSameOriginNav;
}
return { closedPromise, dialog };
}
_onFirstDialogOpen() {

View File

@@ -28,7 +28,7 @@ add_task(async function test_subdialog_esc_does_not_cancel_load() {
let dialogBox = gBrowser.getTabDialogBox(browser);
let dialogClose = dialogBox.open(TEST_DIALOG_PATH, {
keepOpenSameOriginNav: true,
});
}).closedPromise;
let dialogs = dialogBox.getTabDialogManager()._dialogs;
@@ -66,7 +66,7 @@ add_task(async function test_subdialog_esc_on_dropdown_does_not_close_dialog() {
let dialogBox = gBrowser.getTabDialogBox(browser);
let dialogClose = dialogBox.open(TEST_DIALOG_PATH, {
keepOpenSameOriginNav: true,
});
}).closedPromise;
let dialogs = dialogBox.getTabDialogManager()._dialogs;

View File

@@ -87,15 +87,15 @@ add_task(async function test_tabdialogbox_multiple_focus() {
{
testCustomFocusHandler: true,
}
);
let dialogBClose = dialogBox.open(TEST_DIALOG_PATH);
).closedPromise;
let dialogBClose = dialogBox.open(TEST_DIALOG_PATH).closedPromise;
let dialogCClose = dialogBox.open(
TEST_DIALOG_PATH,
{},
{
testCustomFocusHandler: true,
}
);
).closedPromise;
let dialogs = dialogBox._tabDialogManager._dialogs;
let [dialogA, dialogB, dialogC] = dialogs;

View File

@@ -16,8 +16,8 @@ add_task(async function test_tabdialogbox_multiple_close_on_nav() {
// Open two dialogs and wait for them to be ready.
let dialogBox = gBrowser.getTabDialogBox(browser);
let closedPromises = [
dialogBox.open(TEST_DIALOG_PATH),
dialogBox.open(TEST_DIALOG_PATH),
dialogBox.open(TEST_DIALOG_PATH).closedPromise,
dialogBox.open(TEST_DIALOG_PATH).closedPromise,
];
let dialogs = dialogBox.getTabDialogManager()._dialogs;
@@ -46,7 +46,7 @@ add_task(async function test_tabdialogbox_close_on_content_nav() {
) {
// Open a dialog and wait for it to be ready
let dialogBox = gBrowser.getTabDialogBox(browser);
let closedPromise = dialogBox.open(TEST_DIALOG_PATH);
let { closedPromise } = dialogBox.open(TEST_DIALOG_PATH);
let dialog = dialogBox.getTabDialogManager()._topDialog;
@@ -71,7 +71,7 @@ add_task(async function test_tabdialogbox_close_on_content_nav() {
// Open a new dialog
closedPromise = dialogBox.open(TEST_DIALOG_PATH, {
keepOpenSameOriginNav: true,
});
}).closedPromise;
info("Waiting for dialog to open.");
await dialog._dialogReady;
@@ -118,8 +118,8 @@ add_task(async function test_tabdialogbox_hide() {
let dialogBox = gBrowser.getTabDialogBox(browser);
let dialogBoxManager = dialogBox.getTabDialogManager();
let closedPromises = [
dialogBox.open(TEST_DIALOG_PATH),
dialogBox.open(TEST_DIALOG_PATH),
dialogBox.open(TEST_DIALOG_PATH).closedPromise,
dialogBox.open(TEST_DIALOG_PATH).closedPromise,
];
let dialogs = dialogBox.getTabDialogManager()._dialogs;

View File

@@ -207,14 +207,12 @@ var PrintUtils = {
printFrameOnly: !!aPrintFrameOnly,
});
let dialogBox = this.getTabDialogBox(sourceBrowser);
let promise = dialogBox.open(
let { closedPromise, dialog } = dialogBox.open(
`chrome://global/content/print.html?printInitiationTime=${aPrintInitiationTime}`,
{ features: "resizable=no", sizeTo: "available" },
args
);
// TODO: Update this to something like dialogBox.lastOpenedDialog()._frame
let dialogs = dialogBox._tabDialogManager._dialogs;
let settingsBrowser = dialogs[dialogs.length - 1]._frame;
let settingsBrowser = dialog._frame;
let printPreview = new PrintPreview({
sourceBrowsingContext: aBrowsingContext,
settingsBrowser,
@@ -226,7 +224,7 @@ var PrintUtils = {
// This will create the source browser in connectedCallback() if we sent
// openWindowInfo. Otherwise the browser will be null.
settingsBrowser.parentElement.insertBefore(printPreview, settingsBrowser);
return { promise, browser: printPreview.sourceBrowser };
return { promise: closedPromise, browser: printPreview.sourceBrowser };
},
/**

View File

@@ -541,7 +541,7 @@ class nsContentDispatchChooser {
keepOpenSameOriginNav: true,
},
aDialogArgs
);
).closedPromise;
}
// If we don't have a BrowsingContext, we need to show a standalone window.