Bug 1493292 - Remove len from nsIFormatConverter. r=smaug
☠☠ backed out by 4b0554a10847 ☠ ☠
authorTom Schuster <evilpies@gmail.com>
Tue, 20 Nov 2018 14:47:13 +0000
changeset 447227 f198bf91320bf774f2c9f204c426ac0c2da95aa2
parent 447226 6487aa307123e63554a714e0cece6273e57017b1
child 447228 5bad4fe7108eda1ca69c5f5aac82b4042c874deb
push id35073
push usershindli@mozilla.com
push dateTue, 20 Nov 2018 21:42:44 +0000
treeherdermozilla-central@117bb70216d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1493292
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1493292 - Remove len from nsIFormatConverter. r=smaug Depends on D11204 Differential Revision: https://phabricator.services.mozilla.com/D11205
toolkit/mozapps/extensions/internal/AddonRepository.jsm
widget/nsHTMLFormatConverter.cpp
widget/nsIFormatConverter.idl
widget/nsTransferable.cpp
--- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm
@@ -86,18 +86,17 @@ function convertHTMLToPlainText(html) {
   var converter = Cc["@mozilla.org/widget/htmlformatconverter;1"].
                   createInstance(Ci.nsIFormatConverter);
 
   var input = Cc["@mozilla.org/supports-string;1"].
               createInstance(Ci.nsISupportsString);
   input.data = html.replace(/\n/g, "<br>");
 
   var output = {};
-  converter.convert("text/html", input, input.data.length, "text/unicode",
-                    output, {});
+  converter.convert("text/html", input, "text/unicode", output);
 
   if (output.value instanceof Ci.nsISupportsString)
     return output.value.data.replace(/\r\n/g, "\n");
   return html;
 }
 
 async function getAddonsToCache(aIds) {
   let types = Preferences.get(PREF_GETADDONS_CACHE_TYPES) || DEFAULT_CACHE_TYPES;
--- a/widget/nsHTMLFormatConverter.cpp
+++ b/widget/nsHTMLFormatConverter.cpp
@@ -97,25 +97,24 @@ 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,
-                               const char *aToDataFlavor, nsISupports **aToData, uint32_t *aDataToLen)
+nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromData,
+                               const char *aToDataFlavor, nsISupports **aToData)
 {
-  if ( !aToData || !aDataToLen )
+  if ( !aToData )
     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
     // length represents the length in 1-byte chars, so we need to divide by two.
     nsCOMPtr<nsISupportsString> dataWrapper0 ( do_QueryInterface(aFromData) );
@@ -127,36 +126,30 @@ nsHTMLFormatConverter::Convert(const cha
     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, 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, outStr.get(), dataLen, 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, outStr.get(), dataLen, aToData );
-        if ( *aToData )
-          *aDataToLen = dataLen;
       }
     } // else if AOL mail
     else {
       rv = NS_ERROR_FAILURE;
     }
   } // if we got html mime
   else
     rv = NS_ERROR_FAILURE;
--- a/widget/nsIFormatConverter.idl
+++ b/widget/nsIFormatConverter.idl
@@ -34,17 +34,17 @@ interface nsIFormatConverter : nsISuppor
 
   /**
     * Converts from one flavor to another.
     *
     * @param  aFromFormatConverter flavor to convert from
     * @param  aFromFormatConverter flavor to convert to (destination own the memory)
     * @returns returns NS_OK if it was converted
     */
-  void convert ( in string aFromDataFlavor, in nsISupports aFromData, in unsigned long aDataLen,
-                   in string aToDataFlavor, out nsISupports aToData, out unsigned long aDataToLen ) ; 
+  void convert ( in string aFromDataFlavor, in nsISupports aFromData,
+                   in string aToDataFlavor, out nsISupports aToData ) ; 
 
 };
 
 
 %{ C++
 
 %}
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -302,19 +302,18 @@ nsTransferable::GetTransferData(const ch
           rv = dataProvider->GetFlavorData(this, aFlavor,
                                            getter_AddRefs(dataBytes));
           if (NS_FAILED(rv)) {
             // Give up.
             return rv;
           }
         }
 
-        uint32_t dataLen;
-        return mFormatConv->Convert(data.GetFlavor().get(), dataBytes, 0,
-                                    aFlavor, aData, &dataLen);
+        return mFormatConv->Convert(data.GetFlavor().get(), dataBytes, aFlavor,
+                                    aData);
       }
     }
   }
 
   return NS_ERROR_FAILURE;
 }
 
 //
@@ -363,23 +362,20 @@ nsTransferable::SetTransferData(const ch
   if (mFormatConv) {
     for (size_t i = 0; i < mDataArray.Length(); ++i) {
       DataStruct& data = mDataArray.ElementAt(i);
       bool canConvert = false;
       mFormatConv->CanConvert(aFlavor, data.GetFlavor().get(), &canConvert);
 
       if (canConvert) {
         nsCOMPtr<nsISupports> ConvertedData;
-        uint32_t ConvertedLen;
         mFormatConv->Convert(aFlavor,
                              aData,
-                             0,
                              data.GetFlavor().get(),
-                             getter_AddRefs(ConvertedData),
-                             &ConvertedLen);
+                             getter_AddRefs(ConvertedData));
         data.SetData(ConvertedData, mPrivateData);
         return NS_OK;
       }
     }
   }
 
   // Can't set data neither directly nor through converter. Just add this flavor
   // and try again