WebDownload.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #ifndef WebDownload_h
  26. #define WebDownload_h
  27. #include "WebKit.h"
  28. #include <WebCore/COMPtr.h>
  29. #include <wtf/RetainPtr.h>
  30. #include <wtf/text/WTFString.h>
  31. #if USE(CFNETWORK)
  32. #include <CFNetwork/CFURLDownloadPriv.h>
  33. #elif USE(CURL)
  34. #include <WebCore/CurlDownload.h>
  35. #endif
  36. namespace WebCore {
  37. class KURL;
  38. class ResourceHandle;
  39. class ResourceRequest;
  40. class ResourceResponse;
  41. }
  42. class WebDownload
  43. : public IWebDownload
  44. , public IWebURLAuthenticationChallengeSender
  45. #if USE(CURL)
  46. , public CurlDownloadListener
  47. #endif
  48. {
  49. public:
  50. static WebDownload* createInstance(const WebCore::KURL&, IWebDownloadDelegate*);
  51. static WebDownload* createInstance(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, IWebDownloadDelegate*);
  52. static WebDownload* createInstance();
  53. private:
  54. WebDownload();
  55. void init(WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, IWebDownloadDelegate*);
  56. void init(const WebCore::KURL&, IWebDownloadDelegate*);
  57. ~WebDownload();
  58. public:
  59. // IUnknown
  60. virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
  61. virtual ULONG STDMETHODCALLTYPE AddRef(void);
  62. virtual ULONG STDMETHODCALLTYPE Release(void);
  63. // IWebDownload
  64. virtual HRESULT STDMETHODCALLTYPE initWithRequest(
  65. /* [in] */ IWebURLRequest* request,
  66. /* [in] */ IWebDownloadDelegate* delegate);
  67. virtual HRESULT STDMETHODCALLTYPE initToResumeWithBundle(
  68. /* [in] */ BSTR bundlePath,
  69. /* [in] */ IWebDownloadDelegate* delegate);
  70. virtual HRESULT STDMETHODCALLTYPE canResumeDownloadDecodedWithEncodingMIMEType(
  71. /* [in] */ BSTR mimeType,
  72. /* [out, retval] */ BOOL* result);
  73. virtual HRESULT STDMETHODCALLTYPE start();
  74. virtual HRESULT STDMETHODCALLTYPE cancel();
  75. virtual HRESULT STDMETHODCALLTYPE cancelForResume();
  76. virtual HRESULT STDMETHODCALLTYPE deletesFileUponFailure(
  77. /* [out, retval] */ BOOL* result);
  78. virtual HRESULT STDMETHODCALLTYPE bundlePathForTargetPath(
  79. /* [in] */ BSTR target,
  80. /* [out, retval] */ BSTR* bundle);
  81. virtual HRESULT STDMETHODCALLTYPE request(
  82. /* [out, retval] */ IWebURLRequest** request);
  83. virtual HRESULT STDMETHODCALLTYPE setDeletesFileUponFailure(
  84. /* [in] */ BOOL deletesFileUponFailure);
  85. virtual HRESULT STDMETHODCALLTYPE setDestination(
  86. /* [in] */ BSTR path,
  87. /* [in] */ BOOL allowOverwrite);
  88. // IWebURLAuthenticationChallengeSender
  89. virtual HRESULT STDMETHODCALLTYPE cancelAuthenticationChallenge(
  90. /* [in] */ IWebURLAuthenticationChallenge* challenge);
  91. virtual HRESULT STDMETHODCALLTYPE continueWithoutCredentialForAuthenticationChallenge(
  92. /* [in] */ IWebURLAuthenticationChallenge* challenge);
  93. virtual HRESULT STDMETHODCALLTYPE useCredential(
  94. /* [in] */ IWebURLCredential* credential,
  95. /* [in] */ IWebURLAuthenticationChallenge* challenge);
  96. #if USE(CFNETWORK)
  97. // CFURLDownload Callbacks
  98. void didStart();
  99. CFURLRequestRef willSendRequest(CFURLRequestRef, CFURLResponseRef);
  100. void didReceiveAuthenticationChallenge(CFURLAuthChallengeRef);
  101. void didReceiveResponse(CFURLResponseRef);
  102. void willResumeWithResponse(CFURLResponseRef, UInt64);
  103. void didReceiveData(CFIndex);
  104. bool shouldDecodeDataOfMIMEType(CFStringRef);
  105. void decideDestinationWithSuggestedObjectName(CFStringRef);
  106. void didCreateDestination(CFURLRef);
  107. void didFinish();
  108. void didFail(CFErrorRef);
  109. #elif USE(CURL)
  110. virtual void didReceiveResponse();
  111. virtual void didReceiveDataOfLength(int size);
  112. virtual void didFinish();
  113. virtual void didFail();
  114. #endif
  115. protected:
  116. ULONG m_refCount;
  117. WTF::String m_destination;
  118. WTF::String m_bundlePath;
  119. #if USE(CFNETWORK)
  120. RetainPtr<CFURLDownloadRef> m_download;
  121. #elif USE(CURL)
  122. CurlDownload m_download;
  123. #endif
  124. COMPtr<IWebMutableURLRequest> m_request;
  125. COMPtr<IWebDownloadDelegate> m_delegate;
  126. #ifndef NDEBUG
  127. double m_startTime;
  128. double m_dataTime;
  129. int m_received;
  130. #endif
  131. };
  132. #endif