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
This commit is contained in:
@@ -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 <nsIPlatformCharset> 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<nsICharsetConverterManager> ccm(do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID , &rv));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr <nsIUnicodeDecoder> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user