Commit b96d141f authored by Agi Sferro's avatar Agi Sferro
Browse files

Bug 1629113 - Add nsIPromptCollection. r=johannh,pbz

This new prompt service will handle specialized prompts like beforeUnloadCheck.

The plan is to eventually phase out generic prompts like confirmExBC and just
have specialized prompts.

Differential Revision: https://phabricator.services.mozilla.com/D72720
parent 4c37a4d1
...@@ -46,6 +46,7 @@ DIRS += [ ...@@ -46,6 +46,7 @@ DIRS += [
'pocket', 'pocket',
'preferences', 'preferences',
'privatebrowsing', 'privatebrowsing',
'prompts',
'protections', 'protections',
'protocolhandler', 'protocolhandler',
'resistfingerprinting', 'resistfingerprinting',
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["PromptCollection"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
/**
* Implements nsIPromptCollection
* @class PromptCollection
*/
class PromptCollection {
beforeUnloadCheck(browsingContext) {
let title;
let message;
let leaveLabel;
let stayLabel;
try {
title = this.domBundle.GetStringFromName("OnBeforeUnloadTitle");
message = this.domBundle.GetStringFromName("OnBeforeUnloadMessage");
leaveLabel = this.domBundle.GetStringFromName(
"OnBeforeUnloadLeaveButton"
);
stayLabel = this.domBundle.GetStringFromName("OnBeforeUnloadStayButton");
} catch (exception) {
Cu.reportError("Failed to get strings from dom.properties");
return false;
}
let contentViewer = browsingContext?.docShell?.contentViewer;
let modalType = contentViewer?.isTabModalPromptAllowed
? Ci.nsIPromptService.MODAL_TYPE_CONTENT
: Ci.nsIPromptService.MODAL_TYPE_WINDOW;
let buttonFlags =
Ci.nsIPromptService.BUTTON_POS_0_DEFAULT |
(Ci.nsIPromptService.BUTTON_TITLE_IS_STRING *
Ci.nsIPromptService.BUTTON_POS_0) |
(Ci.nsIPromptService.BUTTON_TITLE_IS_STRING *
Ci.nsIPromptService.BUTTON_POS_1);
let buttonPressed = Services.prompt.confirmExBC(
browsingContext,
modalType,
title,
message,
buttonFlags,
leaveLabel,
stayLabel,
null,
null,
{}
);
return buttonPressed === 0;
}
}
XPCOMUtils.defineLazyGetter(
PromptCollection.prototype,
"domBundle",
function() {
let bundle = Services.strings.createBundle(
"chrome://global/locale/dom/dom.properties"
);
if (!bundle) {
throw new Error("String bundle for dom not present!");
}
return bundle;
}
);
PromptCollection.prototype.classID = Components.ID(
"{7913837c-9623-11ea-bb37-0242ac130002}"
);
PromptCollection.prototype.QueryInterface = ChromeUtils.generateQI([
Ci.nsIPromptCollection,
]);
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Classes = [
{
'cid': '{7913837c-9623-11ea-bb37-0242ac130002}',
'contract_ids': ['@mozilla.org/embedcomp/prompt-collection;1'],
'jsm': 'resource:///modules/PromptCollection.jsm',
'constructor': 'PromptCollection',
},
]
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
with Files("**"):
BUG_COMPONENT = ("Toolkit", "Notifications and Alerts")
EXTRA_JS_MODULES += [
'PromptCollection.jsm',
]
XPCOM_MANIFESTS += [
'components.conf',
]
...@@ -12,6 +12,7 @@ TEST_DIRS += ['test'] ...@@ -12,6 +12,7 @@ TEST_DIRS += ['test']
XPIDL_SOURCES += [ XPIDL_SOURCES += [
'nsIDialogParamBlock.idl', 'nsIDialogParamBlock.idl',
'nsIOpenWindowInfo.idl', 'nsIOpenWindowInfo.idl',
'nsIPromptCollection.idl',
'nsIPromptFactory.idl', 'nsIPromptFactory.idl',
'nsIPromptService.idl', 'nsIPromptService.idl',
'nsIWindowWatcher.idl', 'nsIWindowWatcher.idl',
......
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
webidl BrowsingContext;
/**
* This interface contains various specialized prompts that the app can
* implement.
*/
[scriptable, uuid(7913837c-9623-11ea-bb37-0242ac130002)]
interface nsIPromptCollection : nsISupports
{
/**
* Puts up a dialog for the before unload prompt.
*
* @param aBrowsingContext
* The browsing context the prompt should be opened for.
*
* @return true if the page should be allowed to navigate away
*/
boolean beforeUnloadCheck(in BrowsingContext aBrowsingContext);
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment