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