-
Notifications
You must be signed in to change notification settings - Fork 28
/
ResourceDownloader.m
90 lines (71 loc) · 1.79 KB
/
ResourceDownloader.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// ResourceDownloader.m
// Google Book Downloader
//
// Created by Ω on 8/25/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ResourceDownloader.h"
@implementation ResourceDownloader
- (void)startFromURL:(NSString *)url
{
requestIndex = [[NSMutableArray alloc] init];
webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 800)];
[webView setResourceLoadDelegate:self];
[webView setFrameLoadDelegate:self];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}
- (void)stop
{
[webView setResourceLoadDelegate:nil];
[webView setFrameLoadDelegate:nil];
[webView release];
webView = nil;
}
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
if (frame == [sender mainFrame])
{
[self onload];
}
}
- (void)onload
{
}
// http://google.com/codesearch#6R_f0l7yfPc/Eclipse%20SWT%20WebKit/carbon/org/eclipse/swt/browser/WebKit.java&q=didFinishLoadingFromDataSource&ct=rc&cd=20&sq=&l=1307
- (void)resourceLoaded:(WebResource *)resource
{
}
- (void)webView:(WebView *)sender
resource:(id)identifier
didFinishLoadingFromDataSource:(WebDataSource *)dataSource
{
if (webView != nil)
{
[self resourceLoaded:[dataSource subresourceForURL:[(NSURLRequest *)identifier URL]]];
}
r--;
}
- (void)webView:(WebView *)sender resource:(id)identifier didFailLoadingWithError:(NSError *)error fromDataSource:(WebDataSource *)dataSource;
{
r--;
}
- (id) webView : (WebView *) sender identifierForInitialRequest : (NSURLRequest *) request fromDataSource : (id) dataSource
{
[requestIndex addObject:[request URL]];
r++;
return request;
}
- (int)currentDownloads
{
return r;
}
- (void)dealloc
{
[webView release];
webView = nil;
[requestIndex release];
requestIndex = nil;
[super dealloc];
}
@end