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
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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<nsILocalFile> fileName;
|
||||
nsCOMPtr<nsIProperties> 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<nsIFile> binPath;
|
||||
char cleanupMessage[256];
|
||||
char* lastResortMessage = "A previous install did not complete correctly. Finishing install.";
|
||||
PRInt32 numRead;
|
||||
|
||||
registryFile->Clone(getter_AddRefs(binPath));
|
||||
nsCOMPtr<nsILocalFile>cleanupMessageFile = do_QueryInterface(binPath, &rv);
|
||||
#ifdef XP_MAC
|
||||
nsCOMPtr<nsIFile> 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<nsIFile> 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<nsIEntropyCollector> 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");
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user