[Attachment Support] Add a way to write blob data to a file URL from the UI 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 class URL;
51 struct SecurityOriginData;
52 }
53
54 namespace WebKit {
55
56 class DownloadProxy;
57 class DownloadProxyMap;
58 class WebProcessPool;
59 enum class WebsiteDataFetchOption;
60 enum class WebsiteDataType;
61 struct NetworkProcessCreationParameters;
62 struct WebsiteData;
63
64 class NetworkProcessProxy : public ChildProcessProxy, private ProcessThrottlerClient {
65 public:
66     static Ref<NetworkProcessProxy> create(WebProcessPool&);
67     ~NetworkProcessProxy();
68
69     void getNetworkProcessConnection(Ref<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>&&);
70
71     DownloadProxy* createDownloadProxy(const WebCore::ResourceRequest&);
72
73     void fetchWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, OptionSet<WebsiteDataFetchOption>, WTF::Function<void(WebsiteData)>&& completionHandler);
74     void deleteWebsiteData(PAL::SessionID, OptionSet<WebsiteDataType>, WallTime modifiedSince, WTF::Function<void()>&& completionHandler);
75     void deleteWebsiteDataForOrigins(PAL::SessionID, OptionSet<WebKit::WebsiteDataType>, const Vector<WebCore::SecurityOriginData>& origins, const Vector<String>& cookieHostNames, WTF::Function<void()>&& completionHandler);
76
77 #if PLATFORM(COCOA)
78     void setProcessSuppressionEnabled(bool);
79 #endif
80
81 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
82     void hasStorageAccessForPrevalentDomains(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, CompletionHandler<void(bool)>&& callback);
83     void updateStorageAccessForPrevalentDomains(PAL::SessionID, const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID, bool value, CompletionHandler<void(bool)>&& callback);
84 #endif
85
86     void writeBlobToFilePath(const WebCore::URL&, const String& path, CompletionHandler<void(bool)>&& callback);
87
88     void processReadyToSuspend();
89
90     void setIsHoldingLockedFiles(bool);
91
92     ProcessThrottler& throttler() { return m_throttler; }
93     WebProcessPool& processPool() { return m_processPool; }
94
95 private:
96     NetworkProcessProxy(WebProcessPool&);
97
98     // ChildProcessProxy
99     void getLaunchOptions(ProcessLauncher::LaunchOptions&) override;
100     void connectionWillOpen(IPC::Connection&) override;
101     void processWillShutDown(IPC::Connection&) override;
102
103     void networkProcessFailedToLaunch();
104     void networkProcessCrashed();
105     void clearCallbackStates();
106
107     // ProcessThrottlerClient
108     void sendProcessWillSuspendImminently() override;
109     void sendPrepareToSuspend() override;
110     void sendCancelPrepareToSuspend() override;
111     void sendProcessDidResume() override;
112     void didSetAssertionState(AssertionState) override;
113
114     // IPC::Connection::Client
115     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
116     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
117     void didClose(IPC::Connection&) override;
118     void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
119
120     // Message handlers
121     void didReceiveNetworkProcessProxyMessage(IPC::Connection&, IPC::Decoder&);
122     void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&);
123     void didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const WebCore::AuthenticationChallenge&, uint64_t challengeID);
124     void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&);
125     void didDeleteWebsiteData(uint64_t callbackID);
126     void didDeleteWebsiteDataForOrigins(uint64_t callbackID);
127     void didWriteBlobToFilePath(bool success, uint64_t callbackID);
128     void grantSandboxExtensionsToStorageProcessForBlobs(uint64_t requestID, const Vector<String>& paths);
129     void logDiagnosticMessage(uint64_t pageID, const String& message, const String& description, WebCore::ShouldSample);
130     void logDiagnosticMessageWithResult(uint64_t pageID, const String& message, const String& description, uint32_t result, WebCore::ShouldSample);
131     void logDiagnosticMessageWithValue(uint64_t pageID, const String& message, const String& description, double value, unsigned significantFigures, WebCore::ShouldSample);
132 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
133     void canAuthenticateAgainstProtectionSpace(uint64_t loaderID, uint64_t pageID, uint64_t frameID, const WebCore::ProtectionSpace&);
134 #endif
135 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
136     void storageAccessRequestResult(bool wasGranted, uint64_t contextId);
137 #endif
138
139     // ProcessLauncher::Client
140     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
141
142     WebProcessPool& m_processPool;
143     
144     unsigned m_numPendingConnectionRequests;
145     Deque<Ref<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>> m_pendingConnectionReplies;
146
147     HashMap<uint64_t, WTF::Function<void (WebsiteData)>> m_pendingFetchWebsiteDataCallbacks;
148     HashMap<uint64_t, WTF::Function<void ()>> m_pendingDeleteWebsiteDataCallbacks;
149     HashMap<uint64_t, WTF::Function<void ()>> m_pendingDeleteWebsiteDataForOriginsCallbacks;
150
151     std::unique_ptr<DownloadProxyMap> m_downloadProxyMap;
152 #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER)
153     LegacyCustomProtocolManagerProxy m_customProtocolManagerProxy;
154 #endif
155     ProcessThrottler m_throttler;
156     ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles;
157
158     HashMap<uint64_t, CompletionHandler<void(bool success)>> m_writeBlobToFilePathCallbackMap;
159     HashMap<uint64_t, WTF::CompletionHandler<void(bool wasGranted)>> m_storageAccessResponseCallbackMap;
160 };
161
162 } // namespace WebKit
163
164 #endif // NetworkProcessProxy_h