From 70874b415d09329aaab1d033ecdaec4e493c72b2 Mon Sep 17 00:00:00 2001 From: "jshin%mailaps.org" Date: Tue, 16 Nov 2004 18:08:25 +0000 Subject: [PATCH] bug 268266 : profile and appstartup code should use NS_CopyNativeToUnicode (r=cbie, sr=darin, a to aviary=bsmedberg) git-svn-id: svn://10.0.0.236/trunk@165402 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/startup/src/Makefile.in | 1 - .../components/startup/src/nsAppStartup.cpp | 74 ++----------------- 2 files changed, 6 insertions(+), 69 deletions(-) diff --git a/mozilla/toolkit/components/startup/src/Makefile.in b/mozilla/toolkit/components/startup/src/Makefile.in index 0ab2abb8985..7bcdd2d28c7 100644 --- a/mozilla/toolkit/components/startup/src/Makefile.in +++ b/mozilla/toolkit/components/startup/src/Makefile.in @@ -64,7 +64,6 @@ REQUIRES = \ windowwatcher \ intl \ util \ - uconv \ xulapp \ $(NULL) diff --git a/mozilla/toolkit/components/startup/src/nsAppStartup.cpp b/mozilla/toolkit/components/startup/src/nsAppStartup.cpp index d006fa34674..3dcf61771a2 100644 --- a/mozilla/toolkit/components/startup/src/nsAppStartup.cpp +++ b/mozilla/toolkit/components/startup/src/nsAppStartup.cpp @@ -42,7 +42,6 @@ #include "nsAppStartup.h" #include "nsIAppShellService.h" -#include "nsICharsetConverterManager.h" #include "nsICloseAllWindows.h" #include "nsIDOMWindowInternal.h" #include "nsIEventQueue.h" @@ -50,7 +49,6 @@ #include "nsIInterfaceRequestor.h" #include "nsILocalFile.h" #include "nsIObserverService.h" -#include "nsIPlatformCharset.h" #include "nsIPrefBranch.h" #include "nsIPrefService.h" #include "nsIProfileChangeStatus.h" @@ -58,12 +56,12 @@ #include "nsIStringBundle.h" #include "nsISupportsPrimitives.h" #include "nsITimelineService.h" -#include "nsIUnicodeDecoder.h" #include "nsIWebBrowserChrome.h" #include "nsIWebShellWindow.h" #include "nsIWindowMediator.h" #include "nsIWindowWatcher.h" #include "nsIXULWindow.h" +#include "nsNativeCharsetUtils.h" #include "prprf.h" #include "nsCRT.h" @@ -74,9 +72,6 @@ NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); -// Static Function Prototypes -static nsresult ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString); - // // nsAppStartup // @@ -610,30 +605,11 @@ nsAppStartup::OpenBrowserWindow(PRInt32 height, PRInt32 width) #endif /* DEBUG_CMD_LINE */ nsAutoString url; - if (nsCRT::IsAscii(urlToLoad)) { - url.AssignWithConversion(urlToLoad); - } - else { - // get a platform charset - nsCAutoString charSet; - nsCOMPtr platformCharset(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv)); - if (NS_FAILED(rv)) { - NS_ASSERTION(0, "Failed to get a platform charset"); - return rv; - } - - rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, charSet); - if (NS_FAILED(rv)) { - NS_ASSERTION(0, "Failed to get a charset"); - return rv; - } - - // convert the cmdLine URL to Unicode - rv = ConvertToUnicode(charSet, urlToLoad, url); - if (NS_FAILED(rv)) { - NS_ASSERTION(0, "Failed to convert commandline url to unicode"); - return rv; - } + // convert the cmdLine URL to Unicode + rv = NS_CopyNativeToUnicode(nsDependentCString(urlToLoad), url); + if (NS_FAILED(rv)) { + NS_ERROR("Failed to convert commandline url to unicode"); + return rv; } rv = OpenWindow(chromeUrlForTask, url, width, height); @@ -788,41 +764,3 @@ nsAppStartup::Observe(nsISupports *aSubject, return NS_OK; } - -static nsresult -ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString) -{ - nsresult rv; - - // convert result to unicode - nsCOMPtr ccm(do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID , &rv)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr decoder; - rv = ccm->GetUnicodeDecoderRaw(aCharset.get(), getter_AddRefs(decoder)); - if (NS_FAILED(rv)) - return rv; - - PRInt32 uniLength = 0; - PRInt32 srcLength = strlen(inString); - rv = decoder->GetMaxLength(inString, srcLength, &uniLength); - if (NS_FAILED(rv)) - return rv; - - PRUnichar *unichars = new PRUnichar [uniLength]; - if (nsnull != unichars) { - // convert to unicode - rv = decoder->Convert(inString, &srcLength, unichars, &uniLength); - if (NS_SUCCEEDED(rv)) { - // Pass back the unicode string - outString.Assign(unichars, uniLength); - } - delete [] unichars; - } - else { - rv = NS_ERROR_OUT_OF_MEMORY; - } - - return rv; -}