2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
30 #include <WebCore/COMPtr.h>
31 #include <WebCore/PlatformString.h>
32 #include <wtf/RetainPtr.h>
35 #include <CFNetwork/CFURLDownloadPriv.h>
41 class ResourceRequest;
42 class ResourceResponse;
45 class WebDownload : public IWebDownload, public IWebURLAuthenticationChallengeSender
48 static WebDownload* createInstance(const WebCore::KURL&, IWebDownloadDelegate*);
49 static WebDownload* createInstance(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, IWebDownloadDelegate*);
50 static WebDownload* createInstance();
53 void init(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, IWebDownloadDelegate*);
54 void init(const WebCore::KURL&, IWebDownloadDelegate*);
58 virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
59 virtual ULONG STDMETHODCALLTYPE AddRef(void);
60 virtual ULONG STDMETHODCALLTYPE Release(void);
63 virtual HRESULT STDMETHODCALLTYPE initWithRequest(
64 /* [in] */ IWebURLRequest* request,
65 /* [in] */ IWebDownloadDelegate* delegate);
67 virtual HRESULT STDMETHODCALLTYPE initToResumeWithBundle(
68 /* [in] */ BSTR bundlePath,
69 /* [in] */ IWebDownloadDelegate* delegate);
71 virtual HRESULT STDMETHODCALLTYPE canResumeDownloadDecodedWithEncodingMIMEType(
72 /* [in] */ BSTR mimeType,
73 /* [out, retval] */ BOOL* result);
75 virtual HRESULT STDMETHODCALLTYPE start();
77 virtual HRESULT STDMETHODCALLTYPE cancel();
79 virtual HRESULT STDMETHODCALLTYPE cancelForResume();
81 virtual HRESULT STDMETHODCALLTYPE deletesFileUponFailure(
82 /* [out, retval] */ BOOL* result);
84 virtual HRESULT STDMETHODCALLTYPE bundlePathForTargetPath(
85 /* [in] */ BSTR target,
86 /* [out, retval] */ BSTR* bundle);
88 virtual HRESULT STDMETHODCALLTYPE request(
89 /* [out, retval] */ IWebURLRequest** request);
91 virtual HRESULT STDMETHODCALLTYPE setDeletesFileUponFailure(
92 /* [in] */ BOOL deletesFileUponFailure);
94 virtual HRESULT STDMETHODCALLTYPE setDestination(
96 /* [in] */ BOOL allowOverwrite);
98 // IWebURLAuthenticationChallengeSender
99 virtual HRESULT STDMETHODCALLTYPE cancelAuthenticationChallenge(
100 /* [in] */ IWebURLAuthenticationChallenge* challenge);
102 virtual HRESULT STDMETHODCALLTYPE continueWithoutCredentialForAuthenticationChallenge(
103 /* [in] */ IWebURLAuthenticationChallenge* challenge);
105 virtual HRESULT STDMETHODCALLTYPE useCredential(
106 /* [in] */ IWebURLCredential* credential,
107 /* [in] */ IWebURLAuthenticationChallenge* challenge);
110 // CFURLDownload Callbacks
112 CFURLRequestRef willSendRequest(CFURLRequestRef, CFURLResponseRef);
113 void didReceiveAuthenticationChallenge(CFURLAuthChallengeRef);
114 void didReceiveResponse(CFURLResponseRef);
115 void willResumeWithResponse(CFURLResponseRef, UInt64);
116 void didReceiveData(CFIndex);
117 bool shouldDecodeDataOfMIMEType(CFStringRef);
118 void decideDestinationWithSuggestedObjectName(CFStringRef);
119 void didCreateDestination(CFURLRef);
121 void didFail(CFErrorRef);
127 WTF::String m_destination;
128 WTF::String m_bundlePath;
130 RetainPtr<CFURLDownloadRef> m_download;
132 COMPtr<IWebMutableURLRequest> m_request;
133 COMPtr<IWebDownloadDelegate> m_delegate;