From 11fac3f79679ae3dbda990c105dcebc71f8f493f Mon Sep 17 00:00:00 2001 From: "kaie%netscape.com" Date: Thu, 23 Aug 2001 05:25:15 +0000 Subject: [PATCH] b=76915 r=dveditz sr=sfraser a=asa Giving GUI feedback instead of crashing Part 3 of 3 - changes to existing code git-svn-id: svn://10.0.0.236/trunk@101697 18797224-902f-48f8-a5cc-f745e15eee43 --- .../manager/ssl/src/nsNSSComponent.cpp | 5 +- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 113 ++++++++++++------ mozilla/xpfe/bootstrap/showOSAlert.cpp | 26 ++-- 3 files changed, 99 insertions(+), 45 deletions(-) diff --git a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp index c90cb67e86a..17cc91d12e0 100644 --- a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp +++ b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp @@ -464,7 +464,10 @@ nsNSSComponent::InitializeNSS() if (NS_FAILED(rv)) return rv; - NSS_InitReadWrite(profileStr); + if (NSS_InitReadWrite(profileStr) != SECSuccess) { + return NS_ERROR_ABORT; + } + NSS_SetDomesticPolicy(); // SSL_EnableCipher(SSL_RSA_WITH_NULL_MD5, SSL_ALLOWED); diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index 9a444a7001b..e47b517ebab 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -72,6 +72,7 @@ #include "nsIXULWindow.h" #include "nsIWebBrowserChrome.h" #include "nsIDocShell.h" +#include "nsIEntropyCollector.h" // for X remote support #ifdef MOZ_ENABLE_XREMOTE @@ -1008,6 +1009,44 @@ static nsresult InitializeWindowCreator() return NS_ERROR_FAILURE; } +// Maximum allowed / used length of alert message is 255 chars, due to restrictions on Mac. +// Please make sure that file contents and fallback_alert_text are at most 255 chars. +// Fallback_alert_text must be non-const, because of inplace conversion on Mac. +static void ShowOSAlertFromFile(int argc, char **argv, const char *alert_filename, char* fallback_alert_text) +{ + char message[256] = { 0 }; + PRInt32 numRead = 0; + char *messageToShow = fallback_alert_text; + nsresult rv; + nsCOMPtr fileName; + nsCOMPtr directoryService; + + directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = directoryService->Get(NS_APP_RES_DIR, + NS_GET_IID(nsIFile), + getter_AddRefs(fileName)); + if (NS_SUCCEEDED(rv) && fileName) { + fileName->Append(alert_filename); + PRFileDesc* fd = 0; + fileName->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd); + if (fd) { + numRead = PR_Read(fd, message, sizeof(message)-1); + if (numRead > 0) { + message[numRead] = 0; + messageToShow = message; + } + } + } + } + + #ifdef MOZ_WIDGET_GTK + gtk_init(&argc, &argv); + #endif + + ShowOSAlert( messageToShow ); +} + static nsresult VerifyInstallation(int argc, char **argv) { nsresult rv; @@ -1033,44 +1072,10 @@ static nsresult VerifyInstallation(int argc, char **argv) if (exists) { nsCOMPtr binPath; - char cleanupMessage[256]; char* lastResortMessage = "A previous install did not complete correctly. Finishing install."; - PRInt32 numRead; - - registryFile->Clone(getter_AddRefs(binPath)); - nsCOMPtrcleanupMessageFile = do_QueryInterface(binPath, &rv); -#ifdef XP_MAC - nsCOMPtr messageFileParent; - cleanupMessageFile->GetParent(getter_AddRefs(messageFileParent)); - cleanupMessageFile = do_QueryInterface(messageFileParent, &rv); -#endif - cleanupMessageFile->SetLeafName("res"); - cleanupMessageFile->Append(CLEANUP_MESSAGE_FILENAME); - - PRFileDesc* fd; - cleanupMessageFile->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd); - if (fd) - { - numRead = PR_Read(fd, cleanupMessage, sizeof(cleanupMessage)); - if (numRead > 0) - cleanupMessage[numRead] = 0; - else - { - //Something was wrong with the translated message file. empty? - strcpy(cleanupMessage, lastResortMessage); - } - } - else - { - //Couldn't open the translated message file - strcpy(cleanupMessage, lastResortMessage); - } - //The cleanup registry file exists so we have cleanup work to do -#ifdef MOZ_WIDGET_GTK - gtk_init(&argc, &argv); -#endif - ShowOSAlert(cleanupMessage); + ShowOSAlertFromFile(argc, argv, CLEANUP_MESSAGE_FILENAME, lastResortMessage); + nsCOMPtr cleanupUtility; registryFile->Clone(getter_AddRefs(cleanupUtility)); cleanupUtility->SetLeafName(CLEANUP_UTIL); @@ -1087,6 +1092,39 @@ static nsresult VerifyInstallation(int argc, char **argv) return NS_OK; } +static nsresult VerifyPsmAbsentOrSane(int argc, char **argv) +{ + nsresult rv; + + nsCOMPtr enCol = + do_GetService(NS_ENTROPYCOLLECTOR_CONTRACTID, &rv); + + if (rv == NS_ERROR_ABORT) { + // In case the security component can not do its internal initialization, + // we must warn the user and exit. + + const char *panicMsg = "PANIC! The security component of Mozilla can not initialize.\n\n" + "While this can have multiple reasons, it is likely that there is a problem " + "with the directory on your hard disk where Mozilla stores your preferences. " + "Maybe the files containing security certificates can't be accessed or created.\n\n" + "Please check that the profile directory is readable and writeable, i.e. that you " + "have the proper permissions to write and read to all those files.\n" + "In addition you should check that there is free space left on the disk.\n\n" + "Please fix this problem or show this message to your system administrator.\n\n" + "The browser will now abort."; + + const char *panicMessageFilename = "nssifail.txt"; + + ShowOSAlertFromFile(argc, argv, panicMessageFilename, panicMsg); + + return rv; + } + + // Any other return code means: Security component could initialize NSS fine, + // or, security components are not available. + return NS_OK; +} + #ifdef DEBUG_warren #ifdef XP_PC #define _CRTDBG_MAP_ALLOC @@ -1292,6 +1330,9 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) appShell->EnumerateAndInitializeComponents(); NS_TIMELINE_LEAVE("appShell->EnumerateAndInitializeComponents"); + rv = VerifyPsmAbsentOrSane(argc, argv); + if (NS_FAILED(rv)) return rv; + // rjc: now must explicitly call appshell's CreateHiddenWindow() function AFTER profile manager. // if the profile manager ever switches to using nsIDOMWindowInternal stuff, this might have to change NS_TIMELINE_ENTER("appShell->CreateHiddenWindow"); diff --git a/mozilla/xpfe/bootstrap/showOSAlert.cpp b/mozilla/xpfe/bootstrap/showOSAlert.cpp index 1b3835cbf0a..0c2b55401b5 100644 --- a/mozilla/xpfe/bootstrap/showOSAlert.cpp +++ b/mozilla/xpfe/bootstrap/showOSAlert.cpp @@ -22,6 +22,7 @@ */ #include +#include #include "nscore.h" //defines and includes for previous installation cleanup process @@ -107,6 +108,8 @@ NS_gtk_alert(char *aMessage, char *aTitle, char *aOKBtnText) alertDlg = gtk_dialog_new(); msgLabel = gtk_label_new(aMessage); + if (msgLabel) + gtk_label_set_line_wrap(GTK_LABEL(msgLabel), TRUE); okBtn = gtk_button_new_with_label(okBtnText); packerLbl = gtk_packer_new(); packerBtn = gtk_packer_new(); @@ -159,28 +162,35 @@ NS_gtk_alert(char *aMessage, char *aTitle, char *aOKBtnText) #endif //MOZ_WIDGET_GTK +// The maximum allowed length of aMessage is 255 characters! void ShowOSAlert(char* aMessage) { #ifdef DEBUG_dbragg printf("\n****Inside ShowOSAlert ***\n"); #endif + 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, aMessage, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND ); + MessageBox(NULL, message_copy, NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND ); #elif (XP_MAC) short buttonClicked; - StandardAlert(kAlertStopAlert, c2pstr(aMessage), nil, nil, &buttonClicked); + StandardAlert(kAlertStopAlert, c2pstr(message_copy), nil, nil, &buttonClicked); #elif defined (MOZ_WIDGET_GTK) - NS_gtk_alert(aMessage, NULL, "OK"); + NS_gtk_alert(message_copy, NULL, "OK"); #elif defined (XP_OS2) HAB hab = WinInitialize(0); HMQ hmq = WinCreateMsgQueue(hmq,0); - WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, aMessage, "", 0, MB_OK); + WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, message_copy, "", 0, MB_OK); WinDestroyMsgQueue(hmq); WinTerminate(hab); -#else - fprintf(stdout, "%s\n", aMessage); #endif - + // It can't hurt to display the message on the console in any case, + // even if we have already tried to display it in a GUI window. + fprintf(stdout, "%s\n", aMessage); } -