| 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> | |
| 41 | 40 |
| 42 using blink::WebIDBCallbacks; | 41 using blink::WebIDBCallbacks; |
| 43 using blink::WebIDBCursor; | 42 using blink::WebIDBCursor; |
| 44 using blink::WebIDBDatabase; | 43 using blink::WebIDBDatabase; |
| 45 | 44 |
| 46 namespace blink { | 45 namespace blink { |
| 47 | 46 |
| 48 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) | 47 IDBIndex::IDBIndex(const IDBIndexMetadata& metadata, IDBObjectStore* objectStore
, IDBTransaction* transaction) |
| 49 : m_metadata(metadata) | 48 : m_metadata(metadata) |
| 50 , m_objectStore(objectStore) | 49 , m_objectStore(objectStore) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return nullptr; | 94 return nullptr; |
| 96 } | 95 } |
| 97 | 96 |
| 98 return openCursor(scriptState, keyRange, direction); | 97 return openCursor(scriptState, keyRange, direction); |
| 99 } | 98 } |
| 100 | 99 |
| 101 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) | 100 IDBRequest* IDBIndex::openCursor(ScriptState* scriptState, IDBKeyRange* keyRange
, WebIDBCursorDirection direction) |
| 102 { | 101 { |
| 103 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 102 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 104 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 103 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()); | 104 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, false, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::crea
te(request).leakPtr()); |
| 106 return request; | 105 return request; |
| 107 } | 106 } |
| 108 | 107 |
| 109 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 108 IDBRequest* IDBIndex::count(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) |
| 110 { | 109 { |
| 111 IDB_TRACE("IDBIndex::count"); | 110 IDB_TRACE("IDBIndex::count"); |
| 112 if (isDeleted()) { | 111 if (isDeleted()) { |
| 113 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 112 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 114 return nullptr; | 113 return nullptr; |
| 115 } | 114 } |
| 116 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 115 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 117 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 116 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 118 return nullptr; | 117 return nullptr; |
| 119 } | 118 } |
| 120 if (!m_transaction->isActive()) { | 119 if (!m_transaction->isActive()) { |
| 121 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 120 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 122 return nullptr; | 121 return nullptr; |
| 123 } | 122 } |
| 124 | 123 |
| 125 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 124 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 126 if (exceptionState.hadException()) | 125 if (exceptionState.hadException()) |
| 127 return nullptr; | 126 return nullptr; |
| 128 | 127 |
| 129 if (!backendDB()) { | 128 if (!backendDB()) { |
| 130 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 129 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 131 return nullptr; | 130 return nullptr; |
| 132 } | 131 } |
| 133 | 132 |
| 134 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 133 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()); | 134 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id,
keyRange, WebIDBCallbacksImpl::create(request).leakPtr()); |
| 136 return request; | 135 return request; |
| 137 } | 136 } |
| 138 | 137 |
| 139 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) | 138 IDBRequest* IDBIndex::openKeyCursor(ScriptState* scriptState, const ScriptValue&
range, const String& directionString, ExceptionState& exceptionState) |
| 140 { | 139 { |
| 141 IDB_TRACE("IDBIndex::openKeyCursor"); | 140 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 142 if (isDeleted()) { | 141 if (isDeleted()) { |
| 143 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); | 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::indexDe
letedErrorMessage); |
| 144 return nullptr; | 143 return nullptr; |
| 145 } | 144 } |
| 146 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 145 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 147 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 146 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 148 return nullptr; | 147 return nullptr; |
| 149 } | 148 } |
| 150 if (!m_transaction->isActive()) { | 149 if (!m_transaction->isActive()) { |
| 151 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 150 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 152 return nullptr; | 151 return nullptr; |
| 153 } | 152 } |
| 154 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); | 153 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng); |
| 155 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); | 154 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->getExecuti
onContext(), range, exceptionState); |
| 156 if (exceptionState.hadException()) | 155 if (exceptionState.hadException()) |
| 157 return nullptr; | 156 return nullptr; |
| 158 if (!backendDB()) { | 157 if (!backendDB()) { |
| 159 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 158 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 160 return nullptr; | 159 return nullptr; |
| 161 } | 160 } |
| 162 | 161 |
| 163 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 162 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 164 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 163 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()); | 164 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata
.id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::creat
e(request).leakPtr()); |
| 166 return request; | 165 return request; |
| 167 } | 166 } |
| 168 | 167 |
| 169 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) | 168 IDBRequest* IDBIndex::get(ScriptState* scriptState, const ScriptValue& key, Exce
ptionState& exceptionState) |
| 170 { | 169 { |
| 171 IDB_TRACE("IDBIndex::get"); | 170 IDB_TRACE("IDBIndex::get"); |
| 172 return getInternal(scriptState, key, exceptionState, false); | 171 return getInternal(scriptState, key, exceptionState, false); |
| 173 } | 172 } |
| 174 | 173 |
| 175 IDBRequest* IDBIndex::getAll(ScriptState* scriptState, const ScriptValue& range,
ExceptionState& exceptionState) | 174 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) { | 220 if (!keyRange) { |
| 222 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 221 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
| 223 return nullptr; | 222 return nullptr; |
| 224 } | 223 } |
| 225 if (!backendDB()) { | 224 if (!backendDB()) { |
| 226 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 225 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 227 return nullptr; | 226 return nullptr; |
| 228 } | 227 } |
| 229 | 228 |
| 230 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 229 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()); | 230 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke
yRange, keyOnly, WebIDBCallbacksImpl::create(request).leakPtr()); |
| 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, WebIDBCallbacksImpl::create(request).leakPtr()); |
| 263 return request; | 262 return request; |
| 264 } | 263 } |
| 265 | 264 |
| 266 WebIDBDatabase* IDBIndex::backendDB() const | 265 WebIDBDatabase* 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 |