summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/prompts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--comm/mail/components/prompts/PromptCollection.jsm100
-rw-r--r--comm/mail/components/prompts/components.conf12
-rw-r--r--comm/mail/components/prompts/moz.build11
3 files changed, 123 insertions, 0 deletions
diff --git a/comm/mail/components/prompts/PromptCollection.jsm b/comm/mail/components/prompts/PromptCollection.jsm
new file mode 100644
index 0000000000..ddb413de6f
--- /dev/null
+++ b/comm/mail/components/prompts/PromptCollection.jsm
@@ -0,0 +1,100 @@
+/* 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 { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+/**
+ * Implements nsIPromptCollection
+ *
+ * @class PromptCollection
+ */
+class PromptCollection {
+ asyncBeforeUnloadCheck(browsingContext) {
+ let title;
+ let message;
+ let leaveLabel;
+ let stayLabel;
+
+ try {
+ title = this.domBundle.GetStringFromName("OnBeforeUnloadTitle");
+ message = this.domBundle.GetStringFromName("OnBeforeUnloadMessage2");
+ leaveLabel = this.domBundle.GetStringFromName(
+ "OnBeforeUnloadLeaveButton"
+ );
+ stayLabel = this.domBundle.GetStringFromName("OnBeforeUnloadStayButton");
+ } catch (exception) {
+ console.error("Failed to get strings from dom.properties");
+ return false;
+ }
+
+ let contentViewer = browsingContext?.docShell?.contentViewer;
+
+ // TODO: Do we really want to allow modal dialogs from inactive
+ // content viewers at all, particularly for permit unload prompts?
+ let modalAllowed = contentViewer
+ ? contentViewer.isTabModalPromptAllowed
+ : browsingContext.ancestorsAreCurrent;
+
+ let modalType =
+ Ci.nsIPromptService[
+ modalAllowed ? "MODAL_TYPE_CONTENT" : "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);
+
+ return Services.prompt
+ .asyncConfirmEx(
+ browsingContext,
+ modalType,
+ title,
+ message,
+ buttonFlags,
+ leaveLabel,
+ stayLabel,
+ null,
+ null,
+ false,
+ // Tell the prompt service that this is a permit unload prompt
+ // so that it can set the appropriate flag on the detail object
+ // of the events it dispatches.
+ { inPermitUnload: true }
+ )
+ .then(
+ result =>
+ result.QueryInterface(Ci.nsIPropertyBag2).get("buttonNumClicked") == 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([
+ "nsIPromptCollection",
+]);
diff --git a/comm/mail/components/prompts/components.conf b/comm/mail/components/prompts/components.conf
new file mode 100644
index 0000000000..0c00e72d67
--- /dev/null
+++ b/comm/mail/components/prompts/components.conf
@@ -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',
+ },
+]
diff --git a/comm/mail/components/prompts/moz.build b/comm/mail/components/prompts/moz.build
new file mode 100644
index 0000000000..143c3dcd8d
--- /dev/null
+++ b/comm/mail/components/prompts/moz.build
@@ -0,0 +1,11 @@
+# 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/.
+
+EXTRA_JS_MODULES += [
+ "PromptCollection.jsm",
+]
+
+XPCOM_MANIFESTS += [
+ "components.conf",
+]