Web Inspector: Only Capture Extra Network Load Metrics when there is a Web Inspector...
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / NetworkConnectionToWebProcess.h
1 /*
2  * Copyright (C) 2012-2016 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 #pragma once
27
28 #include "BlockingResponseMap.h"
29 #include "Connection.h"
30 #include "DownloadID.h"
31 #include "NetworkConnectionToWebProcessMessages.h"
32 #include "NetworkRTCProvider.h"
33
34 #include <WebCore/ResourceLoadPriority.h>
35 #include <wtf/RefCounted.h>
36
37 namespace WebCore {
38 class BlobDataFileReference;
39 class ResourceRequest;
40 }
41
42 namespace WebKit {
43
44 class NetworkConnectionToWebProcess;
45 class NetworkResourceLoader;
46 class NetworkSocketStream;
47 class SyncNetworkResourceLoader;
48 typedef uint64_t ResourceLoadIdentifier;
49
50 namespace NetworkCache {
51 struct DataKey;
52 }
53
54 class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, IPC::Connection::Client {
55 public:
56     static Ref<NetworkConnectionToWebProcess> create(IPC::Connection::Identifier);
57     virtual ~NetworkConnectionToWebProcess();
58
59     IPC::Connection& connection() { return m_connection.get(); }
60
61     void didCleanupResourceLoader(NetworkResourceLoader&);
62
63     bool captureExtraNetworkLoadMetricsEnabled() const { return m_captureExtraNetworkLoadMetricsEnabled; }
64
65     RefPtr<WebCore::BlobDataFileReference> getBlobDataFileReferenceForPath(const String& path);
66
67 private:
68     NetworkConnectionToWebProcess(IPC::Connection::Identifier);
69
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;
75
76     // Message handlers.
77     void didReceiveNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&);
78     void didReceiveSyncNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
79
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&);
84
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&);
90
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);
97
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);
107
108     void storeDerivedDataToCache(const WebKit::NetworkCache::DataKey&, const IPC::DataReference&);
109
110     void setCaptureExtraNetworkLoadMetricsEnabled(bool);
111
112     void createSocketStream(WebCore::URL&&, WebCore::SessionID, String cachePartition, uint64_t);
113     void destroySocketStream(uint64_t);
114     
115     void ensureLegacyPrivateBrowsingSession();
116
117 #if USE(LIBWEBRTC)
118     NetworkRTCProvider& rtcProvider();
119 #endif
120     
121     Ref<IPC::Connection> m_connection;
122
123     HashMap<uint64_t, RefPtr<NetworkSocketStream>> m_networkSocketStreams;
124     HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
125     HashMap<String, RefPtr<WebCore::BlobDataFileReference>> m_blobDataFileReferences;
126
127 #if USE(LIBWEBRTC)
128     RefPtr<NetworkRTCProvider> m_rtcProvider;
129 #endif
130
131     bool m_captureExtraNetworkLoadMetricsEnabled { false };
132 };
133
134 } // namespace WebKit