Download.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2010, 2011 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 INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef Download_h
  26. #define Download_h
  27. #include "MessageSender.h"
  28. #include <WebCore/ResourceRequest.h>
  29. #include <wtf/Noncopyable.h>
  30. #include <wtf/PassOwnPtr.h>
  31. #if PLATFORM(MAC)
  32. #include <wtf/RetainPtr.h>
  33. OBJC_CLASS NSURLDownload;
  34. OBJC_CLASS WKDownloadAsDelegate;
  35. #endif
  36. #if PLATFORM(GTK) || PLATFORM(EFL)
  37. #include <WebCore/ResourceHandle.h>
  38. #include <WebCore/ResourceHandleClient.h>
  39. #endif
  40. #if USE(CFNETWORK)
  41. #include <CFNetwork/CFURLDownloadPriv.h>
  42. #endif
  43. namespace CoreIPC {
  44. class DataReference;
  45. }
  46. namespace WebCore {
  47. class AuthenticationChallenge;
  48. class Credential;
  49. class ResourceError;
  50. class ResourceHandle;
  51. class ResourceResponse;
  52. }
  53. namespace WebKit {
  54. class DownloadAuthenticationClient;
  55. class DownloadManager;
  56. class SandboxExtension;
  57. class WebPage;
  58. #if PLATFORM(QT)
  59. class QtFileDownloader;
  60. #endif
  61. class Download : public CoreIPC::MessageSender {
  62. WTF_MAKE_NONCOPYABLE(Download);
  63. public:
  64. static PassOwnPtr<Download> create(DownloadManager&, uint64_t downloadID, const WebCore::ResourceRequest&);
  65. ~Download();
  66. void start();
  67. void startWithHandle(WebCore::ResourceHandle*, const WebCore::ResourceResponse&);
  68. void cancel();
  69. uint64_t downloadID() const { return m_downloadID; }
  70. void didStart();
  71. void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&);
  72. void didReceiveResponse(const WebCore::ResourceResponse&);
  73. void didReceiveData(uint64_t length);
  74. bool shouldDecodeSourceDataOfMIMEType(const String& mimeType);
  75. String decideDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite);
  76. void didCreateDestination(const String& path);
  77. void didFinish();
  78. void platformDidFinish();
  79. void didFail(const WebCore::ResourceError&, const CoreIPC::DataReference& resumeData);
  80. void didCancel(const CoreIPC::DataReference& resumeData);
  81. void didDecideDestination(const String&, bool allowOverwrite);
  82. #if PLATFORM(QT)
  83. void startTransfer(const String& destination);
  84. #endif
  85. #if USE(CFNETWORK)
  86. const String& destination() const { return m_destination; }
  87. DownloadAuthenticationClient* authenticationClient();
  88. #endif
  89. // Authentication
  90. static void receivedCredential(const WebCore::AuthenticationChallenge&, const WebCore::Credential&);
  91. static void receivedRequestToContinueWithoutCredential(const WebCore::AuthenticationChallenge&);
  92. static void receivedCancellation(const WebCore::AuthenticationChallenge&);
  93. void useCredential(const WebCore::AuthenticationChallenge&, const WebCore::Credential&);
  94. void continueWithoutCredential(const WebCore::AuthenticationChallenge&);
  95. void cancelAuthenticationChallenge(const WebCore::AuthenticationChallenge&);
  96. private:
  97. Download(DownloadManager&, uint64_t downloadID, const WebCore::ResourceRequest&);
  98. // CoreIPC::MessageSender
  99. virtual CoreIPC::Connection* messageSenderConnection() OVERRIDE;
  100. virtual uint64_t messageSenderDestinationID() OVERRIDE;
  101. void platformInvalidate();
  102. String retrieveDestinationWithSuggestedFilename(const String& filename, bool& allowOverwrite);
  103. DownloadManager& m_downloadManager;
  104. uint64_t m_downloadID;
  105. WebCore::ResourceRequest m_request;
  106. RefPtr<SandboxExtension> m_sandboxExtension;
  107. #if PLATFORM(MAC)
  108. RetainPtr<NSURLDownload> m_nsURLDownload;
  109. RetainPtr<WKDownloadAsDelegate> m_delegate;
  110. #endif
  111. bool m_allowOverwrite;
  112. String m_destination;
  113. String m_bundlePath;
  114. #if USE(CFNETWORK)
  115. RetainPtr<CFURLDownloadRef> m_download;
  116. RefPtr<DownloadAuthenticationClient> m_authenticationClient;
  117. #endif
  118. #if PLATFORM(QT)
  119. QtFileDownloader* m_qtDownloader;
  120. #endif
  121. #if PLATFORM(GTK) || PLATFORM(EFL)
  122. OwnPtr<WebCore::ResourceHandleClient> m_downloadClient;
  123. RefPtr<WebCore::ResourceHandle> m_resourceHandle;
  124. #endif
  125. };
  126. } // namespace WebKit
  127. #endif // Download_h