From be988612ecf032e26eb063d5bdd73354b1f2030d Mon Sep 17 00:00:00 2001 From: "stridey%gmail.com" Date: Mon, 18 Dec 2006 18:28:57 +0000 Subject: [PATCH] Camino only - Bug 346228:Use files' actual icons for favicons of local files. r=murph sr=pink git-svn-id: svn://10.0.0.236/trunk@217135 18797224-902f-48f8-a5cc-f745e15eee43 --- .../camino/src/application/MainController.mm | 1 - .../camino/src/browser/SiteIconProvider.mm | 40 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/mozilla/camino/src/application/MainController.mm b/mozilla/camino/src/application/MainController.mm index b840c08c308..890671d8201 100644 --- a/mozilla/camino/src/application/MainController.mm +++ b/mozilla/camino/src/application/MainController.mm @@ -229,7 +229,6 @@ const int kReuseWindowOnAE = 2; // register some special favicon images [[SiteIconProvider sharedFavoriteIconProvider] registerFaviconImage:[NSImage imageNamed:@"smallDocument"] forPageURI:@"about:blank"]; - [[SiteIconProvider sharedFavoriteIconProvider] registerFaviconImage:[NSImage imageNamed:@"smallDocument"] forPageURI:@"about:local_file"]; [[SiteIconProvider sharedFavoriteIconProvider] registerFaviconImage:[NSImage imageNamed:@"bm_favicon"] forPageURI:@"about:bookmarks"]; [[SiteIconProvider sharedFavoriteIconProvider] registerFaviconImage:[NSImage imageNamed:@"historyicon"] forPageURI:@"about:history"]; diff --git a/mozilla/camino/src/browser/SiteIconProvider.mm b/mozilla/camino/src/browser/SiteIconProvider.mm index 398a6fc4bb6..858971eec42 100644 --- a/mozilla/camino/src/browser/SiteIconProvider.mm +++ b/mozilla/camino/src/browser/SiteIconProvider.mm @@ -366,26 +366,29 @@ NeckoCacheHelper::ClearCache() // So we just go ahead and try to make the image; it will return nil on // failure. NSImage* faviconImage = nil; - - NS_DURING - faviconImage = [[[NSImage alloc] initWithData:data] autorelease]; - NS_HANDLER - NSLog(@"Exception \"%@\" making favicon image for %@", localException, inURI); - faviconImage = nil; - NS_ENDHANDLER + + NSURL* inURIAsNSURL = [NSURL URLWithString:inURI]; + if ([inURIAsNSURL isFileURL]) { + faviconImage = [[NSWorkspace sharedWorkspace] iconForFile:[inURIAsNSURL path]]; + } + else { + NS_DURING + faviconImage = [[[NSImage alloc] initWithData:data] autorelease]; + NS_HANDLER + NSLog(@"Exception \"%@\" making favicon image for %@", localException, inURI); + faviconImage = nil; + NS_ENDHANDLER + } BOOL gotImageData = loadOK && (faviconImage != nil); - if (NS_SUCCEEDED(status) && !gotImageData) // error status indicates that load was attempted from cache - { + if (NS_SUCCEEDED(status) && !gotImageData) // error status indicates that load was attempted from cache [self addToMissedIconsCache:inURI withExpirationSeconds:SITE_ICON_EXPIRATION_SECONDS]; - } - - if (gotImageData) - { + + if (gotImageData) { [faviconImage setDataRetained:YES]; [faviconImage setScalesWhenResized:YES]; [faviconImage setSize:NSMakeSize(16, 16)]; - + // add the image to the cache [[SiteIconCache sharedSiteIconCache] setSiteIcon:faviconImage forURL:inURI @@ -543,15 +546,10 @@ NeckoCacheHelper::ClearCache() + (NSString*)defaultFaviconLocationStringFromURI:(NSString*)inURI { - // about: urls are special - if ([inURI hasPrefix:@"about:"]) + // about: urls and local files are special + if ([inURI hasPrefix:@"about:"] || [inURI hasPrefix:@"file:"]) return inURI; - // show small file icon for local files (this assumes that someone has - // registered the blank document icon for "about:blank") - if ([inURI compare:@"file://" options:NSCaseInsensitiveSearch range:NSMakeRange(0, 7)] == NSOrderedSame) - return @"about:local_file"; - // we use nsIURI here, rather than NSURL, because the former does // a better job with suspect urls (e.g. those containing |), and // allows us go keep the port