Fix bug 316937: store favicons in a separate cache on disk so that you don't lose them on crash.

This commit is contained in:
smfr%smfr.org 2005-11-18 05:57:55 +00:00
Родитель d559606b13
Коммит 344ef84341
2 изменённых файлов: 17 добавлений и 31 удалений

Просмотреть файл

@ -51,8 +51,6 @@ class NeckoCacheHelper;
{
NeckoCacheHelper* mIconsCacheHelper;
NSMutableDictionary* mRequestDict; // dict of favicon url -> request url
NSMutableDictionary* mIconDictionary; // map of favorite url -> NSImage
}
+ (SiteIconProvider*)sharedFavoriteIconProvider;
@ -60,18 +58,6 @@ class NeckoCacheHelper;
// get the default location (http://www.foo.bar/favicon.ico) for the given URI
+ (NSString*)defaultFaviconLocationStringFromURI:(NSString*)inURI;
// Start a favicon.ico load for the given URI, which can be any URI.
// The caller will get a 'SiteIconLoadNotificationName' notification
// when the load is done, with the image at the 'SiteIconLoadImageKey' key
// in the notifcation userInfo. The caller will have had to register with the
// NSNotifcationCenter in order to receive this notifcation. The notification
// is dispatched with 'sender' as the object.
// This method returns YES if the uri request was dispatched (i.e. if we know
// that we've looked for, and failed to find, this icon before). If it returns
// YES, then the 'SiteIconLoadNotificationName' notification will be sent out.
- (BOOL)loadFavoriteIcon:(id)sender forURI:(NSString *)inURI allowNetwork:(BOOL)inAllowNetwork;
// fetch the icon for the given page.
// inIconURI is the URI of the icon (if specified via a <link> element), or nil for the default
// site icon location.

Просмотреть файл

@ -39,6 +39,8 @@
#import "SiteIconProvider.h"
#import "SiteIconCache.h"
#include "prtime.h"
#include "nsString.h"
#include "nsISupports.h"
@ -304,7 +306,6 @@ MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI)
if ((self = [super init]))
{
mRequestDict = [[NSMutableDictionary alloc] initWithCapacity:5];
mIconDictionary = [[NSMutableDictionary alloc] initWithCapacity:100];
mIconsCacheHelper = new NeckoCacheHelper();
nsresult rv = mIconsCacheHelper->Init("MissedIconsCache");
@ -322,13 +323,15 @@ MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI)
delete mIconsCacheHelper;
[mRequestDict release];
[mIconDictionary release];
[super dealloc];
}
- (NSString*)favoriteIconURLFromPageURL:(NSString*)inPageURL
{
if ([inPageURL length] == 0)
return nil;
NSString* faviconURL = nil;
// do we have a link icon for this page?
@ -370,11 +373,6 @@ MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI)
return inCache;
}
- (BOOL)loadFavoriteIcon:(id)sender forURI:(NSString *)inURI allowNetwork:(BOOL)inAllowNetwork
{
return [self fetchFavoriteIconForPage:inURI withIconLocation:nil allowNetwork:inAllowNetwork notifyingClient:sender];
}
#define SITE_ICON_EXPIRATION_SECONDS (60 * 60 * 24 * 7) // 1 week
// this is called on the main thread
@ -415,7 +413,10 @@ MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI)
[faviconImage setSize:NSMakeSize(16, 16)];
// add the image to the cache
[mIconDictionary setObject:faviconImage forKey:inURI];
[[SiteIconCache sharedSiteIconCache] setSiteIcon:faviconImage
forURL:inURI
withExpiration:[NSDate dateWithTimeIntervalSinceNow:SITE_ICON_EXPIRATION_SECONDS]
memoryOnly:NO];
}
// figure out what URL triggered this favicon request
@ -466,16 +467,12 @@ MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI)
- (NSImage*)favoriteIconForPage:(NSString*)inPageURI
{
if ([inPageURI length] == 0)
return nil;
// map uri to image location uri
NSString* iconURL = [self favoriteIconURLFromPageURL:inPageURI];
NSImage* siteIcon = [mIconDictionary objectForKey:iconURL];
#ifdef VERBOSE_SITE_ICON_LOADING
NSLog(@"got icon %p for url %@", siteIcon, iconURL);
#endif
return siteIcon;
if ([iconURL length] == 0)
return nil;
return [[SiteIconCache sharedSiteIconCache] siteIconForURL:iconURL];
}
- (void)registerFaviconImage:(NSImage*)inImage forPageURI:(NSString*)inURI
@ -483,7 +480,10 @@ MakeFaviconURIFromURI(const nsAString& inURIString, nsAString& outFaviconURI)
if (inImage == nil || [inURI length] == 0)
return;
[mIconDictionary setObject:inImage forKey:inURI];
[[SiteIconCache sharedSiteIconCache] setSiteIcon:inImage
forURL:inURI
withExpiration:[NSDate distantFuture]
memoryOnly:YES];
}
- (BOOL)fetchFavoriteIconForPage:(NSString*)inPageURI