Bug 410610 - Can't open a local HTML file that has accents (special unicode characters) in its filename, r=luser+Neil
authorbenjamin@smedbergs.us
Mon, 07 Jan 2008 08:38:12 -0800
changeset 9989 5e0e10529e8d4ceb6ffaa4891453e3c209547e33
parent 9988 d615882412c803f578a5c625833062978abb5170
child 9990 51ce5fbcb3299199325ca6362602bd19f3c7d0aa
push idunknown
push userunknown
push dateunknown
reviewersluser
bugs410610
milestone1.9b3pre
Bug 410610 - Can't open a local HTML file that has accents (special unicode characters) in its filename, r=luser+Neil
toolkit/profile/src/nsToolkitProfileService.cpp
toolkit/xre/Makefile.in
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsNativeAppSupportWin.cpp
toolkit/xre/nsWindowsRestart.cpp
toolkit/xre/nsWindowsWMain.cpp
xpfe/bootstrap/showOSAlert.cpp
--- a/toolkit/profile/src/nsToolkitProfileService.cpp
+++ b/toolkit/profile/src/nsToolkitProfileService.cpp
@@ -681,40 +681,17 @@ nsToolkitProfileService::CreateProfile(n
     if (exists) {
         rv = rootDir->IsDirectory(&exists);
         NS_ENSURE_SUCCESS(rv, rv);
 
         if (!exists)
             return NS_ERROR_FILE_NOT_DIRECTORY;
     }
     else {
-        nsCOMPtr<nsIFile> profileDefaultsDir;
-        nsCOMPtr<nsIFile> profileDirParent;
-        nsCAutoString profileDirName;
-
-        rv = rootDir->GetParent(getter_AddRefs(profileDirParent));
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        rv = rootDir->GetNativeLeafName(profileDirName);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        PRBool dummy;
-        rv = gDirServiceProvider->GetFile(NS_APP_PROFILE_DEFAULTS_50_DIR, &dummy,
-                                          getter_AddRefs(profileDefaultsDir));
-
-        if (NS_SUCCEEDED(rv))
-            rv = profileDefaultsDir->CopyToNative(profileDirParent,
-                                                  profileDirName);
-        if (NS_FAILED(rv)) {
-            // if copying failed, lets just ensure that the profile directory exists.
-            rv = rootDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
-            NS_ENSURE_SUCCESS(rv, rv);
-        }
-      
-        rv = rootDir->SetPermissions(0700);
+        rv = rootDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
         NS_ENSURE_SUCCESS(rv, rv);
     }
 
     rv = localDir->Exists(&exists);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!exists) {
         rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -126,17 +126,17 @@ endif
 
 ifdef MOZ_UPDATER
 CPPSRCS += nsUpdateDriver.cpp
 DEFINES += -DMOZ_UPDATER
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 CPPSRCS += nsNativeAppSupportWin.cpp
-DEFINES += -DWIN32_LEAN_AND_MEAN
+DEFINES += -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 CMMSRCS = nsNativeAppSupportCocoa.mm
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
 CPPSRCS += nsNativeAppSupportOS2.cpp
 else
 ifeq ($(MOZ_WIDGET_TOOLKIT),beos)
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -387,17 +387,17 @@ static void Output(PRBool isError, const
   char *msg = PR_vsmprintf(fmt, ap);
   if (msg)
   {
     UINT flags = MB_OK;
     if (isError)
       flags |= MB_ICONERROR;
     else 
       flags |= MB_ICONINFORMATION;
-    MessageBox(NULL, msg, "XULRunner", flags);
+    MessageBoxA(NULL, msg, "XULRunner", flags);
     PR_smprintf_free(msg);
   }
 #else
   vfprintf(stderr, fmt, ap);
 #endif
 
   va_end(ap);
 }
--- a/toolkit/xre/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -124,17 +124,17 @@ activateWindow( nsIDOMWindowInternal *wi
 #endif
 
 // Simple Win32 mutex wrapper.
 struct Mutex {
     Mutex( const char *name )
         : mName( name ),
           mHandle( 0 ),
           mState( -1 ) {
-        mHandle = CreateMutex( 0, FALSE, mName.get() );
+        mHandle = CreateMutexA( 0, FALSE, mName.get() );
 #if MOZ_DEBUG_DDE
         printf( "CreateMutex error = 0x%08X\n", (int)GetLastError() );
 #endif
     }
     ~Mutex() {
         if ( mHandle ) {
             // Make sure we release it if we own it.
             Unlock();
@@ -323,18 +323,18 @@ private:
                                                     UINT     uFmt,
                                                     HCONV    hconv,
                                                     HSZ      hsz1,
                                                     HSZ      hsz2,
                                                     HDDEDATA hdata,
                                                     ULONG    dwData1,
                                                     ULONG    dwData2 );
     static void HandleCommandLine(const char* aCmdLineString, nsIFile* aWorkingDir, PRUint32 aState);
-    static void ParseDDEArg( HSZ args, int index, nsCString& string);
-    static void ParseDDEArg( const char* args, int index, nsCString& aString);
+    static void ParseDDEArg( HSZ args, int index, nsString& string);
+    static void ParseDDEArg( const WCHAR* args, int index, nsString& aString);
     static void ActivateLastWindow();
     static HDDEDATA CreateDDEData( DWORD value );
     static HDDEDATA CreateDDEData( LPBYTE value, DWORD len );
     static PRBool   InitTopicStrings();
     static int      FindTopic( HSZ topic );
     static nsresult OpenWindow( const char *urlstr, const char *args );
     static nsresult OpenBrowserWindow();
     static nsresult ReParent( nsISupports *window, HWND newParent );
@@ -482,17 +482,17 @@ PRBool nsNativeAppSupportWin::mCanHandle
 char nsNativeAppSupportWin::mMutexName[ 128 ] = { 0 };
 
 
 // Message window encapsulation.
 struct MessageWindow {
     // ctor/dtor are simplistic
     MessageWindow() {
         // Try to find window.
-        mHandle = ::FindWindow( className(), 0 );
+        mHandle = ::FindWindowA( className(), 0 );
     }
 
     // Act like an HWND.
     operator HWND() {
         return mHandle;
     }
 
     // Class name: appName + "MessageWindow"
@@ -507,32 +507,32 @@ struct MessageWindow {
                          "MessageWindow" );
             mClassName = classNameBuffer;
         }
         return mClassName;
     }
 
     // Create: Register class and create window.
     NS_IMETHOD Create() {
-        WNDCLASS classStruct = { 0,                          // style
+        WNDCLASSA classStruct = { 0,                          // style
                                  &MessageWindow::WindowProc, // lpfnWndProc
                                  0,                          // cbClsExtra
                                  0,                          // cbWndExtra
                                  0,                          // hInstance
                                  0,                          // hIcon
                                  0,                          // hCursor
                                  0,                          // hbrBackground
                                  0,                          // lpszMenuName
                                  className() };              // lpszClassName
 
         // Register the window class.
-        NS_ENSURE_TRUE( ::RegisterClass( &classStruct ), NS_ERROR_FAILURE );
+        NS_ENSURE_TRUE( ::RegisterClassA( &classStruct ), NS_ERROR_FAILURE );
 
         // Create the window.
-        NS_ENSURE_TRUE( ( mHandle = ::CreateWindow( className(),
+        NS_ENSURE_TRUE( ( mHandle = ::CreateWindowA(className(),
                                                     0,          // title
                                                     WS_CAPTION, // style
                                                     0,0,0,0,    // x, y, cx, cy
                                                     0,          // parent
                                                     0,          // menu
                                                     0,          // instance
                                                     0 ) ),      // create struct
                         NS_ERROR_FAILURE );
@@ -716,17 +716,17 @@ nsNativeAppSupportWin::Start( PRBool *aR
     startupLock.Unlock();
 
     return rv;
 }
 
 PRBool
 nsNativeAppSupportWin::InitTopicStrings() {
     for ( int i = 0; i < topicCount; i++ ) {
-        if ( !( mTopics[ i ] = DdeCreateStringHandle( mInstance, const_cast<char *>(topicNames[ i ]), CP_WINANSI ) ) ) {
+        if ( !( mTopics[ i ] = DdeCreateStringHandleA( mInstance, const_cast<char *>(topicNames[ i ]), CP_WINANSI ) ) ) {
             return PR_FALSE;
         }
     }
     return PR_TRUE;
 }
 
 int
 nsNativeAppSupportWin::FindTopic( HSZ topic ) {
@@ -756,17 +756,17 @@ nsNativeAppSupportWin::StartDDE() {
     // Initialize DDE.
     NS_ENSURE_TRUE( DMLERR_NO_ERROR == DdeInitialize( &mInstance,
                                                       nsNativeAppSupportWin::HandleDDENotification,
                                                       APPCLASS_STANDARD,
                                                       0 ),
                     NS_ERROR_FAILURE );
 
     // Allocate DDE strings.
-    NS_ENSURE_TRUE( ( mApplication = DdeCreateStringHandle( mInstance, (char*) gAppData->name, CP_WINANSI ) ) && InitTopicStrings(),
+    NS_ENSURE_TRUE( ( mApplication = DdeCreateStringHandleA( mInstance, (char*) gAppData->name, CP_WINANSI ) ) && InitTopicStrings(),
                     NS_ERROR_FAILURE );
 
     // Next step is to register a DDE service.
     NS_ENSURE_TRUE( DdeNameService( mInstance, mApplication, 0, DNS_REGISTER ), NS_ERROR_FAILURE );
 
 #if MOZ_DEBUG_DDE
     printf( "DDE server started\n" );
 #endif
@@ -987,36 +987,36 @@ nsNativeAppSupportWin::HandleDDENotifica
         }
     } else if ( uType & XCLASS_DATA ) {
         if ( uType == XTYP_REQUEST ) {
             switch ( FindTopic( hsz1 ) ) {
                 case topicOpenURL: {
                     // Open a given URL...
 
                     // Get the URL from the first argument in the command.
-                    nsCAutoString url;
+                    nsAutoString url;
                     ParseDDEArg(hsz2, 0, url);
 
                     // Read the 3rd argument in the command to determine if a
                     // new window is to be used.
-                    nsCAutoString windowID;
+                    nsAutoString windowID;
                     ParseDDEArg(hsz2, 2, windowID);
                     // "" means to open the URL in a new window.
-                    if ( windowID.Equals( "" ) ) {
-                        url.Insert("mozilla -new-window ", 0);
+                    if ( windowID.IsEmpty() ) {
+                        url.Insert(NS_LITERAL_STRING("mozilla -new-window "), 0);
                     }
                     else {
-                        url.Insert("mozilla -url ", 0);
+                        url.Insert(NS_LITERAL_STRING("mozilla -url "), 0);
                     }
 
 #if MOZ_DEBUG_DDE
-                    printf( "Handling dde XTYP_REQUEST request: [%s]...\n", url.get() );
+                    printf( "Handling dde XTYP_REQUEST request: [%s]...\n", NS_ConvertUTF16toUTF8(url).get() );
 #endif
                     // Now handle it.
-                    HandleCommandLine(url.get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);
+                    HandleCommandLine(NS_ConvertUTF16toUTF8(url).get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);
 
                     // Return pseudo window ID.
                     result = CreateDDEData( 1 );
                     break;
                 }
                 case topicGetWindowInfo: {
                     // This topic has to get the current URL, get the current
                     // page title and then format the output into the DDE
@@ -1104,22 +1104,22 @@ nsNativeAppSupportWin::HandleDDENotifica
 #if MOZ_DEBUG_DDE
                         printf( "WWW_GetWindowInfo->%s\n", outpt.get() );
 #endif
                     } while ( PR_FALSE );
                     break;
                 }
                 case topicActivate: {
                     // Activate a Nav window...
-                    nsCAutoString windowID;
+                    nsAutoString windowID;
                     ParseDDEArg(hsz2, 0, windowID);
                     // 4294967295 is decimal for 0xFFFFFFFF which is also a
                     //   correct value to do that Activate last window stuff
-                    if ( windowID.Equals( "-1" ) ||
-                         windowID.Equals( "4294967295" ) ) {
+                    if ( windowID.EqualsLiteral( "-1" ) ||
+                         windowID.EqualsLiteral( "4294967295" ) ) {
                         // We only support activating the most recent window (or a new one).
                         ActivateLastWindow();
                         // Return pseudo window ID.
                         result = CreateDDEData( 1 );
                     }
                     break;
                 }
                 case topicVersion: {
@@ -1158,36 +1158,36 @@ nsNativeAppSupportWin::HandleDDENotifica
             DWORD bytes;
             LPBYTE request = DdeAccessData( hdata, &bytes );
 #if MOZ_DEBUG_DDE
             printf( "Handling dde request: [%s]...\n", (char*)request );
 #endif
             // Default is to open in current window.
             PRBool new_window = PR_FALSE;
 
-            nsCAutoString url;
-            ParseDDEArg((const char*) request, 0, url);
+            nsAutoString url;
+            ParseDDEArg((const WCHAR*) request, 0, url);
 
             // Read the 3rd argument in the command to determine if a
             // new window is to be used.
-            nsCAutoString windowID;
-            ParseDDEArg((const char*) request, 2, windowID);
+            nsAutoString windowID;
+            ParseDDEArg((const WCHAR*) request, 2, windowID);
 
             // "" means to open the URL in a new window.
-            if ( windowID.Equals( "" ) ) {
-                url.Insert("mozilla -new-window ", 0);
+            if ( windowID.IsEmpty() ) {
+                url.Insert(NS_LITERAL_STRING("mozilla -new-window "), 0);
             }
             else {
-                url.Insert("mozilla -url ", 0);
+                url.Insert(NS_LITERAL_STRING("mozilla -url "), 0);
             }
 #if MOZ_DEBUG_DDE
-            printf( "Handling dde XTYP_REQUEST request: [%s]...\n", url.get() );
+            printf( "Handling dde XTYP_REQUEST request: [%s]...\n", NS_ConvertUTF16toUTF8(url).get() );
 #endif
             // Now handle it.
-            HandleCommandLine(url.get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);
+            HandleCommandLine(NS_ConvertUTF16toUTF8(url).get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT);
 
             // Release the data.
             DdeUnaccessData( hdata );
             result = (HDDEDATA)DDE_FACK;
         } else {
             result = (HDDEDATA)DDE_FNOTPROCESSED;
         }
     } else if ( uType & XCLASS_NOTIFICATION ) {
@@ -1199,81 +1199,80 @@ nsNativeAppSupportWin::HandleDDENotifica
 }
 
 // Utility function to advance to end of quoted string.
 // p+offset must point to the comma preceding the arg on entry.
 // On return, p+result points to the closing '"' (or end of the string
 // if the closing '"' is missing) if the arg is quoted.  If the arg
 // is not quoted, then p+result will point to the first character
 // of the arg.
-static PRInt32 advanceToEndOfQuotedArg( const char *p, PRInt32 offset, PRInt32 len ) {
+static PRInt32 advanceToEndOfQuotedArg( const WCHAR *p, PRInt32 offset, PRInt32 len ) {
     // Check whether the current arg is quoted.
     if ( p[++offset] == '"' ) {
         // Advance past the closing quote.
         while ( offset < len && p[++offset] != '"' ) {
             // If the current character is a backslash, then the
             // next character can't be a *real* '"', so skip it.
             if ( p[offset] == '\\' ) {
                 offset++;
             }
         }
     }
     return offset;
 }
 
-void nsNativeAppSupportWin::ParseDDEArg( const char* args, int index, nsCString& aString) {
+void nsNativeAppSupportWin::ParseDDEArg( const WCHAR* args, int index, nsString& aString) {
     if ( args ) {
-        int argLen = strlen(args);
-        nsDependentCString temp(args, argLen);
+        nsDependentString temp(args);
 
         // offset points to the comma preceding the desired arg.
         PRInt32 offset = -1;
         // Skip commas till we get to the arg we want.
         while( index-- ) {
             // If this arg is quoted, then go to closing quote.
-            offset = advanceToEndOfQuotedArg( args, offset, argLen);
+            offset = advanceToEndOfQuotedArg( args, offset, temp.Length());
             // Find next comma.
             offset = temp.FindChar( ',', offset );
             if ( offset == kNotFound ) {
                 // No more commas, give up.
                 aString = args;
                 return;
             }
         }
         // The desired argument starts just past the preceding comma,
         // which offset points to, and extends until the following
         // comma (or the end of the string).
         //
         // Since the argument might be enclosed in quotes, we need to
         // deal with that before searching for the terminating comma.
         // We advance offset so it ends up pointing to the start of
         // the argument we want.
-        PRInt32 end = advanceToEndOfQuotedArg( args, offset++, argLen );
+        PRInt32 end = advanceToEndOfQuotedArg( args, offset++, temp.Length() );
         // Find next comma (or end of string).
         end = temp.FindChar( ',', end );
         if ( end == kNotFound ) {
             // Arg is the rest of the string.
-            end = argLen;
+            end = temp.Length();
         }
         // Extract result.
         aString.Assign( args + offset, end - offset );
     }
     return;
 }
 
 // Utility to parse out argument from a DDE item string.
-void nsNativeAppSupportWin::ParseDDEArg( HSZ args, int index, nsCString& aString) {
-    DWORD argLen = DdeQueryString( mInstance, args, NULL, NULL, CP_WINANSI );
+void nsNativeAppSupportWin::ParseDDEArg( HSZ args, int index, nsString& aString) {
+    DWORD argLen = DdeQueryStringW( mInstance, args, NULL, NULL, CP_WINUNICODE );
     // there wasn't any string, so return empty string
     if ( !argLen ) return;
-    nsCAutoString temp;
+    nsAutoString temp;
     // Ensure result's buffer is sufficiently big.
     temp.SetLength( argLen );
     // Now get the string contents.
-    DdeQueryString( mInstance, args, temp.BeginWriting(), temp.Length(), CP_WINANSI );
+    DdeQueryString( mInstance, args, temp.BeginWriting(), temp.Length(), CP_WINUNICODE );
     // Parse out the given arg.
     ParseDDEArg(temp.get(), index, aString);
     return;
 }
 
 void nsNativeAppSupportWin::ActivateLastWindow() {
     nsCOMPtr<nsIDOMWindowInternal> navWin;
     GetMostRecentWindow( NS_LITERAL_STRING("navigator:browser").get(), getter_AddRefs( navWin ) );
--- a/toolkit/xre/nsWindowsRestart.cpp
+++ b/toolkit/xre/nsWindowsRestart.cpp
@@ -230,17 +230,17 @@ AllocConvertUTF8toUTF16(const char *arg)
   // UTF16 can't be longer in units than UTF8
   int len = strlen(arg);
   PRUnichar *s = new PRUnichar[(len + 1) * sizeof(PRUnichar)];
   if (!s)
     return NULL;
 
   ConvertUTF8toUTF16 convert(s);
   convert.write(arg, len);
-  s[len] = '\0';
+  convert.write_terminator();
   return s;
 }
 
 static void
 FreeAllocStrings(int argc, PRUnichar **argv)
 {
   while (argc) {
     --argc;
--- a/toolkit/xre/nsWindowsWMain.cpp
+++ b/toolkit/xre/nsWindowsWMain.cpp
@@ -18,17 +18,17 @@ AllocConvertUTF16toUTF8(const WCHAR *arg
   // be generous... UTF16 units can expand up to 3 UTF8 units
   int len = wcslen(arg);
   char *s = new char[len * 3 + 1];
   if (!s)
     return NULL;
 
   ConvertUTF16toUTF8 convert(s);
   convert.write(arg, len);
-  s[len] = '\0';
+  convert.write_terminator();
   return s;
 }
 
 static void
 FreeAllocStrings(int argc, char **argv)
 {
   while (argc) {
     --argc;
--- a/xpfe/bootstrap/showOSAlert.cpp
+++ b/xpfe/bootstrap/showOSAlert.cpp
@@ -65,17 +65,17 @@ printf("\n****Inside ShowOSAlert ***\n")
     const PRInt32 max_len = 255;
     char message_copy[max_len+1] = { 0 };
     PRInt32 input_len = strlen(aMessage);
     PRInt32 copy_len = (input_len > max_len) ? max_len : input_len;
     strncpy(message_copy, aMessage, copy_len);
     message_copy[copy_len] = 0;
 
 #if defined (XP_WIN)
-    MessageBox(NULL, message_copy, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND );
+    MessageBoxA(NULL, message_copy, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND );
 #elif (XP_MAC)
     short buttonClicked;
     StandardAlert(kAlertStopAlert, c2pstr(message_copy), nil, nil, &buttonClicked);
 #elif defined (XP_OS2)
     /* Set our app to be a PM app before attempting Win calls */
     PPIB ppib;
     PTIB ptib;
     DosGetInfoBlocks(&ptib, &ppib);