Deque's contains() and findIf() should be const
[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
220     WebPageGroup& defaultPageGroup() { return m_defaultPageGroup.get(); }
221
222     void setAlwaysUsesComplexTextCodePath(bool);
223     void setShouldUseFontSmoothing(bool);
224     
225     void registerURLSchemeAsEmptyDocument(const String&);
226     void registerURLSchemeAsSecure(const String&);
227     void registerURLSchemeAsBypassingContentSecurityPolicy(const String&);
228     void setDomainRelaxationForbiddenForURLScheme(const String&);
229     void setCanHandleHTTPSServerTrustEvaluation(bool);
230     void registerURLSchemeAsLocal(const String&);
231     void registerURLSchemeAsNoAccess(const String&);
232     void registerURLSchemeAsDisplayIsolated(const String&);
233     void registerURLSchemeAsCORSEnabled(const String&);
234     void registerURLSchemeAsCachePartitioned(const String&);
235     void registerURLSchemeServiceWorkersCanHandle(const String&);
236     void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&);
237
238     void preconnectToServer(const WebCore::URL&);
239
240     VisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); }
241
242     void setCacheModel(CacheModel);
243     CacheModel cacheModel() const { return m_configuration->cacheModel(); }
244
245     void setDefaultRequestTimeoutInterval(double);
246
247     void startMemorySampler(const double interval);
248     void stopMemorySampler();
249
250 #if USE(SOUP)
251     void setInitialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
252     void setNetworkProxySettings(const WebCore::SoupNetworkProxySettings&);
253 #endif
254     void setEnhancedAccessibility(bool);
255     
256     // Downloads.
257     DownloadProxy* createDownloadProxy(const WebCore::ResourceRequest&, WebPageProxy* originatingPage);
258     API::DownloadClient& downloadClient() { return *m_downloadClient; }
259
260     API::LegacyContextHistoryClient& historyClient() { return *m_historyClient; }
261     WebContextClient& client() { return m_client; }
262
263     API::CustomProtocolManagerClient& customProtocolManagerClient() const { return *m_customProtocolManagerClient; }
264
265     struct Statistics {
266         unsigned wkViewCount;
267         unsigned wkPageCount;
268         unsigned wkFrameCount;
269     };
270     static Statistics& statistics();    
271
272     void useTestingNetworkSession();
273     bool isUsingTestingNetworkSession() const { return m_shouldUseTestingNetworkSession; }
274
275     void setAllowsAnySSLCertificateForWebSocket(bool);
276
277     void clearCachedCredentials();
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 prewarmProcess();
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_FAMILY)
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<std::pair<RefPtr<WebProcessProxy>, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>>&&);
339
340     void getNetworkProcessConnection(WebProcessProxy&, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply&&);
341
342 #if ENABLE(SERVICE_WORKER)
343     void establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy&, WebCore::SecurityOriginData&&, std::optional<PAL::SessionID>);
344     ServiceWorkerProcessProxy* serviceWorkerProcessProxyFromPageID(uint64_t pageID) const;
345     const HashMap<WebCore::SecurityOriginData, ServiceWorkerProcessProxy*>& serviceWorkerProxies() const { return m_serviceWorkerProcesses; }
346     void setAllowsAnySSLCertificateForServiceWorker(bool allows) { m_allowsAnySSLCertificateForServiceWorker = allows; }
347     bool allowsAnySSLCertificateForServiceWorker() const { return m_allowsAnySSLCertificateForServiceWorker; }
348     void updateServiceWorkerUserAgent(const String& userAgent);
349     bool mayHaveRegisteredServiceWorkers(const WebsiteDataStore&);
350 #endif
351
352 #if PLATFORM(COCOA)
353     bool processSuppressionEnabled() const;
354 #endif
355
356     void windowServerConnectionStateChanged();
357
358     static void willStartUsingPrivateBrowsing();
359     static void willStopUsingPrivateBrowsing();
360
361 #if USE(SOUP)
362     void setIgnoreTLSErrors(bool);
363     bool ignoreTLSErrors() const { return m_ignoreTLSErrors; }
364 #endif
365
366     static void setInvalidMessageCallback(void (*)(WKStringRef));
367     static void didReceiveInvalidMessage(const IPC::StringReference& messageReceiverName, const IPC::StringReference& messageName);
368
369     void processDidCachePage(WebProcessProxy*);
370
371     bool isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const;
372     void resetHSTSHosts();
373     void resetHSTSHostsAddedAfterDate(double startDateIntervalSince1970);
374
375     void registerSchemeForCustomProtocol(const String&);
376     void unregisterSchemeForCustomProtocol(const String&);
377
378     static void registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
379     static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
380
381 #if PLATFORM(COCOA)
382     void updateProcessSuppressionState();
383
384     NSMutableDictionary *ensureBundleParameters();
385     NSMutableDictionary *bundleParameters() { return m_bundleParameters.get(); }
386 #else
387     void updateProcessSuppressionState() const { }
388 #endif
389
390     void updateHiddenPageThrottlingAutoIncreaseLimit();
391
392     void setMemoryCacheDisabled(bool);
393     void setFontWhitelist(API::Array*);
394
395     UserObservablePageCounter::Token userObservablePageCount()
396     {
397         return m_userObservablePageCounter.count();
398     }
399
400     ProcessSuppressionDisabledToken processSuppressionDisabledForPageCount()
401     {
402         return m_processSuppressionDisabledForPageCounter.count();
403     }
404
405     HiddenPageThrottlingAutoIncreasesCounter::Token hiddenPageThrottlingAutoIncreasesCount()
406     {
407         return m_hiddenPageThrottlingAutoIncreasesCounter.count();
408     }
409
410     void setResourceLoadStatisticsEnabled(bool);
411     void clearResourceLoadStatistics();
412
413     bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
414     bool shouldTakeUIBackgroundAssertion() const { return m_shouldTakeUIBackgroundAssertion; }
415
416 #if ENABLE(GAMEPAD)
417     void gamepadConnected(const UIGamepad&);
418     void gamepadDisconnected(const UIGamepad&);
419
420     void setInitialConnectedGamepads(const Vector<std::unique_ptr<UIGamepad>>&);
421 #endif
422
423 #if PLATFORM(COCOA)
424     bool cookieStoragePartitioningEnabled() const { return m_cookieStoragePartitioningEnabled; }
425     void setCookieStoragePartitioningEnabled(bool);
426     bool storageAccessAPIEnabled() const { return m_storageAccessAPIEnabled; }
427     void setStorageAccessAPIEnabled(bool);
428 #endif
429
430 #if ENABLE(SERVICE_WORKER)
431     void postMessageToServiceWorkerClient(const WebCore::ServiceWorkerClientIdentifier& destinationIdentifier, WebCore::MessageWithMessagePorts&&, WebCore::ServiceWorkerIdentifier sourceIdentifier, const String& sourceOrigin);
432     void postMessageToServiceWorker(WebCore::ServiceWorkerIdentifier destination, WebCore::MessageWithMessagePorts&&, const WebCore::ServiceWorkerOrClientIdentifier& source, WebCore::SWServerConnectionIdentifier);
433 #endif
434
435     static uint64_t registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&&);
436     static void unregisterProcessPoolCreationListener(uint64_t identifier);
437
438 #if PLATFORM(IOS_FAMILY)
439     ForegroundWebProcessToken foregroundWebProcessToken() const { return ForegroundWebProcessToken(m_foregroundWebProcessCounter.count()); }
440     BackgroundWebProcessToken backgroundWebProcessToken() const { return BackgroundWebProcessToken(m_backgroundWebProcessCounter.count()); }
441 #endif
442
443     Ref<WebProcessProxy> processForNavigation(WebPageProxy&, const API::Navigation&, ProcessSwapRequestedByClient, WebCore::PolicyAction&, String& reason);
444
445     // SuspendedPageProxy management.
446     void addSuspendedPageProxy(std::unique_ptr<SuspendedPageProxy>&&);
447     void removeAllSuspendedPageProxiesForPage(WebPageProxy&);
448     std::unique_ptr<SuspendedPageProxy> takeSuspendedPageProxy(SuspendedPageProxy&);
449     bool hasSuspendedPageProxyFor(WebProcessProxy&) const;
450
451     void didReachGoodTimeToPrewarm();
452
453     void didCollectPrewarmInformation(const String& registrableDomain, const WebCore::PrewarmInformation&);
454
455     void screenPropertiesStateChanged();
456
457     void addMockMediaDevice(const WebCore::MockMediaDevice&);
458     void clearMockMediaDevices();
459     void removeMockMediaDevice(const String& persistentId);
460     void resetMockMediaDevices();
461
462     void sendDisplayConfigurationChangedMessageForTesting();
463
464 #if PLATFORM(GTK) || PLATFORM(WPE)
465     void setSandboxEnabled(bool enabled) { m_sandboxEnabled = enabled; };
466     bool sandboxEnabled() const { return m_sandboxEnabled; };
467 #endif
468
469 private:
470     void platformInitialize();
471
472     void platformInitializeWebProcess(WebProcessCreationParameters&);
473     void platformInvalidateContext();
474
475     Ref<WebProcessProxy> processForNavigationInternal(WebPageProxy&, const API::Navigation&, ProcessSwapRequestedByClient, WebCore::PolicyAction&, String& reason);
476
477     RefPtr<WebProcessProxy> tryTakePrewarmedProcess(WebsiteDataStore&);
478
479     WebProcessProxy& createNewWebProcess(WebsiteDataStore&, WebProcessProxy::IsPrewarmed = WebProcessProxy::IsPrewarmed::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_FAMILY)
511     String cookieStorageDirectory() const;
512 #endif
513
514 #if PLATFORM(IOS_FAMILY)
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     void tryPrewarmWithDomainInformation(WebProcessProxy&, const WebCore::URL&);
538
539     Ref<API::ProcessPoolConfiguration> m_configuration;
540
541     IPC::MessageReceiverMap m_messageReceiverMap;
542
543     Vector<RefPtr<WebProcessProxy>> m_processes;
544     WebProcessProxy* m_prewarmedProcess { nullptr };
545
546     WebProcessProxy* m_processWithPageCache { nullptr };
547 #if ENABLE(SERVICE_WORKER)
548     HashMap<WebCore::SecurityOriginData, ServiceWorkerProcessProxy*> m_serviceWorkerProcesses;
549     bool m_waitingForWorkerContextProcessConnection { false };
550     bool m_allowsAnySSLCertificateForServiceWorker { false };
551     bool m_shouldDisableServiceWorkerProcessTerminationDelay { false };
552     String m_serviceWorkerUserAgent;
553     std::optional<WebPreferencesStore> m_serviceWorkerPreferences;
554     HashMap<String, bool> m_mayHaveRegisteredServiceWorkers;
555 #endif
556
557     Ref<WebPageGroup> m_defaultPageGroup;
558
559     RefPtr<API::Object> m_injectedBundleInitializationUserData;
560     std::unique_ptr<API::InjectedBundleClient> m_injectedBundleClient;
561
562     WebContextClient m_client;
563     WebContextConnectionClient m_connectionClient;
564     std::unique_ptr<API::AutomationClient> m_automationClient;
565     std::unique_ptr<API::DownloadClient> m_downloadClient;
566     std::unique_ptr<API::LegacyContextHistoryClient> m_historyClient;
567     std::unique_ptr<API::CustomProtocolManagerClient> m_customProtocolManagerClient;
568
569     RefPtr<WebAutomationSession> m_automationSession;
570
571 #if ENABLE(NETSCAPE_PLUGIN_API)
572     PluginInfoStore m_pluginInfoStore;
573 #endif
574     Ref<VisitedLinkStore> m_visitedLinkStore;
575     bool m_visitedLinksPopulated { false };
576
577     PlugInAutoStartProvider m_plugInAutoStartProvider { this };
578         
579     HashSet<String> m_schemesToRegisterAsEmptyDocument;
580     HashSet<String> m_schemesToRegisterAsSecure;
581     HashSet<String> m_schemesToRegisterAsBypassingContentSecurityPolicy;
582     HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
583     HashSet<String> m_schemesToRegisterAsLocal;
584     HashSet<String> m_schemesToRegisterAsNoAccess;
585     HashSet<String> m_schemesToRegisterAsDisplayIsolated;
586     HashSet<String> m_schemesToRegisterAsCORSEnabled;
587     HashSet<String> m_schemesToRegisterAsAlwaysRevalidated;
588     HashSet<String> m_schemesToRegisterAsCachePartitioned;
589     HashSet<String> m_schemesServiceWorkersCanHandle;
590     HashSet<String> m_schemesToRegisterAsCanDisplayOnlyIfCanRequest;
591
592     bool m_alwaysUsesComplexTextCodePath { false };
593     bool m_shouldUseFontSmoothing { true };
594
595     Vector<String> m_fontWhitelist;
596
597     // Messages that were posted before any pages were created.
598     // The client should use initialization messages instead, so that a restarted process would get the same state.
599     Vector<std::pair<String, RefPtr<API::Object>>> m_messagesToInjectedBundlePostedToEmptyContext;
600
601     bool m_memorySamplerEnabled { false };
602     double m_memorySamplerInterval { 1400.0 };
603
604     RefPtr<API::WebsiteDataStore> m_websiteDataStore;
605
606     typedef HashMap<const char*, RefPtr<WebContextSupplement>, PtrHash<const char*>> WebContextSupplementMap;
607     WebContextSupplementMap m_supplements;
608
609 #if USE(SOUP)
610     HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy { HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain };
611     WebCore::SoupNetworkProxySettings m_networkProxySettings;
612 #endif
613     HashSet<String, ASCIICaseInsensitiveHash> m_urlSchemesRegisteredForCustomProtocols;
614
615 #if PLATFORM(MAC)
616     RetainPtr<NSObject> m_enhancedAccessibilityObserver;
617     RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver;
618     RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver;
619     RetainPtr<NSObject> m_automaticQuoteSubstitutionNotificationObserver;
620     RetainPtr<NSObject> m_automaticDashSubstitutionNotificationObserver;
621     RetainPtr<NSObject> m_accessibilityDisplayOptionsNotificationObserver;
622 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
623     RetainPtr<NSObject> m_scrollerStyleNotificationObserver;
624 #endif
625
626     std::unique_ptr<HighPerformanceGraphicsUsageSampler> m_highPerformanceGraphicsUsageSampler;
627     std::unique_ptr<PerActivityStateCPUUsageSampler> m_perActivityStateCPUUsageSampler;
628 #endif
629
630     bool m_shouldUseTestingNetworkSession { false };
631
632     bool m_processTerminationEnabled { true };
633
634     bool m_canHandleHTTPSServerTrustEvaluation { true };
635     bool m_didNetworkProcessCrash { false };
636     std::unique_ptr<NetworkProcessProxy> m_networkProcess;
637
638     HashMap<uint64_t, RefPtr<DictionaryCallback>> m_dictionaryCallbacks;
639     HashMap<uint64_t, RefPtr<StatisticsRequest>> m_statisticsRequests;
640
641 #if USE(SOUP)
642     bool m_ignoreTLSErrors { true };
643 #endif
644
645     bool m_memoryCacheDisabled { false };
646     bool m_javaScriptConfigurationFileEnabled { false };
647     bool m_alwaysRunsAtBackgroundPriority;
648     bool m_shouldTakeUIBackgroundAssertion;
649     bool m_shouldMakeNextWebProcessLaunchFailForTesting { false };
650     bool m_shouldMakeNextNetworkProcessLaunchFailForTesting { false };
651
652     UserObservablePageCounter m_userObservablePageCounter;
653     ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;
654     HiddenPageThrottlingAutoIncreasesCounter m_hiddenPageThrottlingAutoIncreasesCounter;
655     RunLoop::Timer<WebProcessPool> m_hiddenPageThrottlingTimer;
656
657 #if PLATFORM(COCOA)
658     RetainPtr<NSMutableDictionary> m_bundleParameters;
659     ProcessSuppressionDisabledToken m_pluginProcessManagerProcessSuppressionDisabledToken;
660 #endif
661
662 #if ENABLE(CONTENT_EXTENSIONS)
663     HashMap<String, String> m_encodedContentExtensions;
664 #endif
665
666 #if ENABLE(NETSCAPE_PLUGIN_API)
667     HashMap<String, HashMap<String, HashMap<String, uint8_t>>> m_pluginLoadClientPolicies;
668 #endif
669
670 #if ENABLE(GAMEPAD)
671     HashSet<WebProcessProxy*> m_processesUsingGamepads;
672 #endif
673
674 #if PLATFORM(COCOA)
675     bool m_cookieStoragePartitioningEnabled { false };
676     bool m_storageAccessAPIEnabled { false };
677 #endif
678
679     struct Paths {
680         String injectedBundlePath;
681         String applicationCacheDirectory;
682         String webSQLDatabaseDirectory;
683         String mediaCacheDirectory;
684         String mediaKeyStorageDirectory;
685         String uiProcessBundleResourcePath;
686         String indexedDatabaseDirectory;
687
688 #if PLATFORM(IOS_FAMILY)
689         String cookieStorageDirectory;
690         String containerCachesDirectory;
691         String containerTemporaryDirectory;
692 #endif
693
694         Vector<String> additionalWebProcessSandboxExtensionPaths;
695     };
696     Paths m_resolvedPaths;
697
698     HashMap<PAL::SessionID, HashSet<WebPageProxy*>> m_sessionToPagesMap;
699     RunLoop::Timer<WebProcessPool> m_serviceWorkerProcessesTerminationTimer;
700
701 #if PLATFORM(IOS_FAMILY)
702     ForegroundWebProcessCounter m_foregroundWebProcessCounter;
703     BackgroundWebProcessCounter m_backgroundWebProcessCounter;
704     ProcessThrottler::ForegroundActivityToken m_foregroundTokenForNetworkProcess;
705     ProcessThrottler::BackgroundActivityToken m_backgroundTokenForNetworkProcess;
706 #if ENABLE(SERVICE_WORKER)
707     HashMap<WebCore::SecurityOriginData, ProcessThrottler::ForegroundActivityToken> m_foregroundTokensForServiceWorkerProcesses;
708     HashMap<WebCore::SecurityOriginData, ProcessThrottler::BackgroundActivityToken> m_backgroundTokensForServiceWorkerProcesses;
709 #endif
710 #endif
711
712     Deque<std::unique_ptr<SuspendedPageProxy>> m_suspendedPages;
713     HashMap<String, RefPtr<WebProcessProxy>> m_swappedProcessesPerRegistrableDomain;
714
715     HashMap<String, std::unique_ptr<WebCore::PrewarmInformation>> m_prewarmInformationPerRegistrableDomain;
716
717 #if PLATFORM(GTK) || PLATFORM(WPE)
718     bool m_sandboxEnabled { false };
719 #endif
720 };
721
722 template<typename T>
723 void WebProcessPool::sendToNetworkingProcess(T&& message)
724 {
725     if (m_networkProcess && m_networkProcess->canSendMessage())
726         m_networkProcess->send(std::forward<T>(message), 0);
727 }
728
729 template<typename T>
730 void WebProcessPool::sendToNetworkingProcessRelaunchingIfNecessary(T&& message)
731 {
732     ensureNetworkProcess();
733     m_networkProcess->send(std::forward<T>(message), 0);
734 }
735
736 template<typename T>
737 void WebProcessPool::sendToAllProcesses(const T& message)
738 {
739     size_t processCount = m_processes.size();
740     for (size_t i = 0; i < processCount; ++i) {
741         WebProcessProxy* process = m_processes[i].get();
742         if (process->canSendMessage())
743             process->send(T(message), 0);
744     }
745 }
746
747 template<typename T>
748 void WebProcessPool::sendToAllProcessesRelaunchingThemIfNecessary(const T& message)
749 {
750     // 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.
751     sendToAllProcesses(message);
752 }
753
754 template<typename T>
755 void WebProcessPool::sendToOneProcess(T&& message)
756 {
757     bool messageSent = false;
758     size_t processCount = m_processes.size();
759     for (size_t i = 0; i < processCount; ++i) {
760         WebProcessProxy* process = m_processes[i].get();
761         if (process->canSendMessage()) {
762             process->send(std::forward<T>(message), 0);
763             messageSent = true;
764             break;
765         }
766     }
767
768     if (!messageSent) {
769         prewarmProcess();
770         RefPtr<WebProcessProxy> process = m_processes.last();
771         if (process->canSendMessage())
772             process->send(std::forward<T>(message), 0);
773     }
774 }
775
776 } // namespace WebKit