Bug 1493292 - Remove len from nsIFormatConverter. r=smaug

Depends on D11204

Differential Revision: https://phabricator.services.mozilla.com/D11205

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2018-11-20 14:47:13 +00:00
Родитель e2f59a0c22
Коммит 2ab01e399b
4 изменённых файлов: 9 добавлений и 21 удалений

Просмотреть файл

@ -91,8 +91,7 @@ function convertHTMLToPlainText(html) {
input.data = html.replace(/\n/g, "<br>"); input.data = html.replace(/\n/g, "<br>");
var output = {}; var output = {};
converter.convert("text/html", input, input.data.length, "text/unicode", converter.convert("text/html", input, "text/unicode", output);
output, {});
if (output.value instanceof Ci.nsISupportsString) if (output.value instanceof Ci.nsISupportsString)
return output.value.data.replace(/\r\n/g, "\n"); return output.value.data.replace(/\r\n/g, "\n");

Просмотреть файл

@ -102,15 +102,14 @@ nsHTMLFormatConverter::CanConvert(const char *aFromDataFlavor, const char *aToDa
//XXX unicode out of the string. Lame lame lame. //XXX unicode out of the string. Lame lame lame.
// //
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromData, uint32_t aDataLen, nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromData,
const char *aToDataFlavor, nsISupports **aToData, uint32_t *aDataToLen) const char *aToDataFlavor, nsISupports **aToData)
{ {
if ( !aToData || !aDataToLen ) if ( !aToData )
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
nsresult rv = NS_OK; nsresult rv = NS_OK;
*aToData = nullptr; *aToData = nullptr;
*aDataToLen = 0;
if ( !nsCRT::strcmp(aFromDataFlavor, kHTMLMime) ) { if ( !nsCRT::strcmp(aFromDataFlavor, kHTMLMime) ) {
nsAutoCString toFlavor ( aToDataFlavor ); nsAutoCString toFlavor ( aToDataFlavor );
@ -132,16 +131,12 @@ nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDa
if (toFlavor.Equals(kHTMLMime)) { if (toFlavor.Equals(kHTMLMime)) {
int32_t dataLen = dataStr.Length() * 2; int32_t dataLen = dataStr.Length() * 2;
nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, dataStr.get(), dataLen, aToData ); nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, dataStr.get(), dataLen, aToData );
if ( *aToData )
*aDataToLen = dataLen;
} else { } else {
nsAutoString outStr; nsAutoString outStr;
res = ConvertFromHTMLToUnicode(dataStr, outStr); res = ConvertFromHTMLToUnicode(dataStr, outStr);
if (NS_SUCCEEDED(res)) { if (NS_SUCCEEDED(res)) {
int32_t dataLen = outStr.Length() * 2; int32_t dataLen = outStr.Length() * 2;
nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, outStr.get(), dataLen, aToData ); nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, outStr.get(), dataLen, aToData );
if ( *aToData )
*aDataToLen = dataLen;
} }
} }
} // else if HTML or Unicode } // else if HTML or Unicode
@ -150,8 +145,6 @@ nsHTMLFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDa
if ( NS_SUCCEEDED(ConvertFromHTMLToAOLMail(dataStr, outStr)) ) { if ( NS_SUCCEEDED(ConvertFromHTMLToAOLMail(dataStr, outStr)) ) {
int32_t dataLen = outStr.Length() * 2; int32_t dataLen = outStr.Length() * 2;
nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, outStr.get(), dataLen, aToData ); nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, outStr.get(), dataLen, aToData );
if ( *aToData )
*aDataToLen = dataLen;
} }
} // else if AOL mail } // else if AOL mail
else { else {

Просмотреть файл

@ -39,8 +39,8 @@ interface nsIFormatConverter : nsISupports
* @param aFromFormatConverter flavor to convert to (destination own the memory) * @param aFromFormatConverter flavor to convert to (destination own the memory)
* @returns returns NS_OK if it was converted * @returns returns NS_OK if it was converted
*/ */
void convert ( in string aFromDataFlavor, in nsISupports aFromData, in unsigned long aDataLen, void convert ( in string aFromDataFlavor, in nsISupports aFromData,
in string aToDataFlavor, out nsISupports aToData, out unsigned long aDataToLen ) ; in string aToDataFlavor, out nsISupports aToData ) ;
}; };

Просмотреть файл

@ -307,9 +307,8 @@ nsTransferable::GetTransferData(const char* aFlavor,
} }
} }
uint32_t dataLen; return mFormatConv->Convert(data.GetFlavor().get(), dataBytes, aFlavor,
return mFormatConv->Convert(data.GetFlavor().get(), dataBytes, 0, aData);
aFlavor, aData, &dataLen);
} }
} }
} }
@ -368,13 +367,10 @@ nsTransferable::SetTransferData(const char* aFlavor,
if (canConvert) { if (canConvert) {
nsCOMPtr<nsISupports> ConvertedData; nsCOMPtr<nsISupports> ConvertedData;
uint32_t ConvertedLen;
mFormatConv->Convert(aFlavor, mFormatConv->Convert(aFlavor,
aData, aData,
0,
data.GetFlavor().get(), data.GetFlavor().get(),
getter_AddRefs(ConvertedData), getter_AddRefs(ConvertedData));
&ConvertedLen);
data.SetData(ConvertedData, mPrivateData); data.SetData(ConvertedData, mPrivateData);
return NS_OK; return NS_OK;
} }