Remove "virtual" from all lines that have both "virtual" and "override".
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / NetworkProcess.h
1 /*
2  * Copyright (C) 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 NetworkProcess_h
27 #define NetworkProcess_h
28
29 #include "CacheModel.h"
30 #include "ChildProcess.h"
31 #include "DownloadManager.h"
32 #include "MessageReceiverMap.h"
33 #include <WebCore/DiagnosticLoggingClient.h>
34 #include <WebCore/MemoryPressureHandler.h>
35 #include <WebCore/SessionID.h>
36 #include <memory>
37 #include <wtf/Forward.h>
38 #include <wtf/NeverDestroyed.h>
39
40 #if PLATFORM(IOS)
41 #include "WebSQLiteDatabaseTracker.h"
42 #endif
43
44 namespace WebCore {
45 class DownloadID;
46 class CertificateInfo;
47 class NetworkStorageSession;
48 class SecurityOrigin;
49 class SessionID;
50 struct SecurityOriginData;
51 }
52
53 namespace WebKit {
54 class AuthenticationManager;
55 class NetworkConnectionToWebProcess;
56 class NetworkProcessSupplement;
57 enum class WebsiteDataFetchOption;
58 enum class WebsiteDataType;
59 struct NetworkProcessCreationParameters;
60
61 class NetworkProcess : public ChildProcess, private DownloadManager::Client {
62     WTF_MAKE_NONCOPYABLE(NetworkProcess);
63     friend class NeverDestroyed<NetworkProcess>;
64     friend class NeverDestroyed<DownloadManager>;
65 public:
66     static NetworkProcess& singleton();
67
68     template <typename T>
69     T* supplement()
70     {
71         return static_cast<T*>(m_supplements.get(T::supplementName()));
72     }
73
74     template <typename T>
75     void addSupplement()
76     {
77         m_supplements.add(T::supplementName(), std::make_unique<T>(this));
78     }
79
80     void removeNetworkConnectionToWebProcess(NetworkConnectionToWebProcess*);
81
82     AuthenticationManager& authenticationManager();
83     DownloadManager& downloadManager();
84     bool canHandleHTTPSServerTrustEvaluation() const { return m_canHandleHTTPSServerTrustEvaluation; }
85
86     void processWillSuspendImminently(bool& handled);
87     void prepareToSuspend();
88     void cancelPrepareToSuspend();
89     void processDidResume();
90
91     // Diagnostic messages logging.
92     void logDiagnosticMessage(uint64_t webPageID, const String& message, const String& description, WebCore::ShouldSample);
93     void logDiagnosticMessageWithResult(uint64_t webPageID, const String& message, const String& description, WebCore::DiagnosticLoggingResultType, WebCore::ShouldSample);
94     void logDiagnosticMessageWithValue(uint64_t webPageID, const String& message, const String& description, const String& value, WebCore::ShouldSample);
95
96 #if USE(CFURLCACHE)
97     static Vector<Ref<WebCore::SecurityOrigin>> cfURLCacheOrigins();
98     static void clearCFURLCacheForOrigins(const Vector<WebCore::SecurityOriginData>&);
99 #endif
100
101 #if PLATFORM(COCOA)
102     void clearHSTSCache(WebCore::NetworkStorageSession&, std::chrono::system_clock::time_point modifiedSince);
103 #endif
104
105 #if USE(NETWORK_SESSION)
106     void findPendingDownloadLocation(NetworkDataTask&, ResponseCompletionHandler);
107 #endif
108     
109     void prefetchDNS(const String&);
110
111     void ensurePrivateBrowsingSession(WebCore::SessionID);
112
113 private:
114     NetworkProcess();
115     ~NetworkProcess();
116
117     void platformInitializeNetworkProcess(const NetworkProcessCreationParameters&);
118
119     void terminate() override;
120     void platformTerminate();
121
122     void lowMemoryHandler(WebCore::Critical);
123     void platformLowMemoryHandler(WebCore::Critical);
124
125     // ChildProcess
126     void initializeProcess(const ChildProcessInitializationParameters&) override;
127     void initializeProcessName(const ChildProcessInitializationParameters&) override;
128     void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) override;
129     void initializeConnection(IPC::Connection*) override;
130     bool shouldTerminate() override;
131
132     // IPC::Connection::Client
133     void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
134     void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
135     void didClose(IPC::Connection&) override;
136     void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
137     IPC::ProcessType localProcessType() override { return IPC::ProcessType::Network; }
138     IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::UI; }
139
140     // DownloadManager::Client
141     void didCreateDownload() override;
142     void didDestroyDownload() override;
143     IPC::Connection* downloadProxyConnection() override;
144     AuthenticationManager& downloadsAuthenticationManager() override;
145 #if USE(NETWORK_SESSION)
146     void pendingDownloadCanceled(DownloadID) override;
147 #endif
148
149     // Message Handlers
150     void didReceiveNetworkProcessMessage(IPC::Connection&, IPC::MessageDecoder&);
151     void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
152     void initializeNetworkProcess(const NetworkProcessCreationParameters&);
153     void createNetworkConnectionToWebProcess();
154     void destroyPrivateBrowsingSession(WebCore::SessionID);
155
156     void fetchWebsiteData(WebCore::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, uint64_t callbackID);
157     void deleteWebsiteData(WebCore::SessionID, OptionSet<WebsiteDataType>, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID);
158     void deleteWebsiteDataForOrigins(WebCore::SessionID, OptionSet<WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, uint64_t callbackID);
159
160     void clearCachedCredentials();
161
162     // FIXME: This should take a session ID so we can identify which disk cache to delete.
163     void clearDiskCache(std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler);
164
165     void downloadRequest(WebCore::SessionID, DownloadID, const WebCore::ResourceRequest&);
166     void resumeDownload(WebCore::SessionID, DownloadID, const IPC::DataReference& resumeData, const String& path, const SandboxExtension::Handle&);
167     void cancelDownload(DownloadID);
168 #if USE(NETWORK_SESSION)
169     void continueCanAuthenticateAgainstProtectionSpace(DownloadID, bool canAuthenticate);
170     void continueWillSendRequest(DownloadID, const WebCore::ResourceRequest&);
171     void continueDecidePendingDownloadDestination(DownloadID, String destination, const SandboxExtension::Handle& sandboxExtensionHandle, bool allowOverwrite);
172 #endif
173     void setCacheModel(uint32_t);
174     void allowSpecificHTTPSCertificateForHost(const WebCore::CertificateInfo&, const String& host);
175     void setCanHandleHTTPSServerTrustEvaluation(bool);
176     void getNetworkProcessStatistics(uint64_t callbackID);
177     void clearCacheForAllOrigins(uint32_t cachesToClear);
178
179 #if USE(SOUP)
180     void setIgnoreTLSErrors(bool);
181     void userPreferredLanguagesChanged(const Vector<String>&);
182 #endif
183
184     // Platform Helpers
185     void platformSetCacheModel(CacheModel);
186
187     // Connections to WebProcesses.
188     Vector<RefPtr<NetworkConnectionToWebProcess>> m_webProcessConnections;
189
190     String m_diskCacheDirectory;
191     bool m_hasSetCacheModel;
192     CacheModel m_cacheModel;
193     int64_t m_diskCacheSizeOverride { -1 };
194     bool m_suppressMemoryPressureHandler { false };
195     bool m_diskCacheIsDisabledForTesting;
196     bool m_canHandleHTTPSServerTrustEvaluation;
197
198     typedef HashMap<const char*, std::unique_ptr<NetworkProcessSupplement>, PtrHash<const char*>> NetworkProcessSupplementMap;
199     NetworkProcessSupplementMap m_supplements;
200
201 #if PLATFORM(COCOA)
202     void platformInitializeNetworkProcessCocoa(const NetworkProcessCreationParameters&);
203
204     // FIXME: We'd like to be able to do this without the #ifdef, but WorkQueue + BinarySemaphore isn't good enough since
205     // multiple requests to clear the cache can come in before previous requests complete, and we need to wait for all of them.
206     // In the future using WorkQueue and a counting semaphore would work, as would WorkQueue supporting the libdispatch concept of "work groups".
207     dispatch_group_t m_clearCacheDispatchGroup;
208 #endif
209
210 #if PLATFORM(IOS)
211     WebSQLiteDatabaseTracker m_webSQLiteDatabaseTracker;
212 #endif
213 };
214
215 } // namespace WebKit
216
217 #endif // NetworkProcess_h