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 bool captureExtraNetworkLoadMetricsEnabled() const { return m_captureExtraNetworkLoadMetricsEnabled; }
65 RefPtr<WebCore::BlobDataFileReference> getBlobDataFileReferenceForPath(const String& path);
68 NetworkConnectionToWebProcess(IPC::Connection::Identifier);
70 // IPC::Connection::Client
71 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
72 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
73 void didClose(IPC::Connection&) override;
74 void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
77 void didReceiveNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&);
78 void didReceiveSyncNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
80 void scheduleResourceLoad(const NetworkResourceLoadParameters&);
81 void performSynchronousLoad(const NetworkResourceLoadParameters&, Ref<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
82 void loadPing(const NetworkResourceLoadParameters&);
83 void prefetchDNS(const String&);
85 void removeLoadIdentifier(ResourceLoadIdentifier);
86 void setDefersLoading(ResourceLoadIdentifier, bool);
87 void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::URL& redirectURL);
88 void startDownload(WebCore::SessionID, DownloadID, const WebCore::ResourceRequest&, const String& suggestedName = { });
89 void convertMainResourceLoadToDownload(WebCore::SessionID, uint64_t mainResourceLoadIdentifier, DownloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
91 void cookiesForDOM(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
92 void setCookiesFromDOM(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, const String&);
93 void cookiesEnabled(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, bool& result);
94 void cookieRequestHeaderFieldValue(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
95 void getRawCookies(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&);
96 void deleteCookie(WebCore::SessionID, const WebCore::URL&, const String& cookieName);
98 void registerFileBlobURL(const WebCore::URL&, const String& path, const SandboxExtension::Handle&, const String& contentType);
99 void registerBlobURL(const WebCore::URL&, Vector<WebCore::BlobPart>&&, const String& contentType);
100 void registerBlobURLFromURL(const WebCore::URL&, const WebCore::URL& srcURL);
101 void preregisterSandboxExtensionsForOptionallyFileBackedBlob(const Vector<String>& fileBackedPath, const SandboxExtension::HandleArray&);
102 void registerBlobURLOptionallyFileBacked(const WebCore::URL&, const WebCore::URL& srcURL, const String& fileBackedPath, const String& contentType);
103 void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end);
104 void blobSize(const WebCore::URL&, uint64_t& resultSize);
105 void unregisterBlobURL(const WebCore::URL&);
106 void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, uint64_t requestIdentifier);
108 void storeDerivedDataToCache(const WebKit::NetworkCache::DataKey&, const IPC::DataReference&);
110 void setCaptureExtraNetworkLoadMetricsEnabled(bool);
112 void createSocketStream(WebCore::URL&&, WebCore::SessionID, String cachePartition, uint64_t);
113 void destroySocketStream(uint64_t);
115 void ensureLegacyPrivateBrowsingSession();
118 NetworkRTCProvider& rtcProvider();
121 Ref<IPC::Connection> m_connection;
123 HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
124 HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
125 HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
128 RefPtr<NetworkRTCProvider> m_rtcProvider;
131 bool m_captureExtraNetworkLoadMetricsEnabled { false };
134 } // namespace WebKit