Bug 1313280 - Fix invalid non-UTF-8 bytes from widget/. r=jimm
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Wed, 02 Nov 2016 20:46:53 +0900
changeset 351931 53b841d7ad4dbcabd43d080c8837a0ea402fce31
parent 351930 b1d62e7171efc9d8ec596456399b2d35737d865b
child 351932 a37db7ce8715e3d40726a9a9f3e776fcebc2846e
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1313280
milestone52.0a1
Bug 1313280 - Fix invalid non-UTF-8 bytes from widget/. r=jimm MozReview-Commit-ID: 8rVh7Kbn7F
widget/nsHTMLFormatConverter.cpp
--- a/widget/nsHTMLFormatConverter.cpp
+++ b/widget/nsHTMLFormatConverter.cpp
@@ -38,23 +38,23 @@ NS_IMPL_ISUPPORTS(nsHTMLFormatConverter,
 // Flavors (strings) are wrapped in a primitive object so that JavaScript can
 // access them easily via XPConnect.
 //
 NS_IMETHODIMP
 nsHTMLFormatConverter::GetInputDataFlavors(nsIArray **_retval)
 {
   if ( !_retval )
     return NS_ERROR_INVALID_ARG;
-  
+
   nsCOMPtr<nsIMutableArray> array = nsArray::Create();
   nsresult rv = AddFlavorToList ( array, kHTMLMime );
-  
+
   array.forget(_retval);
   return rv;
-  
+
 } // GetInputDataFlavors
 
 
 //
 // GetOutputDataFlavors
 //
 // Creates a new list and returns the list of all the flavors this converter
 // knows how to export (convert). In this case, it's all sorts of things that HTML can be
@@ -63,17 +63,17 @@ nsHTMLFormatConverter::GetInputDataFlavo
 // Flavors (strings) are wrapped in a primitive object so that JavaScript can
 // access them easily via XPConnect.
 //
 NS_IMETHODIMP
 nsHTMLFormatConverter::GetOutputDataFlavors(nsIArray **_retval)
 {
   if ( !_retval )
     return NS_ERROR_INVALID_ARG;
-  
+
   nsCOMPtr<nsIMutableArray> array = nsArray::Create();
   nsresult rv = AddFlavorToList ( array, kHTMLMime );
   if ( NS_FAILED(rv) )
     return rv;
   rv = AddFlavorToList ( array, kUnicodeMime );
   if ( NS_FAILED(rv) )
     return rv;
 
@@ -88,17 +88,17 @@ nsHTMLFormatConverter::GetOutputDataFlav
 //
 // Convenience routine for adding a flavor wrapped in an nsISupportsCString object
 // to a list
 //
 nsresult
 nsHTMLFormatConverter :: AddFlavorToList ( nsCOMPtr<nsIMutableArray>& inList, const char* inFlavor )
 {
   nsresult rv;
-  
+
   nsCOMPtr<nsISupportsCString> dataFlavor =
       do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
   if ( dataFlavor ) {
     dataFlavor->SetData ( nsDependentCString(inFlavor) );
     // add to list as an nsISupports so the correct interface gets the addref
     // in AppendElement()
     nsCOMPtr<nsISupports> genericFlavor ( do_QueryInterface(dataFlavor) );
     inList->AppendElement ( genericFlavor, /*weak =*/ false);
@@ -147,77 +147,77 @@ nsHTMLFormatConverter::CanConvert(const 
 // accessible from JS. Currently, this only accepts HTML input, so anything else is invalid.
 //
 //XXX This method copies the data WAAAAY too many time for my liking. Grrrrrr. Mostly it's because
 //XXX we _must_ put things into nsStrings so that the parser will accept it. Lame lame lame lame. We
 //XXX also can't just get raw unicode out of the nsString, so we have to allocate heap to get
 //XXX unicode out of the string. Lame lame lame.
 //
 NS_IMETHODIMP
-nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromData, uint32_t aDataLen, 
+nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromData, uint32_t aDataLen,
                                const char *aToDataFlavor, nsISupports **aToData, uint32_t *aDataToLen)
 {
   if ( !aToData || !aDataToLen )
     return NS_ERROR_INVALID_ARG;
 
   nsresult rv = NS_OK;
   *aToData = nullptr;
   *aDataToLen = 0;
 
   if ( !nsCRT::strcmp(aFromDataFlavor, kHTMLMime) ) {
     nsAutoCString toFlavor ( aToDataFlavor );
 
     // HTML on clipboard is going to always be double byte so it will be in a primitive
-    // class of nsISupportsString. Also, since the data is in two byte chunks the 
+    // class of nsISupportsString. Also, since the data is in two byte chunks the
     // length represents the length in 1-byte chars, so we need to divide by two.
     nsCOMPtr<nsISupportsString> dataWrapper0 ( do_QueryInterface(aFromData) );
     if (!dataWrapper0) {
       return NS_ERROR_INVALID_ARG;
     }
 
     nsAutoString dataStr;
-    dataWrapper0->GetData ( dataStr );  //еее COPY #1
-    // note: conversion to text/plain is done inside the clipboard. we do not need to worry 
+    dataWrapper0->GetData ( dataStr );  // COPY #1
+    // note: conversion to text/plain is done inside the clipboard. we do not need to worry
     // about it here.
     if ( toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kUnicodeMime) ) {
       nsresult res;
       if (toFlavor.Equals(kHTMLMime)) {
         int32_t dataLen = dataStr.Length() * 2;
         nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor.get(), dataStr.get(), dataLen, aToData );
         if ( *aToData )
           *aDataToLen = dataLen;
       } else {
         nsAutoString outStr;
         res = ConvertFromHTMLToUnicode(dataStr, outStr);
         if (NS_SUCCEEDED(res)) {
           int32_t dataLen = outStr.Length() * 2;
           nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor.get(), outStr.get(), dataLen, aToData );
-          if ( *aToData ) 
+          if ( *aToData )
             *aDataToLen = dataLen;
         }
       }
     } // else if HTML or Unicode
     else if ( toFlavor.Equals(kAOLMailMime) ) {
       nsAutoString outStr;
       if ( NS_SUCCEEDED(ConvertFromHTMLToAOLMail(dataStr, outStr)) ) {
         int32_t dataLen = outStr.Length() * 2;
         nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor.get(), outStr.get(), dataLen, aToData );
-        if ( *aToData ) 
+        if ( *aToData )
           *aDataToLen = dataLen;
       }
     } // else if AOL mail
     else {
       rv = NS_ERROR_FAILURE;
     }
   } // if we got html mime
   else
-    rv = NS_ERROR_FAILURE;      
-    
+    rv = NS_ERROR_FAILURE;
+
   return rv;
-  
+
 } // Convert
 
 
 //
 // ConvertFromHTMLToUnicode
 //
 // Takes HTML and converts it to plain text but in unicode.
 //