Bug 777732 - Remove compose windows recycling (part 2-correction). r=aceman
authorJorg K
Thu, 31 Mar 2016 20:15:36 +0200
changeset 24736 e2b4f60836623eabf99b560def6e3c0ed0a9e444
parent 24735 bfd81bd6163ba7469b7b4744c8656ff847620796
child 24737 5d5f6a1ada2667aaeba53d8ded15e3de6bcd6095
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman
bugs777732
Bug 777732 - Remove compose windows recycling (part 2-correction). r=aceman
mail/extensions/smime/content/msgCompSMIMEOverlay.js
mailnews/extensions/smime/content/msgCompSMIMEOverlay.js
--- a/mail/extensions/smime/content/msgCompSMIMEOverlay.js
+++ b/mail/extensions/smime/content/msgCompSMIMEOverlay.js
@@ -17,24 +17,61 @@ var gEncryptedURIService =
                   .getService(Components.interfaces.nsIEncryptedSMIMEURIsService);
 
 var gNextSecurityButtonCommand = "";
 var gSMFields = null;
 
 var gEncryptOptionChanged;
 var gSignOptionChanged;
 
+function onComposerLoad()
+{
+  // Are we already set up ? Or are the required fields missing ?
+  if (gSMFields || !gMsgCompose || !gMsgCompose.compFields)
+    return;
+
+  gMsgCompose.compFields.securityInfo = null;
+
+  gSMFields = Components.classes["@mozilla.org/messenger-smime/composefields;1"]
+                        .createInstance(Components.interfaces.nsIMsgSMIMECompFields);
+  if (!gSMFields)
+    return;
+
+  gMsgCompose.compFields.securityInfo = gSMFields;
+
+  // Set up the intial security state.
+  gSMFields.requireEncryptMessage =
+    gCurrentIdentity.getIntAttribute("encryptionpolicy") == kEncryptionPolicy_Always;
+  if (!gSMFields.requireEncryptMessage &&
+      gEncryptedURIService &&
+      gEncryptedURIService.isEncrypted(gMsgCompose.originalMsgURI))
+  {
+    // Override encryption setting if original is known as encrypted.
+    gSMFields.requireEncryptMessage = true;
+  }
+  if (gSMFields.requireEncryptMessage)
+    setEncryptionUI();
+  else
+    setNoEncryptionUI();
+
+  gSMFields.signMessage = gCurrentIdentity.getBoolAttribute("sign_mail");
+  if (gSMFields.signMessage)
+    setSignatureUI();
+  else
+    setNoSignatureUI();
+}
+
 addEventListener("load", smimeComposeOnLoad, false);
 
 // this function gets called multiple times.
 function smimeComposeOnLoad()
 {
   removeEventListener("load", smimeComposeOnLoad, false);
 
-  onComposerReOpen();
+  onComposerLoad();
 
   top.controllers.appendController(SecurityController);
 
   addEventListener("compose-from-changed", onComposerFromChanged, true);
   addEventListener("compose-send-message", onComposerSendMessage, true);
 
   addEventListener("unload", smimeComposeOnUnload, false);
 }
--- a/mailnews/extensions/smime/content/msgCompSMIMEOverlay.js
+++ b/mailnews/extensions/smime/content/msgCompSMIMEOverlay.js
@@ -15,24 +15,61 @@ var gEncryptedURIService =
         Components.classes["@mozilla.org/messenger-smime/smime-encrypted-uris-service;1"]
                   .getService(Components.interfaces.nsIEncryptedSMIMEURIsService);
 
 var gNextSecurityButtonCommand = "";
 var gSMFields = null;
 var gEncryptOptionChanged;
 var gSignOptionChanged;
 
+function onComposerLoad()
+{
+  // Are we already set up ? Or are the required fields missing ?
+  if (gSMFields || !gMsgCompose || !gMsgCompose.compFields)
+    return;
+
+  gMsgCompose.compFields.securityInfo = null;
+
+  gSMFields = Components.classes["@mozilla.org/messenger-smime/composefields;1"]
+                        .createInstance(Components.interfaces.nsIMsgSMIMECompFields);
+  if (!gSMFields)
+    return;
+
+  gMsgCompose.compFields.securityInfo = gSMFields;
+
+  // Set up the intial security state.
+  gSMFields.requireEncryptMessage =
+    gCurrentIdentity.getIntAttribute("encryptionpolicy") == kEncryptionPolicy_Always;
+  if (!gSMFields.requireEncryptMessage &&
+      gEncryptedURIService &&
+      gEncryptedURIService.isEncrypted(gMsgCompose.originalMsgURI))
+  {
+    // Override encryption setting if original is known as encrypted.
+    gSMFields.requireEncryptMessage = true;
+  }
+  if (gSMFields.requireEncryptMessage)
+    setEncryptionUI();
+  else
+    setNoEncryptionUI();
+
+  gSMFields.signMessage = gCurrentIdentity.getBoolAttribute("sign_mail");
+  if (gSMFields.signMessage)
+    setSignatureUI();
+  else
+    setNoSignatureUI();
+}
+
 addEventListener("load", smimeComposeOnLoad, false);
 
 // this function gets called multiple times
 function smimeComposeOnLoad()
 {
   removeEventListener("load", smimeComposeOnLoad, false);
 
-  onComposerReOpen();
+  onComposerLoad();
 
   top.controllers.appendController(SecurityController);
 
   addEventListener("compose-from-changed", onComposerFromChanged, true);
   addEventListener("compose-send-message", onComposerSendMessage, true);
 
   addEventListener("unload", smimeComposeOnUnload, false);
 }