#include "config.h"
#include "WebKitDLL.h"
#include "WebDownload.h"
#include "DefaultDownloadDelegate.h"
#include "MarshallingHelpers.h"
#include "WebError.h"
#include "WebKit.h"
#include "WebKitLogging.h"
#include "WebMutableURLRequest.h"
#include "WebURLAuthenticationChallenge.h"
#include "WebURLCredential.h"
#include "WebURLResponse.h"
#include <wtf/text/CString.h>
#include <WebCore/BString.h>
#include <WebCore/DownloadBundle.h>
#include <WebCore/NotImplemented.h>
#include <WebCore/ResourceError.h>
#include <WebCore/ResourceHandle.h>
#include <WebCore/ResourceRequest.h>
#include <WebCore/ResourceResponse.h>
#include <wtf/CurrentTime.h>
#include <wtf/StdLibExtras.h>
using namespace WebCore;
WebDownload::WebDownload()
: m_refCount(0)
{
gClassCount++;
gClassNameCount.add("WebDownload");
}
WebDownload::~WebDownload()
{
LOG(Download, "WebDownload - Destroying download (%p)", this);
cancel();
gClassCount--;
gClassNameCount.remove("WebDownload");
}
WebDownload* WebDownload::createInstance()
{
WebDownload* instance = new WebDownload();
instance->AddRef();
return instance;
}
WebDownload* WebDownload::createInstance(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response, IWebDownloadDelegate* delegate)
{
WebDownload* instance = new WebDownload();
instance->AddRef();
instance->init(handle, request, response, delegate);
return instance;
}
WebDownload* WebDownload::createInstance(const KURL& url, IWebDownloadDelegate* delegate)
{
WebDownload* instance = new WebDownload();
instance->AddRef();
instance->init(url, delegate);
return instance;
}
HRESULT STDMETHODCALLTYPE WebDownload::QueryInterface(REFIID riid, void** ppvObject)
{
*ppvObject = 0;
if (IsEqualGUID(riid, IID_IUnknown))
*ppvObject = static_cast<IWebDownload*>(this);
else if (IsEqualGUID(riid, IID_IWebDownload))
*ppvObject = static_cast<IWebDownload*>(this);
else if (IsEqualGUID(riid, IID_IWebURLAuthenticationChallengeSender))
*ppvObject = static_cast<IWebURLAuthenticationChallengeSender*>(this);
else if (IsEqualGUID(riid, CLSID_WebDownload))
*ppvObject = static_cast<WebDownload*>(this);
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
ULONG STDMETHODCALLTYPE WebDownload::AddRef(void)
{
return ++m_refCount;
}
ULONG STDMETHODCALLTYPE WebDownload::Release(void)
{
ULONG newRef = --m_refCount;
if (!newRef)
delete(this);
return newRef;
}
HRESULT STDMETHODCALLTYPE WebDownload::canResumeDownloadDecodedWithEncodingMIMEType(
BSTR,
BOOL*)
{
notImplemented();
return E_FAIL;
}
HRESULT STDMETHODCALLTYPE WebDownload::bundlePathForTargetPath(
BSTR targetPath,
BSTR* bundlePath)
{
if (!targetPath)
return E_INVALIDARG;
String bundle(targetPath, SysStringLen(targetPath));
if (bundle.isEmpty())
return E_INVALIDARG;
if (bundle[bundle.length()-1] == '/')
bundle.truncate(1);
bundle.append(DownloadBundle::fileExtension());
*bundlePath = SysAllocStringLen(bundle.characters(), bundle.length());
if (!*bundlePath)
return E_FAIL;
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebDownload::request(
IWebURLRequest** request)
{
if (request) {
*request = m_request.get();
if (*request)
(*request)->AddRef();
}
return S_OK;
}