Revision: 27794
http://sourceforge.net/p/bibdesk/svn/27794
Author: hofman
Date: 2022-08-11 23:15:26 +0000 (Thu, 11 Aug 2022)
Log Message:
-----------
Download favicon using callback block rathervthan delegate method, so we can
use and compare the original mainFrameURL, which can change and should be
ignored when it happens.
Modified Paths:
--------------
trunk/bibdesk/BDSKDownloader.h
trunk/bibdesk/BDSKDownloader.m
trunk/bibdesk/BDSKWebView.h
trunk/bibdesk/BDSKWebView.m
Modified: trunk/bibdesk/BDSKDownloader.h
===================================================================
--- trunk/bibdesk/BDSKDownloader.h 2022-08-11 22:40:45 UTC (rev 27793)
+++ trunk/bibdesk/BDSKDownloader.h 2022-08-11 23:15:26 UTC (rev 27794)
@@ -52,7 +52,7 @@
- (BDSKDownload *)startDataDownloadWithRequest:(NSURLRequest *)request
delegate:(id <BDSKDownloaderDelegate>)aDelegate;
- (NSData *)downloadDataWithRequest:(NSURLRequest *)request
returningResponse:(NSURLResponse **)response error:(NSError **)error;
-- (void)downloadDataWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError
*error))completionHandler;
+- (NSURLSessionTask *)downloadDataWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError
*error))completionHandler;
@end
Modified: trunk/bibdesk/BDSKDownloader.m
===================================================================
--- trunk/bibdesk/BDSKDownloader.m 2022-08-11 22:40:45 UTC (rev 27793)
+++ trunk/bibdesk/BDSKDownloader.m 2022-08-11 23:15:26 UTC (rev 27794)
@@ -136,8 +136,10 @@
return [returnData autorelease];
}
-- (void)downloadDataWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError
*error))completionHandler {
- [[[self session] dataTaskWithRequest:request
completionHandler:completionHandler] resume];
+- (NSURLSessionTask *)downloadDataWithRequest:(NSURLRequest *)request
completionHandler:(void (^)(NSData *data, NSURLResponse *response, NSError
*error))completionHandler {
+ NSURLSessionTask *task = [[self session] dataTaskWithRequest:request
completionHandler:completionHandler];
+ [task resume];
+ return task;
}
#pragma mark Delegate interaction
Modified: trunk/bibdesk/BDSKWebView.h
===================================================================
--- trunk/bibdesk/BDSKWebView.h 2022-08-11 22:40:45 UTC (rev 27793)
+++ trunk/bibdesk/BDSKWebView.h 2022-08-11 23:15:26 UTC (rev 27794)
@@ -49,12 +49,12 @@
BDSKWebMenuItemTagSavePage
};
-@class BDSKWebDelegate, BDSKDownload;
+@class BDSKWebDelegate;
@protocol BDSKWebViewDelegate, BDSKWebViewNavigationDelegate;
@interface BDSKWebView : WebView {
BDSKWebDelegate *webDelegate;
- BDSKDownload *faviconDownload;
+ NSURLSessionTask *faviconDownload;
NSImage *favicon;
BOOL faviconFromOrigin;
}
Modified: trunk/bibdesk/BDSKWebView.m
===================================================================
--- trunk/bibdesk/BDSKWebView.m 2022-08-11 22:40:45 UTC (rev 27793)
+++ trunk/bibdesk/BDSKWebView.m 2022-08-11 23:15:26 UTC (rev 27794)
@@ -75,7 +75,7 @@
#pragma mark -
-@interface BDSKWebView () <BDSKDownloaderDelegate>
+@interface BDSKWebView ()
- (void)setFavicon:(NSImage *)icon;
- (void)retrieveFavicon;
- (void)resetFavicon;
@@ -284,7 +284,7 @@
}
if (faviconDownload) {
[faviconDownload cancel];
- [faviconDownload release];
+ BDSKDESTROY(faviconDownload);
}
// different pages from the same site can have the same favicon
@@ -296,8 +296,20 @@
}
faviconFromOrigin = NO;
+ urlString = [self mainFrameURL];
NSURLRequest *request = [NSURLRequest requestWithURL:faviconURL];
- faviconDownload = [[[BDSKDownloader sharedDownloader]
startDataDownloadWithRequest:request delegate:self] retain];
+ faviconDownload = [[[BDSKDownloader sharedDownloader]
downloadDataWithRequest:request completionHandler:^(NSData *data, NSURLResponse
*response, NSError *error){
+ BDSKDESTROY(faviconDownload);
+ if (error == nil && data && [urlString isEqualToString:[self
mainFrameURL]]) {
+ NSImage *anIcon = [[NSImage alloc] initWithData:data];
+ if (anIcon) {
+ [self setFavicon:anIcon];
+ [[BDSKWebIconDatabase sharedDatabase] setIcon:anIcon
withData:data fromURLString:[faviconURL absoluteString]
+ forURLString:urlString];
+ [anIcon release];
+ }
+ }
+ }] retain];
}
- (void)resetFavicon {
@@ -311,27 +323,6 @@
BDSKDESTROY(favicon);
}
-- (void)downloader:(BDSKDownloader *)downloader download:(BDSKDownload
*)download didCompleteWithError:(NSError *)error {
- if (faviconDownload != download)
- return;
- NSData *data = [[download data] retain];
- BDSKDESTROY(faviconDownload);
- if (error) {
- [data release];
- return;
- }
- if (data) {
- NSImage *icon = [[NSImage alloc] initWithData:data];
- if (icon) {
- [self setFavicon:icon];
- [[BDSKWebIconDatabase sharedDatabase] setIcon:icon withData:data
fromURLString:[[[[download task] originalRequest] URL] absoluteString]
- forURLString:[self mainFrameURL]];
- [icon release];
- }
- [data release];
- }
-}
-
- (NSImage *)mainFrameIcon {
return favicon ?: [[BDSKWebIconDatabase sharedDatabase]
iconForURLString:[self mainFrameURL]] ?: [NSImage imageNamed:@"Bookmark"];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit