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