1 | /* |
2 | * Copyright (C) 2010, 2011, 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 NetworkProcessConnection_h |
27 | #define NetworkProcessConnection_h |
28 | |
29 | #include "Connection.h" |
30 | #include "ShareableResource.h" |
31 | #include "WebIDBConnectionToServer.h" |
32 | #include <WebCore/ServiceWorkerTypes.h> |
33 | #include <wtf/RefCounted.h> |
34 | #include <wtf/text/WTFString.h> |
35 | |
36 | namespace IPC { |
37 | class DataReference; |
38 | } |
39 | |
40 | namespace PAL { |
41 | class SessionID; |
42 | } |
43 | |
44 | namespace WebCore { |
45 | class ResourceError; |
46 | class ResourceRequest; |
47 | class ResourceResponse; |
48 | } |
49 | |
50 | namespace WebKit { |
51 | |
52 | class WebSWClientConnection; |
53 | |
54 | typedef uint64_t ResourceLoadIdentifier; |
55 | |
56 | class NetworkProcessConnection : public RefCounted<NetworkProcessConnection>, IPC::Connection::Client { |
57 | public: |
58 | static Ref<NetworkProcessConnection> create(IPC::Connection::Identifier connectionIdentifier) |
59 | { |
60 | return adoptRef(*new NetworkProcessConnection(connectionIdentifier)); |
61 | } |
62 | ~NetworkProcessConnection(); |
63 | |
64 | IPC::Connection& connection() { return m_connection.get(); } |
65 | |
66 | void didReceiveNetworkProcessConnectionMessage(IPC::Connection&, IPC::Decoder&); |
67 | |
68 | void writeBlobsToTemporaryFiles(const Vector<String>& blobURLs, CompletionHandler<void(Vector<String>&& filePaths)>&&); |
69 | |
70 | #if ENABLE(INDEXED_DATABASE) |
71 | WebIDBConnectionToServer* existingIDBConnectionToServerForIdentifier(uint64_t identifier) const { return m_webIDBConnectionsByIdentifier.get(identifier); }; |
72 | WebIDBConnectionToServer& idbConnectionToServerForSession(PAL::SessionID); |
73 | #endif |
74 | |
75 | #if ENABLE(SERVICE_WORKER) |
76 | WebSWClientConnection* existingServiceWorkerConnectionForSession(PAL::SessionID sessionID) { return m_swConnectionsBySession.get(sessionID); } |
77 | WebSWClientConnection& serviceWorkerConnectionForSession(PAL::SessionID); |
78 | |
79 | WebCore::SWServerConnectionIdentifier initializeSWClientConnection(WebSWClientConnection&); |
80 | void removeSWClientConnection(WebSWClientConnection&); |
81 | #endif |
82 | |
83 | private: |
84 | NetworkProcessConnection(IPC::Connection::Identifier); |
85 | |
86 | // IPC::Connection::Client |
87 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
88 | void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override; |
89 | void didClose(IPC::Connection&) override; |
90 | void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; |
91 | |
92 | void didFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError&&, WebCore::ResourceResponse&&); |
93 | void didFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError&&); |
94 | void setOnLineState(bool isOnLine); |
95 | |
96 | #if ENABLE(SHAREABLE_RESOURCE) |
97 | // Message handlers. |
98 | void didCacheResource(const WebCore::ResourceRequest&, const ShareableResource::Handle&, PAL::SessionID); |
99 | #endif |
100 | |
101 | // The connection from the web process to the network process. |
102 | Ref<IPC::Connection> m_connection; |
103 | |
104 | #if ENABLE(INDEXED_DATABASE) |
105 | HashMap<PAL::SessionID, RefPtr<WebIDBConnectionToServer>> m_webIDBConnectionsBySession; |
106 | HashMap<uint64_t, RefPtr<WebIDBConnectionToServer>> m_webIDBConnectionsByIdentifier; |
107 | #endif |
108 | |
109 | #if ENABLE(SERVICE_WORKER) |
110 | HashMap<PAL::SessionID, RefPtr<WebSWClientConnection>> m_swConnectionsBySession; |
111 | HashMap<WebCore::SWServerConnectionIdentifier, WebSWClientConnection*> m_swConnectionsByIdentifier; |
112 | #endif |
113 | }; |
114 | |
115 | } // namespace WebKit |
116 | |
117 | #endif // NetworkProcessConnection_h |
118 | |