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