| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "modules/indexeddb/IDBIndex.h" | 26 #include "modules/indexeddb/IDBIndex.h" |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/modules/v8/ToV8ForModules.h" | 29 #include "bindings/modules/v8/ToV8ForModules.h" |
| 30 #include "bindings/modules/v8/V8BindingForModules.h" | 30 #include "bindings/modules/v8/V8BindingForModules.h" |
| 31 #include "core/dom/ExceptionCode.h" | 31 #include "core/dom/ExceptionCode.h" |
| 32 #include "core/dom/ExecutionContext.h" | 32 #include "core/dom/ExecutionContext.h" |
| 33 #include "modules/indexeddb/IDBDatabase.h" | 33 #include "modules/indexeddb/IDBDatabase.h" |
| 34 #include "modules/indexeddb/IDBDatabaseProxy.h" |
| 34 #include "modules/indexeddb/IDBKey.h" | 35 #include "modules/indexeddb/IDBKey.h" |
| 35 #include "modules/indexeddb/IDBObjectStore.h" | 36 #include "modules/indexeddb/IDBObjectStore.h" |
| 36 #include "modules/indexeddb/IDBTracing.h" | 37 #include "modules/indexeddb/IDBTracing.h" |
| 37 #include "modules/indexeddb/IDBTransaction.h" | 38 #include "modules/indexeddb/IDBTransaction.h" |
| 38 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | |
| 39 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" | 39 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" |
| 40 #include <memory> | 40 #include <memory> |
| 41 | 41 |
| 42 using blink::WebIDBCallbacks; | 42 using indexed_db::mojom::blink::CursorDirection; |
| 43 using blink::WebIDBCursor; | |
| 44 using blink::WebIDBDatabase; | |
| 45 | 43 |
| 46 namespace blink { | 44 namespace blink { |
| 47 | 45 |
| 48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) | 46 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) |
| 49 : m_metadata(metadata) | 47 : m_metadata(metadata) |
| 50 , m_objectStore(objectStore) | 48 , m_objectStore(objectStore) |
| 51 , m_transaction(transaction) | 49 , m_transaction(transaction) |
| 52 { | 50 { |
| 53 ASSERT(m_objectStore); | 51 ASSERT(m_objectStore); |
| 54 ASSERT(m_transaction); | 52 ASSERT(m_transaction); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 78 return nullptr; | 76 return nullptr; |
| 79 } | 77 } |
| 80 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 78 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 81 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 79 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 82 return nullptr; | 80 return nullptr; |
| 83 } | 81 } |
| 84 if (!m_transaction->isActive()) { | 82 if (!m_transaction->isActive()) { |
| 85 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 83 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 86 return nullptr; | 84 return nullptr; |
| 87 } | 85 } |
| 88 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); | 86 CursorDirection direction = IDBCursor::stringToDirection(directionString); |
| 89 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 87 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 90 if (exceptionState.hadException()) | 88 if (exceptionState.hadException()) |
| 91 return nullptr; | 89 return nullptr; |
| 92 | 90 |
| 93 if (!backendDB()) { | 91 if (!backendDB()) { |
| 94 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 92 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 95 return nullptr; | 93 return nullptr; |
| 96 } | 94 } |
| 97 | 95 |
| 98 return openCursor(scriptState, keyRange, direction); | 96 return openCursor(scriptState, keyRange, direction); |
| 99 } | 97 } |
| 100 | 98 |
| 101 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) | 99 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, CursorDirection direction) |
| 102 { | 100 { |
| 103 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 101 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 104 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 102 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 105 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea
te(request).release()); | 103 backendDB()->OpenCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, indexed_db::mojom::blink::TaskType::Normal); |
| 106 return request; | 104 return request; |
| 107 } | 105 } |
| 108 | 106 |
| 109 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 107 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
| 110 { | 108 { |
| 111 IDB_TRACE("IDBIndex::count"); | 109 IDB_TRACE("IDBIndex::count"); |
| 112 if (isDeleted()) { | 110 if (isDeleted()) { |
| 113 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 111 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 114 return nullptr; | 112 return nullptr; |
| 115 } | 113 } |
| 116 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 114 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 117 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 115 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 118 return nullptr; | 116 return nullptr; |
| 119 } | 117 } |
| 120 if (!m_transaction->isActive()) { | 118 if (!m_transaction->isActive()) { |
| 121 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 119 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 122 return nullptr; | 120 return nullptr; |
| 123 } | 121 } |
| 124 | 122 |
| 125 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 123 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 126 if (exceptionState.hadException()) | 124 if (exceptionState.hadException()) |
| 127 return nullptr; | 125 return nullptr; |
| 128 | 126 |
| 129 if (!backendDB()) { | 127 if (!backendDB()) { |
| 130 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 128 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 131 return nullptr; | 129 return nullptr; |
| 132 } | 130 } |
| 133 | 131 |
| 134 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 132 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 135 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, WebIDBCallbacksImpl::create(request).release()); | 133 backendDB()->Count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange); |
| 136 return request; | 134 return request; |
| 137 } | 135 } |
| 138 | 136 |
| 139 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) | 137 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) |
| 140 { | 138 { |
| 141 IDB_TRACE("IDBIndex::openKeyCursor"); | 139 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 142 if (isDeleted()) { | 140 if (isDeleted()) { |
| 143 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 141 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 144 return nullptr; | 142 return nullptr; |
| 145 } | 143 } |
| 146 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 144 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 147 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 145 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 148 return nullptr; | 146 return nullptr; |
| 149 } | 147 } |
| 150 if (!m_transaction->isActive()) { | 148 if (!m_transaction->isActive()) { |
| 151 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 149 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 152 return nullptr; | 150 return nullptr; |
| 153 } | 151 } |
| 154 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); | 152 CursorDirection direction = IDBCursor::stringToDirection(directionString); |
| 155 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 153 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 156 if (exceptionState.hadException()) | 154 if (exceptionState.hadException()) |
| 157 return nullptr; | 155 return nullptr; |
| 158 if (!backendDB()) { | 156 if (!backendDB()) { |
| 159 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 157 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 160 return nullptr; | 158 return nullptr; |
| 161 } | 159 } |
| 162 | 160 |
| 163 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 161 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 164 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 162 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
| 165 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat
e(request).release()); | 163 backendDB()->OpenCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, indexed_db::mojom::blink::TaskType::Normal); |
| 166 return request; | 164 return request; |
| 167 } | 165 } |
| 168 | 166 |
| 169 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) | 167 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) |
| 170 { | 168 { |
| 171 IDB_TRACE("IDBIndex::get"); | 169 IDB_TRACE("IDBIndex::get"); |
| 172 return getInternal(scriptState, key, exceptionState, false); | 170 return getInternal(scriptState, key, exceptionState, false); |
| 173 } | 171 } |
| 174 | 172 |
| 175 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 173 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if (!keyRange) { | 219 if (!keyRange) { |
| 222 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 220 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
| 223 return nullptr; | 221 return nullptr; |
| 224 } | 222 } |
| 225 if (!backendDB()) { | 223 if (!backendDB()) { |
| 226 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 224 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 227 return nullptr; | 225 return nullptr; |
| 228 } | 226 } |
| 229 | 227 |
| 230 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 228 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 231 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, keyOnly, WebIDBCallbacksImpl::create(request).release()); | 229 indexed_db::mojom::blink::Database::GetCallback getCallback = convertToBaseC
allback(WTF::bind(&IDBRequest::onGetResult, wrapWeakPersistent(request))); |
| 230 backendDB()->Get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, keyOnly, getCallback); |
| 232 return request; | 231 return request; |
| 233 } | 232 } |
| 234 | 233 |
| 235 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
& range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) | 234 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
& range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) |
| 236 { | 235 { |
| 237 if (!maxCount) | 236 if (!maxCount) |
| 238 maxCount = std::numeric_limits<uint32_t>::max(); | 237 maxCount = std::numeric_limits<uint32_t>::max(); |
| 239 | 238 |
| 240 if (isDeleted()) { | 239 if (isDeleted()) { |
| 241 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 240 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 252 | 251 |
| 253 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 252 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 254 if (exceptionState.hadException()) | 253 if (exceptionState.hadException()) |
| 255 return nullptr; | 254 return nullptr; |
| 256 if (!backendDB()) { | 255 if (!backendDB()) { |
| 257 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 256 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 258 return nullptr; | 257 return nullptr; |
| 259 } | 258 } |
| 260 | 259 |
| 261 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 260 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 262 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); | 261 backendDB()->GetAll(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, maxCount, keyOnly); |
| 263 return request; | 262 return request; |
| 264 } | 263 } |
| 265 | 264 |
| 266 WebIDBDatabase* IDBIndex::backendDB() const | 265 IDBDatabaseProxy* IDBIndex::backendDB() const |
| 267 { | 266 { |
| 268 return m_transaction->backendDB(); | 267 return m_transaction->backendDB(); |
| 269 } | 268 } |
| 270 | 269 |
| 271 bool IDBIndex::isDeleted() const | 270 bool IDBIndex::isDeleted() const |
| 272 { | 271 { |
| 273 return m_deleted || m_objectStore->isDeleted(); | 272 return m_deleted || m_objectStore->isDeleted(); |
| 274 } | 273 } |
| 275 | 274 |
| 276 } // namespace blink | 275 } // namespace blink |
| OLD | NEW |