From fff497cdba0bddde23dda80da2501b832ff879fb Mon Sep 17 00:00:00 2001 From: "masayuki%d-toybox.com" Date: Wed, 19 Oct 2005 14:39:28 +0000 Subject: [PATCH] Bug 312287 Cannot open local htm file if its path has non-ASCII character / Cannot open IDN from command line r=jshin, sr=neil git-svn-id: svn://10.0.0.236/trunk@182531 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 4 +- .../xpfe/bootstrap/nsNativeAppSupportWin.cpp | 55 +++++++++++++------ mozilla/xpfe/bootstrap/nsStringSupport.h | 7 +++ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index a0cbe721a1d..9000828031b 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Roland Mainz * Fredrik Holmqvist + * Masayuki Nakano * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -706,7 +707,8 @@ nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool *windowOpened) if (NS_SUCCEEDED(rv)) { // convert the cmdLine URL to Unicode - NS_ConvertUTF8toUTF16 url(urlToLoad); + nsAutoString url; + NS_CopyNativeToUnicode(urlToLoad, url); rv = OpenWindow(chromeUrlForTask, url, width, height); } diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp index 8e8ede02c95..cef7c68c6e1 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp @@ -20,7 +20,8 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Bill Law law@netscape.com + * Bill Law + * Masayuki Nakano * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -78,6 +79,8 @@ #include "nsXPCOM.h" #include "nsXPFEComponentsCID.h" #include "nsEmbedCID.h" +#include "nsIURIFixup.h" +#include "nsCDefaultURIFixup.h" struct JSContext; @@ -398,8 +401,12 @@ private: static PRBool InitTopicStrings(); static int FindTopic( HSZ topic ); static nsresult GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResult ); - static nsresult OpenWindow( const char *urlstr, const char *args, nsIDOMWindow **aResult ); - static nsresult OpenBrowserWindow( const char *args, PRBool newWindow, nsIDOMWindow **aResult ); + static nsresult OpenWindow( const char *urlstr, + const nsAString& aArgs, + nsIDOMWindow **aResult ); + static nsresult OpenBrowserWindow( const nsAString& aArgs, + PRBool newWindow, + nsIDOMWindow **aResult ); static nsresult ReParent( nsISupports *window, HWND newParent ); static nsresult GetStartupURL(nsICmdLineService *args, nsCString& taskURL); static void SetupSysTrayIcon(); @@ -1761,7 +1768,8 @@ void nsNativeAppSupportWin::ActivateLastWindow() { } else { // Need to create a Navigator window, then. nsCOMPtr newWin; - OpenBrowserWindow( "about:blank", PR_TRUE, getter_AddRefs( newWin ) ); + OpenBrowserWindow( NS_LITERAL_STRING( "about:blank" ), + PR_TRUE, getter_AddRefs( newWin ) ); } } @@ -1822,8 +1830,11 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow, nsIDOMWi printf( "Launching browser on url [%s]...\n", arg.get() ); #endif rv = nativeApp->EnsureProfile(args); - if (NS_SUCCEEDED(rv)) - rv = OpenBrowserWindow( arg.get(), newWindow, aResult ); + if (NS_SUCCEEDED(rv)) { + nsAutoString tmpArg; + NS_CopyNativeToUnicode( arg, tmpArg ); + rv = OpenBrowserWindow( tmpArg, newWindow, aResult ); + } return rv; } @@ -1837,7 +1848,7 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow, nsIDOMWi #endif rv = nativeApp->EnsureProfile(args); if (NS_SUCCEEDED(rv)) - rv = OpenWindow( arg.get(), "", aResult ); + rv = OpenWindow( arg.get(), EmptyString(), aResult ); return rv; } @@ -1916,8 +1927,7 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow, nsIDOMWi if (FindCharInString(defaultArgs, '\n') != kNotFound) newWindow = PR_TRUE; - NS_ConvertUTF16toUTF8 url( defaultArgs ); - return OpenBrowserWindow(url.get(), newWindow, aResult); + return OpenBrowserWindow(defaultArgs, newWindow, aResult); } // Parse command line args according to MS spec @@ -2173,14 +2183,18 @@ printf( "Setting ddexec subkey entries\n" ); } nsresult -nsNativeAppSupportWin::OpenWindow( const char*urlstr, const char *args, nsIDOMWindow **aResult ) { +nsNativeAppSupportWin::OpenWindow( const char *urlstr, + const nsAString& aArgs, + nsIDOMWindow **aResult ) +{ nsresult rv = NS_ERROR_FAILURE; nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); - nsCOMPtr sarg(do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID)); + nsCOMPtr + sarg(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); if (sarg) - sarg->SetData(nsDependentCString(args)); + sarg->SetData(aArgs); if (wwatch && sarg) { rv = wwatch->OpenWindow(0, urlstr, "_blank", "chrome,dialog=no,all", @@ -2314,7 +2328,10 @@ nsresult SafeJSContext::Push() { nsresult -nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow, nsIDOMWindow **aResult ) { +nsNativeAppSupportWin::OpenBrowserWindow( const nsAString& aArgs, + PRBool newWindow, + nsIDOMWindow **aResult ) +{ nsresult rv = NS_OK; // Open the argument URL according to the external link preference. // If there is no Nav window, or newWindow is PR_TRUE, open a new one. @@ -2343,13 +2360,15 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow, ns if ( !bwin ) { break; } - nsCOMPtr io( do_GetService( "@mozilla.org/network/io-service;1" ) ); - if ( !io ) { + nsCOMPtr fixup( do_GetService( NS_URIFIXUP_CONTRACTID ) ); + if ( !fixup ) { break; } nsCOMPtr uri; - io->NewURI( nsDependentCString( args ), nsnull, nsnull, getter_AddRefs( uri ) ); - if ( !uri ) { + rv = fixup->CreateFixupURI( NS_ConvertUTF16toUTF8( aArgs ), + nsIURIFixup::FIXUP_FLAG_NONE, + getter_AddRefs( uri ) ); + if ( NS_FAILED(rv) || !uri ) { break; } return bwin->OpenURI( uri, nsnull, nsIBrowserDOMWindow::OPEN_DEFAULTWINDOW, nsIBrowserDOMWindow::OPEN_EXTERNAL, aResult ); @@ -2363,7 +2382,7 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow, ns if (NS_FAILED(rv)) return rv; // Last resort is to open a brand new window. - return OpenWindow( chromeUrlForTask.get(), args, aResult ); + return OpenWindow( chromeUrlForTask.get(), aArgs, aResult ); } void AppendMenuItem( HMENU& menu, PRInt32 aIdentifier, const nsString& aText ) { diff --git a/mozilla/xpfe/bootstrap/nsStringSupport.h b/mozilla/xpfe/bootstrap/nsStringSupport.h index dbbc903524f..54be060707e 100644 --- a/mozilla/xpfe/bootstrap/nsStringSupport.h +++ b/mozilla/xpfe/bootstrap/nsStringSupport.h @@ -19,6 +19,7 @@ * * Contributor(s): * Darin Fisher + * Masayuki Nakano * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -95,6 +96,12 @@ NS_CopyUnicodeToNative(const nsAString &input, nsACString &output) NS_UTF16ToCString(input, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, output); } +inline void +NS_CopyNativeToUnicode(const nsACString &input, nsAString &output) +{ + NS_CStringToUTF16(input, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, output); +} + inline void CopyUTF16toUTF8(const nsAString &input, nsACString &output) {