Bug 943291: Now we use native Windows method to convert strings. r=emk

This commit is contained in:
mycoolclub 2014-09-27 08:37:35 +09:00
parent 141df104d6
commit 3300e040d5

View File

@ -1292,19 +1292,19 @@ HRESULT nsDataObj::GetText(const nsACString & aDataFlavor, FORMATETC& aFE, STGME
if ( aFE.cfFormat == CF_TEXT ) {
// Someone is asking for text/plain; convert the unicode (assuming it's present)
// to text with the correct platform encoding.
char* plainTextData = nullptr;
size_t bufferSize = sizeof(char)*(len + 2);
char* plainTextData = static_cast<char*>(nsMemory::Alloc(bufferSize));
char16_t* castedUnicode = reinterpret_cast<char16_t*>(data);
int32_t plainTextLen = 0;
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, len / 2, &plainTextData, &plainTextLen );
int32_t plainTextLen = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)castedUnicode, len / 2 + 1, plainTextData, bufferSize, NULL, NULL);
// replace the unicode data with our plaintext data. Recall that |plainTextLen| doesn't include
// the null in the length.
nsMemory::Free(data);
if ( plainTextData ) {
if ( plainTextLen ) {
data = plainTextData;
allocLen = plainTextLen + sizeof(char);
allocLen = plainTextLen;
}
else {
nsMemory::Free(plainTextData);
NS_WARNING ( "Oh no, couldn't convert unicode to plain text" );
return S_OK;
}