WebProcess.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 WebProcess_h
  26. #define WebProcess_h
  27. #include "CacheModel.h"
  28. #include "ChildProcess.h"
  29. #include "DownloadManager.h"
  30. #include "PluginProcessConnectionManager.h"
  31. #include "ResourceCachesToClear.h"
  32. #include "SandboxExtension.h"
  33. #include "SharedMemory.h"
  34. #include "TextCheckerState.h"
  35. #include "VisitedLinkTable.h"
  36. #include <WebCore/LinkHash.h>
  37. #include <WebCore/Timer.h>
  38. #include <wtf/Forward.h>
  39. #include <wtf/HashMap.h>
  40. #include <wtf/HashSet.h>
  41. #include <wtf/text/AtomicString.h>
  42. #include <wtf/text/AtomicStringHash.h>
  43. #if PLATFORM(QT)
  44. QT_BEGIN_NAMESPACE
  45. class QNetworkAccessManager;
  46. QT_END_NAMESPACE
  47. #endif
  48. #if PLATFORM(MAC)
  49. #include <dispatch/dispatch.h>
  50. #endif
  51. #if PLATFORM(MANX)
  52. #include "WebNetworkAccessManager.h"
  53. #endif
  54. namespace WebCore {
  55. class PageGroup;
  56. class ResourceRequest;
  57. struct PluginInfo;
  58. }
  59. namespace WebKit {
  60. class DownloadManager;
  61. class EventDispatcher;
  62. class InjectedBundle;
  63. class WebConnectionToUIProcess;
  64. class WebFrame;
  65. class WebIconDatabaseProxy;
  66. class WebPage;
  67. class WebPageGroupProxy;
  68. class WebProcessSupplement;
  69. struct WebPageCreationParameters;
  70. struct WebPageGroupData;
  71. struct WebPreferencesStore;
  72. struct WebProcessCreationParameters;
  73. #if ENABLE(NETWORK_PROCESS)
  74. class NetworkProcessConnection;
  75. class WebResourceLoadScheduler;
  76. #endif
  77. class WebProcess : public ChildProcess, private DownloadManager::Client {
  78. public:
  79. static WebProcess& shared();
  80. template <typename T>
  81. T* supplement()
  82. {
  83. return static_cast<T*>(m_supplements.get(T::supplementName()));
  84. }
  85. template <typename T>
  86. void addSupplement()
  87. {
  88. m_supplements.add(T::supplementName(), adoptPtr<WebProcessSupplement>(new T(this)));
  89. }
  90. WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_webConnection.get(); }
  91. WebPage* webPage(uint64_t pageID) const;
  92. void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
  93. void removeWebPage(uint64_t pageID);
  94. WebPage* focusedWebPage() const;
  95. InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
  96. #if PLATFORM(MAC)
  97. #if USE(ACCELERATED_COMPOSITING)
  98. mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
  99. #endif
  100. #endif
  101. void setShouldTrackVisitedLinks(bool);
  102. void addVisitedLink(WebCore::LinkHash);
  103. bool isLinkVisited(WebCore::LinkHash) const;
  104. bool shouldPlugInAutoStartFromOrigin(const WebPage*, const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
  105. void plugInDidStartFromOrigin(const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
  106. void plugInDidReceiveUserInteraction(const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
  107. bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
  108. WebFrame* webFrame(uint64_t) const;
  109. void addWebFrame(uint64_t, WebFrame*);
  110. void removeWebFrame(uint64_t);
  111. WebPageGroupProxy* webPageGroup(WebCore::PageGroup*);
  112. WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
  113. WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
  114. #if PLATFORM(MAC)
  115. pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
  116. bool shouldForceScreenFontSubstitution() const { return m_shouldForceScreenFontSubstitution; }
  117. void setProcessSuppressionEnabled(bool);
  118. #endif
  119. const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
  120. DownloadManager& downloadManager();
  121. #if PLATFORM(QT)
  122. QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
  123. #endif
  124. void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
  125. #if ENABLE(PLUGIN_PROCESS)
  126. PluginProcessConnectionManager& pluginProcessConnectionManager();
  127. #endif
  128. EventDispatcher& eventDispatcher() { return *m_eventDispatcher; }
  129. #if ENABLE(NETWORK_PROCESS)
  130. NetworkProcessConnection* networkConnection();
  131. void networkProcessConnectionClosed(NetworkProcessConnection*);
  132. bool usesNetworkProcess() const { return m_usesNetworkProcess; }
  133. WebResourceLoadScheduler& webResourceLoadScheduler();
  134. #endif
  135. void setCacheModel(uint32_t);
  136. void ensurePrivateBrowsingSession();
  137. void destroyPrivateBrowsingSession();
  138. void pageDidEnterWindow(uint64_t pageID);
  139. void pageWillLeaveWindow(uint64_t pageID);
  140. void nonVisibleProcessCleanupTimerFired(WebCore::Timer<WebProcess>*);
  141. void updateActivePages();
  142. private:
  143. WebProcess();
  144. // DownloadManager::Client.
  145. virtual void didCreateDownload() OVERRIDE;
  146. virtual void didDestroyDownload() OVERRIDE;
  147. virtual CoreIPC::Connection* downloadProxyConnection() OVERRIDE;
  148. virtual AuthenticationManager& downloadsAuthenticationManager() OVERRIDE;
  149. void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::MessageDecoder&);
  150. void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::MessageDecoder&);
  151. void platformTerminate();
  152. void registerURLSchemeAsEmptyDocument(const String&);
  153. void registerURLSchemeAsSecure(const String&) const;
  154. void setDomainRelaxationForbiddenForURLScheme(const String&) const;
  155. void registerURLSchemeAsLocal(const String&) const;
  156. void registerURLSchemeAsNoAccess(const String&) const;
  157. void registerURLSchemeAsDisplayIsolated(const String&) const;
  158. void registerURLSchemeAsCORSEnabled(const String&) const;
  159. void setDefaultRequestTimeoutInterval(double);
  160. void setAlwaysUsesComplexTextCodePath(bool);
  161. void setShouldUseFontSmoothing(bool);
  162. void userPreferredLanguagesChanged(const Vector<String>&) const;
  163. void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
  164. void setVisitedLinkTable(const SharedMemory::Handle&);
  165. void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
  166. void allVisitedLinkStateChanged();
  167. bool isPlugInAutoStartOriginHash(unsigned plugInOriginHash);
  168. void didAddPlugInAutoStartOriginHash(unsigned plugInOriginHash, double expirationTime);
  169. void resetPlugInAutoStartOriginHashes(const HashMap<unsigned, double>& hashes);
  170. void platformSetCacheModel(CacheModel);
  171. void platformClearResourceCaches(ResourceCachesToClear);
  172. void clearApplicationCache();
  173. void setEnhancedAccessibility(bool);
  174. #if !ENABLE(PLUGIN_PROCESS)
  175. void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
  176. void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
  177. #endif
  178. void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
  179. void stopMemorySampler();
  180. void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
  181. void cancelDownload(uint64_t downloadID);
  182. #if PLATFORM(QT)
  183. void startTransfer(uint64_t downloadID, const String& destination);
  184. #endif
  185. void setTextCheckerState(const TextCheckerState&);
  186. void getWebCoreStatistics(uint64_t callbackID);
  187. void garbageCollectJavaScriptObjects();
  188. void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
  189. void releasePageCache();
  190. #if USE(SOUP)
  191. void setIgnoreTLSErrors(bool);
  192. #endif
  193. void postInjectedBundleMessage(const CoreIPC::DataReference& messageData);
  194. #if PLATFORM(MANX)
  195. void setPrivilegedNetworkBandwidth(uint32_t bandwidthMode);
  196. void setIFilterHTTPProxy(bool enable, String server, int port, String userId, String password);
  197. void setWebSecurityFilter(int filterMode);
  198. #endif
  199. // ChildProcess
  200. virtual void initializeProcess(const ChildProcessInitializationParameters&) OVERRIDE;
  201. virtual void initializeProcessName(const ChildProcessInitializationParameters&) OVERRIDE;
  202. virtual void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) OVERRIDE;
  203. virtual void initializeConnection(CoreIPC::Connection*) OVERRIDE;
  204. virtual bool shouldTerminate() OVERRIDE;
  205. virtual void terminate() OVERRIDE;
  206. void platformInitializeProcess(const ChildProcessInitializationParameters&);
  207. // CoreIPC::Connection::Client
  208. friend class WebConnectionToUIProcess;
  209. virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
  210. virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&);
  211. virtual void didClose(CoreIPC::Connection*);
  212. virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName) OVERRIDE;
  213. // Implemented in generated WebProcessMessageReceiver.cpp
  214. void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
  215. RefPtr<WebConnectionToUIProcess> m_webConnection;
  216. HashMap<uint64_t, RefPtr<WebPage>> m_pageMap;
  217. HashMap<uint64_t, RefPtr<WebPageGroupProxy>> m_pageGroupMap;
  218. RefPtr<InjectedBundle> m_injectedBundle;
  219. RefPtr<EventDispatcher> m_eventDispatcher;
  220. bool m_inDidClose;
  221. // FIXME: The visited link table should not be per process.
  222. VisitedLinkTable m_visitedLinkTable;
  223. bool m_shouldTrackVisitedLinks;
  224. HashMap<unsigned, double> m_plugInAutoStartOriginHashes;
  225. HashSet<String> m_plugInAutoStartOrigins;
  226. bool m_hasSetCacheModel;
  227. CacheModel m_cacheModel;
  228. #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
  229. mach_port_t m_compositingRenderServerPort;
  230. #endif
  231. #if PLATFORM(MAC)
  232. pid_t m_presenterApplicationPid;
  233. dispatch_group_t m_clearResourceCachesDispatchGroup;
  234. bool m_shouldForceScreenFontSubstitution;
  235. #endif
  236. bool m_fullKeyboardAccessEnabled;
  237. #if PLATFORM(QT)
  238. QNetworkAccessManager* m_networkAccessManager;
  239. #endif
  240. HashMap<uint64_t, WebFrame*> m_frameMap;
  241. typedef HashMap<const char*, OwnPtr<WebProcessSupplement>, PtrHash<const char*>> WebProcessSupplementMap;
  242. WebProcessSupplementMap m_supplements;
  243. TextCheckerState m_textCheckerState;
  244. WebIconDatabaseProxy* m_iconDatabaseProxy;
  245. #if ENABLE(NETWORK_PROCESS)
  246. void ensureNetworkProcessConnection();
  247. RefPtr<NetworkProcessConnection> m_networkProcessConnection;
  248. bool m_usesNetworkProcess;
  249. WebResourceLoadScheduler* m_webResourceLoadScheduler;
  250. #endif
  251. #if ENABLE(PLUGIN_PROCESS)
  252. RefPtr<PluginProcessConnectionManager> m_pluginProcessConnectionManager;
  253. #endif
  254. HashSet<uint64_t> m_pagesInWindows;
  255. WebCore::Timer<WebProcess> m_nonVisibleProcessCleanupTimer;
  256. };
  257. } // namespace WebKit
  258. #endif // WebProcess_h