WebDownload.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #include "config.h"
  26. #include "WebKitDLL.h"
  27. #include "WebDownload.h"
  28. #include "DefaultDownloadDelegate.h"
  29. #include "MarshallingHelpers.h"
  30. #include "WebError.h"
  31. #include "WebKit.h"
  32. #include "WebKitLogging.h"
  33. #include "WebMutableURLRequest.h"
  34. #include "WebURLAuthenticationChallenge.h"
  35. #include "WebURLCredential.h"
  36. #include "WebURLResponse.h"
  37. #include <wtf/text/CString.h>
  38. #include <WebCore/BString.h>
  39. #include <WebCore/DownloadBundle.h>
  40. #include <WebCore/NotImplemented.h>
  41. #include <WebCore/ResourceError.h>
  42. #include <WebCore/ResourceHandle.h>
  43. #include <WebCore/ResourceRequest.h>
  44. #include <WebCore/ResourceResponse.h>
  45. #include <wtf/CurrentTime.h>
  46. #include <wtf/StdLibExtras.h>
  47. using namespace WebCore;
  48. // WebDownload ----------------------------------------------------------------
  49. WebDownload::WebDownload()
  50. : m_refCount(0)
  51. {
  52. gClassCount++;
  53. gClassNameCount.add("WebDownload");
  54. }
  55. WebDownload::~WebDownload()
  56. {
  57. LOG(Download, "WebDownload - Destroying download (%p)", this);
  58. cancel();
  59. gClassCount--;
  60. gClassNameCount.remove("WebDownload");
  61. }
  62. WebDownload* WebDownload::createInstance()
  63. {
  64. WebDownload* instance = new WebDownload();
  65. instance->AddRef();
  66. return instance;
  67. }
  68. WebDownload* WebDownload::createInstance(ResourceHandle* handle, const ResourceRequest& request, const ResourceResponse& response, IWebDownloadDelegate* delegate)
  69. {
  70. WebDownload* instance = new WebDownload();
  71. instance->AddRef();
  72. instance->init(handle, request, response, delegate);
  73. return instance;
  74. }
  75. WebDownload* WebDownload::createInstance(const KURL& url, IWebDownloadDelegate* delegate)
  76. {
  77. WebDownload* instance = new WebDownload();
  78. instance->AddRef();
  79. instance->init(url, delegate);
  80. return instance;
  81. }
  82. // IUnknown -------------------------------------------------------------------
  83. HRESULT STDMETHODCALLTYPE WebDownload::QueryInterface(REFIID riid, void** ppvObject)
  84. {
  85. *ppvObject = 0;
  86. if (IsEqualGUID(riid, IID_IUnknown))
  87. *ppvObject = static_cast<IWebDownload*>(this);
  88. else if (IsEqualGUID(riid, IID_IWebDownload))
  89. *ppvObject = static_cast<IWebDownload*>(this);
  90. else if (IsEqualGUID(riid, IID_IWebURLAuthenticationChallengeSender))
  91. *ppvObject = static_cast<IWebURLAuthenticationChallengeSender*>(this);
  92. else if (IsEqualGUID(riid, CLSID_WebDownload))
  93. *ppvObject = static_cast<WebDownload*>(this);
  94. else
  95. return E_NOINTERFACE;
  96. AddRef();
  97. return S_OK;
  98. }
  99. ULONG STDMETHODCALLTYPE WebDownload::AddRef(void)
  100. {
  101. return ++m_refCount;
  102. }
  103. ULONG STDMETHODCALLTYPE WebDownload::Release(void)
  104. {
  105. ULONG newRef = --m_refCount;
  106. if (!newRef)
  107. delete(this);
  108. return newRef;
  109. }
  110. // IWebDownload -------------------------------------------------------------------
  111. HRESULT STDMETHODCALLTYPE WebDownload::canResumeDownloadDecodedWithEncodingMIMEType(
  112. /* [in] */ BSTR,
  113. /* [out, retval] */ BOOL*)
  114. {
  115. notImplemented();
  116. return E_FAIL;
  117. }
  118. HRESULT STDMETHODCALLTYPE WebDownload::bundlePathForTargetPath(
  119. /* [in] */ BSTR targetPath,
  120. /* [out, retval] */ BSTR* bundlePath)
  121. {
  122. if (!targetPath)
  123. return E_INVALIDARG;
  124. String bundle(targetPath, SysStringLen(targetPath));
  125. if (bundle.isEmpty())
  126. return E_INVALIDARG;
  127. if (bundle[bundle.length()-1] == '/')
  128. bundle.truncate(1);
  129. bundle.append(DownloadBundle::fileExtension());
  130. *bundlePath = SysAllocStringLen(bundle.characters(), bundle.length());
  131. if (!*bundlePath)
  132. return E_FAIL;
  133. return S_OK;
  134. }
  135. HRESULT STDMETHODCALLTYPE WebDownload::request(
  136. /* [out, retval] */ IWebURLRequest** request)
  137. {
  138. if (request) {
  139. *request = m_request.get();
  140. if (*request)
  141. (*request)->AddRef();
  142. }
  143. return S_OK;
  144. }