NetworkProcess.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2012, 2013 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 NetworkProcess_h
  26. #define NetworkProcess_h
  27. #if ENABLE(NETWORK_PROCESS)
  28. #include "CacheModel.h"
  29. #include "ChildProcess.h"
  30. #include "DownloadManager.h"
  31. #include "MessageReceiverMap.h"
  32. #include "NetworkResourceLoadScheduler.h"
  33. #include <wtf/Forward.h>
  34. namespace WebCore {
  35. class RunLoop;
  36. }
  37. namespace WebKit {
  38. class AuthenticationManager;
  39. class NetworkConnectionToWebProcess;
  40. class NetworkProcessSupplement;
  41. class PlatformCertificateInfo;
  42. struct NetworkProcessCreationParameters;
  43. class NetworkProcess : public ChildProcess, private DownloadManager::Client {
  44. WTF_MAKE_NONCOPYABLE(NetworkProcess);
  45. public:
  46. static NetworkProcess& shared();
  47. template <typename T>
  48. T* supplement()
  49. {
  50. return static_cast<T*>(m_supplements.get(T::supplementName()));
  51. }
  52. template <typename T>
  53. void addSupplement()
  54. {
  55. m_supplements.add(T::supplementName(), adoptPtr<NetworkProcessSupplement>(new T(this)));
  56. }
  57. void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess*);
  58. NetworkResourceLoadScheduler& networkResourceLoadScheduler() { return m_networkResourceLoadScheduler; }
  59. AuthenticationManager& authenticationManager();
  60. DownloadManager& downloadManager();
  61. private:
  62. NetworkProcess();
  63. ~NetworkProcess();
  64. void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
  65. virtual void terminate() OVERRIDE;
  66. void platformTerminate();
  67. // ChildProcess
  68. virtual void initializeProcess(const ChildProcessInitializationParameters&) OVERRIDE;
  69. virtual void initializeProcessName(const ChildProcessInitializationParameters&) OVERRIDE;
  70. virtual void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) OVERRIDE;
  71. virtual void initializeConnection(CoreIPC::Connection*) OVERRIDE;
  72. virtual bool shouldTerminate() OVERRIDE;
  73. // CoreIPC::Connection::Client
  74. virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) OVERRIDE;
  75. virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
  76. virtual void didClose(CoreIPC::Connection*) OVERRIDE;
  77. virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName) OVERRIDE;
  78. // DownloadManager::Client
  79. virtual void didCreateDownload() OVERRIDE;
  80. virtual void didDestroyDownload() OVERRIDE;
  81. virtual CoreIPC::Connection* downloadProxyConnection() OVERRIDE;
  82. virtual AuthenticationManager& downloadsAuthenticationManager() OVERRIDE;
  83. // Message Handlers
  84. void didReceiveNetworkProcessMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
  85. void initializeNetworkProcess(const NetworkProcessCreationParameters&);
  86. void createNetworkConnectionToWebProcess();
  87. void ensurePrivateBrowsingSession();
  88. void destroyPrivateBrowsingSession();
  89. void downloadRequest(uint64_t downloadID, const WebCore::ResourceRequest&);
  90. void cancelDownload(uint64_t downloadID);
  91. void setCacheModel(uint32_t);
  92. void allowSpecificHTTPSCertificateForHost(const PlatformCertificateInfo&, const String& host);
  93. void getNetworkProcessStatistics(uint64_t callbackID);
  94. void clearCacheForAllOrigins(uint32_t cachesToClear);
  95. // Platform Helpers
  96. void platformSetCacheModel(CacheModel);
  97. // Connections to WebProcesses.
  98. Vector<RefPtr<NetworkConnectionToWebProcess>> m_webProcessConnections;
  99. NetworkResourceLoadScheduler m_networkResourceLoadScheduler;
  100. String m_diskCacheDirectory;
  101. bool m_hasSetCacheModel;
  102. CacheModel m_cacheModel;
  103. typedef HashMap<const char*, OwnPtr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
  104. NetworkProcessSupplementMap m_supplements;
  105. #if PLATFORM(MAC)
  106. // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
  107. // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
  108. // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
  109. dispatch_group_t m_clearCacheDispatchGroup;
  110. #endif
  111. };
  112. } // namespace WebKit
  113. #endif // ENABLE(NETWORK_PROCESS)
  114. #endif // NetworkProcess_h