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