e455bc767f3e832ba5c6d2b19ff4977ec3a48fed
[WebKit-https.git] / Source / WebKit2 / NetworkProcess / NetworkConnectionToWebProcess.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 NetworkConnectionToWebProcess_h
27 #define NetworkConnectionToWebProcess_h
28
29 #include "BlockingResponseMap.h"
30 #include "Connection.h"
31 #include "NetworkConnectionToWebProcessMessages.h"
32 #include <WebCore/ResourceLoadPriority.h>
33 #include <wtf/HashSet.h>
34 #include <wtf/RefCounted.h>
35
36 namespace WebCore {
37 class ResourceRequest;
38 }
39
40 namespace WebKit {
41
42 class NetworkConnectionToWebProcess;
43 class NetworkResourceLoader;
44 class SyncNetworkResourceLoader;
45 typedef uint64_t ResourceLoadIdentifier;
46
47 class NetworkConnectionToWebProcess : public RefCounted<NetworkConnectionToWebProcess>, IPC::Connection::Client {
48 public:
49     static Ref<NetworkConnectionToWebProcess> create(IPC::Connection::Identifier);
50     virtual ~NetworkConnectionToWebProcess();
51
52     IPC::Connection* connection() const { return m_connection.get(); }
53
54     void didCleanupResourceLoader(NetworkResourceLoader&);
55
56 private:
57     NetworkConnectionToWebProcess(IPC::Connection::Identifier);
58
59     // IPC::Connection::Client
60     virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
61     virtual void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
62     virtual void didClose(IPC::Connection&) override;
63     virtual void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
64     virtual IPC::ProcessType localProcessType() override { return IPC::ProcessType::Network; }
65     virtual IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Web; }
66
67     // Message handlers.
68     void didReceiveNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::MessageDecoder&);
69     void didReceiveSyncNetworkConnectionToWebProcessMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
70     
71     void scheduleResourceLoad(const NetworkResourceLoadParameters&);
72     void performSynchronousLoad(const NetworkResourceLoadParameters&, RefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
73     void loadPing(const NetworkResourceLoadParameters&);
74     void prefetchDNS(const String&);
75
76     void removeLoadIdentifier(ResourceLoadIdentifier);
77     void setDefersLoading(ResourceLoadIdentifier, bool);
78     void crossOriginRedirectReceived(ResourceLoadIdentifier, const WebCore::URL& redirectURL);
79     void startDownload(WebCore::SessionID, uint64_t downloadID, const WebCore::ResourceRequest&);
80     void convertMainResourceLoadToDownload(WebCore::SessionID, uint64_t mainResourceLoadIdentifier, uint64_t downloadID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&);
81
82     void cookiesForDOM(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
83     void setCookiesFromDOM(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, const String&);
84     void cookiesEnabled(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, bool& result);
85     void cookieRequestHeaderFieldValue(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, String& result);
86     void getRawCookies(WebCore::SessionID, const WebCore::URL& firstParty, const WebCore::URL&, Vector<WebCore::Cookie>&);
87     void deleteCookie(WebCore::SessionID, const WebCore::URL&, const String& cookieName);
88
89     void registerFileBlobURL(const WebCore::URL&, const String& path, const SandboxExtension::Handle&, const String& contentType);
90     void registerBlobURL(const WebCore::URL&, Vector<WebCore::BlobPart>, const String& contentType);
91     void registerBlobURLFromURL(const WebCore::URL&, const WebCore::URL& srcURL);
92     void registerBlobURLForSlice(const WebCore::URL&, const WebCore::URL& srcURL, int64_t start, int64_t end);
93     void blobSize(const WebCore::URL&, uint64_t& resultSize);
94     void unregisterBlobURL(const WebCore::URL&);
95
96     RefPtr<IPC::Connection> m_connection;
97
98     HashMap<ResourceLoadIdentifier, RefPtr<NetworkResourceLoader>> m_networkResourceLoaders;
99 };
100
101 } // namespace WebKit
102
103 #endif // NetworkConnectionToWebProcess_h