Reduce getters/setters in WebFramePolicyListenerProxy
[WebKit-https.git] / Source / WebKit / UIProcess / WebProcessPool.h
1 /*
2  * Copyright (C) 2010-2016 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
26 #pragma once
27
28 #include "APIDictionary.h"
29 #include "APIObject.h"
30 #include "APIProcessPoolConfiguration.h"
31 #include "APIWebsiteDataStore.h"
32 #include "DownloadProxyMap.h"
33 #include "GenericCallback.h"
34 #include "HiddenPageThrottlingAutoIncreasesCounter.h"
35 #include "MessageReceiver.h"
36 #include "MessageReceiverMap.h"
37 #include "NetworkProcessProxy.h"
38 #include "PlugInAutoStartProvider.h"
39 #include "PluginInfoStore.h"
40 #include "ProcessThrottler.h"
41 #include "ServiceWorkerProcessProxy.h"
42 #include "StatisticsRequest.h"
43 #include "StorageProcessProxy.h"
44 #include "VisitedLinkStore.h"
45 #include "WebContextClient.h"
46 #include "WebContextConnectionClient.h"
47 #include "WebProcessProxy.h"
48 #include <WebCore/SecurityOriginHash.h>
49 #include <WebCore/SharedStringHash.h>
50 #include <pal/SessionID.h>
51 #include <wtf/Forward.h>
52 #include <wtf/HashMap.h>
53 #include <wtf/HashSet.h>
54 #include <wtf/ProcessID.h>
55 #include <wtf/RefCounter.h>
56 #include <wtf/RefPtr.h>
57 #include <wtf/text/StringHash.h>
58 #include <wtf/text/WTFString.h>
59
60 #if ENABLE(MEDIA_SESSION)
61 #include "WebMediaSessionFocusManager.h"
62 #endif
63
64 #if USE(SOUP)
65 #include <WebCore/SoupNetworkProxySettings.h>
66 #endif
67
68 #if PLATFORM(COCOA)
69 OBJC_CLASS NSMutableDictionary;
70 OBJC_CLASS NSObject;
71 OBJC_CLASS NSString;
72 #endif
73
74 namespace API {
75 class AutomationClient;
76 class CustomProtocolManagerClient;
77 class DownloadClient;
78 class HTTPCookieStore;
79 class InjectedBundleClient;
80 class LegacyContextHistoryClient;
81 class Navigation;
82 class PageConfiguration;
83 }
84
85 namespace WebCore {
86 struct MockMediaDevice;
87 }
88
89 namespace WebKit {
90
91 class DownloadProxy;
92 class HighPerformanceGraphicsUsageSampler;
93 class UIGamepad;
94 class PerActivityStateCPUUsageSampler;
95 class ServiceWorkerProcessProxy;
96 class WebAutomationSession;
97 class WebContextSupplement;
98 class WebPageGroup;
99 class WebPageProxy;
100 struct NetworkProcessCreationParameters;
101 struct StatisticsData;
102 struct WebProcessCreationParameters;
103     
104 typedef GenericCallback<API::Dictionary*> DictionaryCallback;
105
106 #if PLATFORM(COCOA)
107 int networkProcessLatencyQOS();
108 int networkProcessThroughputQOS();
109 int webProcessLatencyQOS();
110 int webProcessThroughputQOS();
111 #endif
112
113 enum class ShouldProcessSwapIfPossible;
114
115 class WebProcessPool final : public API::ObjectImpl<API::Object::Type::ProcessPool>, public CanMakeWeakPtr<WebProcessPool>, private IPC::MessageReceiver {
116 public:
117     static Ref<WebProcessPool> create(API::ProcessPoolConfiguration&);
118
119     explicit WebProcessPool(API::ProcessPoolConfiguration&);        
120     virtual ~WebProcessPool();
121
122     void notifyThisWebProcessPoolWasCreated();
123
124     API::ProcessPoolConfiguration& configuration() { return m_configuration.get(); }
125
126     static const Vector<WebProcessPool*>& allProcessPools();
127
128     template <typename T>
129     T* supplement()
130     {
131         return static_cast<T*>(m_supplements.get(T::supplementName()));
132     }
133
134     template <typename T>
135     void addSupplement()
136     {
137         m_supplements.add(T::supplementName(), T::create(this));
138     }
139
140     void addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver&);
141     void addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver&);
142     void removeMessageReceiver(IPC::StringReference messageReceiverName);
143     void removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID);
144
145     bool dispatchMessage(IPC::Connection&, IPC::Decoder&);
146     bool dispatchSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
147
148     void initializeClient(const WKContextClientBase*);
149     void setInjectedBundleClient(std::unique_ptr<API::InjectedBundleClient>&&);
150     void initializeConnectionClient(const WKContextConnectionClientBase*);
151     void setHistoryClient(std::unique_ptr<API::LegacyContextHistoryClient>&&);
152     void setDownloadClient(std::unique_ptr<API::DownloadClient>&&);
153     void setAutomationClient(std::unique_ptr<API::AutomationClient>&&);
154     void setLegacyCustomProtocolManagerClient(std::unique_ptr<API::CustomProtocolManagerClient>&&);
155
156     void setMaximumNumberOfProcesses(unsigned); // Can only be called when there are no processes running.
157     unsigned maximumNumberOfProcesses() const { return !m_configuration->maximumProcessCount() ? UINT_MAX : m_configuration->maximumProcessCount(); }
158
159     const Vector<RefPtr<WebProcessProxy>>& processes() const { return m_processes; }
160
161     // WebProcess or NetworkProcess as approporiate for current process model. The connection must be non-null.
162     IPC::Connection* networkingProcessConnection();
163
164     template<typename T> void sendToAllProcesses(const T& message);
165     template<typename T> void sendToAllProcessesRelaunchingThemIfNecessary(const T& message);
166     template<typename T> void sendToOneProcess(T&& message);
167
168     // Sends the message to WebProcess or NetworkProcess as approporiate for current process model.
169     template<typename T> void sendToNetworkingProcess(T&& message);
170     template<typename T, typename U> void sendSyncToNetworkingProcess(T&& message, U&& reply);
171     template<typename T> void sendToNetworkingProcessRelaunchingIfNecessary(T&& message);
172
173     // Sends the message to WebProcess or StorageProcess as approporiate for current process model.
174     template<typename T> void sendToStorageProcess(T&& message);
175     template<typename T> void sendToStorageProcessRelaunchingIfNecessary(T&& message);
176
177     void processDidFinishLaunching(WebProcessProxy*);
178
179     // Disconnect the process from the context.
180     void disconnectProcess(WebProcessProxy*);
181
182     API::WebsiteDataStore* websiteDataStore() const { return m_websiteDataStore.get(); }
183     void setPrimaryDataStore(API::WebsiteDataStore& dataStore) { m_websiteDataStore = &dataStore; }
184
185     Ref<WebPageProxy> createWebPage(PageClient&, Ref<API::PageConfiguration>&&);
186
187     void pageBeginUsingWebsiteDataStore(WebPageProxy&);
188     void pageEndUsingWebsiteDataStore(WebPageProxy&);
189
190     const String& injectedBundlePath() const { return m_configuration->injectedBundlePath(); }
191
192     DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&, const String& suggestedFilename = { });
193     DownloadProxy* resumeDownload(const API::Data* resumeData, const String& path);
194
195     void setInjectedBundleInitializationUserData(RefPtr<API::Object>&& userData) { m_injectedBundleInitializationUserData = WTFMove(userData); }
196
197     void postMessageToInjectedBundle(const String&, API::Object*);
198
199     void populateVisitedLinks();
200
201 #if ENABLE(NETSCAPE_PLUGIN_API)
202     void setAdditionalPluginsDirectory(const String&);
203     void refreshPlugins();
204
205     PluginInfoStore& pluginInfoStore() { return m_pluginInfoStore; }
206
207     void setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy, const String& host, const String& bundleIdentifier, const String& versionString);
208     void resetPluginLoadClientPolicies(HashMap<String, HashMap<String, HashMap<String, uint8_t>>>&&);
209     void clearPluginClientPolicies();
210     const HashMap<String, HashMap<String, HashMap<String, uint8_t>>>& pluginLoadClientPolicies() const { return m_pluginLoadClientPolicies; }
211 #endif
212
213     void addSupportedPlugin(String&& matchingDomain, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions);
214     void clearSupportedPlugins();
215
216     ProcessID networkProcessIdentifier();
217     ProcessID storageProcessIdentifier();
218
219     WebPageGroup& defaultPageGroup() { return m_defaultPageGroup.get(); }
220
221     void setAlwaysUsesComplexTextCodePath(bool);
222     void setShouldUseFontSmoothing(bool);
223     
224     void registerURLSchemeAsEmptyDocument(const String&);
225     void registerURLSchemeAsSecure(const String&);
226     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&);
227     void setDomainRelaxationForbiddenForURLScheme(const String&);
228     void setCanHandleHTTPSServerTrustEvaluation(bool);
229     void registerURLSchemeAsLocal(const String&);
230     void registerURLSchemeAsNoAccess(const String&);
231     void registerURLSchemeAsDisplayIsolated(const String&);
232     void registerURLSchemeAsCORSEnabled(const String&);
233     void registerURLSchemeAsCachePartitioned(const String&);
234     void registerURLSchemeServiceWorkersCanHandle(const String&);
235     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&);
236
237     void preconnectToServer(const WebCore::URL&);
238
239     VisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); }
240
241     void setCacheModel(CacheModel);
242     CacheModel cacheModel() const { return m_configuration->cacheModel(); }
243
244     void setDefaultRequestTimeoutInterval(double);
245
246     void startMemorySampler(const double interval);
247     void stopMemorySampler();
248
249 #if USE(SOUP)
250     void setInitialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
251     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
252 #endif
253     void setEnhancedAccessibility(bool);
254     
255     // Downloads.
256     DownloadProxy* createDownloadProxy(const WebCore::ResourceRequest&, WebPageProxy* originatingPage);
257     API::DownloadClient& downloadClient() { return *m_downloadClient; }
258
259     API::LegacyContextHistoryClient& historyClient() { return *m_historyClient; }
260     WebContextClient& client() { return m_client; }
261
262     API::CustomProtocolManagerClient& customProtocolManagerClient() const { return *m_customProtocolManagerClient; }
263
264     struct Statistics {
265         unsigned wkViewCount;
266         unsigned wkPageCount;
267         unsigned wkFrameCount;
268     };
269     static Statistics& statistics();    
270
271     void useTestingNetworkSession();
272     bool isUsingTestingNetworkSession() const { return m_shouldUseTestingNetworkSession; }
273
274     void setAllowsAnySSLCertificateForWebSocket(bool);
275
276     void clearCachedCredentials();
277     void terminateStorageProcessForTesting();
278     void terminateNetworkProcess();
279     void terminateServiceWorkerProcesses();
280     void disableServiceWorkerProcessTerminationDelay();
281
282     void syncNetworkProcessCookies();
283
284     void setShouldMakeNextWebProcessLaunchFailForTesting(bool value) { m_shouldMakeNextWebProcessLaunchFailForTesting = value; }
285     bool shouldMakeNextWebProcessLaunchFailForTesting() const { return m_shouldMakeNextWebProcessLaunchFailForTesting; }
286     void setShouldMakeNextNetworkProcessLaunchFailForTesting(bool value) { m_shouldMakeNextNetworkProcessLaunchFailForTesting = value; }
287     bool shouldMakeNextNetworkProcessLaunchFailForTesting() const { return m_shouldMakeNextNetworkProcessLaunchFailForTesting; }
288
289     void reportWebContentCPUTime(Seconds cpuTime, uint64_t activityState);
290
291     void allowSpecificHTTPSCertificateForHost(const WebCertificateInfo*, const String& host);
292
293     WebProcessProxy& createNewWebProcessRespectingProcessCountLimit(WebsiteDataStore&); // Will return an existing one if limit is met.
294     void warmInitialProcess();
295
296     bool shouldTerminate(WebProcessProxy*);
297
298     void disableProcessTermination() { m_processTerminationEnabled = false; }
299     void enableProcessTermination();
300
301     void updateAutomationCapabilities() const;
302     void setAutomationSession(RefPtr<WebAutomationSession>&&);
303     WebAutomationSession* automationSession() const { return m_automationSession.get(); }
304
305     // Defaults to false.
306     void setHTTPPipeliningEnabled(bool);
307     bool httpPipeliningEnabled() const;
308
309     void getStatistics(uint32_t statisticsMask, Function<void (API::Dictionary*, CallbackBase::Error)>&&);
310     
311     bool javaScriptConfigurationFileEnabled() { return m_javaScriptConfigurationFileEnabled; }
312     void setJavaScriptConfigurationFileEnabled(bool flag);
313 #if PLATFORM(IOS)
314     void setJavaScriptConfigurationFileEnabledFromDefaults();
315 #endif
316
317     void garbageCollectJavaScriptObjects();
318     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
319
320 #if PLATFORM(COCOA)
321     static bool omitPDFSupport();
322 #endif
323
324     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
325 #if OS(LINUX)
326     void sendMemoryPressureEvent(bool isCritical);
327 #endif
328     void textCheckerStateChanged();
329
330     Ref<API::Dictionary> plugInAutoStartOriginHashes() const;
331     void setPlugInAutoStartOriginHashes(API::Dictionary&);
332     void setPlugInAutoStartOrigins(API::Array&);
333     void setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary&, WallTime);
334
335     // Network Process Management
336     NetworkProcessProxy& ensureNetworkProcess(WebsiteDataStore* withWebsiteDataStore = nullptr);
337     NetworkProcessProxy* networkProcess() { return m_networkProcess.get(); }
338     void networkProcessCrashed(NetworkProcessProxy&, Vector<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>&&);
339
340     void getNetworkProcessConnection(Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply&&);
341
342     void ensureStorageProcessAndWebsiteDataStore(WebsiteDataStore* relevantDataStore);
343     StorageProcessProxy* storageProcess() { return m_storageProcess.get(); }
344     void getStorageProcessConnection(WebProcessProxy&, PAL::SessionID initialSessionID, Messages::WebProcessProxy::GetStorageProcessConnection::DelayedReply&&);
345     void storageProcessCrashed(StorageProcessProxy*);
346 #if ENABLE(SERVICE_WORKER)
347     void establishWorkerContextConnectionToStorageProcess(StorageProcessProxy&, WebCore::SecurityOriginData&&, std::optional<PAL::SessionID>);
348     ServiceWorkerProcessProxy* serviceWorkerProcessProxyFromPageID(uint64_t pageID) const;
349     const HashMap<WebCore::SecurityOriginData, ServiceWorkerProcessProxy*>& serviceWorkerProxies() const { return m_serviceWorkerProcesses; }
350     void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
351     bool allowsAnySSLCertificateForServiceWorker() const { return m_allowsAnySSLCertificateForServiceWorker; }
352     void updateServiceWorkerUserAgent(const String& userAgent);
353     bool mayHaveRegisteredServiceWorkers(const WebsiteDataStore&);
354 #endif
355
356 #if PLATFORM(COCOA)
357     bool processSuppressionEnabled() const;
358 #endif
359
360     void windowServerConnectionStateChanged();
361
362     static void willStartUsingPrivateBrowsing();
363     static void willStopUsingPrivateBrowsing();
364
365 #if USE(SOUP)
366     void setIgnoreTLSErrors(bool);
367     bool ignoreTLSErrors() const { return m_ignoreTLSErrors; }
368 #endif
369
370     static void setInvalidMessageCallback(void (*)(WKStringRef));
371     static void didReceiveInvalidMessage(const IPC::StringReference& messageReceiverName, const IPC::StringReference& messageName);
372
373     void processDidCachePage(WebProcessProxy*);
374
375     bool isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const;
376     void resetHSTSHosts();
377     void resetHSTSHostsAddedAfterDate(double startDateIntervalSince1970);
378
379     void registerSchemeForCustomProtocol(const String&);
380     void unregisterSchemeForCustomProtocol(const String&);
381
382     static void registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
383     static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
384
385 #if PLATFORM(COCOA)
386     void updateProcessSuppressionState();
387
388     NSMutableDictionary *ensureBundleParameters();
389     NSMutableDictionary *bundleParameters() { return m_bundleParameters.get(); }
390 #else
391     void updateProcessSuppressionState() const { }
392 #endif
393
394     void updateHiddenPageThrottlingAutoIncreaseLimit();
395
396     void setMemoryCacheDisabled(bool);
397     void setFontWhitelist(API::Array*);
398
399     UserObservablePageCounter::Token userObservablePageCount()
400     {
401         return m_userObservablePageCounter.count();
402     }
403
404     ProcessSuppressionDisabledToken processSuppressionDisabledForPageCount()
405     {
406         return m_processSuppressionDisabledForPageCounter.count();
407     }
408
409     HiddenPageThrottlingAutoIncreasesCounter::Token hiddenPageThrottlingAutoIncreasesCount()
410     {
411         return m_hiddenPageThrottlingAutoIncreasesCounter.count();
412     }
413
414     // FIXME: Move these to API::WebsiteDataStore.
415     static String legacyPlatformDefaultLocalStorageDirectory();
416     static String legacyPlatformDefaultIndexedDBDatabaseDirectory();
417     static String legacyPlatformDefaultWebSQLDatabaseDirectory();
418     static String legacyPlatformDefaultMediaKeysStorageDirectory();
419     static String legacyPlatformDefaultMediaCacheDirectory();
420     static String legacyPlatformDefaultApplicationCacheDirectory();
421     static String legacyPlatformDefaultNetworkCacheDirectory();
422     static String legacyPlatformDefaultJavaScriptConfigurationDirectory();
423
424     void setResourceLoadStatisticsEnabled(bool);
425     void clearResourceLoadStatistics();
426
427     bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
428     bool shouldTakeUIBackgroundAssertion() const { return m_shouldTakeUIBackgroundAssertion; }
429
430 #if ENABLE(GAMEPAD)
431     void gamepadConnected(const UIGamepad&);
432     void gamepadDisconnected(const UIGamepad&);
433
434     void setInitialConnectedGamepads(const Vector<std::unique_ptr<UIGamepad>>&);
435 #endif
436
437 #if PLATFORM(COCOA)
438     bool cookieStoragePartitioningEnabled() const { return m_cookieStoragePartitioningEnabled; }
439     void setCookieStoragePartitioningEnabled(bool);
440     bool storageAccessAPIEnabled() const { return m_storageAccessAPIEnabled; }
441     void setStorageAccessAPIEnabled(bool);
442 #endif
443
444 #if ENABLE(SERVICE_WORKER)
445     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
446     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
447 #endif
448
449     static uint64_t registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&&);
450     static void unregisterProcessPoolCreationListener(uint64_t identifier);
451
452 #if PLATFORM(IOS)
453     ForegroundWebProcessToken foregroundWebProcessToken() const { return ForegroundWebProcessToken(m_foregroundWebProcessCounter.count()); }
454     BackgroundWebProcessToken backgroundWebProcessToken() const { return BackgroundWebProcessToken(m_backgroundWebProcessCounter.count()); }
455 #endif
456
457     Ref<WebProcessProxy> processForNavigation(WebPageProxy&, const API::Navigation&, ShouldProcessSwapIfPossible, WebCore::PolicyAction&);
458     void registerSuspendedPageProxy(SuspendedPageProxy&);
459     void unregisterSuspendedPageProxy(SuspendedPageProxy&);
460     void didReachGoodTimeToPrewarm();
461
462     void screenPropertiesStateChanged();
463
464     void addMockMediaDevice(const WebCore::MockMediaDevice&);
465     void clearMockMediaDevices();
466     void removeMockMediaDevice(const String& persistentId);
467     void resetMockMediaDevices();
468
469 private:
470     void platformInitialize();
471
472     void platformInitializeWebProcess(WebProcessCreationParameters&);
473     void platformInvalidateContext();
474
475     Ref<WebProcessProxy> processForNavigationInternal(WebPageProxy&, const API::Navigation&, ShouldProcessSwapIfPossible, WebCore::PolicyAction&);
476
477     RefPtr<WebProcessProxy> tryTakePrewarmedProcess(WebsiteDataStore&);
478
479     WebProcessProxy& createNewWebProcess(WebsiteDataStore&, WebProcessProxy::IsInPrewarmedPool = WebProcessProxy::IsInPrewarmedPool::No);
480     void initializeNewWebProcess(WebProcessProxy&, WebsiteDataStore&);
481
482     void requestWebContentStatistics(StatisticsRequest*);
483     void requestNetworkingStatistics(StatisticsRequest*);
484
485     void platformInitializeNetworkProcess(NetworkProcessCreationParameters&);
486
487     void handleMessage(IPC::Connection&, const String& messageName, const UserData& messageBody);
488     void handleSynchronousMessage(IPC::Connection&, const String& messageName, const UserData& messageBody, UserData& returnUserData);
489
490     void didGetStatistics(const StatisticsData&, uint64_t callbackID);
491
492 #if ENABLE(GAMEPAD)
493     void startedUsingGamepads(IPC::Connection&);
494     void stoppedUsingGamepads(IPC::Connection&);
495
496     void processStoppedUsingGamepads(WebProcessProxy&);
497 #endif
498
499     void reinstateNetworkProcessAssertionState(NetworkProcessProxy&);
500     void updateProcessAssertions();
501
502     // IPC::MessageReceiver.
503     // Implemented in generated WebProcessPoolMessageReceiver.cpp
504     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
505     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
506
507     static void languageChanged(void* context);
508     void languageChanged();
509
510 #if PLATFORM(IOS)
511     String cookieStorageDirectory() const;
512 #endif
513
514 #if PLATFORM(IOS)
515     String parentBundleDirectory() const;
516     String networkingCachesDirectory() const;
517     String webContentCachesDirectory() const;
518     String containerTemporaryDirectory() const;
519 #endif
520
521 #if PLATFORM(COCOA)
522     void registerNotificationObservers();
523     void unregisterNotificationObservers();
524 #endif
525
526     void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash, PAL::SessionID);
527     void plugInDidReceiveUserInteraction(unsigned plugInOriginHash, PAL::SessionID);
528
529     void setAnyPageGroupMightHavePrivateBrowsingEnabled(bool);
530
531     void resolvePathsForSandboxExtensions();
532     void platformResolvePathsForSandboxExtensions();
533
534     void addProcessToOriginCacheSet(WebPageProxy&);
535     void removeProcessFromOriginCacheSet(WebProcessProxy&);
536
537     Ref<API::ProcessPoolConfiguration> m_configuration;
538
539     IPC::MessageReceiverMap m_messageReceiverMap;
540
541     Vector<RefPtr<WebProcessProxy>> m_processes;
542     unsigned m_prewarmedProcessCount { 0 };
543
544     WebProcessProxy* m_processWithPageCache { nullptr };
545 #if ENABLE(SERVICE_WORKER)
546     HashMap<WebCore::SecurityOriginData, ServiceWorkerProcessProxy*> m_serviceWorkerProcesses;
547     bool m_waitingForWorkerContextProcessConnection { false };
548     bool m_allowsAnySSLCertificateForServiceWorker { false };
549     bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
550     String m_serviceWorkerUserAgent;
551     std::optional<WebPreferencesStore> m_serviceWorkerPreferences;
552     HashMap<String, bool> m_mayHaveRegisteredServiceWorkers;
553 #endif
554
555     Ref<WebPageGroup> m_defaultPageGroup;
556
557     RefPtr<API::Object> m_injectedBundleInitializationUserData;
558     std::unique_ptr<API::InjectedBundleClient> m_injectedBundleClient;
559
560     WebContextClient m_client;
561     WebContextConnectionClient m_connectionClient;
562     std::unique_ptr<API::AutomationClient> m_automationClient;
563     std::unique_ptr<API::DownloadClient> m_downloadClient;
564     std::unique_ptr<API::LegacyContextHistoryClient> m_historyClient;
565     std::unique_ptr<API::CustomProtocolManagerClient> m_customProtocolManagerClient;
566
567     RefPtr<WebAutomationSession> m_automationSession;
568
569 #if ENABLE(NETSCAPE_PLUGIN_API)
570     PluginInfoStore m_pluginInfoStore;
571 #endif
572     Ref<VisitedLinkStore> m_visitedLinkStore;
573     bool m_visitedLinksPopulated { false };
574
575     PlugInAutoStartProvider m_plugInAutoStartProvider { this };
576         
577     HashSet<String> m_schemesToRegisterAsEmptyDocument;
578     HashSet<String> m_schemesToRegisterAsSecure;
579     HashSet<String> m_schemesToRegisterAsBypassingContentSecurityPolicy;
580     HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
581     HashSet<String> m_schemesToRegisterAsLocal;
582     HashSet<String> m_schemesToRegisterAsNoAccess;
583     HashSet<String> m_schemesToRegisterAsDisplayIsolated;
584     HashSet<String> m_schemesToRegisterAsCORSEnabled;
585     HashSet<String> m_schemesToRegisterAsAlwaysRevalidated;
586     HashSet<String> m_schemesToRegisterAsCachePartitioned;
587     HashSet<String> m_schemesServiceWorkersCanHandle;
588     HashSet<String> m_schemesToRegisterAsCanDisplayOnlyIfCanRequest;
589
590     bool m_alwaysUsesComplexTextCodePath { false };
591     bool m_shouldUseFontSmoothing { true };
592
593     Vector<String> m_fontWhitelist;
594
595     // Messages that were posted before any pages were created.
596     // The client should use initialization messages instead, so that a restarted process would get the same state.
597     Vector<std::pair<String, RefPtr<API::Object>>> m_messagesToInjectedBundlePostedToEmptyContext;
598
599     bool m_memorySamplerEnabled { false };
600     double m_memorySamplerInterval { 1400.0 };
601
602     RefPtr<API::WebsiteDataStore> m_websiteDataStore;
603
604     typedef HashMap<const char*, RefPtr<WebContextSupplement>, PtrHash<const char*>> WebContextSupplementMap;
605     WebContextSupplementMap m_supplements;
606
607 #if USE(SOUP)
608     HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy { HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain };
609     WebCore::SoupNetworkProxySettings m_networkProxySettings;
610 #endif
611     HashSet<String, ASCIICaseInsensitiveHash> m_urlSchemesRegisteredForCustomProtocols;
612
613 #if PLATFORM(MAC)
614     RetainPtr<NSObject> m_enhancedAccessibilityObserver;
615     RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver;
616     RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver;
617     RetainPtr<NSObject> m_automaticQuoteSubstitutionNotificationObserver;
618     RetainPtr<NSObject> m_automaticDashSubstitutionNotificationObserver;
619     RetainPtr<NSObject> m_accessibilityDisplayOptionsNotificationObserver;
620 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
621     RetainPtr<NSObject> m_scrollerStyleNotificationObserver;
622 #endif
623
624     std::unique_ptr<HighPerformanceGraphicsUsageSampler> m_highPerformanceGraphicsUsageSampler;
625     std::unique_ptr<PerActivityStateCPUUsageSampler> m_perActivityStateCPUUsageSampler;
626 #endif
627
628     bool m_shouldUseTestingNetworkSession { false };
629
630     bool m_processTerminationEnabled { true };
631
632     bool m_canHandleHTTPSServerTrustEvaluation { true };
633     bool m_didNetworkProcessCrash { false };
634     RefPtr<NetworkProcessProxy> m_networkProcess;
635     RefPtr<StorageProcessProxy> m_storageProcess;
636
637     HashMap<uint64_t, RefPtr<DictionaryCallback>> m_dictionaryCallbacks;
638     HashMap<uint64_t, RefPtr<StatisticsRequest>> m_statisticsRequests;
639
640 #if USE(SOUP)
641     bool m_ignoreTLSErrors { true };
642 #endif
643
644     bool m_memoryCacheDisabled { false };
645     bool m_javaScriptConfigurationFileEnabled { false };
646     bool m_alwaysRunsAtBackgroundPriority;
647     bool m_shouldTakeUIBackgroundAssertion;
648     bool m_shouldMakeNextWebProcessLaunchFailForTesting { false };
649     bool m_shouldMakeNextNetworkProcessLaunchFailForTesting { false };
650
651     UserObservablePageCounter m_userObservablePageCounter;
652     ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;
653     HiddenPageThrottlingAutoIncreasesCounter m_hiddenPageThrottlingAutoIncreasesCounter;
654     RunLoop::Timer<WebProcessPool> m_hiddenPageThrottlingTimer;
655
656 #if PLATFORM(COCOA)
657     RetainPtr<NSMutableDictionary> m_bundleParameters;
658     ProcessSuppressionDisabledToken m_pluginProcessManagerProcessSuppressionDisabledToken;
659 #endif
660
661 #if ENABLE(CONTENT_EXTENSIONS)
662     HashMap<String, String> m_encodedContentExtensions;
663 #endif
664
665 #if ENABLE(NETSCAPE_PLUGIN_API)
666     HashMap<String, HashMap<String, HashMap<String, uint8_t>>> m_pluginLoadClientPolicies;
667 #endif
668
669 #if ENABLE(GAMEPAD)
670     HashSet<WebProcessProxy*> m_processesUsingGamepads;
671 #endif
672
673 #if PLATFORM(COCOA)
674     bool m_cookieStoragePartitioningEnabled { false };
675     bool m_storageAccessAPIEnabled { false };
676 #endif
677
678     struct Paths {
679         String injectedBundlePath;
680         String applicationCacheDirectory;
681         String webSQLDatabaseDirectory;
682         String mediaCacheDirectory;
683         String mediaKeyStorageDirectory;
684         String uiProcessBundleResourcePath;
685         String indexedDatabaseDirectory;
686
687 #if PLATFORM(IOS)
688         String cookieStorageDirectory;
689         String containerCachesDirectory;
690         String containerTemporaryDirectory;
691 #endif
692
693         Vector<String> additionalWebProcessSandboxExtensionPaths;
694     };
695     Paths m_resolvedPaths;
696
697     HashMap<PAL::SessionID, HashSet<WebPageProxy*>> m_sessionToPagesMap;
698     RunLoop::Timer<WebProcessPool> m_serviceWorkerProcessesTerminationTimer;
699
700 #if PLATFORM(IOS)
701     ForegroundWebProcessCounter m_foregroundWebProcessCounter;
702     BackgroundWebProcessCounter m_backgroundWebProcessCounter;
703     ProcessThrottler::ForegroundActivityToken m_foregroundTokenForNetworkProcess;
704     ProcessThrottler::BackgroundActivityToken m_backgroundTokenForNetworkProcess;
705 #if ENABLE(SERVICE_WORKER)
706     HashMap<WebCore::SecurityOriginData, ProcessThrottler::ForegroundActivityToken> m_foregroundTokensForServiceWorkerProcesses;
707     HashMap<WebCore::SecurityOriginData, ProcessThrottler::BackgroundActivityToken> m_backgroundTokensForServiceWorkerProcesses;
708 #endif
709 #endif
710
711     HashMap<WebCore::SecurityOriginData, Vector<SuspendedPageProxy*>> m_suspendedPages;
712     HashMap<WebCore::SecurityOriginData, RefPtr<WebProcessProxy>> m_swappedProcesses;
713 };
714
715 template<typename T>
716 void WebProcessPool::sendToNetworkingProcess(T&& message)
717 {
718     if (m_networkProcess && m_networkProcess->canSendMessage())
719         m_networkProcess->send(std::forward<T>(message), 0);
720 }
721
722 template<typename T>
723 void WebProcessPool::sendToNetworkingProcessRelaunchingIfNecessary(T&& message)
724 {
725     ensureNetworkProcess();
726     m_networkProcess->send(std::forward<T>(message), 0);
727 }
728
729 template<typename T>
730 void WebProcessPool::sendToStorageProcess(T&& message)
731 {
732     if (m_storageProcess && m_storageProcess->canSendMessage())
733         m_storageProcess->send(std::forward<T>(message), 0);
734 }
735
736 template<typename T>
737 void WebProcessPool::sendToStorageProcessRelaunchingIfNecessary(T&& message)
738 {
739     ensureStorageProcessAndWebsiteDataStore(nullptr);
740     m_storageProcess->send(std::forward<T>(message), 0);
741 }
742
743 template<typename T>
744 void WebProcessPool::sendToAllProcesses(const T& message)
745 {
746     size_t processCount = m_processes.size();
747     for (size_t i = 0; i < processCount; ++i) {
748         WebProcessProxy* process = m_processes[i].get();
749         if (process->canSendMessage())
750             process->send(T(message), 0);
751     }
752 }
753
754 template<typename T>
755 void WebProcessPool::sendToAllProcessesRelaunchingThemIfNecessary(const T& message)
756 {
757     // FIXME (Multi-WebProcess): WebProcessPool doesn't track processes that have exited, so it cannot relaunch these. Perhaps this functionality won't be needed in this mode.
758     sendToAllProcesses(message);
759 }
760
761 template<typename T>
762 void WebProcessPool::sendToOneProcess(T&& message)
763 {
764     bool messageSent = false;
765     size_t processCount = m_processes.size();
766     for (size_t i = 0; i < processCount; ++i) {
767         WebProcessProxy* process = m_processes[i].get();
768         if (process->canSendMessage()) {
769             process->send(std::forward<T>(message), 0);
770             messageSent = true;
771             break;
772         }
773     }
774
775     if (!messageSent) {
776         warmInitialProcess();
777         RefPtr<WebProcessProxy> process = m_processes.last();
778         if (process->canSendMessage())
779             process->send(std::forward<T>(message), 0);
780     }
781 }
782
783 } // namespace WebKit