Ben Copsey

Start work on storing external resources in files on disk

@@ -21,6 +21,7 @@ typedef enum _ASIWebContentType { @@ -21,6 +21,7 @@ typedef enum _ASIWebContentType {
21 ASICSSWebContentType = 2 21 ASICSSWebContentType = 2
22 } ASIWebContentType; 22 } ASIWebContentType;
23 23
  24 +
24 @interface ASIWebPageRequest : ASIHTTPRequest { 25 @interface ASIWebPageRequest : ASIHTTPRequest {
25 ASINetworkQueue *externalResourceQueue; 26 ASINetworkQueue *externalResourceQueue;
26 NSMutableDictionary *resourceList; 27 NSMutableDictionary *resourceList;
@@ -31,6 +32,8 @@ typedef enum _ASIWebContentType { @@ -31,6 +32,8 @@ typedef enum _ASIWebContentType {
31 ASIWebPageRequest *parentRequest; 32 ASIWebPageRequest *parentRequest;
32 } 33 }
33 34
  35 +- (NSString *)contentForExternalURL:(NSString *)theURL;
  36 +- (NSString *)cachePathForRequest:(ASIWebPageRequest *)theRequest;
34 37
35 @property (assign, nonatomic) ASIWebPageRequest *parentRequest; 38 @property (assign, nonatomic) ASIWebPageRequest *parentRequest;
36 @end 39 @end
This diff is collapsed. Click to expand it.
@@ -406,6 +406,7 @@ @@ -406,6 +406,7 @@
406 [request setShowAccurateProgress:NO]; 406 [request setShowAccurateProgress:NO];
407 [request setDownloadProgressDelegate:progressIndicator]; 407 [request setDownloadProgressDelegate:progressIndicator];
408 [request setDownloadCache:[ASIDownloadCache sharedCache]]; 408 [request setDownloadCache:[ASIDownloadCache sharedCache]];
  409 + [request setDownloadDestinationPath:@"/Users/ben/Desktop/fink"];
409 [[ASIDownloadCache sharedCache] setDefaultCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy]; 410 [[ASIDownloadCache sharedCache] setDefaultCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
410 [[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO]; 411 [[ASIDownloadCache sharedCache] setShouldRespectCacheControlHeaders:NO];
411 [request startAsynchronous]; 412 [request startAsynchronous];
@@ -418,8 +419,15 @@ @@ -418,8 +419,15 @@
418 419
419 - (void)webPageFetchSucceeded:(ASIHTTPRequest *)request 420 - (void)webPageFetchSucceeded:(ASIHTTPRequest *)request
420 { 421 {
  422 + if ([request downloadDestinationPath]) {
  423 + NSString *response = [NSString stringWithContentsOfFile:[request downloadDestinationPath] encoding:[request responseEncoding] error:nil];
  424 + [webPageSource setString:response];
  425 + [[webView mainFrame] loadHTMLString:response baseURL:[request url]];
  426 + } else {
421 [webPageSource setString:[request responseString]]; 427 [webPageSource setString:[request responseString]];
422 [[webView mainFrame] loadHTMLString:[request responseString] baseURL:[request url]]; 428 [[webView mainFrame] loadHTMLString:[request responseString] baseURL:[request url]];
  429 + }
  430 +
423 [urlField setStringValue:[[request url] absoluteString]]; 431 [urlField setStringValue:[[request url] absoluteString]];
424 } 432 }
425 433