Bug 1505911 - Adapt to mozITXTToHTMLConv API changes (AString instead of wstring) in C-C. r=valentin
authorJorg K <jorgk@jorgk.com>
Sat, 01 Dec 2018 14:28:51 +0100
changeset 32983 e4612d760fefe9e52c9df8edafbf1d56605483c3
parent 32982 f93942f170c422356fc66624dc70c08ebdd53df5
child 32984 f93acb5a0e1b922f5a5c76e5aeebfbf208bea88b
push id2343
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:37:21 +0000
treeherdercomm-beta@a0750c375f71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1505911
Bug 1505911 - Adapt to mozITXTToHTMLConv API changes (AString instead of wstring) in C-C. r=valentin
mailnews/addrbook/src/nsAbCardProperty.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/mime/src/mimetpfl.cpp
mailnews/mime/src/mimetpla.cpp
--- a/mailnews/addrbook/src/nsAbCardProperty.cpp
+++ b/mailnews/addrbook/src/nsAbCardProperty.cpp
@@ -811,28 +811,26 @@ nsresult nsAbCardProperty::ConvertToXMLP
 
   nsString xmlStr;
   xmlStr.SetLength(4096); // to reduce allocations. should be enough for most cards
   xmlStr.AssignLiteral("<GeneratedName>\n");
 
   // use ScanTXT to convert < > & to safe values.
   nsString safeText;
   if (!generatedName.IsEmpty()) {
-    rv = conv->ScanTXT(generatedName.get(), mozITXTToHTMLConv::kEntities,
-                       getter_Copies(safeText));
+    rv = conv->ScanTXT(generatedName, mozITXTToHTMLConv::kEntities, safeText);
     NS_ENSURE_SUCCESS(rv,rv);
   }
 
   if (safeText.IsEmpty()) {
     nsAutoString primaryEmail;
     GetPrimaryEmail(primaryEmail);
 
     // use ScanTXT to convert < > & to safe values.
-    rv = conv->ScanTXT(primaryEmail.get(), mozITXTToHTMLConv::kEntities,
-                       getter_Copies(safeText));
+    rv = conv->ScanTXT(primaryEmail, mozITXTToHTMLConv::kEntities, safeText);
     NS_ENSURE_SUCCESS(rv,rv);
   }
   xmlStr.Append(safeText);
 
   xmlStr.AppendLiteral("</GeneratedName>\n"
                        "<table><tr><td>");
 
   rv = AppendSection(NAME_ATTRS_ARRAY, sizeof(NAME_ATTRS_ARRAY)/sizeof(AppendItem), EmptyString(), bundle, conv, xmlStr);
@@ -882,28 +880,26 @@ nsresult nsAbCardProperty::ConvertToXMLP
 
           xmlStr.AppendLiteral("<PrimaryEmail>\n");
 
           rv = listCard->GetDisplayName(displayName);
           NS_ENSURE_SUCCESS(rv,rv);
 
           // use ScanTXT to convert < > & to safe values.
           nsString safeText;
-          rv = conv->ScanTXT(displayName.get(), mozITXTToHTMLConv::kEntities,
-                             getter_Copies(safeText));
+          rv = conv->ScanTXT(displayName, mozITXTToHTMLConv::kEntities, safeText);
           NS_ENSURE_SUCCESS(rv,rv);
           xmlStr.Append(safeText);
 
           xmlStr.AppendLiteral(" &lt;");
 
           listCard->GetPrimaryEmail(primaryEmail);
 
           // use ScanTXT to convert < > & to safe values.
-          rv = conv->ScanTXT(primaryEmail.get(), mozITXTToHTMLConv::kEntities,
-                             getter_Copies(safeText));
+          rv = conv->ScanTXT(primaryEmail, mozITXTToHTMLConv::kEntities, safeText);
           NS_ENSURE_SUCCESS(rv,rv);
           xmlStr.Append(safeText);
 
           xmlStr.AppendLiteral("&gt;</PrimaryEmail>\n");
         }
       }
     }
     xmlStr.AppendLiteral("</section>");
