DownloadManager.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2010 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 DownloadManager_h
  26. #define DownloadManager_h
  27. #include <wtf/Forward.h>
  28. #include <wtf/HashMap.h>
  29. #include <wtf/Noncopyable.h>
  30. namespace WebCore {
  31. class ResourceHandle;
  32. class ResourceRequest;
  33. class ResourceResponse;
  34. }
  35. namespace CoreIPC {
  36. class Connection;
  37. }
  38. namespace WebKit {
  39. class AuthenticationManager;
  40. class Download;
  41. class WebPage;
  42. class DownloadManager {
  43. WTF_MAKE_NONCOPYABLE(DownloadManager);
  44. public:
  45. class Client {
  46. public:
  47. virtual ~Client() { }
  48. virtual void didCreateDownload() = 0;
  49. virtual void didDestroyDownload() = 0;
  50. virtual CoreIPC::Connection* downloadProxyConnection() = 0;
  51. virtual AuthenticationManager& downloadsAuthenticationManager() = 0;
  52. };
  53. explicit DownloadManager(Client*);
  54. void startDownload(uint64_t downloadID, const WebCore::ResourceRequest&);
  55. void convertHandleToDownload(uint64_t downloadID, WebCore::ResourceHandle*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
  56. void cancelDownload(uint64_t downloadID);
  57. void downloadFinished(Download*);
  58. bool isDownloading() const { return !m_downloads.isEmpty(); }
  59. uint64_t activeDownloadCount() const { return m_downloads.size(); }
  60. void didCreateDownload();
  61. void didDestroyDownload();
  62. CoreIPC::Connection* downloadProxyConnection();
  63. AuthenticationManager& downloadsAuthenticationManager();
  64. #if PLATFORM(QT)
  65. void startTransfer(uint64_t downloadID, const String& destination);
  66. #endif
  67. private:
  68. Client* m_client;
  69. HashMap<uint64_t, Download*> m_downloads;
  70. };
  71. } // namespace WebKit
  72. #endif // DownloadManager_h