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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); | 136 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); |
137 | 137 |
138 for (size_t i = 0; i < indexKey->array().size(); ++i) | 138 for (size_t i = 0; i < indexKey->array().size(); ++i) |
139 indexKeys->append(indexKey->array()[i]); | 139 indexKeys->append(indexKey->array()[i]); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, ScriptValue& value, co
nst ScriptValue& key, ExceptionState& exceptionState) | 143 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, ScriptValue& value, co
nst ScriptValue& key, ExceptionState& exceptionState) |
144 { | 144 { |
145 IDB_TRACE("IDBObjectStore::add"); | 145 IDB_TRACE("IDBObjectStore::add"); |
146 return put(scriptState, blink::WebIDBPutModeAddOnly, IDBAny::create(this), v
alue, key, exceptionState); | 146 return put(scriptState, WebIDBPutModeAddOnly, IDBAny::create(this), value, k
ey, exceptionState); |
147 } | 147 } |
148 | 148 |
149 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, ScriptValue& value, co
nst ScriptValue& key, ExceptionState& exceptionState) | 149 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, ScriptValue& value, co
nst ScriptValue& key, ExceptionState& exceptionState) |
150 { | 150 { |
151 IDB_TRACE("IDBObjectStore::put"); | 151 IDB_TRACE("IDBObjectStore::put"); |
152 return put(scriptState, blink::WebIDBPutModeAddOrUpdate, IDBAny::create(this
), value, key, exceptionState); | 152 return put(scriptState, WebIDBPutModeAddOrUpdate, IDBAny::create(this), valu
e, key, exceptionState); |
153 } | 153 } |
154 | 154 |
155 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, blink::WebIDBPutMode p
utMode, IDBAny* source, ScriptValue& value, const ScriptValue& keyValue, Excepti
onState& exceptionState) | 155 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, WebIDBPutMode putMode,
IDBAny* source, ScriptValue& value, const ScriptValue& keyValue, ExceptionState
& exceptionState) |
156 { | 156 { |
157 IDBKey* key = keyValue.isUndefined() ? nullptr : scriptValueToIDBKey(scriptS
tate->isolate(), keyValue); | 157 IDBKey* key = keyValue.isUndefined() ? nullptr : scriptValueToIDBKey(scriptS
tate->isolate(), keyValue); |
158 return put(scriptState, putMode, source, value, key, exceptionState); | 158 return put(scriptState, putMode, source, value, key, exceptionState); |
159 } | 159 } |
160 | 160 |
161 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, blink::WebIDBPutMode p
utMode, IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionState& excepti
onState) | 161 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, WebIDBPutMode putMode,
IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionState& exceptionState
) |
162 { | 162 { |
163 if (isDeleted()) { | 163 if (isDeleted()) { |
164 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 164 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
165 return 0; | 165 return 0; |
166 } | 166 } |
167 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 167 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
168 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 168 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
169 return 0; | 169 return 0; |
170 } | 170 } |
171 if (!m_transaction->isActive()) { | 171 if (!m_transaction->isActive()) { |
(...skipping 13 matching lines...) Expand all Loading... |
185 // Keys that need to be extracted must be taken from a clone so that | 185 // Keys that need to be extracted must be taken from a clone so that |
186 // side effects (i.e. getters) are not triggered. Construct the | 186 // side effects (i.e. getters) are not triggered. Construct the |
187 // clone lazily since the operation may be expensive. | 187 // clone lazily since the operation may be expensive. |
188 ScriptValue clone; | 188 ScriptValue clone; |
189 value.clear(); | 189 value.clear(); |
190 | 190 |
191 const IDBKeyPath& keyPath = m_metadata.keyPath; | 191 const IDBKeyPath& keyPath = m_metadata.keyPath; |
192 const bool usesInLineKeys = !keyPath.isNull(); | 192 const bool usesInLineKeys = !keyPath.isNull(); |
193 const bool hasKeyGenerator = autoIncrement(); | 193 const bool hasKeyGenerator = autoIncrement(); |
194 | 194 |
195 if (putMode != blink::WebIDBPutModeCursorUpdate && usesInLineKeys && key) { | 195 if (putMode != WebIDBPutModeCursorUpdate && usesInLineKeys && key) { |
196 exceptionState.throwDOMException(DataError, "The object store uses in-li
ne keys and the key parameter was provided."); | 196 exceptionState.throwDOMException(DataError, "The object store uses in-li
ne keys and the key parameter was provided."); |
197 return 0; | 197 return 0; |
198 } | 198 } |
199 | 199 |
200 // This test logically belongs in IDBCursor, but must operate on the cloned
value. | 200 // This test logically belongs in IDBCursor, but must operate on the cloned
value. |
201 if (putMode == blink::WebIDBPutModeCursorUpdate && usesInLineKeys) { | 201 if (putMode == WebIDBPutModeCursorUpdate && usesInLineKeys) { |
202 ASSERT(key); | 202 ASSERT(key); |
203 if (clone.isEmpty()) | 203 if (clone.isEmpty()) |
204 clone = deserializeScriptValue(scriptState, serializedValue.get(), &
blobInfo); | 204 clone = deserializeScriptValue(scriptState, serializedValue.get(), &
blobInfo); |
205 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState->
isolate(), clone, keyPath); | 205 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState->
isolate(), clone, keyPath); |
206 if (!keyPathKey || !keyPathKey->isEqual(key)) { | 206 if (!keyPathKey || !keyPathKey->isEqual(key)) { |
207 exceptionState.throwDOMException(DataError, "The effective object st
ore of this cursor uses in-line keys and evaluating the key path of the value pa
rameter results in a different value than the cursor's effective key."); | 207 exceptionState.throwDOMException(DataError, "The effective object st
ore of this cursor uses in-line keys and evaluating the key path of the value pa
rameter results in a different value than the cursor's effective key."); |
208 return nullptr; | 208 return nullptr; |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 generateIndexKeysForValue(scriptState->isolate(), it->value, clone, &key
s); | 253 generateIndexKeysForValue(scriptState->isolate(), it->value, clone, &key
s); |
254 indexIds.append(it->key); | 254 indexIds.append(it->key); |
255 indexKeys.append(keys); | 255 indexKeys.append(keys); |
256 } | 256 } |
257 | 257 |
258 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction.
get()); | 258 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction.
get()); |
259 Vector<char> wireBytes; | 259 Vector<char> wireBytes; |
260 serializedValue->toWireBytes(wireBytes); | 260 serializedValue->toWireBytes(wireBytes); |
261 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 261 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
262 | 262 |
263 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo
bInfo, key, static_cast<blink::WebIDBPutMode>(putMode), WebIDBCallbacksImpl::cre
ate(request).leakPtr(), indexIds, indexKeys); | 263 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo,
key, static_cast<WebIDBPutMode>(putMode), WebIDBCallbacksImpl::create(request).l
eakPtr(), indexIds, indexKeys); |
264 return request; | 264 return request; |
265 } | 265 } |
266 | 266 |
267 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip
tValue& key, ExceptionState& exceptionState) | 267 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip
tValue& key, ExceptionState& exceptionState) |
268 { | 268 { |
269 IDB_TRACE("IDBObjectStore::delete"); | 269 IDB_TRACE("IDBObjectStore::delete"); |
270 if (isDeleted()) { | 270 if (isDeleted()) { |
271 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 271 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
272 return 0; | 272 return 0; |
273 } | 273 } |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); | 466 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); |
467 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get()); | 467 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get()); |
468 m_indexMap.set(name, index); | 468 m_indexMap.set(name, index); |
469 m_metadata.indexes.set(indexId, metadata); | 469 m_metadata.indexes.set(indexId, metadata); |
470 m_transaction->db()->indexCreated(id(), metadata); | 470 m_transaction->db()->indexCreated(id(), metadata); |
471 | 471 |
472 ASSERT(!exceptionState.hadException()); | 472 ASSERT(!exceptionState.hadException()); |
473 if (exceptionState.hadException()) | 473 if (exceptionState.hadException()) |
474 return 0; | 474 return 0; |
475 | 475 |
476 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*>
(0), blink::WebIDBCursorDirectionNext, blink::WebIDBTaskTypePreemptive); | 476 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*>
(0), WebIDBCursorDirectionNext, WebIDBTaskTypePreemptive); |
477 indexRequest->preventPropagation(); | 477 indexRequest->preventPropagation(); |
478 | 478 |
479 // This is kept alive by being the success handler of the request, which is
in turn kept alive by the owning transaction. | 479 // This is kept alive by being the success handler of the request, which is
in turn kept alive by the owning transaction. |
480 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState,
transaction()->db(), m_transaction->id(), id(), metadata); | 480 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState,
transaction()->db(), m_transaction->id(), id(), metadata); |
481 indexRequest->setOnsuccess(indexPopulator); | 481 indexRequest->setOnsuccess(indexPopulator); |
482 return index; | 482 return index; |
483 } | 483 } |
484 | 484 |
485 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta
te) | 485 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta
te) |
486 { | 486 { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 } | 568 } |
569 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 569 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
570 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 570 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
571 return 0; | 571 return 0; |
572 } | 572 } |
573 if (!m_transaction->isActive()) { | 573 if (!m_transaction->isActive()) { |
574 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 574 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
575 return 0; | 575 return 0; |
576 } | 576 } |
577 | 577 |
578 blink::WebIDBCursorDirection direction = IDBCursor::stringToDirection(direct
ionString, exceptionState); | 578 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng, exceptionState); |
579 if (exceptionState.hadException()) | 579 if (exceptionState.hadException()) |
580 return 0; | 580 return 0; |
581 | 581 |
582 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); | 582 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); |
583 if (exceptionState.hadException()) | 583 if (exceptionState.hadException()) |
584 return 0; | 584 return 0; |
585 | 585 |
586 if (!backendDB()) { | 586 if (!backendDB()) { |
587 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 587 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
588 return 0; | 588 return 0; |
589 } | 589 } |
590 | 590 |
591 return openCursor(scriptState, keyRange, direction, blink::WebIDBTaskTypeNor
mal); | 591 return openCursor(scriptState, keyRange, direction, WebIDBTaskTypeNormal); |
592 } | 592 } |
593 | 593 |
594 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra
nge, blink::WebIDBCursorDirection direction, blink::WebIDBTaskType taskType) | 594 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra
nge, WebIDBCursorDirection direction, WebIDBTaskType taskType) |
595 { | 595 { |
596 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 596 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
597 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 597 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
598 | 598 |
599 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak
Ptr()); | 599 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak
Ptr()); |
600 return request; | 600 return request; |
601 } | 601 } |
602 | 602 |
603 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script
Value& range, const String& directionString, ExceptionState& exceptionState) | 603 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script
Value& range, const String& directionString, ExceptionState& exceptionState) |
604 { | 604 { |
605 IDB_TRACE("IDBObjectStore::openKeyCursor"); | 605 IDB_TRACE("IDBObjectStore::openKeyCursor"); |
606 if (isDeleted()) { | 606 if (isDeleted()) { |
607 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 607 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
608 return 0; | 608 return 0; |
609 } | 609 } |
610 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 610 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
611 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 611 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
612 return 0; | 612 return 0; |
613 } | 613 } |
614 if (!m_transaction->isActive()) { | 614 if (!m_transaction->isActive()) { |
615 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 615 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
616 return 0; | 616 return 0; |
617 } | 617 } |
618 | 618 |
619 blink::WebIDBCursorDirection direction = IDBCursor::stringToDirection(direct
ionString, exceptionState); | 619 WebIDBCursorDirection direction = IDBCursor::stringToDirection(directionStri
ng, exceptionState); |
620 if (exceptionState.hadException()) | 620 if (exceptionState.hadException()) |
621 return 0; | 621 return 0; |
622 | 622 |
623 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); | 623 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); |
624 if (exceptionState.hadException()) | 624 if (exceptionState.hadException()) |
625 return 0; | 625 return 0; |
626 | 626 |
627 if (!backendDB()) { | 627 if (!backendDB()) { |
628 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 628 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
629 return 0; | 629 return 0; |
630 } | 630 } |
631 | 631 |
632 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 632 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
633 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 633 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
634 | 634 |
635 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, keyRange, direction, true, blink::WebIDBTaskTypeNormal, WebIDBCallbacksImpl:
:create(request).leakPtr()); | 635 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, keyRange, direction, true, WebIDBTaskTypeNormal, WebIDBCallbacksImpl::create
(request).leakPtr()); |
636 return request; | 636 return request; |
637 } | 637 } |
638 | 638 |
639 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r
ange, ExceptionState& exceptionState) | 639 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r
ange, ExceptionState& exceptionState) |
640 { | 640 { |
641 IDB_TRACE("IDBObjectStore::count"); | 641 IDB_TRACE("IDBObjectStore::count"); |
642 if (isDeleted()) { | 642 if (isDeleted()) { |
643 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 643 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
644 return 0; | 644 return 0; |
645 } | 645 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 } | 684 } |
685 return IDBIndexMetadata::InvalidId; | 685 return IDBIndexMetadata::InvalidId; |
686 } | 686 } |
687 | 687 |
688 WebIDBDatabase* IDBObjectStore::backendDB() const | 688 WebIDBDatabase* IDBObjectStore::backendDB() const |
689 { | 689 { |
690 return m_transaction->backendDB(); | 690 return m_transaction->backendDB(); |
691 } | 691 } |
692 | 692 |
693 } // namespace blink | 693 } // namespace blink |
OLD | NEW |