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