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 21 matching lines...) Expand all Loading... |
32 #include "bindings/modules/v8/ToV8ForModules.h" | 32 #include "bindings/modules/v8/ToV8ForModules.h" |
33 #include "bindings/modules/v8/V8BindingForModules.h" | 33 #include "bindings/modules/v8/V8BindingForModules.h" |
34 #include "core/dom/DOMStringList.h" | 34 #include "core/dom/DOMStringList.h" |
35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
36 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
37 #include "modules/indexeddb/IDBAny.h" | 37 #include "modules/indexeddb/IDBAny.h" |
38 #include "modules/indexeddb/IDBCursorWithValue.h" | 38 #include "modules/indexeddb/IDBCursorWithValue.h" |
39 #include "modules/indexeddb/IDBDatabase.h" | 39 #include "modules/indexeddb/IDBDatabase.h" |
40 #include "modules/indexeddb/IDBKeyPath.h" | 40 #include "modules/indexeddb/IDBKeyPath.h" |
41 #include "modules/indexeddb/IDBTracing.h" | 41 #include "modules/indexeddb/IDBTracing.h" |
42 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | |
43 #include "platform/SharedBuffer.h" | 42 #include "platform/SharedBuffer.h" |
44 #include "public/platform/WebBlobInfo.h" | 43 #include "public/platform/WebBlobInfo.h" |
45 #include "public/platform/WebData.h" | 44 #include "public/platform/WebData.h" |
46 #include "public/platform/WebVector.h" | 45 #include "public/platform/WebVector.h" |
47 #include "public/platform/modules/indexeddb/WebIDBKey.h" | 46 #include "public/platform/modules/indexeddb/WebIDBKey.h" |
48 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" | 47 #include "public/platform/modules/indexeddb/WebIDBKeyRange.h" |
49 #include <memory> | 48 #include <memory> |
50 #include <v8.h> | 49 #include <v8.h> |
51 | 50 |
52 using blink::WebBlobInfo; | 51 using blink::WebBlobInfo; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (!backendDB()) { | 167 if (!backendDB()) { |
169 exceptionState.throwDOMException(InvalidStateError, | 168 exceptionState.throwDOMException(InvalidStateError, |
170 IDBDatabase::databaseClosedErrorMessage); | 169 IDBDatabase::databaseClosedErrorMessage); |
171 return nullptr; | 170 return nullptr; |
172 } | 171 } |
173 | 172 |
174 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 173 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
175 m_transaction.get()); | 174 m_transaction.get()); |
176 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 175 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
177 keyRange, false /* keyOnly */, | 176 keyRange, false /* keyOnly */, |
178 WebIDBCallbacksImpl::create(request).release()); | 177 request->createWebCallbacks().release()); |
179 return request; | 178 return request; |
180 } | 179 } |
181 | 180 |
182 IDBRequest* IDBObjectStore::getKey(ScriptState* scriptState, | 181 IDBRequest* IDBObjectStore::getKey(ScriptState* scriptState, |
183 const ScriptValue& key, | 182 const ScriptValue& key, |
184 ExceptionState& exceptionState) { | 183 ExceptionState& exceptionState) { |
185 IDB_TRACE("IDBObjectStore::getKey"); | 184 IDB_TRACE("IDBObjectStore::getKey"); |
186 if (isDeleted()) { | 185 if (isDeleted()) { |
187 exceptionState.throwDOMException( | 186 exceptionState.throwDOMException( |
188 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); | 187 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
(...skipping 21 matching lines...) Expand all Loading... |
210 if (!backendDB()) { | 209 if (!backendDB()) { |
211 exceptionState.throwDOMException(InvalidStateError, | 210 exceptionState.throwDOMException(InvalidStateError, |
212 IDBDatabase::databaseClosedErrorMessage); | 211 IDBDatabase::databaseClosedErrorMessage); |
213 return nullptr; | 212 return nullptr; |
214 } | 213 } |
215 | 214 |
216 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 215 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
217 m_transaction.get()); | 216 m_transaction.get()); |
218 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 217 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
219 keyRange, true /* keyOnly */, | 218 keyRange, true /* keyOnly */, |
220 WebIDBCallbacksImpl::create(request).release()); | 219 request->createWebCallbacks().release()); |
221 return request; | 220 return request; |
222 } | 221 } |
223 | 222 |
224 IDBRequest* IDBObjectStore::getAll(ScriptState* scriptState, | 223 IDBRequest* IDBObjectStore::getAll(ScriptState* scriptState, |
225 const ScriptValue& keyRange, | 224 const ScriptValue& keyRange, |
226 ExceptionState& exceptionState) { | 225 ExceptionState& exceptionState) { |
227 return getAll(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), | 226 return getAll(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), |
228 exceptionState); | 227 exceptionState); |
229 } | 228 } |
230 | 229 |
(...skipping 27 matching lines...) Expand all Loading... |
258 if (!backendDB()) { | 257 if (!backendDB()) { |
259 exceptionState.throwDOMException(InvalidStateError, | 258 exceptionState.throwDOMException(InvalidStateError, |
260 IDBDatabase::databaseClosedErrorMessage); | 259 IDBDatabase::databaseClosedErrorMessage); |
261 return nullptr; | 260 return nullptr; |
262 } | 261 } |
263 | 262 |
264 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 263 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
265 m_transaction.get()); | 264 m_transaction.get()); |
266 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 265 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
267 range, maxCount, false, | 266 range, maxCount, false, |
268 WebIDBCallbacksImpl::create(request).release()); | 267 request->createWebCallbacks().release()); |
269 return request; | 268 return request; |
270 } | 269 } |
271 | 270 |
272 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* scriptState, | 271 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* scriptState, |
273 const ScriptValue& keyRange, | 272 const ScriptValue& keyRange, |
274 ExceptionState& exceptionState) { | 273 ExceptionState& exceptionState) { |
275 return getAllKeys(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), | 274 return getAllKeys(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), |
276 exceptionState); | 275 exceptionState); |
277 } | 276 } |
278 | 277 |
(...skipping 27 matching lines...) Expand all Loading... |
306 if (!backendDB()) { | 305 if (!backendDB()) { |
307 exceptionState.throwDOMException(InvalidStateError, | 306 exceptionState.throwDOMException(InvalidStateError, |
308 IDBDatabase::databaseClosedErrorMessage); | 307 IDBDatabase::databaseClosedErrorMessage); |
309 return nullptr; | 308 return nullptr; |
310 } | 309 } |
311 | 310 |
312 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 311 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
313 m_transaction.get()); | 312 m_transaction.get()); |
314 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 313 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
315 range, maxCount, true, | 314 range, maxCount, true, |
316 WebIDBCallbacksImpl::create(request).release()); | 315 request->createWebCallbacks().release()); |
317 return request; | 316 return request; |
318 } | 317 } |
319 | 318 |
320 static void generateIndexKeysForValue(v8::Isolate* isolate, | 319 static void generateIndexKeysForValue(v8::Isolate* isolate, |
321 const IDBIndexMetadata& indexMetadata, | 320 const IDBIndexMetadata& indexMetadata, |
322 const ScriptValue& objectValue, | 321 const ScriptValue& objectValue, |
323 IndexKeys* indexKeys) { | 322 IndexKeys* indexKeys) { |
324 DCHECK(indexKeys); | 323 DCHECK(indexKeys); |
325 NonThrowableExceptionState exceptionState; | 324 NonThrowableExceptionState exceptionState; |
326 IDBKey* indexKey = ScriptValue::to<IDBKey*>( | 325 IDBKey* indexKey = ScriptValue::to<IDBKey*>( |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } | 512 } |
514 | 513 |
515 IDBRequest* request = | 514 IDBRequest* request = |
516 IDBRequest::create(scriptState, source, m_transaction.get()); | 515 IDBRequest::create(scriptState, source, m_transaction.get()); |
517 Vector<char> wireBytes; | 516 Vector<char> wireBytes; |
518 serializedValue->toWireBytes(wireBytes); | 517 serializedValue->toWireBytes(wireBytes); |
519 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 518 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
520 | 519 |
521 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo, | 520 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo, |
522 key, static_cast<WebIDBPutMode>(putMode), | 521 key, static_cast<WebIDBPutMode>(putMode), |
523 WebIDBCallbacksImpl::create(request).release(), indexIds, | 522 request->createWebCallbacks().release(), indexIds, |
524 indexKeys); | 523 indexKeys); |
525 return request; | 524 return request; |
526 } | 525 } |
527 | 526 |
528 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, | 527 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, |
529 const ScriptValue& key, | 528 const ScriptValue& key, |
530 ExceptionState& exceptionState) { | 529 ExceptionState& exceptionState) { |
531 IDB_TRACE("IDBObjectStore::delete"); | 530 IDB_TRACE("IDBObjectStore::delete"); |
532 if (isDeleted()) { | 531 if (isDeleted()) { |
533 exceptionState.throwDOMException( | 532 exceptionState.throwDOMException( |
(...skipping 27 matching lines...) Expand all Loading... |
561 } | 560 } |
562 if (!backendDB()) { | 561 if (!backendDB()) { |
563 exceptionState.throwDOMException(InvalidStateError, | 562 exceptionState.throwDOMException(InvalidStateError, |
564 IDBDatabase::databaseClosedErrorMessage); | 563 IDBDatabase::databaseClosedErrorMessage); |
565 return nullptr; | 564 return nullptr; |
566 } | 565 } |
567 | 566 |
568 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 567 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
569 m_transaction.get()); | 568 m_transaction.get()); |
570 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, | 569 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, |
571 WebIDBCallbacksImpl::create(request).release()); | 570 request->createWebCallbacks().release()); |
572 return request; | 571 return request; |
573 } | 572 } |
574 | 573 |
575 IDBRequest* IDBObjectStore::clear(ScriptState* scriptState, | 574 IDBRequest* IDBObjectStore::clear(ScriptState* scriptState, |
576 ExceptionState& exceptionState) { | 575 ExceptionState& exceptionState) { |
577 IDB_TRACE("IDBObjectStore::clear"); | 576 IDB_TRACE("IDBObjectStore::clear"); |
578 if (isDeleted()) { | 577 if (isDeleted()) { |
579 exceptionState.throwDOMException( | 578 exceptionState.throwDOMException( |
580 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); | 579 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
581 return nullptr; | 580 return nullptr; |
(...skipping 15 matching lines...) Expand all Loading... |
597 } | 596 } |
598 if (!backendDB()) { | 597 if (!backendDB()) { |
599 exceptionState.throwDOMException(InvalidStateError, | 598 exceptionState.throwDOMException(InvalidStateError, |
600 IDBDatabase::databaseClosedErrorMessage); | 599 IDBDatabase::databaseClosedErrorMessage); |
601 return nullptr; | 600 return nullptr; |
602 } | 601 } |
603 | 602 |
604 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 603 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
605 m_transaction.get()); | 604 m_transaction.get()); |
606 backendDB()->clear(m_transaction->id(), id(), | 605 backendDB()->clear(m_transaction->id(), id(), |
607 WebIDBCallbacksImpl::create(request).release()); | 606 request->createWebCallbacks().release()); |
608 return request; | 607 return request; |
609 } | 608 } |
610 | 609 |
611 namespace { | 610 namespace { |
612 // This class creates the index keys for a given index by extracting | 611 // This class creates the index keys for a given index by extracting |
613 // them from the SerializedScriptValue, for all the existing values in | 612 // them from the SerializedScriptValue, for all the existing values in |
614 // the objectStore. It only needs to be kept alive by virtue of being | 613 // the objectStore. It only needs to be kept alive by virtue of being |
615 // a listener on an IDBRequest object, in the same way that JavaScript | 614 // a listener on an IDBRequest object, in the same way that JavaScript |
616 // cursor success handlers are kept alive. | 615 // cursor success handlers are kept alive. |
617 class IndexPopulator final : public EventListener { | 616 class IndexPopulator final : public EventListener { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 } | 894 } |
896 | 895 |
897 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, | 896 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, |
898 IDBKeyRange* range, | 897 IDBKeyRange* range, |
899 WebIDBCursorDirection direction, | 898 WebIDBCursorDirection direction, |
900 WebIDBTaskType taskType) { | 899 WebIDBTaskType taskType) { |
901 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 900 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
902 m_transaction.get()); | 901 m_transaction.get()); |
903 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 902 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
904 | 903 |
905 backendDB()->openCursor( | 904 backendDB()->openCursor(m_transaction->id(), id(), |
906 m_transaction->id(), id(), IDBIndexMetadata::InvalidId, range, direction, | 905 IDBIndexMetadata::InvalidId, range, direction, false, |
907 false, taskType, WebIDBCallbacksImpl::create(request).release()); | 906 taskType, request->createWebCallbacks().release()); |
908 return request; | 907 return request; |
909 } | 908 } |
910 | 909 |
911 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, | 910 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, |
912 const ScriptValue& range, | 911 const ScriptValue& range, |
913 const String& directionString, | 912 const String& directionString, |
914 ExceptionState& exceptionState) { | 913 ExceptionState& exceptionState) { |
915 IDB_TRACE("IDBObjectStore::openKeyCursor"); | 914 IDB_TRACE("IDBObjectStore::openKeyCursor"); |
916 if (isDeleted()) { | 915 if (isDeleted()) { |
917 exceptionState.throwDOMException( | 916 exceptionState.throwDOMException( |
(...skipping 24 matching lines...) Expand all Loading... |
942 return nullptr; | 941 return nullptr; |
943 } | 942 } |
944 | 943 |
945 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 944 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
946 m_transaction.get()); | 945 m_transaction.get()); |
947 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 946 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
948 | 947 |
949 backendDB()->openCursor(m_transaction->id(), id(), | 948 backendDB()->openCursor(m_transaction->id(), id(), |
950 IDBIndexMetadata::InvalidId, keyRange, direction, | 949 IDBIndexMetadata::InvalidId, keyRange, direction, |
951 true, WebIDBTaskTypeNormal, | 950 true, WebIDBTaskTypeNormal, |
952 WebIDBCallbacksImpl::create(request).release()); | 951 request->createWebCallbacks().release()); |
953 return request; | 952 return request; |
954 } | 953 } |
955 | 954 |
956 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, | 955 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, |
957 const ScriptValue& range, | 956 const ScriptValue& range, |
958 ExceptionState& exceptionState) { | 957 ExceptionState& exceptionState) { |
959 IDB_TRACE("IDBObjectStore::count"); | 958 IDB_TRACE("IDBObjectStore::count"); |
960 if (isDeleted()) { | 959 if (isDeleted()) { |
961 exceptionState.throwDOMException( | 960 exceptionState.throwDOMException( |
962 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); | 961 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
(...skipping 17 matching lines...) Expand all Loading... |
980 | 979 |
981 if (!backendDB()) { | 980 if (!backendDB()) { |
982 exceptionState.throwDOMException(InvalidStateError, | 981 exceptionState.throwDOMException(InvalidStateError, |
983 IDBDatabase::databaseClosedErrorMessage); | 982 IDBDatabase::databaseClosedErrorMessage); |
984 return nullptr; | 983 return nullptr; |
985 } | 984 } |
986 | 985 |
987 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 986 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
988 m_transaction.get()); | 987 m_transaction.get()); |
989 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 988 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
990 keyRange, WebIDBCallbacksImpl::create(request).release()); | 989 keyRange, request->createWebCallbacks().release()); |
991 return request; | 990 return request; |
992 } | 991 } |
993 | 992 |
994 void IDBObjectStore::markDeleted() { | 993 void IDBObjectStore::markDeleted() { |
995 DCHECK(m_transaction->isVersionChange()) | 994 DCHECK(m_transaction->isVersionChange()) |
996 << "An object store got deleted outside a versionchange transaction."; | 995 << "An object store got deleted outside a versionchange transaction."; |
997 m_deleted = true; | 996 m_deleted = true; |
998 } | 997 } |
999 | 998 |
1000 void IDBObjectStore::abort() { | 999 void IDBObjectStore::abort() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 } | 1034 } |
1036 } | 1035 } |
1037 return IDBIndexMetadata::InvalidId; | 1036 return IDBIndexMetadata::InvalidId; |
1038 } | 1037 } |
1039 | 1038 |
1040 WebIDBDatabase* IDBObjectStore::backendDB() const { | 1039 WebIDBDatabase* IDBObjectStore::backendDB() const { |
1041 return m_transaction->backendDB(); | 1040 return m_transaction->backendDB(); |
1042 } | 1041 } |
1043 | 1042 |
1044 } // namespace blink | 1043 } // namespace blink |
OLD | NEW |