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;
40 class ResourceRequest;
45 class NetworkConnectionToWebProcess;
46 class NetworkResourceLoader;
47 class NetworkSocketStream;
48 class SyncNetworkResourceLoader;
49 typedef uint64_t ResourceLoadIdentifier;
51 namespace NetworkCache {
55 class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, IPC::Connection::Client {
57 static Ref<NetworkConnectionToWebProcess> create(IPC::Connection::Identifier);
58 virtual ~NetworkConnectionToWebProcess();
60 IPC::Connection& connection() { return m_connection.get(); }
62 void didCleanupResourceLoader(NetworkResourceLoader&);
64 bool captureExtraNetworkLoadMetricsEnabled() const { return m_captureExtraNetworkLoadMetricsEnabled; }
66 RefPtr<WebCore::BlobDataFileReference> getBlobDataFileReferenceForPath(const String& path);
68 void cleanupForSuspension(Function<void()>&&);
72 NetworkConnectionToWebProcess(IPC::Connection::Identifier);
74 // IPC::Connection::Client
75 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
76 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
77 void didClose(IPC::Connection&) override;
78 void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
81 void didReceiveNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&);
82 void didReceiveSyncNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
84 void scheduleResourceLoad(const NetworkResourceLoadParameters&);
85 void performSynchronousLoad(const NetworkResourceLoadParameters&, Ref<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
86 void loadPing(NetworkResourceLoadParameters&&, WebCore::HTTPHeaderMap&& originalRequestHeaders);
87 void prefetchDNS(const String&);
89 void removeLoadIdentifier(ResourceLoadIdentifier);
90 void setDefersLoading(ResourceLoadIdentifier, bool);
91 void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::URL& redirectURL);
92 void startDownload(PAL::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedName = { });
93 void convertMainResourceLoadToDownload(PAL::SessionID, uint64_t mainResourceLoadIdentifier, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
95 void cookiesForDOM(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
96 void setCookiesFromDOM(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, const String&);
97 void cookiesEnabled(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, bool& result);
98 void cookieRequestHeaderFieldValue(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
99 void getRawCookies(PAL::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&);
100 void deleteCookie(PAL::SessionID, const WebCore::URL&, const String& cookieName);
102 void registerFileBlobURL(const WebCore::URL&, const String& path, const SandboxExtension::Handle&, const String& contentType);
103 void registerBlobURL(const WebCore::URL&, Vector<WebCore::BlobPart>&&, const String& contentType);
104 void registerBlobURLFromURL(const WebCore::URL&, const WebCore::URL& srcURL);
105 void preregisterSandboxExtensionsForOptionallyFileBackedBlob(const Vector<String>& fileBackedPath, const SandboxExtension::HandleArray&);
106 void registerBlobURLOptionallyFileBacked(const WebCore::URL&, const WebCore::URL& srcURL, const String& fileBackedPath, const String& contentType);
107 void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end);
108 void blobSize(const WebCore::URL&, uint64_t& resultSize);
109 void unregisterBlobURL(const WebCore::URL&);
110 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier);
112 void storeDerivedDataToCache(const WebKit::NetworkCache::DataKey&, const IPC::DataReference&);
114 void setCaptureExtraNetworkLoadMetricsEnabled(bool);
116 void createSocketStream(WebCore::URL&&, PAL::SessionID, String cachePartition, uint64_t);
117 void destroySocketStream(uint64_t);
119 void ensureLegacyPrivateBrowsingSession();
122 NetworkRTCProvider& rtcProvider();
125 Ref<IPC::Connection> m_connection;
127 HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
128 HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
129 HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
132 RefPtr<NetworkRTCProvider> m_rtcProvider;
135 bool m_captureExtraNetworkLoadMetricsEnabled { false };
138 } // namespace WebKit