+2006-08-13 Brady Eidson <beidson@apple.com>
+
+ Reviewed by Maciej
+
+ The way of detecting a failed icon load before was to try and construct
+ an image from the icon and if that image construction failed, mark the icon
+ as missing.
+ A much more efficient way is to check for a 404 response. We'll still
+ check for invalid image data, but most servers will correctly return 404
+ on a missing icon.
+
+ * Misc/WebIconLoader.m:
+ (-[WebIconLoader didFinishLoading]): Added check for 404 response
+
2006-08-13 Maciej Stachowiak <mjs@apple.com>
Reviewed by Darin.
- (void)didFinishLoading
{
-#ifndef ICONDEBUG
+#ifdef ICONDEBUG
+ NSData *data;
+
+ id response = [self response];
+ if ([response isKindOfClass:[NSHTTPURLResponse class]] && ([response statusCode] < 200 || [response statusCode] > 299))
+ data = nil;
+ else
+ data = [self resourceData];
+
+ if (data) {
+ [[WebIconDatabaseBridge sharedBridgeInstance] _setIconData:data forIconURL:[[self URL] _web_originalDataAsString]];
+ LOG(IconDatabase, "NewDB - Icon data set for URL %@", [[self URL] _web_originalDataAsString]);
+ } else {
+ [[WebIconDatabaseBridge sharedBridgeInstance] _setHaveNoIconForIconURL:[[self URL] _web_originalDataAsString]];
+ LOG(IconDatabase, "NewDB - No icon for URL %@", [[self URL] _web_originalDataAsString]);
+ }
+ [frameLoader _iconLoaderReceivedPageIcon:self];
+ [super didFinishLoading];
+#else
NSImage *icon;
-#endif
-
+
NS_DURING
NSData *data = [self resourceData];
-
-#ifdef ICONDEBUG
- if (data) {
- [[WebIconDatabaseBridge sharedBridgeInstance] _setIconData:data forIconURL:[[self URL] _web_originalDataAsString]];
- LOG(IconDatabase, "NewDB - Icon data set for URL %@", [[self URL] _web_originalDataAsString]);
- }
-#else
icon = [data length] > 0 ? [[NSImage alloc] initWithData:data] : nil;
-#endif
NS_HANDLER
-#ifndef ICONDEBUG
icon = nil;
-#endif
NS_ENDHANDLER
-#ifndef ICONDEBUG
+
if ([[icon representations] count] > 0) {
[[WebIconDatabase sharedIconDatabase] _setIcon:icon forIconURL:[[self URL] _web_originalDataAsString]];
} else {
[[WebIconDatabase sharedIconDatabase] _setHaveNoIconForIconURL:[[self URL] _web_originalDataAsString]];
}
-#endif
-
+
[frameLoader _iconLoaderReceivedPageIcon:self];
-
-#ifndef ICONDEBUG
[icon release];
-#endif
-
[super didFinishLoading];
+#endif
}
- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse;