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