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