зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
4c37a4d137
Коммит
b96d141f13
|
@ -46,6 +46,7 @@ DIRS += [
|
|||
'pocket',
|
||||
'preferences',
|
||||
'privatebrowsing',
|
||||
'prompts',
|
||||
'protections',
|
||||
'protocolhandler',
|
||||
'resistfingerprinting',
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
/* 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,
|
||||
]);
|
|
@ -0,0 +1,12 @@
|
|||
# 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',
|
||||
},
|
||||
]
|
|
@ -0,0 +1,14 @@
|
|||
# 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']
|
|||
XPIDL_SOURCES += [
|
||||
'nsIDialogParamBlock.idl',
|
||||
'nsIOpenWindowInfo.idl',
|
||||
'nsIPromptCollection.idl',
|
||||
'nsIPromptFactory.idl',
|
||||
'nsIPromptService.idl',
|
||||
'nsIWindowWatcher.idl',
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/* 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);
|
||||
};
|
Загрузка…
Ссылка в новой задаче