Bug 1645914 - Add a preference to disable OpenPGP and hide the related UI. r=mkmelin a=wsmwk
authorKai Engert <kaie@kuix.de>
Tue, 16 Jun 2020 00:19:00 +0200
changeset 39418 5c08edff5bf2a2a90455109a7701836627aac4de
parent 39417 c399ed6ce163afa0423846a8e9122a9e4b5d93e2
child 39419 9b17071b24c6127577896888722ea80ec5aff8b3
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin, wsmwk
bugs1645914
Bug 1645914 - Add a preference to disable OpenPGP and hide the related UI. r=mkmelin a=wsmwk Differential Revision: https://phabricator.services.mozilla.com/D79758
mail/base/content/mainNavigationToolbox.inc.xhtml
mail/base/content/mainPopupSet.inc.xhtml
mail/base/content/messageWindow.js
mail/base/content/msgHdrView.js
mail/base/content/msgMail3PaneWindow.js
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/messengercompose.xhtml
mail/extensions/am-e2e/am-e2e.inc.xhtml
mail/extensions/am-e2e/am-e2e.js
mail/extensions/am-e2e/prefs/e2e-prefs.js
mail/extensions/openpgp/content/BondOpenPGP.jsm
mail/extensions/openpgp/content/ui/attachmentItemContext.inc.xhtml
--- a/mail/base/content/mainNavigationToolbox.inc.xhtml
+++ b/mail/base/content/mainNavigationToolbox.inc.xhtml
@@ -1102,17 +1102,17 @@
                   label="&deleteJunk.label;"
                   accesskey="&deleteJunk.accesskey;"
                   command="cmd_deleteJunk"/>
         <menuseparator id="tasksMenuAfterDeleteSeparator"/>
         <menuitem id="menu_import" label="&importCmd.label;"
                   accesskey="&importCmd.accesskey;"
                   oncommand="toImport();"/>
 #ifdef MOZ_OPENPGP
-        <menuitem id="manageKeysOpenPGP"
+        <menuitem id="manageKeysOpenPGP" class="openpgp-item"
                   data-l10n-id="openpgp-manage-keys-openpgp-cmd"
                   oncommand="BondOpenPGP.openKeyManager(window)"/>
 #endif
         <menu id="devtoolsMenu" label="&devtoolsMenu.label;" accesskey="&devtoolsMenu.accesskey;">
           <menupopup id="devtoolsPopup">
             <menuitem id="devtoolsToolbox"
                       label="&devToolboxCmd.label;"
                       accesskey="&devToolboxCmd.accesskey;"
--- a/mail/base/content/mainPopupSet.inc.xhtml
+++ b/mail/base/content/mainPopupSet.inc.xhtml
@@ -23,18 +23,19 @@
               oncommand="SendMailToNode(document.popupNode, event)"/>
     <menuitem id="copyEmailAddressItem" label="&CopyEmailAddress.label;"
               accesskey="&CopyEmailAddress.accesskey;"
               oncommand="CopyEmailNewsAddress(document.popupNode)"/>
     <menuitem id="copyNameAndEmailAddressItem" label="&CopyNameAndEmailAddress.label;"
               accesskey="&CopyNameAndEmailAddress.accesskey;"
               oncommand="CopyEmailNewsAddress(document.popupNode, true)"/>
 #ifdef MOZ_OPENPGP
-    <menuseparator/>
+    <menuseparator class="openpgp-item"/>
     <menuitem id="searchKeysOpenPGP" data-l10n-id="openpgp-search-keys-openpgp"
+              class="openpgp-item"
               oncommand="Enigmail.msg.searchKeysOnInternet(document.popupNode)"/>
 #endif
     <menuseparator/>
     <menuitem id="createFilterFromItem" label="&CreateFilterFrom.label;"
               accesskey="&CreateFilterFrom.accesskey;"
               oncommand="CreateFilter(document.popupNode, gMessageDisplay.displayedMessage)"
               observes="cmd_createFilterFromPopup"/>
   </menupopup>
