Make LegacyCustomProtocolManager optional for network process
[WebKit-https.git] / Source / WebKit / UIProcess / Network / NetworkProcessProxy.h
1 /*
2  * Copyright (C) 2012 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 NetworkProcessProxy_h
27 #define NetworkProcessProxy_h
28
29 #include "ChildProcessProxy.h"
30 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
31 #include "LegacyCustomProtocolManagerProxy.h"
32 #endif
33 #include "ProcessLauncher.h"
34 #include "ProcessThrottler.h"
35 #include "ProcessThrottlerClient.h"
36 #include "WebProcessProxyMessages.h"
37 #include <memory>
38 #include <wtf/Deque.h>
39
40 namespace PAL {
41 class SessionID;
42 }
43
44 namespace WebCore {
45 class AuthenticationChallenge;
46 class ProtectionSpace;
47 class ResourceRequest;
48 enum class ShouldSample;
49 class SecurityOrigin;
50 struct SecurityOriginData;
51 }
52
53 namespace WebKit {
54
55 class DownloadProxy;
56 class DownloadProxyMap;
57 class WebProcessPool;
58 enum class WebsiteDataFetchOption;
59 enum class WebsiteDataType;
60 struct NetworkProcessCreationParameters;
61 struct WebsiteData;
62
63 class NetworkProcessProxy : public ChildProcessProxy, private ProcessThrottlerClient {
64 public:
65     static Ref<NetworkProcessProxy> create(WebProcessPool&);
66     ~NetworkProcessProxy();
67
68     void getNetworkProcessConnection(Ref<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>&&);
69
70     DownloadProxy* createDownloadProxy(const WebCore::ResourceRequest&);
71
72     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, WTF::Function<void(WebsiteData)>&& completionHandler);
73     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, std::chrono::system_clock::time_point modifiedSince, WTF::Function<void()>&& completionHandler);
74     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebKit::WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, WTF::Function<void()>&& completionHandler);
75
76 #if PLATFORM(COCOA)
77     void setProcessSuppressionEnabled(bool);
78 #endif
79
80 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
81     void updateStorageAccessForPrevalentDomains(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, bool value, WTF::CompletionHandler<void(bool)>&& callback);
82 #endif
83
84     void processReadyToSuspend();
85
86     void setIsHoldingLockedFiles(bool);
87
88     ProcessThrottler& throttler() { return m_throttler; }
89     WebProcessPool& processPool() { return m_processPool; }
90
91 private:
92     NetworkProcessProxy(WebProcessPool&);
93
94     // ChildProcessProxy
95     void getLaunchOptions(ProcessLauncher::LaunchOptions&) override;
96     void connectionWillOpen(IPC::Connection&) override;
97     void processWillShutDown(IPC::Connection&) override;
98
99     void networkProcessFailedToLaunch();
100     void networkProcessCrashed();
101     void clearCallbackStates();
102
103     // ProcessThrottlerClient
104     void sendProcessWillSuspendImminently() override;
105     void sendPrepareToSuspend() override;
106     void sendCancelPrepareToSuspend() override;
107     void sendProcessDidResume() override;
108     void didSetAssertionState(AssertionState) override;
109
110     // IPC::Connection::Client
111     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
112     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
113     void didClose(IPC::Connection&) override;
114     void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
115
116     // Message handlers
117     void didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::Decoder&);
118     void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&);
119     void didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const WebCore::AuthenticationChallenge&, uint64_t challengeID);
120     void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&);
121     void didDeleteWebsiteData(uint64_t callbackID);
122     void didDeleteWebsiteDataForOrigins(uint64_t callbackID);
123     void grantSandboxExtensionsToStorageProcessForBlobs(uint64_t requestID, const Vector<String>& paths);
124     void logDiagnosticMessage(uint64_t pageID, const String& message, const String& description, WebCore::ShouldSample);
125     void logDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result, WebCore::ShouldSample);
126     void logDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
127 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
128     void canAuthenticateAgainstProtectionSpace(uint64_t loaderID, uint64_t pageID, uint64_t frameID, const WebCore::ProtectionSpace&);
129 #endif
130 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
131     void storageAccessRequestResult(bool wasGranted, uint64_t contextId);
132 #endif
133
134     // ProcessLauncher::Client
135     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
136
137     WebProcessPool& m_processPool;
138     
139     unsigned m_numPendingConnectionRequests;
140     Deque<Ref<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>> m_pendingConnectionReplies;
141
142     HashMap<uint64_t, WTF::Function<void (WebsiteData)>> m_pendingFetchWebsiteDataCallbacks;
143     HashMap<uint64_t, WTF::Function<void ()>> m_pendingDeleteWebsiteDataCallbacks;
144     HashMap<uint64_t, WTF::Function<void ()>> m_pendingDeleteWebsiteDataForOriginsCallbacks;
145
146     std::unique_ptr<DownloadProxyMap> m_downloadProxyMap;
147 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
148     LegacyCustomProtocolManagerProxy m_customProtocolManagerProxy;
149 #endif
150     ProcessThrottler m_throttler;
151     ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles;
152
153     HashMap<uint64_t, WTF::CompletionHandler<void(bool wasGranted)>> m_storageAccessResponseCallbackMap;
154 };
155
156 } // namespace WebKit
157
158 #endif // NetworkProcessProxy_h