@@ -989,17 +985,17 @@ nsresult nsAbCardProperty::AppendLine(co
     return NS_OK;
 
   aResult.Append(char16_t('<'));
   aResult.Append(NS_ConvertUTF8toUTF16(aItem.mColumn));
   aResult.Append(char16_t('>'));
 
   // use ScanTXT to convert < > & to safe values.
   nsString safeText;
-  rv = aConv->ScanTXT(attrValue.get(), mozITXTToHTMLConv::kEntities, getter_Copies(safeText));
+  rv = aConv->ScanTXT(attrValue, mozITXTToHTMLConv::kEntities, safeText);
   NS_ENSURE_SUCCESS(rv,rv);
   aResult.Append(safeText);
 
   aResult.AppendLiteral("</");
   aResult.Append(NS_ConvertUTF8toUTF16(aItem.mColumn));
   aResult.Append(char16_t('>'));
 
   return NS_OK;
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -1478,33 +1478,31 @@ nsMsgComposeAndSend::GetBodyFromEditor()
 
   //
   // Query the editor, get the body of HTML!
   //
   uint32_t flags = nsIDocumentEncoder::OutputFormatted |
                    nsIDocumentEncoder::OutputNoFormattingInPre |
                    nsIDocumentEncoder::OutputDisallowLineBreaking;
   nsAutoString bodyStr;
-  char16_t* bodyText = nullptr;
+  nsAutoString bodyText;
   nsresult rv;
-  char16_t *origHTMLBody = nullptr;
+  nsAutoString origHTMLBody;
 
   // Ok, get the body...the DOM should have been whacked with
   // Content ID's already
   if (mEditor)
     mEditor->OutputToString(NS_LITERAL_STRING(TEXT_HTML), flags, bodyStr);
   else
     bodyStr = NS_ConvertASCIItoUTF16(m_attachment1_body);
 
   // If we really didn't get a body, just return NS_OK
   if (bodyStr.IsEmpty())
     return NS_OK;
-  bodyText = ToNewUnicode(bodyStr);
-  if (!bodyText)
-    return NS_ERROR_OUT_OF_MEMORY;
+  bodyText = bodyStr;
 
   // If we are forcing this to be plain text, we should not be
   // doing this conversion.
   bool doConversion = true;
 
   if ( (mCompFields) && mCompFields->GetForcePlainText() )
     doConversion = false;
 
@@ -1519,18 +1517,18 @@ nsMsgComposeAndSend::GetBodyFromEditor()
       nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
       if (pPrefBranch)
       {
         rv = pPrefBranch->GetBoolPref(PREF_MAIL_SEND_STRUCT, &enable_structs);
         if (enable_structs)
           whattodo = whattodo | mozITXTToHTMLConv::kStructPhrase;
       }
 
-      char16_t* wresult;
-      rv = conv->ScanHTML(bodyText, whattodo, &wresult);
+      nsAutoString wresult;
+      rv = conv->ScanHTML(bodyText, whattodo, wresult);
       if (NS_SUCCEEDED(rv))
       {
         // Save the original body for possible attachment as plain text
         // We should have what the user typed in stored in mOriginalHTMLBody
         origHTMLBody = bodyText;
         bodyText = wresult;
       }
     }
@@ -1539,19 +1537,19 @@ nsMsgComposeAndSend::GetBodyFromEditor()
   nsCString attachment1_body;
 
   // Convert body to mail charset
   nsCString    outCString;
   const char  *aCharset = mCompFields->GetCharacterSet();
 
   if (aCharset && *aCharset)
   {
-    bool isAsciiOnly = NS_IsAscii(bodyText);
+    bool isAsciiOnly = NS_IsAscii(bodyText.get());
     rv = nsMsgI18NConvertFromUnicode(nsDependentCString(aCharset),
-                                     nsDependentString(bodyText),
+                                     bodyText,
                                      outCString,
                                      true);
     if (mCompFields->GetForceMsgEncoding())
       isAsciiOnly = false;
     mCompFields->SetBodyIsAsciiOnly(isAsciiOnly);
 
     // If the body contains characters outside the current mail charset,
     // convert to UTF-8.
@@ -1568,45 +1566,43 @@ nsMsgComposeAndSend::GetBodyFromEditor()
         if (prefBranch)
         {
           nsCString prefName("mailnews.disable_fallback_to_utf8.");
           prefName.Append(aCharset);
           prefBranch->GetBoolPref(prefName.get(), &disableFallback);
         }
         if (!disableFallback)
         {
-          CopyUTF16toUTF8(nsDependentString(bodyText), outCString);
+          CopyUTF16toUTF8(bodyText, outCString);
           mCompFields->SetCharacterSet("UTF-8");
         }
       }
     }
 
     if (NS_SUCCEEDED(rv))
       attachment1_body = outCString;
 
     // If we have an origHTMLBody that is not null, this means that it is
     // different than the bodyText because of formatting conversions. Because of
     // this we need to do the charset conversion on this part separately
