|
1 /* |
|
2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #ifndef WebDownload_h |
|
27 #define WebDownload_h |
|
28 |
|
29 #include "COMPtr.h" |
|
30 #include "IWebDownload.h" |
|
31 #include "IWebURLAuthenticationChallenge.h" |
|
32 |
|
33 #include <CFNetwork/CFURLDownloadPriv.h> |
|
34 #include <WebCore/PlatformString.h> |
|
35 #include <wtf/RetainPtr.h> |
|
36 |
|
37 namespace WebCore { |
|
38 class KURL; |
|
39 class ResourceHandle; |
|
40 struct ResourceRequest; |
|
41 class ResourceResponse; |
|
42 } |
|
43 |
|
44 class WebDownload : public IWebDownload, public IWebURLAuthenticationChallengeSender |
|
45 { |
|
46 public: |
|
47 static WebDownload* createInstance(const WebCore::KURL&, IWebDownloadDelegate*); |
|
48 static WebDownload* createInstance(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, IWebDownloadDelegate*); |
|
49 static WebDownload* createInstance(); |
|
50 private: |
|
51 WebDownload(); |
|
52 void init(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, IWebDownloadDelegate*); |
|
53 void init(const WebCore::KURL&, IWebDownloadDelegate*); |
|
54 ~WebDownload(); |
|
55 public: |
|
56 // IUnknown |
|
57 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); |
|
58 virtual ULONG STDMETHODCALLTYPE AddRef(void); |
|
59 virtual ULONG STDMETHODCALLTYPE Release(void); |
|
60 |
|
61 // IWebDownload |
|
62 virtual HRESULT STDMETHODCALLTYPE initWithRequest( |
|
63 /* [in] */ IWebURLRequest* request, |
|
64 /* [in] */ IWebDownloadDelegate* delegate); |
|
65 |
|
66 virtual HRESULT STDMETHODCALLTYPE initToResumeWithBundle( |
|
67 /* [in] */ BSTR bundlePath, |
|
68 /* [in] */ IWebDownloadDelegate* delegate); |
|
69 |
|
70 virtual HRESULT STDMETHODCALLTYPE canResumeDownloadDecodedWithEncodingMIMEType( |
|
71 /* [in] */ BSTR mimeType, |
|
72 /* [out, retval] */ BOOL* result); |
|
73 |
|
74 virtual HRESULT STDMETHODCALLTYPE start(); |
|
75 |
|
76 virtual HRESULT STDMETHODCALLTYPE cancel(); |
|
77 |
|
78 virtual HRESULT STDMETHODCALLTYPE cancelForResume(); |
|
79 |
|
80 virtual HRESULT STDMETHODCALLTYPE deletesFileUponFailure( |
|
81 /* [out, retval] */ BOOL* result); |
|
82 |
|
83 virtual HRESULT STDMETHODCALLTYPE bundlePathForTargetPath( |
|
84 /* [in] */ BSTR target, |
|
85 /* [out, retval] */ BSTR* bundle); |
|
86 |
|
87 virtual HRESULT STDMETHODCALLTYPE request( |
|
88 /* [out, retval] */ IWebURLRequest** request); |
|
89 |
|
90 virtual HRESULT STDMETHODCALLTYPE setDeletesFileUponFailure( |
|
91 /* [in] */ BOOL deletesFileUponFailure); |
|
92 |
|
93 virtual HRESULT STDMETHODCALLTYPE setDestination( |
|
94 /* [in] */ BSTR path, |
|
95 /* [in] */ BOOL allowOverwrite); |
|
96 |
|
97 // IWebURLAuthenticationChallengeSender |
|
98 virtual HRESULT STDMETHODCALLTYPE cancelAuthenticationChallenge( |
|
99 /* [in] */ IWebURLAuthenticationChallenge* challenge); |
|
100 |
|
101 virtual HRESULT STDMETHODCALLTYPE continueWithoutCredentialForAuthenticationChallenge( |
|
102 /* [in] */ IWebURLAuthenticationChallenge* challenge); |
|
103 |
|
104 virtual HRESULT STDMETHODCALLTYPE useCredential( |
|
105 /* [in] */ IWebURLCredential* credential, |
|
106 /* [in] */ IWebURLAuthenticationChallenge* challenge); |
|
107 |
|
108 // CFURLDownload Callbacks |
|
109 void didStart(); |
|
110 CFURLRequestRef willSendRequest(CFURLRequestRef, CFURLResponseRef); |
|
111 void didReceiveAuthenticationChallenge(CFURLAuthChallengeRef); |
|
112 void didReceiveResponse(CFURLResponseRef); |
|
113 void willResumeWithResponse(CFURLResponseRef, UInt64); |
|
114 void didReceiveData(CFIndex); |
|
115 bool shouldDecodeDataOfMIMEType(CFStringRef); |
|
116 void decideDestinationWithSuggestedObjectName(CFStringRef); |
|
117 void didCreateDestination(CFURLRef); |
|
118 void didFinish(); |
|
119 void didFail(CFErrorRef); |
|
120 |
|
121 protected: |
|
122 ULONG m_refCount; |
|
123 |
|
124 WebCore::String m_destination; |
|
125 WebCore::String m_bundlePath; |
|
126 RetainPtr<CFURLDownloadRef> m_download; |
|
127 COMPtr<IWebMutableURLRequest> m_request; |
|
128 COMPtr<IWebDownloadDelegate> m_delegate; |
|
129 |
|
130 #ifndef NDEBUG |
|
131 double m_startTime; |
|
132 double m_dataTime; |
|
133 int m_received; |
|
134 #endif |
|
135 }; |
|
136 |
|
137 |
|
138 #endif |