--- a/mail/base/content/messageWindow.js
+++ b/mail/base/content/messageWindow.js
@@ -391,21 +391,25 @@ function OnLoadMessageWindow() {
   // By reassigning this here, we fix the find bar (bug 1562677).
   document.getElementById("FindToolbar").browser = document.getElementById(
     "messagepane"
   );
 
   ToolbarIconColor.init();
   setTimeout(delayedOnLoadMessageWindow, 0); // when debugging, set this to 5000, so you can see what happens after the window comes up.
 
-  if (MailConstants.MOZ_OPENPGP) {
+  if (MailConstants.MOZ_OPENPGP && BondOpenPGP.allDependenciesLoaded()) {
     Enigmail.msg.messengerStartup.bind(Enigmail.msg);
     Enigmail.msg.messengerStartup();
     Enigmail.hdrView.hdrViewLoad.bind(Enigmail.hdrView);
     Enigmail.hdrView.hdrViewLoad();
+  } else {
+    for (let item of document.querySelectorAll(".openpgp-item")) {
+      item.hidden = true;
+    }
   }
 }
 
 function delayedOnLoadMessageWindow() {
   HideMenus();
   ShowMenus();
   MailOfflineMgr.init();
   CreateMailWindowGlobals();
--- a/mail/base/content/msgHdrView.js
+++ b/mail/base/content/msgHdrView.js
@@ -316,16 +316,22 @@ function OnLoadMsgHeaderPane() {
   // the message pane.
   var headerViewElement = document.getElementById("msgHeaderView");
   headerViewElement.loaded = true;
   headerViewElement.dispatchEvent(
     new Event("messagepane-loaded", { bubbles: false, cancelable: true })
   );
 
   top.controllers.appendController(AttachmentMenuController);
+
+  if (!MailConstants.MOZ_OPENPGP || !BondOpenPGP.allDependenciesLoaded()) {
+    for (let item of document.querySelectorAll(".openpgp-item")) {
+      item.hidden = true;
+    }
+  }
 }
 
 function OnUnloadMsgHeaderPane() {
   Services.prefs.removeObserver(
     "mail.showCondensedAddresses",
     MsgHdrViewObserver
   );
   Services.prefs.removeObserver(
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -613,16 +613,20 @@ function OnLoadMessenger() {
     LoadPostAccountWizard();
   }
 
   if (MailConstants.MOZ_OPENPGP && BondOpenPGP.allDependenciesLoaded()) {
     Enigmail.msg.messengerStartup.bind(Enigmail.msg);
     Enigmail.msg.messengerStartup();
     Enigmail.hdrView.hdrViewLoad.bind(Enigmail.hdrView);
     Enigmail.hdrView.hdrViewLoad();
+  } else {
+    for (let item of document.querySelectorAll(".openpgp-item")) {
+      item.hidden = true;
+    }
   }
 }
 
 function _showNewInstallModal() {
   Services.ww.openWindow(
     null,
     "chrome://messenger/content/newInstall.xhtml",
     "_blank",
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -3938,16 +3938,22 @@ function ComposeLoad() {
   attachmentBucketMarkEmptyBucket();
   updateStringsOfAddressingFields();
 
   for (let input of document.querySelectorAll(".address-input")) {
     input.onBeforeHandleKeyDown = event =>
       addressInputOnBeforeHandleKeyDown(event);
   }
 
+  if (!MailConstants.MOZ_OPENPGP || !BondOpenPGP.allDependenciesLoaded()) {
+    for (let item of document.querySelectorAll(".openpgp-item")) {
+      item.hidden = true;
+    }
+  }
+
   top.controllers.appendController(SecurityController);
   gMsgCompose.compFields.composeSecure = null;
   gSMFields = Cc[
     "@mozilla.org/messengercompose/composesecure;1"
   ].createInstance(Ci.nsIMsgComposeSecure);
   if (gSMFields) {
     gMsgCompose.compFields.composeSecure = gSMFields;
   }
--- a/mail/components/compose/content/messengercompose.xhtml
+++ b/mail/components/compose/content/messengercompose.xhtml
@@ -1738,19 +1738,20 @@
             <menupopup is="folder-menupopup" id="fccMenuPopup" mode="filing"
                        showFileHereLabel="true" fileHereLabel="&fileHereMenu.label;"/>
           </menu>
           <menuseparator/>
           <menuitem type="checkbox" command="cmd_customizeFromAddress"
                     accesskey="&customizeFromAddress.accesskey;"/>
 
 #ifdef MOZ_OPENPGP
-          <menuseparator id="encryptTechOptionsSeparator_Menubar"/>
+          <menuseparator id="encryptTechOptionsSeparator_Menubar"
+                         class="openpgp-item"/>
 
-          <menu id="menu_encTech_Menubar"
+          <menu id="menu_encTech_Menubar" class="openpgp-item"
                 label="&menu_securityTech.label;" accesskey="&menu_securityTech.accesskey;">
             <menupopup id="button-encTech_Menubar" oncommand="onSecurityChoice(event.target.value);">
               <menuitem id="encTech_OpenPGP_Menubar"
                         label="&menu_techPGP.label;" accesskey="&menu_techPGP.accesskey;"
                         value="OpenPGP" type="radio" name="radiogroup_encTech"/>
               <menuitem id="encTech_SMIME_Menubar"
                         label="&menu_techSMIME.label;" accesskey="&menu_techSMIME.accesskey;"
                         value="SMIME" type="radio" name="radiogroup_encTech"/>
@@ -1786,18 +1787,18 @@
           <menuitem id="menu_securitySign_Menubar"
                     type="checkbox"
                     label="&menu_securitySign.label;"
                     accesskey="&menu_securitySign.accesskey;"
                     value="sig"
                     oncommand="onSecurityChoice(event.target.value);"/>
 
 #ifdef MOZ_OPENPGP
-        <menuseparator id="myPublicKeySeparator_Menubar"/>
-        <menuitem id="menu_securityMyPublicKey_Menubar"
+        <menuseparator id="myPublicKeySeparator_Menubar" class="openpgp-item"/>
+        <menuitem id="menu_securityMyPublicKey_Menubar" class="openpgp-item"
                   type="checkbox"
                   label="&menu_securityAttachMyKey.label;"
                   accesskey="&menu_securityAttachMyKey.accesskey;"
                   value="mykey"
                   oncommand="onSecurityChoice(event.target.value);"/>
 #endif
         </menupopup>
       </menu>
@@ -1911,17 +1912,17 @@
     <toolbarbutton is="toolbarbutton-menu-button" id="button-security"
                    type="menu-button"
                    class="toolbarbutton-1"
                    label="&securityButton.label;"
                    tooltiptext="&securityButton.tooltip;"
                    oncommand="onSecurityChoice(event.target.value);">
       <menupopup onpopupshowing="setSecuritySettings('_Toolbar');">
 #ifdef MOZ_OPENPGP
-        <menu id="menu_encTech_Toolbar"
+        <menu id="menu_encTech_Toolbar" class="openpgp-item"
               label="&menu_securityTech.label;" accesskey="&menu_securityTech.accesskey;">
           <menupopup id="button-encTech_Toolbar">
             <menuitem id="encTech_OpenPGP_Toolbar"
                       label="&menu_techPGP.label;" accesskey="&menu_techPGP.accesskey;"
                       value="OpenPGP" type="radio" name="radiogroup_encTech"/>
             <menuitem id="encTech_SMIME_Toolbar"
                       label="&menu_techSMIME.label;" accesskey="&menu_techSMIME.accesskey;"
                       value="SMIME" type="radio" name="radiogroup_encTech"/>
@@ -1953,18 +1954,20 @@
 
         <menuitem id="menu_securitySign_Toolbar"
                   type="checkbox"
                   label="&menu_securitySign.label;"
                   accesskey="&menu_securitySign.accesskey;"
                   value="sig"/>
 
 #ifdef MOZ_OPENPGP
-        <menuseparator id="myPublicKeySeparator_Toolbar"/>
+        <menuseparator id="myPublicKeySeparator_Toolbar"
+                       class="openpgp-item"/>
         <menuitem id="menu_securityMyPublicKey_Toolbar"
+                  class="openpgp-item"
                   type="checkbox"
                   label="&menu_securityAttachMyKey.label;"
                   accesskey="&menu_securityAttachMyKey.accesskey;"
                   value="mykey"/>
 #endif
 
         <menuseparator id="statusInfoSeparator"/>
         <menuitem id="menu_securityStatus_Toolbar"
--- a/mail/extensions/am-e2e/am-e2e.inc.xhtml
+++ b/mail/extensions/am-e2e/am-e2e.inc.xhtml
@@ -20,17 +20,17 @@
           <label is="text-link" id="acceptLearnMoreE2E"
                  href="https://support.mozilla.org/kb/introduction-to-e2e-encryption"
                  value="&e2eLearnMore.label;"/>
         </description>
       </vbox>
 
 #ifdef MOZ_OPENPGP
       <html:div>
-      <html:fieldset id="openpgpOptions">
+      <html:fieldset id="openpgpOptions" class="openpgp-item">
         <html:legend>&openpgpKeys.label;</html:legend>
 
         <label id="identity_openpgp_key_nameLabel"
                value="&openpgpKey.message;" control="identity_openpgp_key_id"/>
         <hbox align="center" class="input-container">
           <html:input id="identity_openpgp_key_id" type="text"
                       class="input-inline"
                       readonly="readonly"
@@ -144,23 +144,25 @@
         <description flex="1">&e2eSigning.description;</description>
         <checkbox id="identity_sign_mail" wsm_persist="true"
                   prefstring="mail.identity.%identitykey%.sign_mail"
                   label="&signMessage2.label;" accesskey="&signMessage.accesskey;"/>
 
 #ifdef MOZ_OPENPGP
         <separator/>
 
+        <html:div class="openpgp-item">
         <description>&e2eTechPref.description;</description>
         <radiogroup id="technologyChoices" class="indent">
           <radio id="technology_automatic" wsm_persist="true" value="0"
                  label="&technologyAutomatic.label;"/>
 
           <radio id="technology_prefer_openpgp" wsm_persist="true" value="2"
                  label="&technologyOpenPGP.label;"/>
 
           <radio id="technology_prefer_smime" wsm_persist="true" value="1"
                  label="&technologySMIME.label;"/>
         </radiogroup>
+        </html:div>
 #endif
       </html:fieldset>
       </html:div>
     </vbox>
--- a/mail/extensions/am-e2e/am-e2e.js
+++ b/mail/extensions/am-e2e/am-e2e.js
@@ -42,16 +42,21 @@ var kEncryptionCertPref = "identity_encr
 var kSigningCertPref = "identity_signing_cert_name";
 var kOpenPGPKeyPref = "identity_openpgp_key_id";
 
 var gTechAuto = null;
 var gTechPrefOpenPGP = null;
 var gTechPrefSMIME = null;
 
 function onInit() {
+  if (!MailConstants.MOZ_OPENPGP || !BondOpenPGP.allDependenciesLoaded()) {
+    for (let item of document.querySelectorAll(".openpgp-item")) {
+      item.hidden = true;
+    }
+  }
   e2eInitializeFields();
 }
 
 function e2eInitializeFields() {
   // initialize all of our elements based on the current identity values....
   gEncryptionCertName = document.getElementById(kEncryptionCertPref);
   gHiddenEncryptionPolicy = document.getElementById(
     "identity_encryptionpolicy"
--- a/mail/extensions/am-e2e/prefs/e2e-prefs.js
+++ b/mail/extensions/am-e2e/prefs/e2e-prefs.js
@@ -18,16 +18,19 @@ pref("mail.identity.default.sign_mail", 
 
 pref("mail.identity.default.encryption_cert_name", "");
 pref("mail.identity.default.signing_cert_name", "");
 
 /**
  * OpenPGP prefs
  */
 
+// If false, hide and disable the OpenPGP functionality
+pref("mail.openpgp.enable", true);
+
 // If true, we allow the use of GnuPG for OpenPGP secret key operations
 pref("mail.openpgp.allow_external_gnupg", false);
 // If allow_external_gnupg is true: Optionally use a different gpg executable
 pref("mail.openpgp.alternative_gpg_path", "");
 // The hexadecimal OpenPGP key ID used for an identity.
 pref("mail.identity.default.openpgp_key_id", "");
 
 // When sending, encrypt to this additional key. Not available in release channel builds.
--- a/mail/extensions/openpgp/content/BondOpenPGP.jsm
+++ b/mail/extensions/openpgp/content/BondOpenPGP.jsm
@@ -46,41 +46,49 @@ var { RNPLibLoader } = ChromeUtils.impor
 
 var BondOpenPGP = {
   logException(exc) {
     try {
       Services.console.logStringMessage(exc.toString() + "\n" + exc.stack);
     } catch (x) {}
   },
 
+  isEnabled: false,
   initDone: false,
 
   init() {
     if (!MailConstants.MOZ_OPENPGP) {
       return;
     }
     if (this.initDone) {
       return;
     }
     this.initDone = true;
+    this.isEnabled = Services.prefs.getBoolPref("mail.openpgp.enable");
+    if (!this.isEnabled) {
+      return;
+    }
     if (!getRNP().init({})) {
       return;
     }
 
     if (Services.prefs.getBoolPref("mail.openpgp.allow_external_gnupg")) {
       getGPGME().init({});
     }
 
     // trigger service init
     getEnigmailCore().getService();
     //Services.console.logStringMessage("OpenPGP bootstrap completed");
   },
 
   allDependenciesLoaded() {
     this.init();
+    if (!this.isEnabled) {
+      return false;
+    }
     return getRNP().allDependenciesLoaded();
   },
 
   openKeyManager(window) {
     if (this.allDependenciesLoaded()) {
       getEnigmailWindows().openKeyManager(window);
     }
   },
--- a/mail/extensions/openpgp/content/ui/attachmentItemContext.inc.xhtml
+++ b/mail/extensions/openpgp/content/ui/attachmentItemContext.inc.xhtml
@@ -1,13 +1,13 @@
     <menuseparator/>
-    <menuitem id="enigmail_ctxImportKey"
+    <menuitem id="enigmail_ctxImportKey" class="openpgp-item"
               data-l10n-id="openpgp-ctx-import-key"
               oncommand="Enigmail.msg.handleAttachmentSel('importKey');"/>
-    <menuitem id="enigmail_ctxDecryptOpen"
+    <menuitem id="enigmail_ctxDecryptOpen" class="openpgp-item"
               data-l10n-id="openpgp-ctx-decrypt-open"
               oncommand="Enigmail.msg.handleAttachmentSel('openAttachment');"/>
-    <menuitem id="enigmail_ctxDecryptSave"
+    <menuitem id="enigmail_ctxDecryptSave" class="openpgp-item"
               data-l10n-id="openpgp-ctx-decrypt-save"
               oncommand="Enigmail.msg.handleAttachmentSel('saveAttachment');"/>
-    <menuitem id="enigmail_ctxVerifyAtt"
+    <menuitem id="enigmail_ctxVerifyAtt" class="openpgp-item"
               data-l10n-id="openpgp-ctx-verify-att"
               oncommand="Enigmail.msg.handleAttachmentSel('verifySig');"/>