Remove WebContext::sharedProcessContext()
[WebKit-https.git] / Source / WebKit2 / UIProcess / WebContext.h
1 /*
2  * Copyright (C) 2010, 2011, 2012, 2013 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 #ifndef WebContext_h
27 #define WebContext_h
28
29 #include "APIObject.h"
30 #include "DownloadProxyMap.h"
31 #include "GenericCallback.h"
32 #include "ImmutableDictionary.h"
33 #include "MessageReceiver.h"
34 #include "MessageReceiverMap.h"
35 #include "PlugInAutoStartProvider.h"
36 #include "PluginInfoStore.h"
37 #include "ProcessModel.h"
38 #include "StatisticsRequest.h"
39 #include "StorageManager.h"
40 #include "VisitedLinkProvider.h"
41 #include "WebContextClient.h"
42 #include "WebContextConnectionClient.h"
43 #include "WebContextInjectedBundleClient.h"
44 #include "WebDownloadClient.h"
45 #include "WebHistoryClient.h"
46 #include "WebProcessProxy.h"
47 #include <WebCore/LinkHash.h>
48 #include <wtf/Forward.h>
49 #include <wtf/HashMap.h>
50 #include <wtf/HashSet.h>
51 #include <wtf/PassRefPtr.h>
52 #include <wtf/RefPtr.h>
53 #include <wtf/text/StringHash.h>
54 #include <wtf/text/WTFString.h>
55
56 #if ENABLE(DATABASE_PROCESS)
57 #include "DatabaseProcessProxy.h"
58 #endif
59
60 #if ENABLE(NETWORK_PROCESS)
61 #include "NetworkProcessProxy.h"
62 #endif
63
64 #if PLATFORM(MAC)
65 OBJC_CLASS NSObject;
66 OBJC_CLASS NSString;
67 #endif
68
69 namespace WebKit {
70
71 class DownloadProxy;
72 class WebContextSupplement;
73 class WebIconDatabase;
74 class WebPageGroup;
75 class WebPageProxy;
76 struct StatisticsData;
77 struct WebProcessCreationParameters;
78     
79 typedef GenericCallback<WKDictionaryRef> DictionaryCallback;
80
81 #if ENABLE(NETWORK_INFO)
82 class WebNetworkInfoManagerProxy;
83 #endif
84 #if ENABLE(NETWORK_PROCESS)
85 struct NetworkProcessCreationParameters;
86 #endif
87
88 #if PLATFORM(MAC)
89 extern NSString *SchemeForCustomProtocolRegisteredNotificationName;
90 extern NSString *SchemeForCustomProtocolUnregisteredNotificationName;
91 #endif
92
93 class WebContext : public API::TypedObject<API::Object::Type::Context>, private CoreIPC::MessageReceiver
94 #if ENABLE(NETSCAPE_PLUGIN_API)
95     , private PluginInfoStoreClient
96 #endif
97     {
98 public:
99     WebContext(const String& injectedBundlePath);
100
101     static PassRefPtr<WebContext> create(const String& injectedBundlePath);
102     virtual ~WebContext();
103
104     static const Vector<WebContext*>& allContexts();
105
106     template <typename T>
107     T* supplement()
108     {
109         return static_cast<T*>(m_supplements.get(T::supplementName()));
110     }
111
112     template <typename T>
113     void addSupplement()
114     {
115         m_supplements.add(T::supplementName(), T::create(this));
116     }
117
118     void addMessageReceiver(CoreIPC::StringReference messageReceiverName, CoreIPC::MessageReceiver*);
119     void addMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID, CoreIPC::MessageReceiver*);
120     void removeMessageReceiver(CoreIPC::StringReference messageReceiverName, uint64_t destinationID);
121
122     bool dispatchMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
123     bool dispatchSyncMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, std::unique_ptr<CoreIPC::MessageEncoder>&);
124
125     void initializeClient(const WKContextClientBase*);
126     void initializeInjectedBundleClient(const WKContextInjectedBundleClientBase*);
127     void initializeConnectionClient(const WKContextConnectionClientBase*);
128     void initializeHistoryClient(const WKContextHistoryClientBase*);
129     void initializeDownloadClient(const WKContextDownloadClientBase*);
130
131     void setProcessModel(ProcessModel); // Can only be called when there are no processes running.
132     ProcessModel processModel() const { return m_processModel; }
133
134     void setMaximumNumberOfProcesses(unsigned); // Can only be called when there are no processes running.
135     unsigned maximumNumberOfProcesses() const { return m_webProcessCountLimit; }
136
137     // WebProcess or NetworkProcess as approporiate for current process model. The connection must be non-null.
138     CoreIPC::Connection* networkingProcessConnection();
139
140     template<typename T> void sendToAllProcesses(const T& message);
141     template<typename T> void sendToAllProcessesRelaunchingThemIfNecessary(const T& message);
142     template<typename T> void sendToOneProcess(T&& message);
143
144     // Sends the message to WebProcess or NetworkProcess as approporiate for current process model.
145     template<typename T> void sendToNetworkingProcess(T&& message);
146     template<typename T> void sendToNetworkingProcessRelaunchingIfNecessary(T&& message);
147
148     void processWillOpenConnection(WebProcessProxy*);
149     void processWillCloseConnection(WebProcessProxy*);
150     void processDidFinishLaunching(WebProcessProxy*);
151
152     // Disconnect the process from the context.
153     void disconnectProcess(WebProcessProxy*);
154
155     StorageManager& storageManager() const { return *m_storageManager; }
156
157     PassRefPtr<WebPageProxy> createWebPage(PageClient&, WebPageGroup*, WebPageProxy* relatedPage = 0);
158
159     const String& injectedBundlePath() const { return m_injectedBundlePath; }
160
161     DownloadProxy* download(WebPageProxy* initiatingPage, const WebCore::ResourceRequest&);
162
163     void setInjectedBundleInitializationUserData(PassRefPtr<API::Object> userData) { m_injectedBundleInitializationUserData = userData; }
164
165     void postMessageToInjectedBundle(const String&, API::Object*);
166
167     // InjectedBundle client
168     void didReceiveMessageFromInjectedBundle(const String&, API::Object*);
169     void didReceiveSynchronousMessageFromInjectedBundle(const String&, API::Object*, RefPtr<API::Object>& returnData);
170
171     void populateVisitedLinks();
172
173 #if ENABLE(NETSCAPE_PLUGIN_API)
174     void setAdditionalPluginsDirectory(const String&);
175
176     PluginInfoStore& pluginInfoStore() { return m_pluginInfoStore; }
177 #endif
178
179     void setAlwaysUsesComplexTextCodePath(bool);
180     void setShouldUseFontSmoothing(bool);
181     
182     void registerURLSchemeAsEmptyDocument(const String&);
183     void registerURLSchemeAsSecure(const String&);
184     void setDomainRelaxationForbiddenForURLScheme(const String&);
185     void registerURLSchemeAsLocal(const String&);
186     void registerURLSchemeAsNoAccess(const String&);
187     void registerURLSchemeAsDisplayIsolated(const String&);
188     void registerURLSchemeAsCORSEnabled(const String&);
189
190     void addVisitedLink(const String&);
191     void addVisitedLinkHash(WebCore::LinkHash);
192
193     // MessageReceiver.
194     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) OVERRIDE;
195     virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, std::unique_ptr<CoreIPC::MessageEncoder>&) OVERRIDE;
196
197     void setCacheModel(CacheModel);
198     CacheModel cacheModel() const { return m_cacheModel; }
199
200     void setDefaultRequestTimeoutInterval(double);
201
202     void startMemorySampler(const double interval);
203     void stopMemorySampler();
204
205 #if USE(SOUP)
206     void setInitialHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) { m_initialHTTPCookieAcceptPolicy = policy; }
207 #endif
208     void setEnhancedAccessibility(bool);
209     
210     // Downloads.
211     DownloadProxy* createDownloadProxy();
212     WebDownloadClient& downloadClient() { return m_downloadClient; }
213
214     WebHistoryClient& historyClient() { return m_historyClient; }
215     WebContextClient& client() { return m_client; }
216
217     WebIconDatabase* iconDatabase() const { return m_iconDatabase.get(); }
218 #if ENABLE(NETSCAPE_PLUGIN_API)
219     WebPluginSiteDataManager* pluginSiteDataManager() const { return m_pluginSiteDataManager.get(); }
220 #endif
221
222     struct Statistics {
223         unsigned wkViewCount;
224         unsigned wkPageCount;
225         unsigned wkFrameCount;
226     };
227     static Statistics& statistics();    
228
229     void setApplicationCacheDirectory(const String& dir) { m_overrideApplicationCacheDirectory = dir; }
230     void setDatabaseDirectory(const String& dir) { m_overrideDatabaseDirectory = dir; }
231     void setIconDatabasePath(const String&);
232     String iconDatabasePath() const;
233     void setLocalStorageDirectory(const String&);
234     void setDiskCacheDirectory(const String& dir) { m_overrideDiskCacheDirectory = dir; }
235     void setCookieStorageDirectory(const String& dir) { m_overrideCookieStorageDirectory = dir; }
236
237     void useTestingNetworkSession();
238
239     void allowSpecificHTTPSCertificateForHost(const WebCertificateInfo*, const String& host);
240
241     WebProcessProxy& ensureSharedWebProcess();
242     WebProcessProxy& createNewWebProcessRespectingProcessCountLimit(); // Will return an existing one if limit is met.
243     void warmInitialProcess();
244
245     bool shouldTerminate(WebProcessProxy*);
246
247     void disableProcessTermination() { m_processTerminationEnabled = false; }
248     void enableProcessTermination();
249
250     // Defaults to false.
251     void setHTTPPipeliningEnabled(bool);
252     bool httpPipeliningEnabled() const;
253
254     void getStatistics(uint32_t statisticsMask, PassRefPtr<DictionaryCallback>);
255     
256     void garbageCollectJavaScriptObjects();
257     void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
258
259 #if PLATFORM(MAC)
260     static bool omitPDFSupport();
261 #endif
262
263     void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
264
265     void textCheckerStateChanged();
266
267     PassRefPtr<ImmutableDictionary> plugInAutoStartOriginHashes() const;
268     void setPlugInAutoStartOriginHashes(ImmutableDictionary&);
269     void setPlugInAutoStartOrigins(API::Array&);
270
271     // Network Process Management
272
273     void setUsesNetworkProcess(bool);
274     bool usesNetworkProcess() const;
275
276 #if ENABLE(NETWORK_PROCESS)
277     void ensureNetworkProcess();
278     NetworkProcessProxy* networkProcess() { return m_networkProcess.get(); }
279     void networkProcessCrashed(NetworkProcessProxy*);
280
281     void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
282 #endif
283
284 #if ENABLE(DATABASE_PROCESS)
285     void ensureDatabaseProcess();
286     void getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>);
287 #endif
288
289 #if PLATFORM(MAC)
290     void setProcessSuppressionEnabled(bool);
291     bool processSuppressionEnabled() const { return m_processSuppressionEnabled; }
292     bool canEnableProcessSuppressionForNetworkProcess() const;
293     bool canEnableProcessSuppressionForWebProcess(const WebProcessProxy*) const;
294     static bool canEnableProcessSuppressionForGlobalChildProcesses();
295     void updateProcessSuppressionStateOfChildProcesses();
296 #endif
297
298     static void willStartUsingPrivateBrowsing();
299     static void willStopUsingPrivateBrowsing();
300
301 #if USE(SOUP)
302     void setIgnoreTLSErrors(bool);
303     bool ignoreTLSErrors() const { return m_ignoreTLSErrors; }
304 #endif
305
306     static void setInvalidMessageCallback(void (*)(WKStringRef));
307     static void didReceiveInvalidMessage(const CoreIPC::StringReference& messageReceiverName, const CoreIPC::StringReference& messageName);
308
309     void processDidCachePage(WebProcessProxy*);
310
311     bool isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const;
312     void resetHSTSHosts();
313
314 private:
315     void platformInitialize();
316
317     void platformInitializeWebProcess(WebProcessCreationParameters&);
318     void platformInvalidateContext();
319
320     WebProcessProxy& createNewWebProcess();
321
322     void requestWebContentStatistics(StatisticsRequest*);
323     void requestNetworkingStatistics(StatisticsRequest*);
324
325 #if ENABLE(NETWORK_PROCESS)
326     void platformInitializeNetworkProcess(NetworkProcessCreationParameters&);
327 #endif
328
329 #if PLATFORM(MAC)
330 #if PLATFORM(IOS)
331     void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&);
332     void writeImageToPasteboard(const WebCore::PasteboardImage&);
333     void writeStringToPasteboard(const String& pasteboardType, const String&);
334     void readStringFromPasteboard(uint64_t index, const String& pasteboardType, WTF::String&);
335     void readURLFromPasteboard(uint64_t index, const String& pasteboardType, String&);
336     void readBufferFromPasteboard(uint64_t index, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
337     void getPasteboardItemsCount(uint64_t& itemsCount);
338 #endif
339     void getPasteboardTypes(const String& pasteboardName, Vector<String>& pasteboardTypes);
340     void getPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, Vector<String>& pathnames);
341     void getPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, String&);
342     void getPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, SharedMemory::Handle&, uint64_t& size);
343     void pasteboardCopy(const String& fromPasteboard, const String& toPasteboard, uint64_t& newChangeCount);
344     void getPasteboardChangeCount(const String& pasteboardName, uint64_t& changeCount);
345     void getPasteboardUniqueName(String& pasteboardName);
346     void getPasteboardColor(const String& pasteboardName, WebCore::Color&);
347     void getPasteboardURL(const String& pasteboardName, WTF::String&);
348     void addPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount);
349     void setPasteboardTypes(const String& pasteboardName, const Vector<String>& pasteboardTypes, uint64_t& newChangeCount);
350     void setPasteboardPathnamesForType(const String& pasteboardName, const String& pasteboardType, const Vector<String>& pathnames, uint64_t& newChangeCount);
351     void setPasteboardStringForType(const String& pasteboardName, const String& pasteboardType, const String&, uint64_t& newChangeCount);
352     void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, uint64_t& newChangeCount);
353 #endif
354
355 #if !PLATFORM(MAC)
356     // FIXME: This a dummy message, to avoid breaking the build for platforms that don't require
357     // any synchronous messages, and should be removed when <rdar://problem/8775115> is fixed.
358     void dummy(bool&);
359 #endif
360
361     void didGetStatistics(const StatisticsData&, uint64_t callbackID);
362         
363     // Implemented in generated WebContextMessageReceiver.cpp
364     void didReceiveWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&);
365     void didReceiveSyncWebContextMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, std::unique_ptr<CoreIPC::MessageEncoder>&);
366
367     static void languageChanged(void* context);
368     void languageChanged();
369
370     String applicationCacheDirectory() const;
371     String platformDefaultApplicationCacheDirectory() const;
372
373     String databaseDirectory() const;
374     String platformDefaultDatabaseDirectory() const;
375
376     String platformDefaultIconDatabasePath() const;
377
378     String localStorageDirectory() const;
379     String platformDefaultLocalStorageDirectory() const;
380
381     String diskCacheDirectory() const;
382     String platformDefaultDiskCacheDirectory() const;
383
384     String cookieStorageDirectory() const;
385     String platformDefaultCookieStorageDirectory() const;
386
387 #if PLATFORM(MAC)
388     void processSuppressionEnabledChanged();
389     void registerNotificationObservers();
390     void unregisterNotificationObservers();
391 #endif
392
393 #if ENABLE(CUSTOM_PROTOCOLS)
394     void registerSchemeForCustomProtocol(const String&);
395     void unregisterSchemeForCustomProtocol(const String&);
396 #endif
397
398     void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash);
399     void plugInDidReceiveUserInteraction(unsigned plugInOriginHash);
400
401     void setAnyPageGroupMightHavePrivateBrowsingEnabled(bool);
402
403 #if ENABLE(NETSCAPE_PLUGIN_API)
404     // PluginInfoStoreClient:
405     virtual void pluginInfoStoreDidLoadPlugins(PluginInfoStore*) OVERRIDE;
406 #endif
407
408     CoreIPC::MessageReceiverMap m_messageReceiverMap;
409
410     ProcessModel m_processModel;
411     unsigned m_webProcessCountLimit; // The limit has no effect when process model is ProcessModelSharedSecondaryProcess.
412     
413     Vector<RefPtr<WebProcessProxy>> m_processes;
414     bool m_haveInitialEmptyProcess;
415
416     WebProcessProxy* m_processWithPageCache;
417
418     Ref<WebPageGroup> m_defaultPageGroup;
419
420     RefPtr<API::Object> m_injectedBundleInitializationUserData;
421     String m_injectedBundlePath;
422     WebContextInjectedBundleClient m_injectedBundleClient;
423
424     WebContextClient m_client;
425     WebContextConnectionClient m_connectionClient;
426     WebDownloadClient m_downloadClient;
427     WebHistoryClient m_historyClient;
428
429 #if ENABLE(NETSCAPE_PLUGIN_API)
430     PluginInfoStore m_pluginInfoStore;
431 #endif
432     VisitedLinkProvider m_visitedLinkProvider;
433     PlugInAutoStartProvider m_plugInAutoStartProvider;
434         
435     HashSet<String> m_schemesToRegisterAsEmptyDocument;
436     HashSet<String> m_schemesToRegisterAsSecure;
437     HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
438     HashSet<String> m_schemesToRegisterAsLocal;
439     HashSet<String> m_schemesToRegisterAsNoAccess;
440     HashSet<String> m_schemesToRegisterAsDisplayIsolated;
441     HashSet<String> m_schemesToRegisterAsCORSEnabled;
442
443     bool m_alwaysUsesComplexTextCodePath;
444     bool m_shouldUseFontSmoothing;
445
446     // Messages that were posted before any pages were created.
447     // The client should use initialization messages instead, so that a restarted process would get the same state.
448     Vector<pair<String, RefPtr<API::Object>>> m_messagesToInjectedBundlePostedToEmptyContext;
449
450     CacheModel m_cacheModel;
451
452     bool m_memorySamplerEnabled;
453     double m_memorySamplerInterval;
454
455     RefPtr<WebIconDatabase> m_iconDatabase;
456 #if ENABLE(NETSCAPE_PLUGIN_API)
457     RefPtr<WebPluginSiteDataManager> m_pluginSiteDataManager;
458 #endif
459
460     RefPtr<StorageManager> m_storageManager;
461
462     typedef HashMap<const char*, RefPtr<WebContextSupplement>, PtrHash<const char*>> WebContextSupplementMap;
463     WebContextSupplementMap m_supplements;
464
465 #if USE(SOUP)
466     HTTPCookieAcceptPolicy m_initialHTTPCookieAcceptPolicy;
467 #endif
468
469 #if PLATFORM(MAC)
470     RetainPtr<NSObject> m_enhancedAccessibilityObserver;
471     RetainPtr<NSObject> m_customSchemeRegisteredObserver;
472     RetainPtr<NSObject> m_customSchemeUnregisteredObserver;
473
474     RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver;
475     RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver;
476 #if !PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
477     RetainPtr<NSObject> m_automaticQuoteSubstitutionNotificationObserver;
478     RetainPtr<NSObject> m_automaticDashSubstitutionNotificationObserver;
479 #endif
480 #endif
481
482     String m_overrideApplicationCacheDirectory;
483     String m_overrideDatabaseDirectory;
484     String m_overrideIconDatabasePath;
485     String m_overrideLocalStorageDirectory;
486     String m_overrideDiskCacheDirectory;
487     String m_overrideCookieStorageDirectory;
488
489     bool m_shouldUseTestingNetworkSession;
490
491     bool m_processTerminationEnabled;
492
493 #if ENABLE(NETWORK_PROCESS)
494     bool m_usesNetworkProcess;
495     RefPtr<NetworkProcessProxy> m_networkProcess;
496 #endif
497
498 #if ENABLE(DATABASE_PROCESS)
499     RefPtr<DatabaseProcessProxy> m_databaseProcess;
500 #endif
501     
502     HashMap<uint64_t, RefPtr<DictionaryCallback>> m_dictionaryCallbacks;
503     HashMap<uint64_t, RefPtr<StatisticsRequest>> m_statisticsRequests;
504
505 #if PLATFORM(MAC)
506     bool m_processSuppressionEnabled;
507 #endif
508
509 #if USE(SOUP)
510     bool m_ignoreTLSErrors;
511 #endif
512 };
513
514 template<typename T>
515 void WebContext::sendToNetworkingProcess(T&& message)
516 {
517     switch (m_processModel) {
518     case ProcessModelSharedSecondaryProcess:
519         if (!m_processes.isEmpty() && m_processes[0]->canSendMessage())
520             m_processes[0]->send(std::forward<T>(message), 0);
521         return;
522     case ProcessModelMultipleSecondaryProcesses:
523 #if ENABLE(NETWORK_PROCESS)
524         if (m_networkProcess->canSendMessage())
525             m_networkProcess->send(std::forward<T>(message), 0);
526         return;
527 #else
528         break;
529 #endif
530     }
531     ASSERT_NOT_REACHED();
532 }
533
534 template<typename T>
535 void WebContext::sendToNetworkingProcessRelaunchingIfNecessary(T&& message)
536 {
537     switch (m_processModel) {
538     case ProcessModelSharedSecondaryProcess:
539         ensureSharedWebProcess();
540         m_processes[0]->send(std::forward<T>(message), 0);
541         return;
542     case ProcessModelMultipleSecondaryProcesses:
543 #if ENABLE(NETWORK_PROCESS)
544         ensureNetworkProcess();
545         m_networkProcess->send(std::forward<T>(message), 0);
546         return;
547 #else
548         break;
549 #endif
550     }
551     ASSERT_NOT_REACHED();
552 }
553
554 template<typename T>
555 void WebContext::sendToAllProcesses(const T& message)
556 {
557     size_t processCount = m_processes.size();
558     for (size_t i = 0; i < processCount; ++i) {
559         WebProcessProxy* process = m_processes[i].get();
560         if (process->canSendMessage())
561             process->send(T(message), 0);
562     }
563 }
564
565 template<typename T>
566 void WebContext::sendToAllProcessesRelaunchingThemIfNecessary(const T& message)
567 {
568 // FIXME (Multi-WebProcess): WebContext doesn't track processes that have exited, so it cannot relaunch these. Perhaps this functionality won't be needed in this mode.
569     if (m_processModel == ProcessModelSharedSecondaryProcess)
570         ensureSharedWebProcess();
571     sendToAllProcesses(message);
572 }
573
574 template<typename T>
575 void WebContext::sendToOneProcess(T&& message)
576 {
577     if (m_processModel == ProcessModelSharedSecondaryProcess)
578         ensureSharedWebProcess();
579
580     bool messageSent = false;
581     size_t processCount = m_processes.size();
582     for (size_t i = 0; i < processCount; ++i) {
583         WebProcessProxy* process = m_processes[i].get();
584         if (process->canSendMessage()) {
585             process->send(std::forward<T>(message), 0);
586             messageSent = true;
587             break;
588         }
589     }
590
591     if (!messageSent && m_processModel == ProcessModelMultipleSecondaryProcesses) {
592         warmInitialProcess();
593         RefPtr<WebProcessProxy> process = m_processes.last();
594         if (process->canSendMessage())
595             process->send(std::forward<T>(message), 0);
596     }
597 }
598
599 } // namespace WebKit
600
601 #endif // WebContext_h