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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (!backendDB()) { | 161 if (!backendDB()) { |
163 exceptionState.throwDOMException(InvalidStateError, | 162 exceptionState.throwDOMException(InvalidStateError, |
164 IDBDatabase::databaseClosedErrorMessage); | 163 IDBDatabase::databaseClosedErrorMessage); |
165 return nullptr; | 164 return nullptr; |
166 } | 165 } |
167 | 166 |
168 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 167 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
169 m_transaction.get()); | 168 m_transaction.get()); |
170 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 169 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
171 keyRange, false /* keyOnly */, | 170 keyRange, false /* keyOnly */, |
172 WebIDBCallbacksImpl::create(request).release()); | 171 request->createWebCallbacks().release()); |
173 return request; | 172 return request; |
174 } | 173 } |
175 | 174 |
176 IDBRequest* IDBObjectStore::getKey(ScriptState* scriptState, | 175 IDBRequest* IDBObjectStore::getKey(ScriptState* scriptState, |
177 const ScriptValue& key, | 176 const ScriptValue& key, |
178 ExceptionState& exceptionState) { | 177 ExceptionState& exceptionState) { |
179 IDB_TRACE("IDBObjectStore::getKey"); | 178 IDB_TRACE("IDBObjectStore::getKey"); |
180 if (isDeleted()) { | 179 if (isDeleted()) { |
181 exceptionState.throwDOMException( | 180 exceptionState.throwDOMException( |
182 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); | 181 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
(...skipping 21 matching lines...) Expand all Loading... |
204 if (!backendDB()) { | 203 if (!backendDB()) { |
205 exceptionState.throwDOMException(InvalidStateError, | 204 exceptionState.throwDOMException(InvalidStateError, |
206 IDBDatabase::databaseClosedErrorMessage); | 205 IDBDatabase::databaseClosedErrorMessage); |
207 return nullptr; | 206 return nullptr; |
208 } | 207 } |
209 | 208 |
210 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 209 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
211 m_transaction.get()); | 210 m_transaction.get()); |
212 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 211 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
213 keyRange, true /* keyOnly */, | 212 keyRange, true /* keyOnly */, |
214 WebIDBCallbacksImpl::create(request).release()); | 213 request->createWebCallbacks().release()); |
215 return request; | 214 return request; |
216 } | 215 } |
217 | 216 |
218 IDBRequest* IDBObjectStore::getAll(ScriptState* scriptState, | 217 IDBRequest* IDBObjectStore::getAll(ScriptState* scriptState, |
219 const ScriptValue& keyRange, | 218 const ScriptValue& keyRange, |
220 ExceptionState& exceptionState) { | 219 ExceptionState& exceptionState) { |
221 return getAll(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), | 220 return getAll(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), |
222 exceptionState); | 221 exceptionState); |
223 } | 222 } |
224 | 223 |
(...skipping 27 matching lines...) Expand all Loading... |
252 if (!backendDB()) { | 251 if (!backendDB()) { |
253 exceptionState.throwDOMException(InvalidStateError, | 252 exceptionState.throwDOMException(InvalidStateError, |
254 IDBDatabase::databaseClosedErrorMessage); | 253 IDBDatabase::databaseClosedErrorMessage); |
255 return nullptr; | 254 return nullptr; |
256 } | 255 } |
257 | 256 |
258 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 257 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
259 m_transaction.get()); | 258 m_transaction.get()); |
260 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 259 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
261 range, maxCount, false, | 260 range, maxCount, false, |
262 WebIDBCallbacksImpl::create(request).release()); | 261 request->createWebCallbacks().release()); |
263 return request; | 262 return request; |
264 } | 263 } |
265 | 264 |
266 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* scriptState, | 265 IDBRequest* IDBObjectStore::getAllKeys(ScriptState* scriptState, |
267 const ScriptValue& keyRange, | 266 const ScriptValue& keyRange, |
268 ExceptionState& exceptionState) { | 267 ExceptionState& exceptionState) { |
269 return getAllKeys(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), | 268 return getAllKeys(scriptState, keyRange, std::numeric_limits<uint32_t>::max(), |
270 exceptionState); | 269 exceptionState); |
271 } | 270 } |
272 | 271 |
(...skipping 27 matching lines...) Expand all Loading... |
300 if (!backendDB()) { | 299 if (!backendDB()) { |
301 exceptionState.throwDOMException(InvalidStateError, | 300 exceptionState.throwDOMException(InvalidStateError, |
302 IDBDatabase::databaseClosedErrorMessage); | 301 IDBDatabase::databaseClosedErrorMessage); |
303 return nullptr; | 302 return nullptr; |
304 } | 303 } |
305 | 304 |
306 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 305 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
307 m_transaction.get()); | 306 m_transaction.get()); |
308 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 307 backendDB()->getAll(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
309 range, maxCount, true, | 308 range, maxCount, true, |
310 WebIDBCallbacksImpl::create(request).release()); | 309 request->createWebCallbacks().release()); |
311 return request; | 310 return request; |
312 } | 311 } |
313 | 312 |
314 static void generateIndexKeysForValue(v8::Isolate* isolate, | 313 static void generateIndexKeysForValue(v8::Isolate* isolate, |
315 const IDBIndexMetadata& indexMetadata, | 314 const IDBIndexMetadata& indexMetadata, |
316 const ScriptValue& objectValue, | 315 const ScriptValue& objectValue, |
317 IndexKeys* indexKeys) { | 316 IndexKeys* indexKeys) { |
318 DCHECK(indexKeys); | 317 DCHECK(indexKeys); |
319 NonThrowableExceptionState exceptionState; | 318 NonThrowableExceptionState exceptionState; |
320 IDBKey* indexKey = ScriptValue::to<IDBKey*>( | 319 IDBKey* indexKey = ScriptValue::to<IDBKey*>( |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 507 } |
509 | 508 |
510 IDBRequest* request = | 509 IDBRequest* request = |
511 IDBRequest::create(scriptState, source, m_transaction.get()); | 510 IDBRequest::create(scriptState, source, m_transaction.get()); |
512 Vector<char> wireBytes; | 511 Vector<char> wireBytes; |
513 serializedValue->toWireBytes(wireBytes); | 512 serializedValue->toWireBytes(wireBytes); |
514 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 513 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
515 | 514 |
516 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo, | 515 backendDB()->put(m_transaction->id(), id(), WebData(valueBuffer), blobInfo, |
517 key, static_cast<WebIDBPutMode>(putMode), | 516 key, static_cast<WebIDBPutMode>(putMode), |
518 WebIDBCallbacksImpl::create(request).release(), indexIds, | 517 request->createWebCallbacks().release(), indexIds, |
519 indexKeys); | 518 indexKeys); |
520 return request; | 519 return request; |
521 } | 520 } |
522 | 521 |
523 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, | 522 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, |
524 const ScriptValue& key, | 523 const ScriptValue& key, |
525 ExceptionState& exceptionState) { | 524 ExceptionState& exceptionState) { |
526 IDB_TRACE("IDBObjectStore::delete"); | 525 IDB_TRACE("IDBObjectStore::delete"); |
527 if (isDeleted()) { | 526 if (isDeleted()) { |
528 exceptionState.throwDOMException( | 527 exceptionState.throwDOMException( |
(...skipping 27 matching lines...) Expand all Loading... |
556 } | 555 } |
557 if (!backendDB()) { | 556 if (!backendDB()) { |
558 exceptionState.throwDOMException(InvalidStateError, | 557 exceptionState.throwDOMException(InvalidStateError, |
559 IDBDatabase::databaseClosedErrorMessage); | 558 IDBDatabase::databaseClosedErrorMessage); |
560 return nullptr; | 559 return nullptr; |
561 } | 560 } |
562 | 561 |
563 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 562 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
564 m_transaction.get()); | 563 m_transaction.get()); |
565 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, | 564 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, |
566 WebIDBCallbacksImpl::create(request).release()); | 565 request->createWebCallbacks().release()); |
567 return request; | 566 return request; |
568 } | 567 } |
569 | 568 |
570 IDBRequest* IDBObjectStore::clear(ScriptState* scriptState, | 569 IDBRequest* IDBObjectStore::clear(ScriptState* scriptState, |
571 ExceptionState& exceptionState) { | 570 ExceptionState& exceptionState) { |
572 IDB_TRACE("IDBObjectStore::clear"); | 571 IDB_TRACE("IDBObjectStore::clear"); |
573 if (isDeleted()) { | 572 if (isDeleted()) { |
574 exceptionState.throwDOMException( | 573 exceptionState.throwDOMException( |
575 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); | 574 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
576 return nullptr; | 575 return nullptr; |
(...skipping 15 matching lines...) Expand all Loading... |
592 } | 591 } |
593 if (!backendDB()) { | 592 if (!backendDB()) { |
594 exceptionState.throwDOMException(InvalidStateError, | 593 exceptionState.throwDOMException(InvalidStateError, |
595 IDBDatabase::databaseClosedErrorMessage); | 594 IDBDatabase::databaseClosedErrorMessage); |
596 return nullptr; | 595 return nullptr; |
597 } | 596 } |
598 | 597 |
599 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 598 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
600 m_transaction.get()); | 599 m_transaction.get()); |
601 backendDB()->clear(m_transaction->id(), id(), | 600 backendDB()->clear(m_transaction->id(), id(), |
602 WebIDBCallbacksImpl::create(request).release()); | 601 request->createWebCallbacks().release()); |
603 return request; | 602 return request; |
604 } | 603 } |
605 | 604 |
606 namespace { | 605 namespace { |
607 // This class creates the index keys for a given index by extracting | 606 // This class creates the index keys for a given index by extracting |
608 // them from the SerializedScriptValue, for all the existing values in | 607 // them from the SerializedScriptValue, for all the existing values in |
609 // the objectStore. It only needs to be kept alive by virtue of being | 608 // the objectStore. It only needs to be kept alive by virtue of being |
610 // a listener on an IDBRequest object, in the same way that JavaScript | 609 // a listener on an IDBRequest object, in the same way that JavaScript |
611 // cursor success handlers are kept alive. | 610 // cursor success handlers are kept alive. |
612 class IndexPopulator final : public EventListener { | 611 class IndexPopulator final : public EventListener { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 } | 892 } |
894 | 893 |
895 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, | 894 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, |
896 IDBKeyRange* range, | 895 IDBKeyRange* range, |
897 WebIDBCursorDirection direction, | 896 WebIDBCursorDirection direction, |
898 WebIDBTaskType taskType) { | 897 WebIDBTaskType taskType) { |
899 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 898 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
900 m_transaction.get()); | 899 m_transaction.get()); |
901 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 900 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
902 | 901 |
903 backendDB()->openCursor( | 902 backendDB()->openCursor(m_transaction->id(), id(), |
904 m_transaction->id(), id(), IDBIndexMetadata::InvalidId, range, direction, | 903 IDBIndexMetadata::InvalidId, range, direction, false, |
905 false, taskType, WebIDBCallbacksImpl::create(request).release()); | 904 taskType, request->createWebCallbacks().release()); |
906 return request; | 905 return request; |
907 } | 906 } |
908 | 907 |
909 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, | 908 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, |
910 const ScriptValue& range, | 909 const ScriptValue& range, |
911 const String& directionString, | 910 const String& directionString, |
912 ExceptionState& exceptionState) { | 911 ExceptionState& exceptionState) { |
913 IDB_TRACE("IDBObjectStore::openKeyCursor"); | 912 IDB_TRACE("IDBObjectStore::openKeyCursor"); |
914 if (isDeleted()) { | 913 if (isDeleted()) { |
915 exceptionState.throwDOMException( | 914 exceptionState.throwDOMException( |
(...skipping 24 matching lines...) Expand all Loading... |
940 return nullptr; | 939 return nullptr; |
941 } | 940 } |
942 | 941 |
943 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 942 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
944 m_transaction.get()); | 943 m_transaction.get()); |
945 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 944 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
946 | 945 |
947 backendDB()->openCursor(m_transaction->id(), id(), | 946 backendDB()->openCursor(m_transaction->id(), id(), |
948 IDBIndexMetadata::InvalidId, keyRange, direction, | 947 IDBIndexMetadata::InvalidId, keyRange, direction, |
949 true, WebIDBTaskTypeNormal, | 948 true, WebIDBTaskTypeNormal, |
950 WebIDBCallbacksImpl::create(request).release()); | 949 request->createWebCallbacks().release()); |
951 return request; | 950 return request; |
952 } | 951 } |
953 | 952 |
954 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, | 953 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, |
955 const ScriptValue& range, | 954 const ScriptValue& range, |
956 ExceptionState& exceptionState) { | 955 ExceptionState& exceptionState) { |
957 IDB_TRACE("IDBObjectStore::count"); | 956 IDB_TRACE("IDBObjectStore::count"); |
958 if (isDeleted()) { | 957 if (isDeleted()) { |
959 exceptionState.throwDOMException( | 958 exceptionState.throwDOMException( |
960 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); | 959 InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage); |
(...skipping 17 matching lines...) Expand all Loading... |
978 | 977 |
979 if (!backendDB()) { | 978 if (!backendDB()) { |
980 exceptionState.throwDOMException(InvalidStateError, | 979 exceptionState.throwDOMException(InvalidStateError, |
981 IDBDatabase::databaseClosedErrorMessage); | 980 IDBDatabase::databaseClosedErrorMessage); |
982 return nullptr; | 981 return nullptr; |
983 } | 982 } |
984 | 983 |
985 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), | 984 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this), |
986 m_transaction.get()); | 985 m_transaction.get()); |
987 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, | 986 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, |
988 keyRange, WebIDBCallbacksImpl::create(request).release()); | 987 keyRange, request->createWebCallbacks().release()); |
989 return request; | 988 return request; |
990 } | 989 } |
991 | 990 |
992 void IDBObjectStore::markDeleted() { | 991 void IDBObjectStore::markDeleted() { |
993 DCHECK(m_transaction->isVersionChange()) | 992 DCHECK(m_transaction->isVersionChange()) |
994 << "An object store got deleted outside a versionchange transaction."; | 993 << "An object store got deleted outside a versionchange transaction."; |
995 | 994 |
996 m_deleted = true; | 995 m_deleted = true; |
997 m_metadata->indexes.clear(); | 996 m_metadata->indexes.clear(); |
998 | 997 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 } | 1087 } |
1089 } | 1088 } |
1090 return IDBIndexMetadata::InvalidId; | 1089 return IDBIndexMetadata::InvalidId; |
1091 } | 1090 } |
1092 | 1091 |
1093 WebIDBDatabase* IDBObjectStore::backendDB() const { | 1092 WebIDBDatabase* IDBObjectStore::backendDB() const { |
1094 return m_transaction->backendDB(); | 1093 return m_transaction->backendDB(); |
1095 } | 1094 } |
1096 | 1095 |
1097 } // namespace blink | 1096 } // namespace blink |
OLD | NEW |