summaryrefslogtreecommitdiffstats
path: root/comm/mail/extensions/openpgp/content/BondOpenPGP.jsm
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/extensions/openpgp/content/BondOpenPGP.jsm')
-rw-r--r--comm/mail/extensions/openpgp/content/BondOpenPGP.jsm86
1 files changed, 86 insertions, 0 deletions
diff --git a/comm/mail/extensions/openpgp/content/BondOpenPGP.jsm b/comm/mail/extensions/openpgp/content/BondOpenPGP.jsm
new file mode 100644
index 0000000000..e9d1086cc7
--- /dev/null
+++ b/comm/mail/extensions/openpgp/content/BondOpenPGP.jsm
@@ -0,0 +1,86 @@
+/* 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 https://mozilla.org/MPL/2.0/. */
+
+/* This file is a thin interface on top of the rest of the OpenPGP
+ * integration ot minimize the amount of code that must be
+ * included in files outside the extensions/openpgp directory. */
+
+"use strict";
+
+const EXPORTED_SYMBOLS = ["BondOpenPGP"];
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+const lazy = {};
+
+XPCOMUtils.defineLazyModuleGetters(lazy, {
+ EnigmailKeyRing: "chrome://openpgp/content/modules/keyRing.jsm",
+ EnigmailVerify: "chrome://openpgp/content/modules/mimeVerify.jsm",
+ EnigmailCore: "chrome://openpgp/content/modules/core.jsm",
+ EnigmailWindows: "chrome://openpgp/content/modules/windows.jsm",
+ RNP: "chrome://openpgp/content/modules/RNP.jsm",
+ GPGME: "chrome://openpgp/content/modules/GPGME.jsm",
+});
+
+/*
+// Enable this block to view syntax errors in these files, which are
+// difficult to see when lazy loading.
+var { GPGME } = ChromeUtils.import(
+ "chrome://openpgp/content/modules/GPGME.jsm"
+);
+var { RNP } = ChromeUtils.import(
+ "chrome://openpgp/content/modules/RNP.jsm"
+);
+var { GPGMELibLoader } = ChromeUtils.import(
+ "chrome://openpgp/content/modules/GPGMELib.jsm"
+);
+var { RNPLibLoader } = ChromeUtils.import(
+ "chrome://openpgp/content/modules/RNPLib.jsm"
+);
+*/
+
+var BondOpenPGP = {
+ logException(exc) {
+ try {
+ Services.console.logStringMessage(exc.toString() + "\n" + exc.stack);
+ } catch (x) {}
+ },
+
+ _alreadyTriedInit: false, // if already true, we will not try again
+
+ async init() {
+ if (this._alreadyTriedInit) {
+ // We have previously attempted to init, don't try again.
+ return;
+ }
+
+ this._alreadyTriedInit = true;
+
+ lazy.EnigmailKeyRing.init();
+ lazy.EnigmailVerify.init();
+
+ let initDone = await lazy.RNP.init({});
+ if (!initDone) {
+ let { error } = this.getRNPLibStatus();
+ throw new Error(error);
+ }
+
+ if (Services.prefs.getBoolPref("mail.openpgp.allow_external_gnupg")) {
+ lazy.GPGME.init({});
+ }
+
+ // trigger service init
+ await lazy.EnigmailCore.getService();
+ },
+
+ getRNPLibStatus() {
+ return lazy.RNP.getRNPLibStatus();
+ },
+
+ openKeyManager(window) {
+ lazy.EnigmailWindows.openKeyManager(window);
+ },
+};