bug 457313:nuke nsGlobalWindow::ConvertCharset r+sr=bz

This commit is contained in:
Taras Glek 2008-09-29 16:41:21 -07:00
parent e31c9fa941
commit 1e2fb88a24
2 changed files with 0 additions and 62 deletions

View File

@ -87,7 +87,6 @@
// Interfaces Needed
#include "nsIWidget.h"
#include "nsIBaseWindow.h"
#include "nsICharsetConverterManager.h"
#include "nsIContent.h"
#include "nsIContentViewerEdit.h"
#include "nsIDocShell.h"
@ -5983,65 +5982,6 @@ nsGlobalWindow::UpdateCommands(const nsAString& anAction)
return NS_OK;
}
nsresult
nsGlobalWindow::ConvertCharset(const nsAString& aStr, char** aDest)
{
nsresult result = NS_OK;
nsCOMPtr<nsIUnicodeEncoder> encoder;
nsCOMPtr<nsICharsetConverterManager>
ccm(do_GetService(kCharsetConverterManagerCID));
NS_ENSURE_TRUE(ccm, NS_ERROR_FAILURE);
// Get the document character set
nsCAutoString charset(NS_LITERAL_CSTRING("UTF-8")); // default to utf-8
if (mDoc) {
charset = mDoc->GetDocumentCharacterSet();
}
// Get an encoder for the character set
result = ccm->GetUnicodeEncoderRaw(charset.get(),
getter_AddRefs(encoder));
if (NS_FAILED(result))
return result;
result = encoder->Reset();
if (NS_FAILED(result))
return result;
PRInt32 maxByteLen, srcLen;
srcLen = aStr.Length();
const nsPromiseFlatString& flatSrc = PromiseFlatString(aStr);
const PRUnichar* src = flatSrc.get();
// Get the expected length of result string
result = encoder->GetMaxLength(src, srcLen, &maxByteLen);
if (NS_FAILED(result))
return result;
// Allocate a buffer of the maximum length
*aDest = (char *) nsMemory::Alloc(maxByteLen + 1);
PRInt32 destLen2, destLen = maxByteLen;
if (!*aDest)
return NS_ERROR_OUT_OF_MEMORY;
// Convert from unicode to the character set
result = encoder->Convert(src, &srcLen, *aDest, &destLen);
if (NS_FAILED(result)) {
nsMemory::Free(*aDest);
*aDest = nsnull;
return result;
}
// Allow the encoder to finish the conversion
destLen2 = maxByteLen - destLen;
encoder->Finish(*aDest + destLen, &destLen2);
(*aDest)[destLen + destLen2] = '\0';
return result;
}
PRBool
nsGlobalWindow::GetBlurSuppression()
{

View File

@ -572,8 +572,6 @@ protected:
static PRBool CanMoveResizeWindows();
nsresult ConvertCharset(const nsAString& aStr, char** aDest);
PRBool GetBlurSuppression();
// If aDoFlush is true, we'll flush our own layout; otherwise we'll try to