Camino only - Bug 330534: Show correct expiration date ('On Quit') for session cookies. Patch by cl <bugzilla@chrislawson.net>. r=murph sr=smorgan

This commit is contained in:
stridey%gmail.com 2006-12-19 00:08:23 +00:00
parent 878e9c1787
commit 8da847c93c
5 changed files with 31 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>67 25 406 307 0 0 1600 1002 </string>
<string>37 15 406 307 0 0 1024 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>622</key>
@ -16,8 +16,9 @@
<key>IBOpenObjects</key>
<array>
<integer>5</integer>
<integer>401</integer>
</array>
<key>IBSystem Version</key>
<string>8L2127</string>
<string>8J135</string>
</dict>
</plist>

View File

@ -137,3 +137,9 @@ typedef enum ECookiePolicyPopupIndex
- (void) filterCookiesPermissionsWithString: (NSString*) inFilterString;
- (void) filterCookiesWithString: (NSString*) inFilterString;
@end
// custom formatter for cookies list to handle session cookie expiration sanely
@interface CookieDateFormatter : NSDateFormatter
{
}
@end

View File

@ -327,6 +327,10 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
[mCookiesTable setDeleteAction:@selector(removeCookies:)];
[mCookiesTable setTarget:self];
CookieDateFormatter* cookieDateFormatter = [[CookieDateFormatter alloc] initWithDateFormat:@"%b %d, %Y" allowNaturalLanguage:NO];
[[[mCookiesTable tableColumnWithIdentifier:@"Expires"] dataCell] setFormatter:cookieDateFormatter];
[cookieDateFormatter release];
// start sorted by host
mCachedCookies->Sort(compareCookieHosts, nsnull);
@ -726,15 +730,10 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
} else if ([[aTableColumn identifier] isEqualToString: @"Expires"]) {
PRUint64 expires = 0;
mCachedCookies->ObjectAt(rowIndex)->GetExpires(&expires);
if (expires == 0) {
// if expires is 0, it's a session cookie; display as expiring on the current date.
// It's not perfect, but it's better than showing the epoch.
NSDate *date = [NSDate date];
return date; // special case return
} else {
NSDate *date = [NSDate dateWithTimeIntervalSince1970: (NSTimeInterval)expires];
return date; // special case return
}
// If expires is 0, it's a session cookie.
// We use a custom formatter to display a localised string in this case.
NSDate *date = [NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)expires];
return date; // special case return
} else if ([[aTableColumn identifier] isEqualToString: @"Value"]) {
mCachedCookies->ObjectAt(rowIndex)->GetValue(cookieVal);
}
@ -1147,3 +1146,17 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
}
@end
#pragma mark -
@implementation CookieDateFormatter
- (NSString*)stringForObjectValue:(id)anObject
{
if ([(NSDate*)anObject timeIntervalSince1970] == 0)
return NSLocalizedString(@"CookieExpiresOnQuit", nil);
else
return [super stringForObjectValue:anObject];
}
@end