| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "bindings/core/v8/ScriptState.h" | 29 #include "bindings/core/v8/ScriptState.h" |
| 30 #include "bindings/core/v8/V8HiddenValue.h" | 30 #include "bindings/core/v8/V8HiddenValue.h" |
| 31 #include "bindings/modules/v8/ToV8ForModules.h" | 31 #include "bindings/modules/v8/ToV8ForModules.h" |
| 32 #include "bindings/modules/v8/V8BindingForModules.h" | 32 #include "bindings/modules/v8/V8BindingForModules.h" |
| 33 #include "bindings/modules/v8/V8IDBRequest.h" | 33 #include "bindings/modules/v8/V8IDBRequest.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "modules/IndexedDBNames.h" | 35 #include "modules/IndexedDBNames.h" |
| 36 #include "modules/indexeddb/IDBAny.h" | 36 #include "modules/indexeddb/IDBAny.h" |
| 37 #include "modules/indexeddb/IDBCursorProxy.h" |
| 37 #include "modules/indexeddb/IDBDatabase.h" | 38 #include "modules/indexeddb/IDBDatabase.h" |
| 39 #include "modules/indexeddb/IDBDatabaseProxy.h" |
| 38 #include "modules/indexeddb/IDBObjectStore.h" | 40 #include "modules/indexeddb/IDBObjectStore.h" |
| 39 #include "modules/indexeddb/IDBTracing.h" | 41 #include "modules/indexeddb/IDBTracing.h" |
| 40 #include "modules/indexeddb/IDBTransaction.h" | 42 #include "modules/indexeddb/IDBTransaction.h" |
| 41 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | |
| 42 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | |
| 43 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" | 43 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" |
| 44 #include <limits> | 44 #include <limits> |
| 45 #include <memory> | 45 #include <memory> |
| 46 | 46 |
| 47 using blink::WebIDBCursor; | |
| 48 using blink::WebIDBDatabase; | |
| 49 | |
| 50 namespace blink { | 47 namespace blink { |
| 51 | 48 |
| 52 IDBCursor* IDBCursor::create(std::unique_ptr<WebIDBCursor> backend, WebIDBCursor
Direction direction, IDBRequest* request, IDBAny* source, IDBTransaction* transa
ction) | 49 using indexed_db::mojom::blink::CursorDirection; |
| 50 |
| 51 IDBCursor* IDBCursor::create(std::unique_ptr<IDBCursorProxy> backend, CursorDire
ction direction, IDBRequest* request, IDBAny* source, IDBTransaction* transactio
n) |
| 53 { | 52 { |
| 54 return new IDBCursor(std::move(backend), direction, request, source, transac
tion); | 53 return new IDBCursor(std::move(backend), direction, request, source, transac
tion); |
| 55 } | 54 } |
| 56 | 55 |
| 57 IDBCursor::IDBCursor(std::unique_ptr<WebIDBCursor> backend, WebIDBCursorDirectio
n direction, IDBRequest* request, IDBAny* source, IDBTransaction* transaction) | 56 IDBCursor::IDBCursor(std::unique_ptr<IDBCursorProxy> backend, CursorDirection di
rection, IDBRequest* request, IDBAny* source, IDBTransaction* transaction) |
| 58 : m_backend(std::move(backend)) | 57 : m_backend(std::move(backend)) |
| 59 , m_request(request) | 58 , m_request(request) |
| 60 , m_direction(direction) | 59 , m_direction(direction) |
| 61 , m_source(source) | 60 , m_source(source) |
| 62 , m_transaction(transaction) | 61 , m_transaction(transaction) |
| 63 { | 62 { |
| 64 ASSERT(m_backend); | 63 ASSERT(m_backend); |
| 65 ASSERT(m_request); | 64 ASSERT(m_request); |
| 66 ASSERT(m_source->getType() == IDBAny::IDBObjectStoreType || m_source->getTyp
e() == IDBAny::IDBIndexType); | 65 ASSERT(m_source->getType() == IDBAny::IDBObjectStoreType || m_source->getTyp
e() == IDBAny::IDBIndexType); |
| 67 ASSERT(m_transaction); | 66 ASSERT(m_transaction); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if (!m_transaction->isActive()) { | 112 if (!m_transaction->isActive()) { |
| 114 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 113 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 115 return nullptr; | 114 return nullptr; |
| 116 } | 115 } |
| 117 if (m_transaction->isReadOnly()) { | 116 if (m_transaction->isReadOnly()) { |
| 118 exceptionState.throwDOMException(ReadOnlyError, "The record may not be u
pdated inside a read-only transaction."); | 117 exceptionState.throwDOMException(ReadOnlyError, "The record may not be u
pdated inside a read-only transaction."); |
| 119 return nullptr; | 118 return nullptr; |
| 120 } | 119 } |
| 121 | 120 |
| 122 IDBObjectStore* objectStore = effectiveObjectStore(); | 121 IDBObjectStore* objectStore = effectiveObjectStore(); |
| 123 return objectStore->put(scriptState, WebIDBPutModeCursorUpdate, IDBAny::crea
te(this), value, m_primaryKey, exceptionState); | 122 return objectStore->put(scriptState, indexed_db::mojom::blink::PutMode::Curs
orUpdate, IDBAny::create(this), value, m_primaryKey, exceptionState); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void IDBCursor::advance(unsigned count, ExceptionState& exceptionState) | 125 void IDBCursor::advance(unsigned count, ExceptionState& exceptionState) |
| 127 { | 126 { |
| 128 IDB_TRACE("IDBCursor::advance"); | 127 IDB_TRACE("IDBCursor::advance"); |
| 129 if (!count) { | 128 if (!count) { |
| 130 exceptionState.throwTypeError("A count argument with value 0 (zero) was
supplied, must be greater than 0."); | 129 exceptionState.throwTypeError("A count argument with value 0 (zero) was
supplied, must be greater than 0."); |
| 131 return; | 130 return; |
| 132 } | 131 } |
| 133 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 132 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 134 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 133 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 135 return; | 134 return; |
| 136 } | 135 } |
| 137 if (!m_transaction->isActive()) { | 136 if (!m_transaction->isActive()) { |
| 138 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 137 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 139 return; | 138 return; |
| 140 } | 139 } |
| 141 if (!m_gotValue) { | 140 if (!m_gotValue) { |
| 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); | 141 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); |
| 143 return; | 142 return; |
| 144 } | 143 } |
| 145 if (isDeleted()) { | 144 if (isDeleted()) { |
| 146 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | 145 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 147 return; | 146 return; |
| 148 } | 147 } |
| 149 | 148 |
| 150 m_request->setPendingCursor(this); | 149 m_request->setPendingCursor(this); |
| 151 m_gotValue = false; | 150 m_gotValue = false; |
| 152 m_backend->advance(count, WebIDBCallbacksImpl::create(m_request).release()); | 151 m_backend->Advance(count); |
| 153 } | 152 } |
| 154 | 153 |
| 155 void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& ke
yValue, ExceptionState& exceptionState) | 154 void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& ke
yValue, ExceptionState& exceptionState) |
| 156 { | 155 { |
| 157 IDB_TRACE("IDBCursor::continue"); | 156 IDB_TRACE("IDBCursor::continue"); |
| 158 IDBKey* key = keyValue.isUndefined() || keyValue.isNull() ? nullptr : Script
Value::to<IDBKey*>(scriptState->isolate(), keyValue, exceptionState); | 157 IDBKey* key = keyValue.isUndefined() || keyValue.isNull() ? nullptr : Script
Value::to<IDBKey*>(scriptState->isolate(), keyValue, exceptionState); |
| 159 if (exceptionState.hadException()) | 158 if (exceptionState.hadException()) |
| 160 return; | 159 return; |
| 161 if (key && !key->isValid()) { | 160 if (key && !key->isValid()) { |
| 162 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 161 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 163 return; | 162 return; |
| 164 } | 163 } |
| 165 continueFunction(key, nullptr, exceptionState); | 164 continueFunction(key, nullptr, exceptionState); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue&
keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState) | 167 void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue&
keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState) |
| 169 { | 168 { |
| 170 IDB_TRACE("IDBCursor::continuePrimaryKey"); | 169 IDB_TRACE("IDBCursor::continuePrimaryKey"); |
| 171 if (m_source->getType() != IDBAny::IDBIndexType) { | 170 if (m_source->getType() != IDBAny::IDBIndexType) { |
| 172 exceptionState.throwDOMException(InvalidAccessError, "The cursor's sourc
e is not an index."); | 171 exceptionState.throwDOMException(InvalidAccessError, "The cursor's sourc
e is not an index."); |
| 173 return; | 172 return; |
| 174 } | 173 } |
| 175 if (m_direction != WebIDBCursorDirectionNext && m_direction != WebIDBCursorD
irectionPrev) { | 174 if (m_direction != CursorDirection::Next && m_direction != CursorDirection::
Prev) { |
| 176 exceptionState.throwDOMException(InvalidAccessError, "The cursor's direc
tion is not 'next' or 'prev'."); | 175 exceptionState.throwDOMException(InvalidAccessError, "The cursor's direc
tion is not 'next' or 'prev'."); |
| 177 return; | 176 return; |
| 178 } | 177 } |
| 179 | 178 |
| 180 IDBKey* key = ScriptValue::to<IDBKey*>(scriptState->isolate(), keyValue, exc
eptionState); | 179 IDBKey* key = ScriptValue::to<IDBKey*>(scriptState->isolate(), keyValue, exc
eptionState); |
| 181 if (exceptionState.hadException()) | 180 if (exceptionState.hadException()) |
| 182 return; | 181 return; |
| 183 if (!key->isValid()) { | 182 if (!key->isValid()) { |
| 184 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 183 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 185 return; | 184 return; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 214 return; | 213 return; |
| 215 } | 214 } |
| 216 | 215 |
| 217 if (isDeleted()) { | 216 if (isDeleted()) { |
| 218 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | 217 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 219 return; | 218 return; |
| 220 } | 219 } |
| 221 | 220 |
| 222 if (key) { | 221 if (key) { |
| 223 ASSERT(m_key); | 222 ASSERT(m_key); |
| 224 if (m_direction == WebIDBCursorDirectionNext || m_direction == WebIDBCur
sorDirectionNextNoDuplicate) { | 223 if (m_direction == CursorDirection::Next || m_direction == CursorDirecti
on::NextNoDuplicate) { |
| 225 const bool ok = m_key->isLessThan(key) | 224 const bool ok = m_key->isLessThan(key) |
| 226 || (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessTha
n(primaryKey)); | 225 || (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessTha
n(primaryKey)); |
| 227 if (!ok) { | 226 if (!ok) { |
| 228 exceptionState.throwDOMException(DataError, "The parameter is le
ss than or equal to this cursor's position."); | 227 exceptionState.throwDOMException(DataError, "The parameter is le
ss than or equal to this cursor's position."); |
| 229 return; | 228 return; |
| 230 } | 229 } |
| 231 | 230 |
| 232 } else { | 231 } else { |
| 233 const bool ok = key->isLessThan(m_key.get()) | 232 const bool ok = key->isLessThan(m_key.get()) |
| 234 || (primaryKey && key->isEqual(m_key.get()) && primaryKey->isLes
sThan(m_primaryKey.get())); | 233 || (primaryKey && key->isEqual(m_key.get()) && primaryKey->isLes
sThan(m_primaryKey.get())); |
| 235 if (!ok) { | 234 if (!ok) { |
| 236 exceptionState.throwDOMException(DataError, "The parameter is gr
eater than or equal to this cursor's position."); | 235 exceptionState.throwDOMException(DataError, "The parameter is gr
eater than or equal to this cursor's position."); |
| 237 return; | 236 return; |
| 238 } | 237 } |
| 239 } | 238 } |
| 240 } | 239 } |
| 241 | 240 |
| 242 // FIXME: We're not using the context from when continue was called, which m
eans the callback | 241 // FIXME: We're not using the context from when continue was called, which m
eans the callback |
| 243 // will be on the original context openCursor was called on. Is this
right? | 242 // will be on the original context openCursor was called on. Is this
right? |
| 244 m_request->setPendingCursor(this); | 243 m_request->setPendingCursor(this); |
| 245 m_gotValue = false; | 244 m_gotValue = false; |
| 246 m_backend->continueFunction(key, primaryKey, WebIDBCallbacksImpl::create(m_r
equest).release()); | 245 m_backend->ContinueFunction(key, primaryKey); |
| 247 } | 246 } |
| 248 | 247 |
| 249 IDBRequest* IDBCursor::deleteFunction(ScriptState* scriptState, ExceptionState&
exceptionState) | 248 IDBRequest* IDBCursor::deleteFunction(ScriptState* scriptState, ExceptionState&
exceptionState) |
| 250 { | 249 { |
| 251 IDB_TRACE("IDBCursor::delete"); | 250 IDB_TRACE("IDBCursor::delete"); |
| 252 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 251 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 253 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 252 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 254 return nullptr; | 253 return nullptr; |
| 255 } | 254 } |
| 256 if (!m_transaction->isActive()) { | 255 if (!m_transaction->isActive()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 276 } | 275 } |
| 277 if (!m_transaction->backendDB()) { | 276 if (!m_transaction->backendDB()) { |
| 278 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 277 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 279 return nullptr; | 278 return nullptr; |
| 280 } | 279 } |
| 281 | 280 |
| 282 IDBKeyRange* keyRange = IDBKeyRange::only(m_primaryKey, exceptionState); | 281 IDBKeyRange* keyRange = IDBKeyRange::only(m_primaryKey, exceptionState); |
| 283 ASSERT(!exceptionState.hadException()); | 282 ASSERT(!exceptionState.hadException()); |
| 284 | 283 |
| 285 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 284 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 286 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject
Store()->id(), keyRange, WebIDBCallbacksImpl::create(request).release()); | 285 m_transaction->backendDB()->DeleteRange(m_transaction->id(), effectiveObject
Store()->id(), keyRange); |
| 287 return request; | 286 return request; |
| 288 } | 287 } |
| 289 | 288 |
| 290 void IDBCursor::postSuccessHandlerCallback() | 289 void IDBCursor::postSuccessHandlerCallback() |
| 291 { | 290 { |
| 292 if (m_backend) | 291 if (m_backend) |
| 293 m_backend->postSuccessHandlerCallback(); | 292 m_backend->PostSuccessHandlerCallback(); |
| 294 } | 293 } |
| 295 | 294 |
| 296 void IDBCursor::close() | 295 void IDBCursor::close() |
| 297 { | 296 { |
| 298 m_value.clear(); | 297 m_value.clear(); |
| 299 m_request.clear(); | 298 m_request.clear(); |
| 300 m_backend.reset(); | 299 m_backend.reset(); |
| 301 } | 300 } |
| 302 | 301 |
| 303 ScriptValue IDBCursor::key(ScriptState* scriptState) | 302 ScriptValue IDBCursor::key(ScriptState* scriptState) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 return m_source->idbIndex()->objectStore(); | 363 return m_source->idbIndex()->objectStore(); |
| 365 } | 364 } |
| 366 | 365 |
| 367 bool IDBCursor::isDeleted() const | 366 bool IDBCursor::isDeleted() const |
| 368 { | 367 { |
| 369 if (m_source->getType() == IDBAny::IDBObjectStoreType) | 368 if (m_source->getType() == IDBAny::IDBObjectStoreType) |
| 370 return m_source->idbObjectStore()->isDeleted(); | 369 return m_source->idbObjectStore()->isDeleted(); |
| 371 return m_source->idbIndex()->isDeleted(); | 370 return m_source->idbIndex()->isDeleted(); |
| 372 } | 371 } |
| 373 | 372 |
| 374 WebIDBCursorDirection IDBCursor::stringToDirection(const String& directionString
) | 373 CursorDirection IDBCursor::stringToDirection(const String& directionString) |
| 375 { | 374 { |
| 376 if (directionString == IndexedDBNames::next) | 375 if (directionString == IndexedDBNames::next) |
| 377 return WebIDBCursorDirectionNext; | 376 return CursorDirection::Next; |
| 378 if (directionString == IndexedDBNames::nextunique) | 377 if (directionString == IndexedDBNames::nextunique) |
| 379 return WebIDBCursorDirectionNextNoDuplicate; | 378 return CursorDirection::NextNoDuplicate; |
| 380 if (directionString == IndexedDBNames::prev) | 379 if (directionString == IndexedDBNames::prev) |
| 381 return WebIDBCursorDirectionPrev; | 380 return CursorDirection::Prev; |
| 382 if (directionString == IndexedDBNames::prevunique) | 381 if (directionString == IndexedDBNames::prevunique) |
| 383 return WebIDBCursorDirectionPrevNoDuplicate; | 382 return CursorDirection::PrevNoDuplicate; |
| 384 | 383 |
| 385 ASSERT_NOT_REACHED(); | 384 ASSERT_NOT_REACHED(); |
| 386 return WebIDBCursorDirectionNext; | 385 return CursorDirection::Next; |
| 387 } | 386 } |
| 388 | 387 |
| 389 const String& IDBCursor::direction() const | 388 const String& IDBCursor::direction() const |
| 390 { | 389 { |
| 391 switch (m_direction) { | 390 switch (m_direction) { |
| 392 case WebIDBCursorDirectionNext: | 391 case CursorDirection::Next: |
| 393 return IndexedDBNames::next; | 392 return IndexedDBNames::next; |
| 394 | 393 |
| 395 case WebIDBCursorDirectionNextNoDuplicate: | 394 case CursorDirection::NextNoDuplicate: |
| 396 return IndexedDBNames::nextunique; | 395 return IndexedDBNames::nextunique; |
| 397 | 396 |
| 398 case WebIDBCursorDirectionPrev: | 397 case CursorDirection::Prev: |
| 399 return IndexedDBNames::prev; | 398 return IndexedDBNames::prev; |
| 400 | 399 |
| 401 case WebIDBCursorDirectionPrevNoDuplicate: | 400 case CursorDirection::PrevNoDuplicate: |
| 402 return IndexedDBNames::prevunique; | 401 return IndexedDBNames::prevunique; |
| 403 | 402 |
| 404 default: | 403 default: |
| 405 ASSERT_NOT_REACHED(); | 404 ASSERT_NOT_REACHED(); |
| 406 return IndexedDBNames::next; | 405 return IndexedDBNames::next; |
| 407 } | 406 } |
| 408 } | 407 } |
| 409 | 408 |
| 410 } // namespace blink | 409 } // namespace blink |
| OLD | NEW |