Fix bug 314376: occasional crash when editing trust settings for a newly-added cert, because we were messing with the view hierarchy for a destroyed window. Fixed by setting the certificate view's certificate to nil in -windowWillClose:

Also fix some other bugs in the certificate view that caused the checkbox states to be incorrect, and fail to stick.
Also fix possible exception on quit when quitting with the certificates window frontmost.
This commit is contained in:
smfr%smfr.org 2005-11-01 07:30:54 +00:00
parent 4daeed882a
commit 5a931e3390
5 changed files with 57 additions and 20 deletions

View File

@ -618,13 +618,13 @@ NSString* const CertificateChangedNotificationName = @"CertificateChangedNotific
// sigh, why can't we get these all in one go?
PRBool trusted;
if (NS_SUCCEEDED(certDB->IsCertTrusted(mCert, inType, nsIX509CertDB::TRUSTED_SSL, &trusted)))
if (NS_SUCCEEDED(certDB->IsCertTrusted(mCert, inType, nsIX509CertDB::TRUSTED_SSL, &trusted)) && trusted)
trustMask |= nsIX509CertDB::TRUSTED_SSL;
if (NS_SUCCEEDED(certDB->IsCertTrusted(mCert, inType, nsIX509CertDB::TRUSTED_EMAIL, &trusted)))
if (NS_SUCCEEDED(certDB->IsCertTrusted(mCert, inType, nsIX509CertDB::TRUSTED_EMAIL, &trusted)) && trusted)
trustMask |= nsIX509CertDB::TRUSTED_EMAIL;
if (NS_SUCCEEDED(certDB->IsCertTrusted(mCert, inType, nsIX509CertDB::TRUSTED_OBJSIGN, &trusted)))
if (NS_SUCCEEDED(certDB->IsCertTrusted(mCert, inType, nsIX509CertDB::TRUSTED_OBJSIGN, &trusted)) && trusted)
trustMask |= nsIX509CertDB::TRUSTED_OBJSIGN;
return trustMask;
@ -778,7 +778,7 @@ NSString* const CertificateChangedNotificationName = @"CertificateChangedNotific
mGotVerification = NO;
PRUint32 oldValidity = mVerification;
if (oldValidity != [self generalValidity])
{
{
// this is risky to post a notification from a notification callback
[self performSelector:@selector(postChangedNotification) withObject:nil afterDelay:0];
}

View File

@ -52,6 +52,10 @@
NSButton* mTrustForEmailCheckbox;
NSButton* mTrustForObjSigningCheckbox;
BOOL mTrustedForWebSites;
BOOL mTrustedForEmail;
BOOL mTrustedForObjectSigning;
id mDelegate; // not retained
CertificateItem* mCertItem; // retained
unsigned int mCertTrustType;

View File

@ -118,6 +118,8 @@ const float kGapUnderLine = 5.0f;
- (float)rebuildTrustSettings:(float)inOffset;
- (BOOL)showTrustSettings;
- (IBAction)trustCheckboxClicked:(id)inSender;
- (void)certificateChanged:(NSNotification*)inNotification;
@end
@ -164,6 +166,10 @@ const float kGapUnderLine = 5.0f;
[mCertItem autorelease];
mCertItem = [inCertItem retain];
mTrustedForWebSites = [mCertItem trustedForSSLAsType:mCertTrustType];
mTrustedForEmail = [mCertItem trustedForEmailAsType:mCertTrustType];
mTrustedForObjectSigning = [mCertItem trustedForObjectSigningAsType:mCertTrustType];
[self refreshView];
}
@ -199,6 +205,18 @@ const float kGapUnderLine = 5.0f;
mCertTrustType == nsIX509Cert::EMAIL_CERT);
}
- (IBAction)trustCheckboxClicked:(id)inSender
{
if (inSender == mTrustForWebSitesCheckbox)
mTrustedForWebSites = ([inSender state] == NSOnState);
if (inSender == mTrustForEmailCheckbox)
mTrustedForEmail = ([inSender state] == NSOnState);
if (inSender == mTrustForObjSigningCheckbox)
mTrustedForObjectSigning = ([inSender state] == NSOnState);
}
- (IBAction)toggleDetails:(id)sender
{
mDetailsExpanded = !mDetailsExpanded;
@ -221,19 +239,16 @@ const float kGapUnderLine = 5.0f;
{
unsigned int certTrustMask = 0;
BOOL canGetTrust = ([mCertItem isValid] || [mCertItem isUntrustedRootCACert]) &&
(mTrustForWebSitesCheckbox != nil) &&
(mTrustForEmailCheckbox != nil) &&
(mTrustForObjSigningCheckbox != nil);
BOOL canGetTrust = ([mCertItem isValid] || [mCertItem isUntrustedRootCACert]);
if (canGetTrust)
{
if ([mTrustForWebSitesCheckbox state] == NSOnState)
if (mTrustedForWebSites)
certTrustMask |= nsIX509CertDB::TRUSTED_SSL;
if ([mTrustForEmailCheckbox state] == NSOnState)
if (mTrustedForEmail)
certTrustMask |= nsIX509CertDB::TRUSTED_EMAIL;
if ([mTrustForObjSigningCheckbox state] == NSOnState)
if (mTrustedForObjectSigning)
certTrustMask |= nsIX509CertDB::TRUSTED_OBJSIGN;
}
else
@ -294,7 +309,7 @@ const float kGapUnderLine = 5.0f;
[theTextField setFont:fieldFont];
[theTextField setDrawsBackground:NO];
[theTextField setBezeled:NO];
[theTextField setStringValue:inString];
[theTextField setStringValue:inString ? inString : @""];
[[theTextField cell] setWraps:NO];
NSSize theCellSize = [[theTextField cell] cellSizeForBounds:inFrame];
@ -394,7 +409,8 @@ const float kGapUnderLine = 5.0f;
[dataScrollView setAutoresizingMask:NSViewWidthSizable | NSViewMaxYMargin];
[[dataScrollView verticalScroller] setControlSize:NSSmallControlSize];
[[[scrolledTextView textStorage] mutableString] setString:[inData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
if (inData)
[[[scrolledTextView textStorage] mutableString] setString:[inData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
[scrolledTextView setFont:[NSFont fontWithName:@"Monaco" size:10.0f]];
[scrolledTextView setEditable:NO];
[dataScrollView setAutoresizingMask:NSViewWidthSizable];
@ -569,16 +585,25 @@ const float kGapUnderLine = 5.0f;
// XXX only show relevant checkboxes? (see nsNSSCertificateDB::SetCertTrust)
// XXX only show checkboxes for allowed usages?
[self addLineWithLabelKey:@"TrustSettingsLabel" data:@"" atOffset:&curOffset ignoreBlankLines:NO];
mTrustForWebSitesCheckbox = [self addCheckboxLineWithLabelKey:@"" buttonLabelKey:@"TrustWebSitesCheckboxLabel" action:nil atOffset:&curOffset];
[mTrustForWebSitesCheckbox setState:[mCertItem trustedForSSLAsType:mCertTrustType]];
mTrustForWebSitesCheckbox = [self addCheckboxLineWithLabelKey:@""
buttonLabelKey:@"TrustWebSitesCheckboxLabel"
action:@selector(trustCheckboxClicked:)
atOffset:&curOffset];
[mTrustForWebSitesCheckbox setState:mTrustedForWebSites];
[mTrustForWebSitesCheckbox setEnabled:enableCheckboxes];
mTrustForEmailCheckbox = [self addCheckboxLineWithLabelKey:@"" buttonLabelKey:@"TrustEmailUsersCheckboxLabel" action:nil atOffset:&curOffset];
[mTrustForEmailCheckbox setState:[mCertItem trustedForEmailAsType:mCertTrustType]];
mTrustForEmailCheckbox = [self addCheckboxLineWithLabelKey:@""
buttonLabelKey:@"TrustEmailUsersCheckboxLabel"
action:@selector(trustCheckboxClicked:)
atOffset:&curOffset];
[mTrustForEmailCheckbox setState:mTrustedForEmail];
[mTrustForEmailCheckbox setEnabled:enableCheckboxes];
mTrustForObjSigningCheckbox = [self addCheckboxLineWithLabelKey:@"" buttonLabelKey:@"TrustObjectSignersCheckboxLabel" action:nil atOffset:&curOffset];
[mTrustForObjSigningCheckbox setState:[mCertItem trustedForObjectSigningAsType:mCertTrustType]];
mTrustForObjSigningCheckbox = [self addCheckboxLineWithLabelKey:@""
buttonLabelKey:@"TrustObjectSignersCheckboxLabel"
action:@selector(trustCheckboxClicked:)
atOffset:&curOffset];
[mTrustForObjSigningCheckbox setState:mTrustedForObjectSigning];
[mTrustForObjSigningCheckbox setEnabled:enableCheckboxes];
curOffset += kGapUnderGroup;
@ -702,7 +727,7 @@ const float kGapUnderLine = 5.0f;
CertificateItem* changedCert = [inNotification object];
if ([mCertItem isEqualTo:changedCert])
{
[self refreshView];
[self refreshView];
}
}

View File

@ -462,6 +462,12 @@ static CertificatesWindowController* gCertificatesWindowController;
[self autorelease];
}
- (void)autosaveWindowFrame
{
// MainController expects "main" windows to respond to this method.
// Nothing to do here.
}
#pragma mark -
- (IBAction)viewSelectedCertificates:(id)sender

View File

@ -123,6 +123,8 @@
if (!mRunningModally)
[self autorelease];
[mCertView setCertificateItem:nil];
}
- (int)runModally