-    if (origHTMLBody)
+    if (!origHTMLBody.IsEmpty())
     {
       nsCString newBody;
       rv = nsMsgI18NConvertFromUnicode(nsDependentCString(aCharset),
-                                       nsDependentString(origHTMLBody),
+                                       origHTMLBody,
                                        newBody,
                                        true);
       if (NS_SUCCEEDED(rv))
       {
         mOriginalHTMLBody = ToNewCString(newBody);
       }
     }
     else {
       mOriginalHTMLBody = ToNewCString(attachment1_body);
     }
-
-    free(bodyText);    //Don't need it anymore
   }
   else
     return NS_ERROR_FAILURE;
 
   rv = SnarfAndCopyBody(attachment1_body, TEXT_HTML);
 
   return rv;
 }
--- a/mailnews/mime/src/mimetpfl.cpp
+++ b/mailnews/mime/src/mimetpfl.cpp
@@ -378,17 +378,17 @@ MimeInlineTextPlainFlowed_parse_line (co
         else // this probably never happens...
           CopyUTF8toUTF16(inputStr, lineSource);
       }
       else   // line is in UTF-8
         CopyUTF8toUTF16(inputStr, lineSource);
 
       // This is the main TXT to HTML conversion:
       // escaping (very important), eventually recognizing etc.
-      rv = conv->ScanTXT(lineSource.get(), whattodo, getter_Copies(lineResult));
+      rv = conv->ScanTXT(lineSource, whattodo, lineResult);
       NS_ENSURE_SUCCESS(rv, -1);
     }
   }
   else
   {
     CopyUTF8toUTF16(nsDependentCString(line, length), lineResult);
     status = 0;
   }
--- a/mailnews/mime/src/mimetpla.cpp
+++ b/mailnews/mime/src/mimetpla.cpp
@@ -384,18 +384,18 @@ MimeInlineTextPlain_parse_line (const ch
     {
       if (!plainHTML)
         prefaceResultStr += "<span class=\"moz-txt-citetags\">";
 
       nsString citeTagsSource(StringHead(lineSourceStr, logicalLineStart));
 
       // Convert to HTML
       nsString citeTagsResultUnichar;
-      rv = conv->ScanTXT(citeTagsSource.get(), 0 /* no recognition */,
-                         getter_Copies(citeTagsResultUnichar));
+      rv = conv->ScanTXT(citeTagsSource, 0 /* no recognition */,
+                         citeTagsResultUnichar);
       if (NS_FAILED(rv)) return -1;
 
       prefaceResultStr.Append(NS_ConvertUTF16toUTF8(citeTagsResultUnichar));
       if (!plainHTML)
         prefaceResultStr += "</span>";
     }
 
 
@@ -410,18 +410,17 @@ MimeInlineTextPlain_parse_line (const ch
         prefaceResultStr += "<div class=\"moz-txt-sig\">";
     }
 
 
     /* This is the main TXT to HTML conversion:
        escaping (very important), eventually recognizing etc. */
     nsString lineResultUnichar;
 
-    rv = conv->ScanTXT(lineSourceStr.get() + logicalLineStart,
-                       whattodo, getter_Copies(lineResultUnichar));
+    rv = conv->ScanTXT(Substring(lineSourceStr, logicalLineStart), whattodo, lineResultUnichar);
     NS_ENSURE_SUCCESS(rv, -1);
 
     if (!(text->mIsSig && quoting && text->mStripSig))
     {
       status = MimeObject_write(obj, prefaceResultStr.get(), prefaceResultStr.Length(), true);
       if (status < 0) return status;
       nsAutoCString outString;
       if (obj->options->format_out != nsMimeOutput::nsMimeMessageSaveAs ||