Bug 1489939 - Replace nsIEditorMailSupport with mozilla::HTMLEditor. r=jorgk
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 13 Sep 2018 17:33:33 +0900
changeset 33143 5237216b5de539afc782736f87772555478d6239
parent 33142 e4373d203bcc042f4343015f3dfb3ff5901c5cf5
child 33144 4bcb46410184d0ef4432b396528a2a8d59a23c4e
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1489939
Bug 1489939 - Replace nsIEditorMailSupport with mozilla::HTMLEditor. r=jorgk
mailnews/compose/src/nsMsgCompose.cpp
mailnews/compose/src/nsMsgCompose.h
mailnews/compose/src/nsMsgSend.cpp
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -19,17 +19,17 @@
 #include "nsIMsgSend.h"
 #include "nsMailHeaders.h"
 #include "nsMsgPrompts.h"
 #include "nsMimeTypes.h"
 #include "nsICharsetConverterManager.h"
 #include "nsTextFormatter.h"
 #include "nsIPlaintextEditor.h"
 #include "nsIHTMLEditor.h"
-#include "nsIEditorMailSupport.h"
+#include "nsIEditor.h"
 #include "plstr.h"
 #include "prmem.h"
 #include "nsIDocShell.h"
 #include "nsIRDFService.h"
 #include "nsRDFCID.h"
 #include "nsAbBaseCID.h"
 #include "nsIAbMDBDirectory.h"
 #include "nsCExternalHandlerService.h"
@@ -59,16 +59,17 @@
 #include "nsIMsgDatabase.h"
 #include "nsStringStream.h"
 #include "nsIMutableArray.h"
 #include "nsArrayUtils.h"
 #include "nsIMsgWindow.h"
 #include "nsITextToSubURI.h"
 #include "nsIAbManager.h"
 #include "nsCRT.h"
+#include "mozilla/HTMLEditor.h"
 #include "mozilla/Services.h"
 #include "mozilla/mailnews/MimeHeaderParser.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/HTMLAnchorElement.h"
 #include "mozilla/dom/HTMLImageElement.h"
 #include "mozilla/dom/Selection.h"
 #include "nsStreamConverter.h"
@@ -431,31 +432,27 @@ nsresult nsMsgCompose::ResetUrisForEmbed
 }
 
 
 /* The purpose of this function is to mark any embedded object that wasn't a RFC822 part
    of the original message as moz-do-not-send.
    That will prevent us to attach data not specified by the user or not present in the
    original message.
 */
-nsresult nsMsgCompose::TagEmbeddedObjects(nsIEditorMailSupport *aEditor)
+nsresult nsMsgCompose::TagEmbeddedObjects(nsIEditor *aEditor)
 {
   nsresult rv = NS_OK;
   uint32_t count;
   uint32_t i;
 
   if (!aEditor)
     return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIEditor> editor = do_QueryInterface(aEditor);
-  if (!editor)
-    return NS_ERROR_FAILURE;
-
   nsCOMPtr<nsIDocument> document;
-  editor->GetDocument(getter_AddRefs(document));
+  aEditor->GetDocument(getter_AddRefs(document));
   if (!document)
     return NS_ERROR_FAILURE;
   nsCOMPtr<nsIArray> aNodeList = GetEmbeddedObjects(document);
   if (!aNodeList)
     return NS_ERROR_FAILURE;
 
   if (NS_FAILED(aNodeList->GetLength(&count)))
     return NS_ERROR_FAILURE;
@@ -639,19 +636,18 @@ nsMsgCompose::ConvertAndLoadComposeWindo
   m_editor->EnableUndo(false);
 
   // Ok - now we need to figure out the charset of the aBuf we are going to send
   // into the editor shell. There are I18N calls to sniff the data and then we need
   // to call the new routine in the editor that will allow us to send in the charset
   //
 
   // Now, insert it into the editor...
-  nsCOMPtr<nsIHTMLEditor> htmlEditor (do_QueryInterface(m_editor));
+  RefPtr<HTMLEditor> htmlEditor = m_editor->AsHTMLEditor();
   nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(m_editor));
-  nsCOMPtr<nsIEditorMailSupport> mailEditor (do_QueryInterface(m_editor));
   int32_t reply_on_top = 0;
   bool sig_bottom = true;
   m_identity->GetReplyOnTop(&reply_on_top);
   m_identity->GetSigBottom(&sig_bottom);
   bool sigOnTop = (reply_on_top == 1 && !sig_bottom);
   bool isForwarded = (mType == nsIMsgCompType::ForwardInline);
 
   // When in paragraph mode, don't call InsertLineBreak() since that inserts
