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.
27 #include "WebKitDLL.h"
28 #include "WebDownload.h"
30 #include "DefaultDownloadDelegate.h"
31 #include "MarshallingHelpers.h"
34 #include "WebKitLogging.h"
35 #include "WebMutableURLRequest.h"
36 #include "WebURLAuthenticationChallenge.h"
37 #include "WebURLCredential.h"
38 #include "WebURLResponse.h"
39 #include <wtf/text/CString.h>
41 #include <WebCore/BString.h>
42 #include <WebCore/DownloadBundle.h>
43 #include <WebCore/NotImplemented.h>
44 #include <WebCore/ResourceError.h>
45 #include <WebCore/ResourceHandle.h>
46 #include <WebCore/ResourceRequest.h>
47 #include <WebCore/ResourceResponse.h>
48 #include <wtf/CurrentTime.h>
49 #include <wtf/StdLibExtras.h>
51 using namespace WebCore;
53 // WebDownload ----------------------------------------------------------------
55 WebDownload::WebDownload()
59 gClassNameCount.add("WebDownload");
62 WebDownload::~WebDownload()
64 LOG(Download, "WebDownload - Destroying download (%p)", this);
67 gClassNameCount.remove("WebDownload");
70 WebDownload* WebDownload::createInstance()
72 WebDownload* instance = new WebDownload();
77 WebDownload* WebDownload::createInstance(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response, IWebDownloadDelegate* delegate)
79 WebDownload* instance = new WebDownload();
81 instance->init(handle, request, response, delegate);
85 WebDownload* WebDownload::createInstance(const KURL& url, IWebDownloadDelegate* delegate)
87 WebDownload* instance = new WebDownload();
89 instance->init(url, delegate);
93 // IUnknown -------------------------------------------------------------------
95 HRESULT STDMETHODCALLTYPE WebDownload::QueryInterface(REFIID riid, void** ppvObject)
98 if (IsEqualGUID(riid, IID_IUnknown))
99 *ppvObject = static_cast<IWebDownload*>(this);
100 else if (IsEqualGUID(riid, IID_IWebDownload))
101 *ppvObject = static_cast<IWebDownload*>(this);
102 else if (IsEqualGUID(riid, IID_IWebURLAuthenticationChallengeSender))
103 *ppvObject = static_cast<IWebURLAuthenticationChallengeSender*>(this);
104 else if (IsEqualGUID(riid, CLSID_WebDownload))
105 *ppvObject = static_cast<WebDownload*>(this);
107 return E_NOINTERFACE;
113 ULONG STDMETHODCALLTYPE WebDownload::AddRef(void)
118 ULONG STDMETHODCALLTYPE WebDownload::Release(void)
120 ULONG newRef = --m_refCount;
127 // IWebDownload -------------------------------------------------------------------
129 HRESULT STDMETHODCALLTYPE WebDownload::canResumeDownloadDecodedWithEncodingMIMEType(
131 /* [out, retval] */ BOOL*)
137 HRESULT STDMETHODCALLTYPE WebDownload::bundlePathForTargetPath(
138 /* [in] */ BSTR targetPath,
139 /* [out, retval] */ BSTR* bundlePath)
144 String bundle(targetPath, SysStringLen(targetPath));
145 if (bundle.isEmpty())
148 if (bundle[bundle.length()-1] == '/')
151 bundle += DownloadBundle::fileExtension();
152 *bundlePath = SysAllocStringLen(bundle.characters(), bundle.length());
158 HRESULT STDMETHODCALLTYPE WebDownload::request(
159 /* [out, retval] */ IWebURLRequest** request)
162 *request = m_request.get();
164 (*request)->AddRef();