Commit af9d14ce authored by cblu's avatar cblu
Browse files

- don't set nil data on the web file db

	- store absolute URLs in the db, not base URL/path combination URLs
	- support for multiple hosts with the same built-in icon

        * Misc.subproj/WebIconDatabase.m:
        (-[WebIconDatabase init]): renamed some dictionaries
        (-[WebIconDatabase iconForSiteURL:withSize:]): call _builtInIconsForHost
        (-[WebIconDatabase _updateFileDatabase]): check for nil
        (-[WebIconDatabase _hasIconForSiteURL:]): call _pathForBuiltInIconForHost
        (-[WebIconDatabase _pathForBuiltInIconForHost:]): new
        (-[WebIconDatabase _builtInIconsForHost:]): call _pathForBuiltInIconForHost
        * Misc.subproj/WebIconDatabasePrivate.h:
        * WebView.subproj/WebDataSourcePrivate.m:
        (-[WebDataSource _loadIcon]): use absolute URL


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1964 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b0badeac
2002-09-04 Chris Blumenberg <cblu@apple.com>
- don't set nil data on the web file db
- store absolute URLs in the db, not base URL/path combination URLs
- support for multiple hosts with the same built-in icon
* Misc.subproj/WebIconDatabase.m:
(-[WebIconDatabase init]): renamed some dictionaries
(-[WebIconDatabase iconForSiteURL:withSize:]): call _builtInIconsForHost
(-[WebIconDatabase _updateFileDatabase]): check for nil
(-[WebIconDatabase _hasIconForSiteURL:]): call _pathForBuiltInIconForHost
(-[WebIconDatabase _pathForBuiltInIconForHost:]): new
(-[WebIconDatabase _builtInIconsForHost:]): call _pathForBuiltInIconForHost
* Misc.subproj/WebIconDatabasePrivate.h:
* WebView.subproj/WebDataSourcePrivate.m:
(-[WebDataSource _loadIcon]): use absolute URL
2002-09-04 Chris Blumenberg <cblu@apple.com> 2002-09-04 Chris Blumenberg <cblu@apple.com>
Made the icon DB take a a path for built-in icons so that we only load them when necessary. Made the icon DB take a a path for built-in icons so that we only load them when necessary.
......
2002-09-04 Chris Blumenberg <cblu@apple.com>
- don't set nil data on the web file db
- store absolute URLs in the db, not base URL/path combination URLs
- support for multiple hosts with the same built-in icon
* Misc.subproj/WebIconDatabase.m:
(-[WebIconDatabase init]): renamed some dictionaries
(-[WebIconDatabase iconForSiteURL:withSize:]): call _builtInIconsForHost
(-[WebIconDatabase _updateFileDatabase]): check for nil
(-[WebIconDatabase _hasIconForSiteURL:]): call _pathForBuiltInIconForHost
(-[WebIconDatabase _pathForBuiltInIconForHost:]): new
(-[WebIconDatabase _builtInIconsForHost:]): call _pathForBuiltInIconForHost
* Misc.subproj/WebIconDatabasePrivate.h:
* WebView.subproj/WebDataSourcePrivate.m:
(-[WebDataSource _loadIcon]): use absolute URL
2002-09-04 Chris Blumenberg <cblu@apple.com> 2002-09-04 Chris Blumenberg <cblu@apple.com>
Made the icon DB take a a path for built-in icons so that we only load them when necessary. Made the icon DB take a a path for built-in icons so that we only load them when necessary.
......
...@@ -34,6 +34,7 @@ - (void)_loadIconDictionaries; ...@@ -34,6 +34,7 @@ - (void)_loadIconDictionaries;
- (void)_updateFileDatabase; - (void)_updateFileDatabase;
- (NSMutableArray *)_iconsForIconURL:(NSURL *)iconURL; - (NSMutableArray *)_iconsForIconURL:(NSURL *)iconURL;
- (NSImage *)_iconForFileURL:(NSURL *)fileURL withSize:(NSSize)size; - (NSImage *)_iconForFileURL:(NSURL *)fileURL withSize:(NSSize)size;
- (NSString *)_pathForBuiltInIconForHost:(NSString *)host;
- (NSMutableArray *)_builtInIconsForHost:(NSString *)host; - (NSMutableArray *)_builtInIconsForHost:(NSString *)host;
- (void)_retainIconForIconURL:(NSURL *)iconURL; - (void)_retainIconForIconURL:(NSURL *)iconURL;
- (void)_releaseIconForIconURL:(NSURL *)iconURL; - (void)_releaseIconForIconURL:(NSURL *)iconURL;
...@@ -74,7 +75,7 @@ + (WebIconDatabase *)sharedIconDatabase ...@@ -74,7 +75,7 @@ + (WebIconDatabase *)sharedIconDatabase
_private->iconURLToIcons = [[NSMutableDictionary dictionary] retain]; _private->iconURLToIcons = [[NSMutableDictionary dictionary] retain];
_private->iconURLToRetainCount = [[NSMutableDictionary dictionary] retain]; _private->iconURLToRetainCount = [[NSMutableDictionary dictionary] retain];
_private->futureSiteURLToRetainCount = [[NSMutableDictionary dictionary] retain]; _private->futureSiteURLToRetainCount = [[NSMutableDictionary dictionary] retain];
_private->hostToBuiltInIcons = [[NSMutableDictionary dictionary] retain]; _private->pathToBuiltInIcons = [[NSMutableDictionary dictionary] retain];
_private->hostToBuiltInIconPath = [[NSMutableDictionary dictionary] retain]; _private->hostToBuiltInIconPath = [[NSMutableDictionary dictionary] retain];
_private->iconsToEraseWithURLs = [[NSMutableSet set] retain]; _private->iconsToEraseWithURLs = [[NSMutableSet set] retain];
...@@ -95,7 +96,6 @@ + (WebIconDatabase *)sharedIconDatabase ...@@ -95,7 +96,6 @@ + (WebIconDatabase *)sharedIconDatabase
- (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size - (NSImage *)iconForSiteURL:(NSURL *)siteURL withSize:(NSSize)size
{ {
if(!siteURL){ if(!siteURL){
return [self defaultIconWithSize:size]; return [self defaultIconWithSize:size];
} }
...@@ -310,8 +310,10 @@ - (void)_updateFileDatabase ...@@ -310,8 +310,10 @@ - (void)_updateFileDatabase
while ((iconURL = [enumerator nextObject]) != nil) { while ((iconURL = [enumerator nextObject]) != nil) {
//NSLog(@"writing %@", iconURL); //NSLog(@"writing %@", iconURL);
iconData = [[self _iconForIconURL:iconURL] TIFFRepresentation]; iconData = [[self _iconForIconURL:iconURL] TIFFRepresentation];
[fileDB setObject:iconData forKey:iconURL]; if(iconData){
[_private->iconsOnDiskWithURLs addObject:iconURL]; [fileDB setObject:iconData forKey:iconURL];
[_private->iconsOnDiskWithURLs addObject:iconURL];
}
} }
[_private->iconsToEraseWithURLs removeAllObjects]; [_private->iconsToEraseWithURLs removeAllObjects];
...@@ -328,7 +330,7 @@ - (BOOL)_hasIconForSiteURL:(NSURL *)siteURL ...@@ -328,7 +330,7 @@ - (BOOL)_hasIconForSiteURL:(NSURL *)siteURL
{ {
if([siteURL isFileURL]){ if([siteURL isFileURL]){
return YES; return YES;
}else if([_private->hostToBuiltInIconPath objectForKey:[siteURL host]]){ }else if([self _pathForBuiltInIconForHost:[siteURL host]]){
return YES; return YES;
}else if([_private->siteURLToIconURL objectForKey:siteURL]){ }else if([_private->siteURLToIconURL objectForKey:siteURL]){
return YES; return YES;
...@@ -396,15 +398,13 @@ - (NSImage *)_iconForFileURL:(NSURL *)fileURL withSize:(NSSize)size ...@@ -396,15 +398,13 @@ - (NSImage *)_iconForFileURL:(NSURL *)fileURL withSize:(NSSize)size
} }
} }
- (NSMutableArray *)_builtInIconsForHost:(NSString *)host - (NSString *)_pathForBuiltInIconForHost:(NSString *)host
{ {
NSArray *hostParts = [host componentsSeparatedByString:@"."]; NSArray *hostParts = [host componentsSeparatedByString:@"."];
NSMutableString *truncatedHost = [NSMutableString string]; NSMutableString *truncatedHost = [NSMutableString string];
NSString *hostPart, *path; NSString *hostPart, *path;
NSMutableArray *icons;
BOOL firstPart = YES; BOOL firstPart = YES;
NSImage *icon;
NSEnumerator *enumerator = [hostParts reverseObjectEnumerator]; NSEnumerator *enumerator = [hostParts reverseObjectEnumerator];
while ((hostPart = [enumerator nextObject]) != nil) { while ((hostPart = [enumerator nextObject]) != nil) {
if(firstPart){ if(firstPart){
...@@ -414,18 +414,7 @@ - (NSMutableArray *)_builtInIconsForHost:(NSString *)host ...@@ -414,18 +414,7 @@ - (NSMutableArray *)_builtInIconsForHost:(NSString *)host
[truncatedHost insertString:[NSString stringWithFormat:@"%@.", hostPart] atIndex:0]; [truncatedHost insertString:[NSString stringWithFormat:@"%@.", hostPart] atIndex:0];
path = [_private->hostToBuiltInIconPath objectForKey:truncatedHost]; path = [_private->hostToBuiltInIconPath objectForKey:truncatedHost];
if(path){ if(path){
icons = [_private->hostToBuiltInIcons objectForKey:truncatedHost]; return path;
if(!icons){
icon = [[NSImage alloc] initWithContentsOfFile:path];
if(icon){
icons = [NSMutableArray arrayWithObject:icon];
[_private->hostToBuiltInIcons setObject:icons forKey:host];
[icon release];
}
}
if(icons){
return icons;
}
} }
} }
} }
...@@ -433,6 +422,26 @@ - (NSMutableArray *)_builtInIconsForHost:(NSString *)host ...@@ -433,6 +422,26 @@ - (NSMutableArray *)_builtInIconsForHost:(NSString *)host
return nil; return nil;
} }
- (NSMutableArray *)_builtInIconsForHost:(NSString *)host
{
NSString *path = [self _pathForBuiltInIconForHost:host];
NSMutableArray *icons = nil;
if(path){
icons = [_private->pathToBuiltInIcons objectForKey:path];
if(!icons){
NSImage *icon = [[NSImage alloc] initWithContentsOfFile:path];
if(icon){
icons = [NSMutableArray arrayWithObject:icon];
[_private->pathToBuiltInIcons setObject:icons forKey:path];
[icon release];
}
}
}
return icons;
}
- (void)_setIcon:(NSImage *)icon forIconURL:(NSURL *)iconURL - (void)_setIcon:(NSImage *)icon forIconURL:(NSURL *)iconURL
{ {
if(!icon || !iconURL){ if(!icon || !iconURL){
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
NSMutableDictionary *siteURLToIconURL; NSMutableDictionary *siteURLToIconURL;
NSMutableDictionary *futureSiteURLToRetainCount; NSMutableDictionary *futureSiteURLToRetainCount;
NSMutableDictionary *hostToSiteURLs; NSMutableDictionary *hostToSiteURLs;
NSMutableDictionary *hostToBuiltInIcons; NSMutableDictionary *pathToBuiltInIcons;
NSMutableDictionary *hostToBuiltInIconPath; NSMutableDictionary *hostToBuiltInIconPath;
NSMutableSet *iconsOnDiskWithURLs; NSMutableSet *iconsOnDiskWithURLs;
......
...@@ -462,7 +462,7 @@ - (void)_loadIcon ...@@ -462,7 +462,7 @@ - (void)_loadIcon
if(!_private->iconURL){ if(!_private->iconURL){
// No icon URL from the LINK tag so try the server's root // No icon URL from the LINK tag so try the server's root
_private->iconURL = [[NSURL _web_URLWithString:@"/favicon.ico" relativeToURL:dataSourceURL] retain]; _private->iconURL = [[[NSURL _web_URLWithString:@"/favicon.ico" relativeToURL:dataSourceURL] absoluteURL] retain];
} }
if(_private->iconURL != nil){ if(_private->iconURL != nil){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment