2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
29 #include "CacheModel.h"
30 #include "ChildProcess.h"
31 #include "DownloadManager.h"
32 #include "DrawingArea.h"
33 #include "PluginProcessConnectionManager.h"
34 #include "ResourceCachesToClear.h"
35 #include "SandboxExtension.h"
36 #include "SharedMemory.h"
37 #include "TextCheckerState.h"
38 #include "ViewUpdateDispatcher.h"
39 #include "VisitedLinkTable.h"
40 #include <WebCore/HysteresisActivity.h>
41 #include <WebCore/SessionID.h>
42 #include <WebCore/Timer.h>
43 #include <wtf/Forward.h>
44 #include <wtf/HashMap.h>
45 #include <wtf/HashSet.h>
46 #include <wtf/NeverDestroyed.h>
47 #include <wtf/text/AtomicString.h>
48 #include <wtf/text/AtomicStringHash.h>
51 #include <dispatch/dispatch.h>
52 #include <WebCore/MachSendRight.h>
56 #include "WebSQLiteDatabaseTracker.h"
64 class CertificateInfo;
66 class ResourceRequest;
69 struct SecurityOriginData;
74 class DownloadManager;
75 class EventDispatcher;
77 class NetworkProcessConnection;
78 class ObjCObjectGraph;
80 class WebConnectionToUIProcess;
82 class WebIconDatabaseProxy;
84 class WebPageGroupProxy;
85 class WebProcessSupplement;
86 class WebResourceLoadScheduler;
87 struct WebPageCreationParameters;
88 struct WebPageGroupData;
89 struct WebPreferencesStore;
90 struct WebProcessCreationParameters;
92 #if ENABLE(DATABASE_PROCESS)
93 class WebToDatabaseProcessConnection;
96 class WebProcess : public ChildProcess, private DownloadManager::Client {
97 friend class NeverDestroyed<DownloadManager>;
99 static WebProcess& singleton();
101 template <typename T>
104 return static_cast<T*>(m_supplements.get(T::supplementName()));
107 template <typename T>
110 m_supplements.add(T::supplementName(), std::make_unique<T>(this));
113 WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_webConnection.get(); }
115 WebPage* webPage(uint64_t pageID) const;
116 void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
117 void removeWebPage(uint64_t pageID);
118 WebPage* focusedWebPage() const;
120 InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
123 const WebCore::MachSendRight& compositingRenderServerPort() const { return m_compositingRenderServerPort; }
126 bool shouldPlugInAutoStartFromOrigin(WebPage&, const String& pageOrigin, const String& pluginOrigin, const String& mimeType);
127 void plugInDidStartFromOrigin(const String& pageOrigin, const String& pluginOrigin, const String& mimeType, WebCore::SessionID);
128 void plugInDidReceiveUserInteraction(const String& pageOrigin, const String& pluginOrigin, const String& mimeType, WebCore::SessionID);
129 void setPluginLoadClientPolicy(uint8_t policy, const String& host, const String& bundleIdentifier, const String& versionString);
130 void clearPluginClientPolicies();
132 bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
134 WebFrame* webFrame(uint64_t) const;
135 void addWebFrame(uint64_t, WebFrame*);
136 void removeWebFrame(uint64_t);
138 WebPageGroupProxy* webPageGroup(WebCore::PageGroup*);
139 WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
140 WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
143 pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
146 const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
147 DownloadManager& downloadManager();
149 void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
151 #if ENABLE(NETSCAPE_PLUGIN_API)
152 PluginProcessConnectionManager& pluginProcessConnectionManager();
155 EventDispatcher& eventDispatcher() { return *m_eventDispatcher; }
157 bool usesNetworkProcess() const;
159 NetworkProcessConnection* networkConnection();
160 void networkProcessConnectionClosed(NetworkProcessConnection*);
161 WebResourceLoadScheduler& webResourceLoadScheduler();
163 #if ENABLE(DATABASE_PROCESS)
164 void webToDatabaseProcessConnectionClosed(WebToDatabaseProcessConnection*);
165 WebToDatabaseProcessConnection* webToDatabaseProcessConnection();
168 void setCacheModel(uint32_t);
170 void ensurePrivateBrowsingSession(WebCore::SessionID);
171 void destroyPrivateBrowsingSession(WebCore::SessionID);
173 void pageDidEnterWindow(uint64_t pageID);
174 void pageWillLeaveWindow(uint64_t pageID);
176 void nonVisibleProcessCleanupTimerFired();
179 void destroyRenderingResources();
182 void updateActivePages();
185 void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
188 void processWillSuspendImminently(bool& handled);
189 void prepareToSuspend();
190 void cancelPrepareToSuspend();
191 bool markAllLayersVolatileIfPossible();
192 void setAllLayerTreeStatesFrozen(bool);
193 void processSuspensionCleanupTimerFired();
194 void processDidResume();
197 void resetAllGeolocationPermissions();
200 RefPtr<API::Object> transformHandlesToObjects(API::Object*);
201 static RefPtr<API::Object> transformObjectsToHandles(API::Object*);
204 RefPtr<ObjCObjectGraph> transformHandlesToObjects(ObjCObjectGraph&);
205 static RefPtr<ObjCObjectGraph> transformObjectsToHandles(ObjCObjectGraph&);
208 #if ENABLE(SERVICE_CONTROLS)
209 bool hasImageServices() const { return m_hasImageServices; }
210 bool hasSelectionServices() const { return m_hasSelectionServices; }
211 bool hasRichContentServices() const { return m_hasRichContentServices; }
214 void prefetchDNS(const String&);
220 // DownloadManager::Client.
221 virtual void didCreateDownload() override;
222 virtual void didDestroyDownload() override;
223 virtual IPC::Connection* downloadProxyConnection() override;
224 virtual AuthenticationManager& downloadsAuthenticationManager() override;
226 void initializeWebProcess(WebProcessCreationParameters&&);
227 void platformInitializeWebProcess(WebProcessCreationParameters&&);
229 void platformTerminate();
230 void registerURLSchemeAsEmptyDocument(const String&);
231 void registerURLSchemeAsSecure(const String&) const;
232 void registerURLSchemeAsBypassingContentSecurityPolicy(const String&) const;
233 void setDomainRelaxationForbiddenForURLScheme(const String&) const;
234 void registerURLSchemeAsLocal(const String&) const;
235 void registerURLSchemeAsNoAccess(const String&) const;
236 void registerURLSchemeAsDisplayIsolated(const String&) const;
237 void registerURLSchemeAsCORSEnabled(const String&) const;
238 #if ENABLE(CACHE_PARTITIONING)
239 void registerURLSchemeAsCachePartitioned(const String&) const;
241 void setDefaultRequestTimeoutInterval(double);
242 void setAlwaysUsesComplexTextCodePath(bool);
243 void setShouldUseFontSmoothing(bool);
244 void userPreferredLanguagesChanged(const Vector<String>&) const;
245 void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
247 bool isPlugInAutoStartOriginHash(unsigned plugInOriginHash, WebCore::SessionID);
248 void didAddPlugInAutoStartOriginHash(unsigned plugInOriginHash, double expirationTime, WebCore::SessionID);
249 void resetPlugInAutoStartOriginDefaultHashes(const HashMap<unsigned, double>& hashes);
250 void resetPlugInAutoStartOriginHashes(const HashMap<WebCore::SessionID, HashMap<unsigned, double>>& hashes);
252 void platformSetCacheModel(CacheModel);
253 void platformClearResourceCaches(ResourceCachesToClear);
254 void clearApplicationCache();
256 void setEnhancedAccessibility(bool);
258 void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
259 void stopMemorySampler();
261 void downloadRequest(WebCore::SessionID, uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
262 void resumeDownload(uint64_t downloadID, const IPC::DataReference& resumeData, const String& path, const SandboxExtension::Handle&);
263 void cancelDownload(uint64_t downloadID);
265 void setTextCheckerState(const TextCheckerState&);
267 void getWebCoreStatistics(uint64_t callbackID);
268 void garbageCollectJavaScriptObjects();
269 void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
271 void mainThreadPing();
273 void releasePageCache();
275 void fetchWebsiteData(WebCore::SessionID, uint64_t websiteDataTypes, uint64_t callbackID);
276 void deleteWebsiteData(WebCore::SessionID, uint64_t websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID);
277 void deleteWebsiteDataForOrigins(WebCore::SessionID, uint64_t websiteDataTypes, const Vector<WebCore::SecurityOriginData>& origins, uint64_t callbackID);
280 void setIgnoreTLSErrors(bool);
283 void setMemoryCacheDisabled(bool);
285 #if ENABLE(SERVICE_CONTROLS)
286 void setEnabledServices(bool hasImageServices, bool hasSelectionServices, bool hasRichContentServices);
289 void handleInjectedBundleMessage(const String& messageName, const UserData& messageBody);
290 void setInjectedBundleParameter(const String& key, const IPC::DataReference&);
291 void setInjectedBundleParameters(const IPC::DataReference&);
293 enum class ShouldAcknowledgeWhenReadyToSuspend { No, Yes };
294 void actualPrepareToSuspend(ShouldAcknowledgeWhenReadyToSuspend);
297 virtual void initializeProcess(const ChildProcessInitializationParameters&) override;
298 virtual void initializeProcessName(const ChildProcessInitializationParameters&) override;
299 virtual void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) override;
300 virtual void initializeConnection(IPC::Connection*) override;
301 virtual bool shouldTerminate() override;
302 virtual void terminate() override;
305 virtual void stopRunLoop() override;
308 void platformInitializeProcess(const ChildProcessInitializationParameters&);
310 // IPC::Connection::Client
311 friend class WebConnectionToUIProcess;
312 virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
313 virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
314 virtual void didClose(IPC::Connection&) override;
315 virtual void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
316 virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::Web; }
317 virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::UI; }
319 // Implemented in generated WebProcessMessageReceiver.cpp
320 void didReceiveWebProcessMessage(IPC::Connection&, IPC::MessageDecoder&);
321 void didReceiveSyncWebProcessMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
323 RefPtr<WebConnectionToUIProcess> m_webConnection;
325 HashMap<uint64_t, RefPtr<WebPage>> m_pageMap;
326 HashMap<uint64_t, RefPtr<WebPageGroupProxy>> m_pageGroupMap;
327 RefPtr<InjectedBundle> m_injectedBundle;
329 RefPtr<EventDispatcher> m_eventDispatcher;
331 RefPtr<ViewUpdateDispatcher> m_viewUpdateDispatcher;
333 WebCore::Timer m_processSuspensionCleanupTimer;
337 HashMap<WebCore::SessionID, HashMap<unsigned, double>> m_plugInAutoStartOriginHashes;
338 HashSet<String> m_plugInAutoStartOrigins;
340 bool m_hasSetCacheModel;
341 CacheModel m_cacheModel;
344 WebCore::MachSendRight m_compositingRenderServerPort;
345 pid_t m_presenterApplicationPid;
348 bool m_fullKeyboardAccessEnabled;
350 HashMap<uint64_t, WebFrame*> m_frameMap;
352 typedef HashMap<const char*, std::unique_ptr<WebProcessSupplement>, PtrHash<const char*>> WebProcessSupplementMap;
353 WebProcessSupplementMap m_supplements;
355 TextCheckerState m_textCheckerState;
357 WebIconDatabaseProxy* m_iconDatabaseProxy;
359 void ensureNetworkProcessConnection();
360 RefPtr<NetworkProcessConnection> m_networkProcessConnection;
361 bool m_usesNetworkProcess;
362 WebResourceLoadScheduler* m_webResourceLoadScheduler;
363 HashSet<String> m_dnsPrefetchedHosts;
364 WebCore::HysteresisActivity m_dnsPrefetchHystereris;
366 #if ENABLE(DATABASE_PROCESS)
367 void ensureWebToDatabaseProcessConnection();
368 RefPtr<WebToDatabaseProcessConnection> m_webToDatabaseProcessConnection;
371 #if ENABLE(NETSCAPE_PLUGIN_API)
372 RefPtr<PluginProcessConnectionManager> m_pluginProcessConnectionManager;
375 #if ENABLE(SERVICE_CONTROLS)
376 bool m_hasImageServices;
377 bool m_hasSelectionServices;
378 bool m_hasRichContentServices;
381 HashSet<uint64_t> m_pagesInWindows;
382 WebCore::Timer m_nonVisibleProcessCleanupTimer;
385 WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
388 ShouldAcknowledgeWhenReadyToSuspend m_shouldAcknowledgeWhenReadyToSuspend;
391 } // namespace WebKit
393 #endif // WebProcess_h