Revision: 23990
http://sourceforge.net/p/bibdesk/svn/23990
Author: hofman
Date: 2019-07-10 12:25:52 +0000 (Wed, 10 Jul 2019)
Log Message:
-----------
implement authentication delegate for NSURLConnection, update expected length
through superclass method
Modified Paths:
--------------
trunk/bibdesk/BDSKDownloader.h
trunk/bibdesk/BDSKDownloader.m
trunk/bibdesk/BDSKDownloaderDeprecated.m
trunk/bibdesk/BDSKDownloaderSession.m
Modified: trunk/bibdesk/BDSKDownloader.h
===================================================================
--- trunk/bibdesk/BDSKDownloader.h 2019-07-10 11:54:02 UTC (rev 23989)
+++ trunk/bibdesk/BDSKDownloader.h 2019-07-10 12:25:52 UTC (rev 23990)
@@ -76,7 +76,9 @@
- (void)cleanupDownload:(BDSKDownload *)download;
- (void)download:(BDSKDownload *)download
didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(BDSKDownloaderAuthChallengeDisposition disposition,
NSURLCredential *credential))completionHandler;
+- (void)download:(BDSKDownload *)download
didReceiveExpectedContentLength:(int64_t)expectedContentLength;
- (void)download:(BDSKDownload *)download
decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler;
+- (void)download:(BDSKDownload *)download didCreateDestinationAtURL:(NSURL
*)destinationURL;
- (void)download:(BDSKDownload *)download didReceiveData:(NSData *)data;
@end
Modified: trunk/bibdesk/BDSKDownloader.m
===================================================================
--- trunk/bibdesk/BDSKDownloader.m 2019-07-10 11:54:02 UTC (rev 23989)
+++ trunk/bibdesk/BDSKDownloader.m 2019-07-10 12:25:52 UTC (rev 23990)
@@ -120,6 +120,13 @@
}
}
+- (void)download:(BDSKDownload *)download
didReceiveExpectedContentLength:(int64_t)expectedContentLength {
+ id<BDSKDownloaderDelegate> delegate = [download delegate];
+ if ([delegate
respondsToSelector:@selector(downloader:download:didReceiveExpectedContentLength:)])
{
+ [delegate downloader:self download:download
didReceiveExpectedContentLength:expectedContentLength];
+ }
+
+}
- (void)download:(BDSKDownload *)download
decideDestinationWithSuggestedFilename:(NSString *)suggestedFileName
completionHandler:(void (^)(NSURL *destinationURL, BOOL
allowOverwrite))completionHandler {
id<BDSKDownloaderDelegate> delegate = [download delegate];
if ([delegate
respondsToSelector:@selector(downloader:download:decideDestinationWithSuggestedFilename:completionHandler:)])
{
@@ -130,6 +137,13 @@
}
}
+- (void)download:(BDSKDownload *)download didCreateDestinationAtURL:(NSURL
*)destinationURL {
+ id<BDSKDownloaderDelegate> delegate = [download delegate];
+ if ([delegate
respondsToSelector:@selector(downloader:download:didCreateDestination:)]) {
+ [delegate downloader:self download:download
didCreateDestination:destinationURL];
+ }
+}
+
- (void)download:(BDSKDownload *)download didReceiveData:(NSData *)data {
id<BDSKDownloaderDelegate> delegate = [download delegate];
if ([download data] == nil) {
Modified: trunk/bibdesk/BDSKDownloaderDeprecated.m
===================================================================
--- trunk/bibdesk/BDSKDownloaderDeprecated.m 2019-07-10 11:54:02 UTC (rev
23989)
+++ trunk/bibdesk/BDSKDownloaderDeprecated.m 2019-07-10 12:25:52 UTC (rev
23990)
@@ -105,19 +105,13 @@
- (void)download:(NSURLDownload *)task didCreateDestination:(NSString *)path {
BDSKDownloadDeprecated *download = (BDSKDownloadDeprecated *)[[[self
downloadForTask:task] retain] autorelease];
- id<BDSKDownloaderDelegate> delegate = [download delegate];
- if ([delegate
respondsToSelector:@selector(downloader:download:didCreateDestination:)]) {
- [delegate downloader:self download:download
didCreateDestination:[NSURL fileURLWithPath:path isDirectory:NO]];
- }
+ [self download:download didCreateDestinationAtURL:[NSURL
fileURLWithPath:path isDirectory:NO]];
}
- (void)download:(NSURLDownload *)task didReceiveResponse:(NSURLResponse
*)response {
BDSKDownloadDeprecated *download = (BDSKDownloadDeprecated *)[[[self
downloadForTask:task] retain] autorelease];
- id<BDSKDownloaderDelegate> delegate = [download delegate];
[download setResponse:response];
- if ([delegate
respondsToSelector:@selector(downloader:download:didReceiveExpectedContentLength:)])
{
- [delegate downloader:self download:download
didReceiveExpectedContentLength:[response expectedContentLength]];
- }
+ [self download:download didReceiveExpectedContentLength:[response
expectedContentLength]];
}
- (void)download:(NSURLDownload *)task
didReceiveDataOfLength:(NSUInteger)length {
@@ -150,12 +144,31 @@
#pragma mark NSURLConnectionDelegate
+- (void)connection:(NSURLConnection *)task
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
+ BDSKDownload *download = [[[self downloadForTask:task] retain]
autorelease];
+
+ [self download:download didReceiveChallenge:challenge
completionHandler:^(BDSKDownloaderAuthChallengeDisposition disposition,
NSURLCredential *credential){
+ id <NSURLAuthenticationChallengeSender> sender = [challenge sender];
+ switch (disposition) {
+ case BDSKDownloaderAuthChallengeUseCredential:
+ [sender useCredential:credential
forAuthenticationChallenge:challenge];
+ break;
+ case BDSKDownloaderAuthChallengePerformDefaultHandling:
+ [sender
performDefaultHandlingForAuthenticationChallenge:challenge];
+ break;
+ case BDSKDownloaderAuthChallengeCancelAuthenticationChallenge:
+ [sender cancelAuthenticationChallenge:challenge];
+ break;
+ case BDSKDownloaderAuthChallengeRejectProtectionSpace:
+ [sender
rejectProtectionSpaceAndContinueWithChallenge:challenge];
+ break;
+ }
+ }];
+}
+
- (void)connection:(NSURLConnection *)task didReceiveResponse:(NSURLResponse
*)response {
BDSKDownloadDeprecated *download = (BDSKDownloadDeprecated *)[[[self
downloadForTask:task] retain] autorelease];
- id<BDSKDownloaderDelegate> delegate = [download delegate];
- if ([delegate
respondsToSelector:@selector(downloader:download:didReceiveExpectedContentLength:)])
{
- [delegate downloader:self download:download
didReceiveExpectedContentLength:[response expectedContentLength]];
- }
+ [self download:download didReceiveExpectedContentLength:[response
expectedContentLength]];
[download setResponse:response];
}
Modified: trunk/bibdesk/BDSKDownloaderSession.m
===================================================================
--- trunk/bibdesk/BDSKDownloaderSession.m 2019-07-10 11:54:02 UTC (rev
23989)
+++ trunk/bibdesk/BDSKDownloaderSession.m 2019-07-10 12:25:52 UTC (rev
23990)
@@ -140,9 +140,7 @@
[fm createDirectoryAtPath:[[destinationURL
URLByDeletingLastPathComponent] path] withIntermediateDirectories:YES
attributes:nil error:NULL];
}
if ([fm moveItemAtURL:location toURL:destinationURL error:&error]) {
- if ([delegate
respondsToSelector:@selector(downloader:download:didCreateDestination:)]) {
- [delegate downloader:self download:download
didCreateDestination:destinationURL];
- }
+ [self download:download didCreateDestinationAtURL:destinationURL];
[delegate downloader:self download:download didFinishWithData:nil];
} else {
[delegate downloader:self download:download
didFailWithError:error];
@@ -156,9 +154,7 @@
id<BDSKDownloaderDelegate> delegate = [download delegate];
if ([download receivedExpectedBytes] == NO) {
[download setReceivedExpectedBytes:YES];
- if ([delegate
respondsToSelector:@selector(downloader:download:didReceiveExpectedContentLength:)])
{
- [delegate downloader:self download:download
didReceiveExpectedContentLength:totalBytesExpectedToWrite];
- }
+ [self download:download
didReceiveExpectedContentLength:totalBytesExpectedToWrite];
}
if (bytesWritten >= 0 && [delegate
respondsToSelector:@selector(downloader:download:didReceiveDataOfLength:)]) {
@@ -170,10 +166,7 @@
- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask
*)task didReceiveResponse:(NSURLResponse *)response completionHandler:(void
(^)(NSURLSessionResponseDisposition disposition))completionHandler {
BDSKDownload *download = [[[self downloadForTask:task] retain]
autorelease];
- id<BDSKDownloaderDelegate> delegate = [download delegate];
- if ([delegate
respondsToSelector:@selector(downloader:download:didReceiveExpectedContentLength:)])
{
- [delegate downloader:self download:download
didReceiveExpectedContentLength:[response expectedContentLength]];
- }
+ [self download:download didReceiveExpectedContentLength:[response
expectedContentLength]];
// the delegeate may have cancelled the task, in that case don't call the
callback
if ([self downloadForTask:task])
completionHandler(NSURLSessionResponseAllow);
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