| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) | 66 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) |
| 67 indexNames->append(it->value.name); | 67 indexNames->append(it->value.name); |
| 68 indexNames->sort(); | 68 indexNames->sort(); |
| 69 return indexNames.release(); | 69 return indexNames.release(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
RefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) | 72 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
RefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) |
| 73 { | 73 { |
| 74 IDB_TRACE("IDBObjectStore::get"); | 74 IDB_TRACE("IDBObjectStore::get"); |
| 75 if (isDeleted()) { | 75 if (isDeleted()) { |
| 76 ec = INVALID_STATE_ERR; | 76 ec = InvalidStateError; |
| 77 return 0; | 77 return 0; |
| 78 } | 78 } |
| 79 if (!keyRange) { | 79 if (!keyRange) { |
| 80 ec = DataError; | 80 ec = DataError; |
| 81 return 0; | 81 return 0; |
| 82 } | 82 } |
| 83 if (!m_transaction->isActive()) { | 83 if (!m_transaction->isActive()) { |
| 84 ec = TransactionInactiveError; | 84 ec = TransactionInactiveError; |
| 85 return 0; | 85 return 0; |
| 86 } | 86 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 ScriptExecutionContext* context = state->scriptExecutionContext(); | 137 ScriptExecutionContext* context = state->scriptExecutionContext(); |
| 138 DOMRequestState requestState(context); | 138 DOMRequestState requestState(context); |
| 139 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque
stState, keyValue); | 139 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque
stState, keyValue); |
| 140 return put(putMode, source, state, value, key.release(), ec); | 140 return put(putMode, source, state, value, key.release(), ec); |
| 141 } | 141 } |
| 142 | 142 |
| 143 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass
RefPtr<IDBKey> prpKey, ExceptionCode& ec) | 143 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode
putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass
RefPtr<IDBKey> prpKey, ExceptionCode& ec) |
| 144 { | 144 { |
| 145 RefPtr<IDBKey> key = prpKey; | 145 RefPtr<IDBKey> key = prpKey; |
| 146 if (isDeleted()) { | 146 if (isDeleted()) { |
| 147 ec = INVALID_STATE_ERR; | 147 ec = InvalidStateError; |
| 148 return 0; | 148 return 0; |
| 149 } | 149 } |
| 150 if (!m_transaction->isActive()) { | 150 if (!m_transaction->isActive()) { |
| 151 ec = TransactionInactiveError; | 151 ec = TransactionInactiveError; |
| 152 return 0; | 152 return 0; |
| 153 } | 153 } |
| 154 if (m_transaction->isReadOnly()) { | 154 if (m_transaction->isReadOnly()) { |
| 155 ec = ReadOnlyError; | 155 ec = ReadOnlyError; |
| 156 return 0; | 156 return 0; |
| 157 } | 157 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 serializedValue->toWireBytes(wireBytes); | 223 serializedValue->toWireBytes(wireBytes); |
| 224 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 224 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
| 225 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat
ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index
Keys); | 225 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat
ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index
Keys); |
| 226 return request.release(); | 226 return request.release(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) | 229 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) |
| 230 { | 230 { |
| 231 IDB_TRACE("IDBObjectStore::delete"); | 231 IDB_TRACE("IDBObjectStore::delete"); |
| 232 if (isDeleted()) { | 232 if (isDeleted()) { |
| 233 ec = INVALID_STATE_ERR; | 233 ec = InvalidStateError; |
| 234 return 0; | 234 return 0; |
| 235 } | 235 } |
| 236 if (!m_transaction->isActive()) { | 236 if (!m_transaction->isActive()) { |
| 237 ec = TransactionInactiveError; | 237 ec = TransactionInactiveError; |
| 238 return 0; | 238 return 0; |
| 239 } | 239 } |
| 240 if (m_transaction->isReadOnly()) { | 240 if (m_transaction->isReadOnly()) { |
| 241 ec = ReadOnlyError; | 241 ec = ReadOnlyError; |
| 242 return 0; | 242 return 0; |
| 243 } | 243 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 256 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 256 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
| 257 if (ec) | 257 if (ec) |
| 258 return 0; | 258 return 0; |
| 259 return deleteFunction(context, keyRange.release(), ec); | 259 return deleteFunction(context, keyRange.release(), ec); |
| 260 } | 260 } |
| 261 | 261 |
| 262 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex
ceptionCode& ec) | 262 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex
ceptionCode& ec) |
| 263 { | 263 { |
| 264 IDB_TRACE("IDBObjectStore::clear"); | 264 IDB_TRACE("IDBObjectStore::clear"); |
| 265 if (isDeleted()) { | 265 if (isDeleted()) { |
| 266 ec = INVALID_STATE_ERR; | 266 ec = InvalidStateError; |
| 267 return 0; | 267 return 0; |
| 268 } | 268 } |
| 269 if (!m_transaction->isActive()) { | 269 if (!m_transaction->isActive()) { |
| 270 ec = TransactionInactiveError; | 270 ec = TransactionInactiveError; |
| 271 return 0; | 271 return 0; |
| 272 } | 272 } |
| 273 if (m_transaction->isReadOnly()) { | 273 if (m_transaction->isReadOnly()) { |
| 274 ec = ReadOnlyError; | 274 ec = ReadOnlyError; |
| 275 return 0; | 275 return 0; |
| 276 } | 276 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 bool multiEntry = false; | 358 bool multiEntry = false; |
| 359 options.get("multiEntry", multiEntry); | 359 options.get("multiEntry", multiEntry); |
| 360 | 360 |
| 361 return createIndex(context, name, keyPath, unique, multiEntry, ec); | 361 return createIndex(context, name, keyPath, unique, multiEntry, ec); |
| 362 } | 362 } |
| 363 | 363 |
| 364 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E
xceptionCode& ec) | 364 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context
, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E
xceptionCode& ec) |
| 365 { | 365 { |
| 366 IDB_TRACE("IDBObjectStore::createIndex"); | 366 IDB_TRACE("IDBObjectStore::createIndex"); |
| 367 if (!m_transaction->isVersionChange() || isDeleted()) { | 367 if (!m_transaction->isVersionChange() || isDeleted()) { |
| 368 ec = INVALID_STATE_ERR; | 368 ec = InvalidStateError; |
| 369 return 0; | 369 return 0; |
| 370 } | 370 } |
| 371 if (!m_transaction->isActive()) { | 371 if (!m_transaction->isActive()) { |
| 372 ec = TransactionInactiveError; | 372 ec = TransactionInactiveError; |
| 373 return 0; | 373 return 0; |
| 374 } | 374 } |
| 375 if (!keyPath.isValid()) { | 375 if (!keyPath.isValid()) { |
| 376 ec = SYNTAX_ERR; | 376 ec = SyntaxError; |
| 377 return 0; | 377 return 0; |
| 378 } | 378 } |
| 379 if (name.isNull()) { | 379 if (name.isNull()) { |
| 380 ec = TypeError; | 380 ec = TypeError; |
| 381 return 0; | 381 return 0; |
| 382 } | 382 } |
| 383 if (containsIndex(name)) { | 383 if (containsIndex(name)) { |
| 384 ec = ConstraintError; | 384 ec = ConstraintError; |
| 385 return 0; | 385 return 0; |
| 386 } | 386 } |
| 387 | 387 |
| 388 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { | 388 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { |
| 389 ec = INVALID_ACCESS_ERR; | 389 ec = InvalidAccessError; |
| 390 return 0; | 390 return 0; |
| 391 } | 391 } |
| 392 | 392 |
| 393 int64_t indexId = m_metadata.maxIndexId + 1; | 393 int64_t indexId = m_metadata.maxIndexId + 1; |
| 394 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath,
unique, multiEntry); | 394 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath,
unique, multiEntry); |
| 395 | 395 |
| 396 ++m_metadata.maxIndexId; | 396 ++m_metadata.maxIndexId; |
| 397 | 397 |
| 398 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); | 398 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); |
| 399 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get(
)); | 399 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get(
)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 415 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(),
m_transaction->id(), id(), metadata); | 415 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(),
m_transaction->id(), id(), metadata); |
| 416 indexRequest->setOnsuccess(indexPopulator); | 416 indexRequest->setOnsuccess(indexPopulator); |
| 417 | 417 |
| 418 return index.release(); | 418 return index.release(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionCode& ec
) | 421 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionCode& ec
) |
| 422 { | 422 { |
| 423 IDB_TRACE("IDBObjectStore::index"); | 423 IDB_TRACE("IDBObjectStore::index"); |
| 424 if (isDeleted()) { | 424 if (isDeleted()) { |
| 425 ec = INVALID_STATE_ERR; | 425 ec = InvalidStateError; |
| 426 return 0; | 426 return 0; |
| 427 } | 427 } |
| 428 if (m_transaction->isFinished()) { | 428 if (m_transaction->isFinished()) { |
| 429 ec = INVALID_STATE_ERR; | 429 ec = InvalidStateError; |
| 430 return 0; | 430 return 0; |
| 431 } | 431 } |
| 432 | 432 |
| 433 IDBIndexMap::iterator it = m_indexMap.find(name); | 433 IDBIndexMap::iterator it = m_indexMap.find(name); |
| 434 if (it != m_indexMap.end()) | 434 if (it != m_indexMap.end()) |
| 435 return it->value; | 435 return it->value; |
| 436 | 436 |
| 437 int64_t indexId = findIndexId(name); | 437 int64_t indexId = findIndexId(name); |
| 438 if (indexId == IDBIndexMetadata::InvalidId) { | 438 if (indexId == IDBIndexMetadata::InvalidId) { |
| 439 // FIXME: Should use (NotFoundError, "..."). | 439 // FIXME: Should use (NotFoundError, "..."). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 453 | 453 |
| 454 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio
n.get()); | 454 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio
n.get()); |
| 455 m_indexMap.set(name, index); | 455 m_indexMap.set(name, index); |
| 456 return index.release(); | 456 return index.release(); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void IDBObjectStore::deleteIndex(const String& name, ExceptionCode& ec) | 459 void IDBObjectStore::deleteIndex(const String& name, ExceptionCode& ec) |
| 460 { | 460 { |
| 461 IDB_TRACE("IDBObjectStore::deleteIndex"); | 461 IDB_TRACE("IDBObjectStore::deleteIndex"); |
| 462 if (!m_transaction->isVersionChange() || isDeleted()) { | 462 if (!m_transaction->isVersionChange() || isDeleted()) { |
| 463 ec = INVALID_STATE_ERR; | 463 ec = InvalidStateError; |
| 464 return; | 464 return; |
| 465 } | 465 } |
| 466 if (!m_transaction->isActive()) { | 466 if (!m_transaction->isActive()) { |
| 467 ec = TransactionInactiveError; | 467 ec = TransactionInactiveError; |
| 468 return; | 468 return; |
| 469 } | 469 } |
| 470 int64_t indexId = findIndexId(name); | 470 int64_t indexId = findIndexId(name); |
| 471 if (indexId == IDBIndexMetadata::InvalidId) { | 471 if (indexId == IDBIndexMetadata::InvalidId) { |
| 472 // FIXME: Should use (NotFoundError, "..."). | 472 // FIXME: Should use (NotFoundError, "..."). |
| 473 ec = IDBNotFoundError; | 473 ec = IDBNotFoundError; |
| 474 return; | 474 return; |
| 475 } | 475 } |
| 476 | 476 |
| 477 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); | 477 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); |
| 478 | 478 |
| 479 m_metadata.indexes.remove(indexId); | 479 m_metadata.indexes.remove(indexId); |
| 480 m_transaction->db()->indexDeleted(id(), indexId); | 480 m_transaction->db()->indexDeleted(id(), indexId); |
| 481 IDBIndexMap::iterator it = m_indexMap.find(name); | 481 IDBIndexMap::iterator it = m_indexMap.find(name); |
| 482 if (it != m_indexMap.end()) { | 482 if (it != m_indexMap.end()) { |
| 483 it->value->markDeleted(); | 483 it->value->markDeleted(); |
| 484 m_indexMap.remove(name); | 484 m_indexMap.remove(name); |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 | 487 |
| 488 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack
endInterface::TaskType taskType, ExceptionCode& ec) | 488 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack
endInterface::TaskType taskType, ExceptionCode& ec) |
| 489 { | 489 { |
| 490 IDB_TRACE("IDBObjectStore::openCursor"); | 490 IDB_TRACE("IDBObjectStore::openCursor"); |
| 491 if (isDeleted()) { | 491 if (isDeleted()) { |
| 492 ec = INVALID_STATE_ERR; | 492 ec = InvalidStateError; |
| 493 return 0; | 493 return 0; |
| 494 } | 494 } |
| 495 if (!m_transaction->isActive()) { | 495 if (!m_transaction->isActive()) { |
| 496 ec = TransactionInactiveError; | 496 ec = TransactionInactiveError; |
| 497 return 0; | 497 return 0; |
| 498 } | 498 } |
| 499 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, ec); | 499 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio
nString, ec); |
| 500 if (ec) | 500 if (ec) |
| 501 return 0; | 501 return 0; |
| 502 | 502 |
| 503 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 503 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 504 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 504 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 505 | 505 |
| 506 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>(
taskType), request); | 506 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>(
taskType), request); |
| 507 return request.release(); | 507 return request.release(); |
| 508 } | 508 } |
| 509 | 509 |
| 510 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, const ScriptValue& key, const String& direction, ExceptionCode& ec) | 510 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex
t, const ScriptValue& key, const String& direction, ExceptionCode& ec) |
| 511 { | 511 { |
| 512 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); | 512 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); |
| 513 if (ec) | 513 if (ec) |
| 514 return 0; | 514 return 0; |
| 515 return openCursor(context, keyRange.release(), direction, ec); | 515 return openCursor(context, keyRange.release(), direction, ec); |
| 516 } | 516 } |
| 517 | 517 |
| 518 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa
ssRefPtr<IDBKeyRange> range, ExceptionCode& ec) | 518 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa
ssRefPtr<IDBKeyRange> range, ExceptionCode& ec) |
| 519 { | 519 { |
| 520 IDB_TRACE("IDBObjectStore::count"); | 520 IDB_TRACE("IDBObjectStore::count"); |
| 521 if (isDeleted()) { | 521 if (isDeleted()) { |
| 522 ec = INVALID_STATE_ERR; | 522 ec = InvalidStateError; |
| 523 return 0; | 523 return 0; |
| 524 } | 524 } |
| 525 if (!m_transaction->isActive()) { | 525 if (!m_transaction->isActive()) { |
| 526 ec = TransactionInactiveError; | 526 ec = TransactionInactiveError; |
| 527 return 0; | 527 return 0; |
| 528 } | 528 } |
| 529 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); | 529 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this
), m_transaction.get()); |
| 530 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r
ange, request); | 530 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r
ange, request); |
| 531 return request.release(); | 531 return request.release(); |
| 532 } | 532 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 557 } | 557 } |
| 558 return IDBIndexMetadata::InvalidId; | 558 return IDBIndexMetadata::InvalidId; |
| 559 } | 559 } |
| 560 | 560 |
| 561 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const | 561 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const |
| 562 { | 562 { |
| 563 return m_transaction->backendDB(); | 563 return m_transaction->backendDB(); |
| 564 } | 564 } |
| 565 | 565 |
| 566 } // namespace WebCore | 566 } // namespace WebCore |
| OLD | NEW |