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