2 * Copyright (C) 2012-2016 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #include "BlockingResponseMap.h"
29 #include "Connection.h"
30 #include "DownloadID.h"
31 #include "NetworkConnectionToWebProcessMessages.h"
32 #include "NetworkRTCProvider.h"
34 #include <WebCore/ResourceLoadPriority.h>
35 #include <wtf/RefCounted.h>
38 class BlobDataFileReference;
39 class ResourceRequest;
44 class NetworkConnectionToWebProcess;
45 class NetworkResourceLoader;
46 class NetworkSocketStream;
47 class SyncNetworkResourceLoader;
48 typedef uint64_t ResourceLoadIdentifier;
50 namespace NetworkCache {
54 class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, IPC::Connection::Client {
56 static Ref<NetworkConnectionToWebProcess> create(IPC::Connection::Identifier);
57 virtual ~NetworkConnectionToWebProcess();
59 IPC::Connection& connection() { return m_connection.get(); }
61 void didCleanupResourceLoader(NetworkResourceLoader&);
63 RefPtr<WebCore::BlobDataFileReference> getBlobDataFileReferenceForPath(const String& path);
66 NetworkConnectionToWebProcess(IPC::Connection::Identifier);
68 // IPC::Connection::Client
69 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
70 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
71 void didClose(IPC::Connection&) override;
72 void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
75 void didReceiveNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&);
76 void didReceiveSyncNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
78 void scheduleResourceLoad(const NetworkResourceLoadParameters&);
79 void performSynchronousLoad(const NetworkResourceLoadParameters&, Ref<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
80 void loadPing(const NetworkResourceLoadParameters&);
81 void prefetchDNS(const String&);
83 void removeLoadIdentifier(ResourceLoadIdentifier);
84 void setDefersLoading(ResourceLoadIdentifier, bool);
85 void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::URL& redirectURL);
86 void startDownload(WebCore::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedName = { });
87 void convertMainResourceLoadToDownload(WebCore::SessionID, uint64_t mainResourceLoadIdentifier, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
89 void cookiesForDOM(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
90 void setCookiesFromDOM(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, const String&);
91 void cookiesEnabled(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, bool& result);
92 void cookieRequestHeaderFieldValue(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
93 void getRawCookies(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&);
94 void deleteCookie(WebCore::SessionID, const WebCore::URL&, const String& cookieName);
96 void registerFileBlobURL(const WebCore::URL&, const String& path, const SandboxExtension::Handle&, const String& contentType);
97 void registerBlobURL(const WebCore::URL&, Vector<WebCore::BlobPart>&&, const String& contentType);
98 void registerBlobURLFromURL(const WebCore::URL&, const WebCore::URL& srcURL);
99 void preregisterSandboxExtensionsForOptionallyFileBackedBlob(const Vector<String>& fileBackedPath, const SandboxExtension::HandleArray&);
100 void registerBlobURLOptionallyFileBacked(const WebCore::URL&, const WebCore::URL& srcURL, const String& fileBackedPath, const String& contentType);
101 void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end);
102 void blobSize(const WebCore::URL&, uint64_t& resultSize);
103 void unregisterBlobURL(const WebCore::URL&);
104 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier);
106 void storeDerivedDataToCache(const WebKit::NetworkCache::DataKey&, const IPC::DataReference&);
108 void createSocketStream(WebCore::URL&&, WebCore::SessionID, String cachePartition, uint64_t);
109 void destroySocketStream(uint64_t);
111 void ensureLegacyPrivateBrowsingSession();
114 NetworkRTCProvider& rtcProvider();
117 Ref<IPC::Connection> m_connection;
119 HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
120 HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
121 HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
124 RefPtr<NetworkRTCProvider> m_rtcProvider;
128 } // namespace WebKit