@@ -696,58 +692,58 @@ nsMsgCompose::ConvertAndLoadComposeWindo
           }
         }
       }
 
       InsertDivWrappedTextAtSelection(aPrefix,
                                       NS_LITERAL_STRING("moz-cite-prefix"));
     }
 
-    if (!aBuf.IsEmpty() && mailEditor)
+    if (!aBuf.IsEmpty())
     {
       // This leaves the caret at the right place to insert a bottom signature.
       if (aHTMLEditor) {
         nsAutoString body(aBuf);
         remove_plaintext_tag(body);
-        mailEditor->InsertAsCitedQuotation(body,
+        htmlEditor->InsertAsCitedQuotation(body,
                                            mCiteReference,
                                            true,
                                            getter_AddRefs(nodeInserted));
       } else {
-        mailEditor->InsertAsQuotation(aBuf,
+        htmlEditor->InsertAsQuotation(aBuf,
                                       getter_AddRefs(nodeInserted));
       }
     }
 
     mInsertingQuotedContent = false;
 
-    (void)TagEmbeddedObjects(mailEditor);
+    (void)TagEmbeddedObjects(m_editor);
 
     if (!aSignature.IsEmpty())
     {
       //we cannot add it on top earlier, because TagEmbeddedObjects will mark all images in the signature as "moz-do-not-send"
       if( sigOnTop )
         MoveToBeginningOfDocument();
 
-      if (aHTMLEditor && htmlEditor)
+      if (aHTMLEditor)
         htmlEditor->InsertHTML(aSignature);
-      else if (htmlEditor)
+      else
       {
         textEditor->InsertLineBreak();
         InsertDivWrappedTextAtSelection(aSignature,
                                         NS_LITERAL_STRING("moz-signature"));
       }
 
       if( sigOnTop )
         m_editor->EndOfDocument();
     }
   }
   else
   {
-    if (aHTMLEditor && htmlEditor)
+    if (aHTMLEditor)
     {
       mInsertingQuotedContent = true;
       if (isForwarded && Substring(aBuf, 0, sizeof(MIME_FORWARD_HTML_PREFIX)-1)
                          .EqualsLiteral(MIME_FORWARD_HTML_PREFIX)) {
         // We assign the opening tag inside "<HTML><BODY><BR><BR>" before the
         // two <br> elements.
         // This is a bit hacky but we know that the MIME code prepares the
         // forwarded content like this:
@@ -764,17 +760,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
         htmlEditor->RebuildDocumentFromSource(aBuf);
       }
       mInsertingQuotedContent = false;
 
       // When forwarding a message as inline, or editing as new (which could
       // contain unsanitized remote content), tag any embedded objects
       // with moz-do-not-send=true so they don't get attached upon send.
       if (isForwarded || mType == nsIMsgCompType::EditAsNew)
-        (void)TagEmbeddedObjects(mailEditor);
+        (void)TagEmbeddedObjects(m_editor);
 
       if (!aSignature.IsEmpty())
       {
         if (isForwarded && sigOnTop) {
           // Use our own function, nsEditor::BeginningOfDocument() would position
           // into the <div class="moz-forward-container"> we've just created.
           MoveToBeginningOfDocument();
         } else {
@@ -784,17 +780,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
         }
         htmlEditor->InsertHTML(aSignature);
         if (isForwarded && sigOnTop)
           m_editor->EndOfDocument();
       }
       else
         m_editor->EndOfDocument();
     }
-    else if (htmlEditor)
+    else
     {
       bool sigOnTopInserted = false;
       if (isForwarded && sigOnTop && !aSignature.IsEmpty())
       {
         textEditor->InsertLineBreak();
         InsertDivWrappedTextAtSelection(aSignature,
                                         NS_LITERAL_STRING("moz-signature"));
         m_editor->EndOfDocument();
@@ -838,22 +834,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
 
           // Position into the div, so out content goes there.
           RefPtr<Selection> selection;
           m_editor->GetSelection(getter_AddRefs(selection));
           rv = selection->Collapse(divElem, 0);
           NS_ENSURE_SUCCESS(rv, rv);
         }
 
-        if (mailEditor) {
-          rv = mailEditor->InsertTextWithQuotations(aBuf);
-        } else {
-          // Will we ever get here?
-          rv = textEditor->InsertText(aBuf);
-        }
+        rv = htmlEditor->InsertTextWithQuotations(aBuf);
         NS_ENSURE_SUCCESS(rv, rv);
 
         if (isForwarded) {
           // Special treatment for forwarded messages: Part 2.
           if (sigOnTopInserted) {
             // Sadly the M-C editor inserts a <br> between the <div> for the signature
             // and this <div>, so remove the <br> we don't want.
             nsCOMPtr<nsINode> brBeforeDiv;
@@ -3106,27 +3097,24 @@ QuotingOutputStreamListener::InsertToCom
     {
       if (!aHTMLEditor)
         mCitePrefix.AppendLiteral("\n");
       nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(aEditor));
       if (textEditor)
         textEditor->InsertText(mCitePrefix);
     }
 
-    nsCOMPtr<nsIEditorMailSupport> mailEditor (do_QueryInterface(aEditor));
-    if (mailEditor)
-    {
-      if (aHTMLEditor) {
-        nsAutoString body(mMsgBody);
-        remove_plaintext_tag(body);
-        mailEditor->InsertAsCitedQuotation(body, EmptyString(), true,
-                                           getter_AddRefs(nodeInserted));
-      } else {
-        mailEditor->InsertAsQuotation(mMsgBody, getter_AddRefs(nodeInserted));
-      }
+    RefPtr<mozilla::HTMLEditor> htmlEditor = aEditor->AsHTMLEditor();
+    if (aHTMLEditor) {
+      nsAutoString body(mMsgBody);
+      remove_plaintext_tag(body);
+      htmlEditor->InsertAsCitedQuotation(body, EmptyString(), true,
+                                         getter_AddRefs(nodeInserted));
+    } else {
+      htmlEditor->InsertAsQuotation(mMsgBody, getter_AddRefs(nodeInserted));
     }
     compose->SetInsertingQuotedContent(false);
   }
 
   if (aEditor)
   {
     nsCOMPtr<nsIPlaintextEditor> textEditor = do_QueryInterface(aEditor);
     if (textEditor)
--- a/mailnews/compose/src/nsMsgCompose.h
+++ b/mailnews/compose/src/nsMsgCompose.h
@@ -20,17 +20,17 @@
 #include "nsIMimeConverter.h"
 #include "nsIMsgFolder.h"
 #include "mozIDOMWindow.h"
 #include "mozilla/dom/Element.h"
 
 // Forward declares
 class QuotingOutputStreamListener;
 class nsMsgComposeSendListener;
-class nsIEditorMailSupport;
+class nsIEditor;
 class nsIRDFService;
 class nsIArray;
 struct nsMsgMailList;
 
 class nsMsgCompose : public nsIMsgCompose, public nsSupportsWeakReference
 {
  public:
 
@@ -53,17 +53,17 @@ protected:
   nsresult                      SetQuotingToFollow(bool aVal);
   nsresult                      ConvertHTMLToText(nsIFile *aSigFile, nsString &aSigData);
   nsresult                      ConvertTextToHTML(nsIFile *aSigFile, nsString &aSigData);
   bool                          IsEmbeddedObjectSafe(const char * originalScheme,
                                                      const char * originalHost,
                                                      const char * originalPath,
                                                      mozilla::dom::Element * element);
   nsresult                      ResetUrisForEmbeddedObjects();
-  nsresult                      TagEmbeddedObjects(nsIEditorMailSupport *aMailEditor);
+  nsresult                      TagEmbeddedObjects(nsIEditor *aEditor);
 
   nsCString                     mQuoteCharset;
   nsCString                     mOriginalMsgURI; // used so we can mark message disposition flags after we send the message
 
   int32_t                       mWhatHolder;
 
   nsresult                      LoadDataFromFile(nsIFile *file,
                                                  nsString &sigData,
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -30,27 +30,27 @@
 #include "nsCExternalHandlerService.h"
 #include "nsIMIMEService.h"
 #include "nsIDocument.h"
 #include "nsMsgCompCID.h"
 #include "nsIAbAddressCollector.h"
 #include "nsAbBaseCID.h"
 #include "nsCOMPtr.h"
 #include "mozITXTToHTMLConv.h"
+#include "nsIEditor.h"
 #include "nsIMsgStatusFeedback.h"
 #include "nsIMsgWindow.h"
 #include "nsTextFormatter.h"
 #include "nsIPrompt.h"
 #include "nsMailHeaders.h"
 #include "nsIDocShell.h"
 #include "nsMimeTypes.h"
 #include "nsISmtpUrl.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
-#include "nsIEditorMailSupport.h"
 #include "nsIDocumentEncoder.h"    // for editor output flags
 #include "nsILoadGroup.h"
 #include "nsMsgSendReport.h"
 #include "nsNetCID.h"
 #include "nsError.h"
 #include "nsMsgUtils.h"
 #include "nsIMsgMdnGenerator.h"
 #include "nsISmtpServer.h"