| 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 19 matching lines...) Expand all Loading... |
| 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/IDBKey.h" | 34 #include "modules/indexeddb/IDBKey.h" |
| 35 #include "modules/indexeddb/IDBObjectStore.h" | 35 #include "modules/indexeddb/IDBObjectStore.h" |
| 36 #include "modules/indexeddb/IDBTracing.h" | 36 #include "modules/indexeddb/IDBTracing.h" |
| 37 #include "modules/indexeddb/IDBTransaction.h" | 37 #include "modules/indexeddb/IDBTransaction.h" |
| 38 #include "modules/indexeddb/WebIDBCallbacksImpl.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 | 41 |
| 41 using blink::WebIDBCallbacks; | 42 using blink::WebIDBCallbacks; |
| 42 using blink::WebIDBCursor; | 43 using blink::WebIDBCursor; |
| 43 using blink::WebIDBDatabase; | 44 using blink::WebIDBDatabase; |
| 44 | 45 |
| 45 namespace blink { | 46 namespace blink { |
| 46 | 47 |
| 47 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) | 48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) |
| 48 : m_metadata(metadata) | 49 : m_metadata(metadata) |
| 49 , m_objectStore(objectStore) | 50 , m_objectStore(objectStore) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return nullptr; | 95 return nullptr; |
| 95 } | 96 } |
| 96 | 97 |
| 97 return openCursor(scriptState, keyRange, direction); | 98 return openCursor(scriptState, keyRange, direction); |
| 98 } | 99 } |
| 99 | 100 |
| 100 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) | 101 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) |
| 101 { | 102 { |
| 102 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 103 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 103 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 104 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 104 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea
te(request).leakPtr()); | 105 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea
te(request).release()); |
| 105 return request; | 106 return request; |
| 106 } | 107 } |
| 107 | 108 |
| 108 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 109 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
| 109 { | 110 { |
| 110 IDB_TRACE("IDBIndex::count"); | 111 IDB_TRACE("IDBIndex::count"); |
| 111 if (isDeleted()) { | 112 if (isDeleted()) { |
| 112 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 113 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 113 return nullptr; | 114 return nullptr; |
| 114 } | 115 } |
| 115 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 116 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 116 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 117 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 117 return nullptr; | 118 return nullptr; |
| 118 } | 119 } |
| 119 if (!m_transaction->isActive()) { | 120 if (!m_transaction->isActive()) { |
| 120 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 121 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 121 return nullptr; | 122 return nullptr; |
| 122 } | 123 } |
| 123 | 124 |
| 124 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 125 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 125 if (exceptionState.hadException()) | 126 if (exceptionState.hadException()) |
| 126 return nullptr; | 127 return nullptr; |
| 127 | 128 |
| 128 if (!backendDB()) { | 129 if (!backendDB()) { |
| 129 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 130 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 130 return nullptr; | 131 return nullptr; |
| 131 } | 132 } |
| 132 | 133 |
| 133 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 134 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 134 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, WebIDBCallbacksImpl::create(request).leakPtr()); | 135 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, WebIDBCallbacksImpl::create(request).release()); |
| 135 return request; | 136 return request; |
| 136 } | 137 } |
| 137 | 138 |
| 138 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) | 139 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) |
| 139 { | 140 { |
| 140 IDB_TRACE("IDBIndex::openKeyCursor"); | 141 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 141 if (isDeleted()) { | 142 if (isDeleted()) { |
| 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 143 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 143 return nullptr; | 144 return nullptr; |
| 144 } | 145 } |
| 145 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 146 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 146 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 147 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 147 return nullptr; | 148 return nullptr; |
| 148 } | 149 } |
| 149 if (!m_transaction->isActive()) { | 150 if (!m_transaction->isActive()) { |
| 150 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 151 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 151 return nullptr; | 152 return nullptr; |
| 152 } | 153 } |
| 153 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); | 154 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); |
| 154 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 155 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 155 if (exceptionState.hadException()) | 156 if (exceptionState.hadException()) |
| 156 return nullptr; | 157 return nullptr; |
| 157 if (!backendDB()) { | 158 if (!backendDB()) { |
| 158 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 159 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 159 return nullptr; | 160 return nullptr; |
| 160 } | 161 } |
| 161 | 162 |
| 162 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 163 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 163 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 164 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
| 164 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat
e(request).leakPtr()); | 165 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat
e(request).release()); |
| 165 return request; | 166 return request; |
| 166 } | 167 } |
| 167 | 168 |
| 168 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) | 169 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) |
| 169 { | 170 { |
| 170 IDB_TRACE("IDBIndex::get"); | 171 IDB_TRACE("IDBIndex::get"); |
| 171 return getInternal(scriptState, key, exceptionState, false); | 172 return getInternal(scriptState, key, exceptionState, false); |
| 172 } | 173 } |
| 173 | 174 |
| 174 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 175 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (!keyRange) { | 221 if (!keyRange) { |
| 221 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 222 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
| 222 return nullptr; | 223 return nullptr; |
| 223 } | 224 } |
| 224 if (!backendDB()) { | 225 if (!backendDB()) { |
| 225 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 226 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 226 return nullptr; | 227 return nullptr; |
| 227 } | 228 } |
| 228 | 229 |
| 229 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 230 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 230 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, keyOnly, WebIDBCallbacksImpl::create(request).leakPtr()); | 231 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, keyOnly, WebIDBCallbacksImpl::create(request).release()); |
| 231 return request; | 232 return request; |
| 232 } | 233 } |
| 233 | 234 |
| 234 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
& range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) | 235 IDBRequest* IDBIndex::getAllInternal(ScriptState* scriptState, const ScriptValue
& range, unsigned long maxCount, ExceptionState& exceptionState, bool keyOnly) |
| 235 { | 236 { |
| 236 if (!maxCount) | 237 if (!maxCount) |
| 237 maxCount = std::numeric_limits<uint32_t>::max(); | 238 maxCount = std::numeric_limits<uint32_t>::max(); |
| 238 | 239 |
| 239 if (isDeleted()) { | 240 if (isDeleted()) { |
| 240 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 241 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 251 | 252 |
| 252 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 253 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 253 if (exceptionState.hadException()) | 254 if (exceptionState.hadException()) |
| 254 return nullptr; | 255 return nullptr; |
| 255 if (!backendDB()) { | 256 if (!backendDB()) { |
| 256 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 257 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 257 return nullptr; | 258 return nullptr; |
| 258 } | 259 } |
| 259 | 260 |
| 260 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 261 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 261 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).leakPtr()); | 262 backendDB()->getAll(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, maxCount, keyOnly, WebIDBCallbacksImpl::create(request).release()); |
| 262 return request; | 263 return request; |
| 263 } | 264 } |
| 264 | 265 |
| 265 WebIDBDatabase* IDBIndex::backendDB() const | 266 WebIDBDatabase* IDBIndex::backendDB() const |
| 266 { | 267 { |
| 267 return m_transaction->backendDB(); | 268 return m_transaction->backendDB(); |
| 268 } | 269 } |
| 269 | 270 |
| 270 bool IDBIndex::isDeleted() const | 271 bool IDBIndex::isDeleted() const |
| 271 { | 272 { |
| 272 return m_deleted || m_objectStore->isDeleted(); | 273 return m_deleted || m_objectStore->isDeleted(); |
| 273 } | 274 } |
| 274 | 275 |
| 275 } // namespace blink | 276 } // namespace blink |
| OLD | NEW |