| 1 | /* |
| 2 | * Copyright (C) 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 | #if ENABLE(INDEXED_DATABASE) |
| 29 | |
| 30 | #include "MessageSender.h" |
| 31 | #include "NetworkConnectionToWebProcess.h" |
| 32 | #include <WebCore/IDBConnectionToClient.h> |
| 33 | #include <WebCore/IndexedDB.h> |
| 34 | #include <pal/SessionID.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | class IDBCursorInfo; |
| 38 | class IDBIndexInfo; |
| 39 | class IDBKeyData; |
| 40 | class IDBObjectStoreInfo; |
| 41 | class IDBRequestData; |
| 42 | class IDBTransactionInfo; |
| 43 | class IDBValue; |
| 44 | class SerializedScriptValue; |
| 45 | struct IDBGetAllRecordsData; |
| 46 | struct IDBGetRecordData; |
| 47 | struct IDBIterateCursorData; |
| 48 | struct IDBKeyRangeData; |
| 49 | struct SecurityOriginData; |
| 50 | } |
| 51 | |
| 52 | namespace WebKit { |
| 53 | |
| 54 | class NetworkProcess; |
| 55 | |
| 56 | class WebIDBConnectionToClient final : public WebCore::IDBServer::IDBConnectionToClientDelegate, public IPC::MessageSender, public RefCounted<WebIDBConnectionToClient> { |
| 57 | public: |
| 58 | static Ref<WebIDBConnectionToClient> create(NetworkProcess&, IPC::Connection&, uint64_t serverConnectionIdentifier, PAL::SessionID); |
| 59 | |
| 60 | virtual ~WebIDBConnectionToClient(); |
| 61 | |
| 62 | WebCore::IDBServer::IDBConnectionToClient& connectionToClient(); |
| 63 | uint64_t identifier() const final { return m_identifier; } |
| 64 | uint64_t messageSenderDestinationID() const final { return m_identifier; } |
| 65 | |
| 66 | // IDBConnectionToClientDelegate |
| 67 | void didDeleteDatabase(const WebCore::IDBResultData&) final; |
| 68 | void didOpenDatabase(const WebCore::IDBResultData&) final; |
| 69 | void didAbortTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&) final; |
| 70 | void didCommitTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&) final; |
| 71 | void didCreateObjectStore(const WebCore::IDBResultData&) final; |
| 72 | void didDeleteObjectStore(const WebCore::IDBResultData&) final; |
| 73 | void didRenameObjectStore(const WebCore::IDBResultData&) final; |
| 74 | void didClearObjectStore(const WebCore::IDBResultData&) final; |
| 75 | void didCreateIndex(const WebCore::IDBResultData&) final; |
| 76 | void didDeleteIndex(const WebCore::IDBResultData&) final; |
| 77 | void didRenameIndex(const WebCore::IDBResultData&) final; |
| 78 | void didPutOrAdd(const WebCore::IDBResultData&) final; |
| 79 | void didGetRecord(const WebCore::IDBResultData&) final; |
| 80 | void didGetAllRecords(const WebCore::IDBResultData&) final; |
| 81 | void didGetCount(const WebCore::IDBResultData&) final; |
| 82 | void didDeleteRecord(const WebCore::IDBResultData&) final; |
| 83 | void didOpenCursor(const WebCore::IDBResultData&) final; |
| 84 | void didIterateCursor(const WebCore::IDBResultData&) final; |
| 85 | |
| 86 | void fireVersionChangeEvent(WebCore::IDBServer::UniqueIDBDatabaseConnection&, const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t requestedVersion) final; |
| 87 | void didStartTransaction(const WebCore::IDBResourceIdentifier& transactionIdentifier, const WebCore::IDBError&) final; |
| 88 | void didCloseFromServer(WebCore::IDBServer::UniqueIDBDatabaseConnection&, const WebCore::IDBError&) final; |
| 89 | void notifyOpenDBRequestBlocked(const WebCore::IDBResourceIdentifier& requestIdentifier, uint64_t oldVersion, uint64_t newVersion) final; |
| 90 | |
| 91 | void didGetAllDatabaseNames(uint64_t callbackID, const Vector<String>& databaseNames) final; |
| 92 | |
| 93 | void ref() override { RefCounted<WebIDBConnectionToClient>::ref(); } |
| 94 | void deref() override { RefCounted<WebIDBConnectionToClient>::deref(); } |
| 95 | |
| 96 | // Messages received from WebProcess |
| 97 | void deleteDatabase(const WebCore::IDBRequestData&); |
| 98 | void openDatabase(const WebCore::IDBRequestData&); |
| 99 | void abortTransaction(const WebCore::IDBResourceIdentifier&); |
| 100 | void commitTransaction(const WebCore::IDBResourceIdentifier&); |
| 101 | void didFinishHandlingVersionChangeTransaction(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier&); |
| 102 | void createObjectStore(const WebCore::IDBRequestData&, const WebCore::IDBObjectStoreInfo&); |
| 103 | void deleteObjectStore(const WebCore::IDBRequestData&, const String& objectStoreName); |
| 104 | void renameObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& newName); |
| 105 | void clearObjectStore(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier); |
| 106 | void createIndex(const WebCore::IDBRequestData&, const WebCore::IDBIndexInfo&); |
| 107 | void deleteIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, const String& indexName); |
| 108 | void renameIndex(const WebCore::IDBRequestData&, uint64_t objectStoreIdentifier, uint64_t indexIdentifier, const String& newName); |
| 109 | void putOrAdd(const WebCore::IDBRequestData&, const WebCore::IDBKeyData&, const WebCore::IDBValue&, WebCore::IndexedDB::ObjectStoreOverwriteMode); |
| 110 | void getRecord(const WebCore::IDBRequestData&, const WebCore::IDBGetRecordData&); |
| 111 | void getAllRecords(const WebCore::IDBRequestData&, const WebCore::IDBGetAllRecordsData&); |
| 112 | void getCount(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&); |
| 113 | void deleteRecord(const WebCore::IDBRequestData&, const WebCore::IDBKeyRangeData&); |
| 114 | void openCursor(const WebCore::IDBRequestData&, const WebCore::IDBCursorInfo&); |
| 115 | void iterateCursor(const WebCore::IDBRequestData&, const WebCore::IDBIterateCursorData&); |
| 116 | |
| 117 | void establishTransaction(uint64_t databaseConnectionIdentifier, const WebCore::IDBTransactionInfo&); |
| 118 | void databaseConnectionPendingClose(uint64_t databaseConnectionIdentifier); |
| 119 | void databaseConnectionClosed(uint64_t databaseConnectionIdentifier); |
| 120 | void abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& transactionIdentifier); |
| 121 | void didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const WebCore::IDBResourceIdentifier& requestIdentifier); |
| 122 | void openDBRequestCancelled(const WebCore::IDBRequestData&); |
| 123 | void confirmDidCloseFromServer(uint64_t databaseConnectionIdentifier); |
| 124 | |
| 125 | void getAllDatabaseNames(uint64_t serverConnectionIdentifier, const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& openingOrigin, uint64_t callbackID); |
| 126 | |
| 127 | void disconnectedFromWebProcess(); |
| 128 | |
| 129 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&); |
| 130 | |
| 131 | private: |
| 132 | WebIDBConnectionToClient(NetworkProcess&, IPC::Connection&, uint64_t serverConnectionIdentifier, PAL::SessionID); |
| 133 | |
| 134 | IPC::Connection* messageSenderConnection() const final; |
| 135 | |
| 136 | template<class MessageType> void handleGetResult(const WebCore::IDBResultData&); |
| 137 | |
| 138 | Ref<IPC::Connection> m_connection; |
| 139 | Ref<NetworkProcess> m_networkProcess; |
| 140 | |
| 141 | uint64_t m_identifier; |
| 142 | PAL::SessionID m_sessionID; |
| 143 | RefPtr<WebCore::IDBServer::IDBConnectionToClient> m_connectionToClient; |
| 144 | }; |
| 145 | |
| 146 | } // namespace WebKit |
| 147 | |
| 148 | #endif // ENABLE(INDEXED_DATABASE) |
| 149 | |