| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "modules/indexeddb/IDBOpenDBRequest.h" | 55 #include "modules/indexeddb/IDBOpenDBRequest.h" |
| 56 #include "modules/indexeddb/IDBRequest.h" | 56 #include "modules/indexeddb/IDBRequest.h" |
| 57 #include "modules/indexeddb/IDBTransaction.h" | 57 #include "modules/indexeddb/IDBTransaction.h" |
| 58 #include "platform/JSONValues.h" | 58 #include "platform/JSONValues.h" |
| 59 #include "platform/JSONValuesForV8.h" | 59 #include "platform/JSONValuesForV8.h" |
| 60 #include "platform/weborigin/SecurityOrigin.h" | 60 #include "platform/weborigin/SecurityOrigin.h" |
| 61 #include "public/platform/modules/indexeddb/WebIDBCursor.h" | 61 #include "public/platform/modules/indexeddb/WebIDBCursor.h" |
| 62 #include "public/platform/modules/indexeddb/WebIDBTypes.h" | 62 #include "public/platform/modules/indexeddb/WebIDBTypes.h" |
| 63 #include "wtf/Vector.h" | 63 #include "wtf/Vector.h" |
| 64 | 64 |
| 65 using blink::protocol::TypeBuilder::Array; | 65 using blink::protocol::Array; |
| 66 using blink::protocol::TypeBuilder::IndexedDB::DatabaseWithObjectStores; | 66 using blink::protocol::IndexedDB::DatabaseWithObjectStores; |
| 67 using blink::protocol::TypeBuilder::IndexedDB::DataEntry; | 67 using blink::protocol::IndexedDB::DataEntry; |
| 68 using blink::protocol::TypeBuilder::IndexedDB::Key; | 68 using blink::protocol::IndexedDB::Key; |
| 69 using blink::protocol::TypeBuilder::IndexedDB::KeyPath; | 69 using blink::protocol::IndexedDB::KeyPath; |
| 70 using blink::protocol::TypeBuilder::IndexedDB::KeyRange; | 70 using blink::protocol::IndexedDB::KeyRange; |
| 71 using blink::protocol::TypeBuilder::IndexedDB::ObjectStore; | 71 using blink::protocol::IndexedDB::ObjectStore; |
| 72 using blink::protocol::TypeBuilder::IndexedDB::ObjectStoreIndex; | 72 using blink::protocol::IndexedDB::ObjectStoreIndex; |
| 73 | 73 |
| 74 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::RequestDatabaseNam
esCallback RequestDatabaseNamesCallback; | 74 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::RequestDatabaseNam
esCallback RequestDatabaseNamesCallback; |
| 75 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::RequestDatabaseCal
lback RequestDatabaseCallback; | 75 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::RequestDatabaseCal
lback RequestDatabaseCallback; |
| 76 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::RequestDataCallbac
k RequestDataCallback; | 76 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::RequestDataCallbac
k RequestDataCallback; |
| 77 typedef blink::protocol::Dispatcher::CallbackBase RequestCallback; | 77 typedef blink::protocol::Dispatcher::CallbackBase RequestCallback; |
| 78 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::ClearObjectStoreCa
llback ClearObjectStoreCallback; | 78 typedef blink::protocol::Dispatcher::IndexedDBCommandHandler::ClearObjectStoreCa
llback ClearObjectStoreCallback; |
| 79 | 79 |
| 80 namespace blink { | 80 namespace blink { |
| 81 | 81 |
| 82 namespace IndexedDBAgentState { | 82 namespace IndexedDBAgentState { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); | 112 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); |
| 113 IDBAny* requestResult = idbRequest->resultAsAny(); | 113 IDBAny* requestResult = idbRequest->resultAsAny(); |
| 114 if (requestResult->type() != IDBAny::DOMStringListType) { | 114 if (requestResult->type() != IDBAny::DOMStringListType) { |
| 115 m_requestCallback->sendFailure("Unexpected result type."); | 115 m_requestCallback->sendFailure("Unexpected result type."); |
| 116 return; | 116 return; |
| 117 } | 117 } |
| 118 | 118 |
| 119 RefPtrWillBeRawPtr<DOMStringList> databaseNamesList = requestResult->dom
StringList(); | 119 RefPtrWillBeRawPtr<DOMStringList> databaseNamesList = requestResult->dom
StringList(); |
| 120 RefPtr<protocol::TypeBuilder::Array<String>> databaseNames = protocol::T
ypeBuilder::Array<String>::create(); | 120 OwnPtr<protocol::Array<String>> databaseNames = protocol::Array<String>:
:create(); |
| 121 for (size_t i = 0; i < databaseNamesList->length(); ++i) | 121 for (size_t i = 0; i < databaseNamesList->length(); ++i) |
| 122 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i))
; | 122 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i))
; |
| 123 m_requestCallback->sendSuccess(databaseNames.release()); | 123 m_requestCallback->sendSuccess(databaseNames.release()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 DEFINE_INLINE_VIRTUAL_TRACE() | 126 DEFINE_INLINE_VIRTUAL_TRACE() |
| 127 { | 127 { |
| 128 EventListener::trace(visitor); | 128 EventListener::trace(visitor); |
| 129 } | 129 } |
| 130 | 130 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 265 |
| 266 static IDBIndex* indexForObjectStore(IDBObjectStore* idbObjectStore, const Strin
g& indexName) | 266 static IDBIndex* indexForObjectStore(IDBObjectStore* idbObjectStore, const Strin
g& indexName) |
| 267 { | 267 { |
| 268 TrackExceptionState exceptionState; | 268 TrackExceptionState exceptionState; |
| 269 IDBIndex* idbIndex = idbObjectStore->index(indexName, exceptionState); | 269 IDBIndex* idbIndex = idbObjectStore->index(indexName, exceptionState); |
| 270 if (exceptionState.hadException()) | 270 if (exceptionState.hadException()) |
| 271 return nullptr; | 271 return nullptr; |
| 272 return idbIndex; | 272 return idbIndex; |
| 273 } | 273 } |
| 274 | 274 |
| 275 static PassRefPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath) | 275 static PassOwnPtr<KeyPath> keyPathFromIDBKeyPath(const IDBKeyPath& idbKeyPath) |
| 276 { | 276 { |
| 277 RefPtr<KeyPath> keyPath; | 277 OwnPtr<KeyPath> keyPath; |
| 278 switch (idbKeyPath.type()) { | 278 switch (idbKeyPath.type()) { |
| 279 case IDBKeyPath::NullType: | 279 case IDBKeyPath::NullType: |
| 280 keyPath = KeyPath::create().setType(KeyPath::Type::Null); | 280 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::Null).build(); |
| 281 break; | 281 break; |
| 282 case IDBKeyPath::StringType: | 282 case IDBKeyPath::StringType: |
| 283 keyPath = KeyPath::create().setType(KeyPath::Type::String); | 283 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::String).setString
(idbKeyPath.string()).build(); |
| 284 keyPath->setString(idbKeyPath.string()); | |
| 285 break; | 284 break; |
| 286 case IDBKeyPath::ArrayType: { | 285 case IDBKeyPath::ArrayType: { |
| 287 keyPath = KeyPath::create().setType(KeyPath::Type::Array); | 286 keyPath = KeyPath::create().setType(KeyPath::TypeEnum::Array).build(); |
| 288 RefPtr<protocol::TypeBuilder::Array<String>> array = protocol::TypeBuild
er::Array<String>::create(); | 287 OwnPtr<protocol::Array<String>> array = protocol::Array<String>::create(
); |
| 289 const Vector<String>& stringArray = idbKeyPath.array(); | 288 const Vector<String>& stringArray = idbKeyPath.array(); |
| 290 for (size_t i = 0; i < stringArray.size(); ++i) | 289 for (size_t i = 0; i < stringArray.size(); ++i) |
| 291 array->addItem(stringArray[i]); | 290 array->addItem(stringArray[i]); |
| 292 keyPath->setArray(array); | 291 keyPath->setArray(array.release()); |
| 293 break; | 292 break; |
| 294 } | 293 } |
| 295 default: | 294 default: |
| 296 ASSERT_NOT_REACHED(); | 295 ASSERT_NOT_REACHED(); |
| 297 } | 296 } |
| 298 | 297 |
| 299 return keyPath.release(); | 298 return keyPath.release(); |
| 300 } | 299 } |
| 301 | 300 |
| 302 class DatabaseLoader final : public ExecutableWithDatabase { | 301 class DatabaseLoader final : public ExecutableWithDatabase { |
| 303 public: | 302 public: |
| 304 static PassRefPtr<DatabaseLoader> create(ScriptState* scriptState, PassRefPt
r<RequestDatabaseCallback> requestCallback) | 303 static PassRefPtr<DatabaseLoader> create(ScriptState* scriptState, PassRefPt
r<RequestDatabaseCallback> requestCallback) |
| 305 { | 304 { |
| 306 return adoptRef(new DatabaseLoader(scriptState, requestCallback)); | 305 return adoptRef(new DatabaseLoader(scriptState, requestCallback)); |
| 307 } | 306 } |
| 308 | 307 |
| 309 ~DatabaseLoader() override { } | 308 ~DatabaseLoader() override { } |
| 310 | 309 |
| 311 void execute(IDBDatabase* idbDatabase) override | 310 void execute(IDBDatabase* idbDatabase) override |
| 312 { | 311 { |
| 313 if (!requestCallback()->isActive()) | 312 if (!requestCallback()->isActive()) |
| 314 return; | 313 return; |
| 315 | 314 |
| 316 const IDBDatabaseMetadata databaseMetadata = idbDatabase->metadata(); | 315 const IDBDatabaseMetadata databaseMetadata = idbDatabase->metadata(); |
| 317 | 316 |
| 318 RefPtr<protocol::TypeBuilder::Array<protocol::TypeBuilder::IndexedDB::Ob
jectStore>> objectStores = protocol::TypeBuilder::Array<protocol::TypeBuilder::I
ndexedDB::ObjectStore>::create(); | 317 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStore>> objectStores =
protocol::Array<protocol::IndexedDB::ObjectStore>::create(); |
| 319 | 318 |
| 320 for (const auto& storeMapEntry : databaseMetadata.objectStores) { | 319 for (const auto& storeMapEntry : databaseMetadata.objectStores) { |
| 321 const IDBObjectStoreMetadata& objectStoreMetadata = storeMapEntry.va
lue; | 320 const IDBObjectStoreMetadata& objectStoreMetadata = storeMapEntry.va
lue; |
| 322 | 321 |
| 323 RefPtr<protocol::TypeBuilder::Array<protocol::TypeBuilder::IndexedDB
::ObjectStoreIndex>> indexes = protocol::TypeBuilder::Array<protocol::TypeBuilde
r::IndexedDB::ObjectStoreIndex>::create(); | 322 OwnPtr<protocol::Array<protocol::IndexedDB::ObjectStoreIndex>> index
es = protocol::Array<protocol::IndexedDB::ObjectStoreIndex>::create(); |
| 324 | 323 |
| 325 for (const auto& metadataMapEntry : objectStoreMetadata.indexes) { | 324 for (const auto& metadataMapEntry : objectStoreMetadata.indexes) { |
| 326 const IDBIndexMetadata& indexMetadata = metadataMapEntry.value; | 325 const IDBIndexMetadata& indexMetadata = metadataMapEntry.value; |
| 327 | 326 |
| 328 RefPtr<ObjectStoreIndex> objectStoreIndex = ObjectStoreIndex::cr
eate() | 327 OwnPtr<ObjectStoreIndex> objectStoreIndex = ObjectStoreIndex::cr
eate() |
| 329 .setName(indexMetadata.name) | 328 .setName(indexMetadata.name) |
| 330 .setKeyPath(keyPathFromIDBKeyPath(indexMetadata.keyPath)) | 329 .setKeyPath(keyPathFromIDBKeyPath(indexMetadata.keyPath)) |
| 331 .setUnique(indexMetadata.unique) | 330 .setUnique(indexMetadata.unique) |
| 332 .setMultiEntry(indexMetadata.multiEntry); | 331 .setMultiEntry(indexMetadata.multiEntry).build(); |
| 333 indexes->addItem(objectStoreIndex); | 332 indexes->addItem(objectStoreIndex.release()); |
| 334 } | 333 } |
| 335 | 334 |
| 336 RefPtr<ObjectStore> objectStore = ObjectStore::create() | 335 OwnPtr<ObjectStore> objectStore = ObjectStore::create() |
| 337 .setName(objectStoreMetadata.name) | 336 .setName(objectStoreMetadata.name) |
| 338 .setKeyPath(keyPathFromIDBKeyPath(objectStoreMetadata.keyPath)) | 337 .setKeyPath(keyPathFromIDBKeyPath(objectStoreMetadata.keyPath)) |
| 339 .setAutoIncrement(objectStoreMetadata.autoIncrement) | 338 .setAutoIncrement(objectStoreMetadata.autoIncrement) |
| 340 .setIndexes(indexes); | 339 .setIndexes(indexes.release()).build(); |
| 341 objectStores->addItem(objectStore); | 340 objectStores->addItem(objectStore.release()); |
| 342 } | 341 } |
| 343 RefPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea
te() | 342 OwnPtr<DatabaseWithObjectStores> result = DatabaseWithObjectStores::crea
te() |
| 344 .setName(databaseMetadata.name) | 343 .setName(databaseMetadata.name) |
| 345 .setIntVersion(databaseMetadata.intVersion) | 344 .setIntVersion(databaseMetadata.intVersion) |
| 346 .setObjectStores(objectStores); | 345 .setObjectStores(objectStores.release()).build(); |
| 347 | 346 |
| 348 m_requestCallback->sendSuccess(result); | 347 m_requestCallback->sendSuccess(result.release()); |
| 349 } | 348 } |
| 350 | 349 |
| 351 RequestCallback* requestCallback() override { return m_requestCallback.get()
; } | 350 RequestCallback* requestCallback() override { return m_requestCallback.get()
; } |
| 352 private: | 351 private: |
| 353 DatabaseLoader(ScriptState* scriptState, PassRefPtr<RequestDatabaseCallback>
requestCallback) | 352 DatabaseLoader(ScriptState* scriptState, PassRefPtr<RequestDatabaseCallback>
requestCallback) |
| 354 : ExecutableWithDatabase(scriptState) | 353 : ExecutableWithDatabase(scriptState) |
| 355 , m_requestCallback(requestCallback) { } | 354 , m_requestCallback(requestCallback) { } |
| 356 RefPtr<RequestDatabaseCallback> m_requestCallback; | 355 RefPtr<RequestDatabaseCallback> m_requestCallback; |
| 357 }; | 356 }; |
| 358 | 357 |
| 359 static IDBKey* idbKeyFromInspectorObject(JSONObject* key) | 358 static IDBKey* idbKeyFromInspectorObject(PassOwnPtr<protocol::IndexedDB::Key> ke
y) |
| 360 { | 359 { |
| 361 IDBKey* idbKey; | 360 IDBKey* idbKey; |
| 362 | 361 |
| 363 String type; | 362 if (!key || !key->hasType()) |
| 364 if (!key->getString("type", &type)) | |
| 365 return nullptr; | 363 return nullptr; |
| 364 String type = key->getType(); |
| 366 | 365 |
| 367 DEFINE_STATIC_LOCAL(String, s_number, ("number")); | 366 DEFINE_STATIC_LOCAL(String, s_number, ("number")); |
| 368 DEFINE_STATIC_LOCAL(String, s_string, ("string")); | 367 DEFINE_STATIC_LOCAL(String, s_string, ("string")); |
| 369 DEFINE_STATIC_LOCAL(String, s_date, ("date")); | 368 DEFINE_STATIC_LOCAL(String, s_date, ("date")); |
| 370 DEFINE_STATIC_LOCAL(String, s_array, ("array")); | 369 DEFINE_STATIC_LOCAL(String, s_array, ("array")); |
| 371 | 370 |
| 372 if (type == s_number) { | 371 if (type == s_number) { |
| 373 double number; | 372 if (!key->hasNumber()) |
| 374 if (!key->getNumber("number", &number)) | |
| 375 return nullptr; | 373 return nullptr; |
| 376 idbKey = IDBKey::createNumber(number); | 374 idbKey = IDBKey::createNumber(key->getNumber(0)); |
| 377 } else if (type == s_string) { | 375 } else if (type == s_string) { |
| 378 String string; | 376 if (!key->hasString()) |
| 379 if (!key->getString("string", &string)) | |
| 380 return nullptr; | 377 return nullptr; |
| 381 idbKey = IDBKey::createString(string); | 378 idbKey = IDBKey::createString(key->getString(String())); |
| 382 } else if (type == s_date) { | 379 } else if (type == s_date) { |
| 383 double date; | 380 if (!key->hasDate()) |
| 384 if (!key->getNumber("date", &date)) | |
| 385 return nullptr; | 381 return nullptr; |
| 386 idbKey = IDBKey::createDate(date); | 382 idbKey = IDBKey::createDate(key->getDate(0)); |
| 387 } else if (type == s_array) { | 383 } else if (type == s_array) { |
| 388 IDBKey::KeyArray keyArray; | 384 IDBKey::KeyArray keyArray; |
| 389 RefPtr<JSONArray> array = key->getArray("array"); | 385 auto array = key->getArray(nullptr); |
| 390 for (size_t i = 0; i < array->length(); ++i) { | 386 for (size_t i = 0; array && i < array->length(); ++i) |
| 391 RefPtr<JSONValue> value = array->get(i); | 387 keyArray.append(idbKeyFromInspectorObject(array->get(i))); |
| 392 RefPtr<JSONObject> object; | |
| 393 if (!value->asObject(&object)) | |
| 394 return nullptr; | |
| 395 keyArray.append(idbKeyFromInspectorObject(object.get())); | |
| 396 } | |
| 397 idbKey = IDBKey::createArray(keyArray); | 388 idbKey = IDBKey::createArray(keyArray); |
| 398 } else { | 389 } else { |
| 399 return nullptr; | 390 return nullptr; |
| 400 } | 391 } |
| 401 | 392 |
| 402 return idbKey; | 393 return idbKey; |
| 403 } | 394 } |
| 404 | 395 |
| 405 static IDBKeyRange* idbKeyRangeFromKeyRange(JSONObject* keyRange) | 396 static IDBKeyRange* idbKeyRangeFromKeyRange(PassOwnPtr<protocol::IndexedDB::KeyR
ange> keyRange) |
| 406 { | 397 { |
| 407 RefPtr<JSONObject> lower = keyRange->getObject("lower"); | 398 IDBKey* idbLower = idbKeyFromInspectorObject(keyRange->getLower(nullptr)); |
| 408 IDBKey* idbLower = lower ? idbKeyFromInspectorObject(lower.get()) : nullptr; | 399 if (keyRange->hasLower() && !idbLower) |
| 409 if (lower && !idbLower) | |
| 410 return nullptr; | 400 return nullptr; |
| 411 | 401 |
| 412 RefPtr<JSONObject> upper = keyRange->getObject("upper"); | 402 IDBKey* idbUpper = idbKeyFromInspectorObject(keyRange->getUpper(nullptr)); |
| 413 IDBKey* idbUpper = upper ? idbKeyFromInspectorObject(upper.get()) : nullptr; | 403 if (keyRange->hasUpper() && !idbUpper) |
| 414 if (upper && !idbUpper) | |
| 415 return nullptr; | 404 return nullptr; |
| 416 | 405 |
| 417 bool lowerOpen; | 406 if (!keyRange->hasLowerOpen()) |
| 418 if (!keyRange->getBoolean("lowerOpen", &lowerOpen)) | |
| 419 return nullptr; | 407 return nullptr; |
| 420 IDBKeyRange::LowerBoundType lowerBoundType = lowerOpen ? IDBKeyRange::LowerB
oundOpen : IDBKeyRange::LowerBoundClosed; | 408 IDBKeyRange::LowerBoundType lowerBoundType = keyRange->getLowerOpen() ? IDBK
eyRange::LowerBoundOpen : IDBKeyRange::LowerBoundClosed; |
| 421 | 409 |
| 422 bool upperOpen; | 410 if (!keyRange->hasUpperOpen()) |
| 423 if (!keyRange->getBoolean("upperOpen", &upperOpen)) | |
| 424 return nullptr; | 411 return nullptr; |
| 425 IDBKeyRange::UpperBoundType upperBoundType = upperOpen ? IDBKeyRange::UpperB
oundOpen : IDBKeyRange::UpperBoundClosed; | 412 IDBKeyRange::UpperBoundType upperBoundType = keyRange->getUpperOpen() ? IDBK
eyRange::UpperBoundOpen : IDBKeyRange::UpperBoundClosed; |
| 426 | 413 |
| 427 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp
e); | 414 return IDBKeyRange::create(idbLower, idbUpper, lowerBoundType, upperBoundTyp
e); |
| 428 } | 415 } |
| 429 | 416 |
| 430 class DataLoader; | 417 class DataLoader; |
| 431 | 418 |
| 432 class OpenCursorCallback final : public EventListener { | 419 class OpenCursorCallback final : public EventListener { |
| 433 public: | 420 public: |
| 434 static PassRefPtrWillBeRawPtr<OpenCursorCallback> create(ScriptState* script
State, PassRefPtr<RequestDataCallback> requestCallback, int skipCount, unsigned
pageSize) | 421 static PassRefPtrWillBeRawPtr<OpenCursorCallback> create(ScriptState* script
State, PassRefPtr<RequestDataCallback> requestCallback, int skipCount, unsigned
pageSize) |
| 435 { | 422 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 // object is inspected. | 479 // object is inspected. |
| 493 const String errorMessage("\"Inspection error. Maximum depth reached?\""
); | 480 const String errorMessage("\"Inspection error. Maximum depth reached?\""
); |
| 494 ScriptState* scriptState = m_scriptState.get(); | 481 ScriptState* scriptState = m_scriptState.get(); |
| 495 ScriptState::Scope scope(scriptState); | 482 ScriptState::Scope scope(scriptState); |
| 496 RefPtr<JSONValue> keyJsonValue = toJSONValue(scriptState->context(), idb
Cursor->key(scriptState).v8Value()); | 483 RefPtr<JSONValue> keyJsonValue = toJSONValue(scriptState->context(), idb
Cursor->key(scriptState).v8Value()); |
| 497 RefPtr<JSONValue> primaryKeyJsonValue = toJSONValue(scriptState->context
(), idbCursor->primaryKey(scriptState).v8Value()); | 484 RefPtr<JSONValue> primaryKeyJsonValue = toJSONValue(scriptState->context
(), idbCursor->primaryKey(scriptState).v8Value()); |
| 498 RefPtr<JSONValue> valueJsonValue = toJSONValue(scriptState->context(), i
dbCursor->value(scriptState).v8Value()); | 485 RefPtr<JSONValue> valueJsonValue = toJSONValue(scriptState->context(), i
dbCursor->value(scriptState).v8Value()); |
| 499 String key = keyJsonValue ? keyJsonValue->toJSONString() : errorMessage; | 486 String key = keyJsonValue ? keyJsonValue->toJSONString() : errorMessage; |
| 500 String value = valueJsonValue ? valueJsonValue->toJSONString() : errorMe
ssage; | 487 String value = valueJsonValue ? valueJsonValue->toJSONString() : errorMe
ssage; |
| 501 String primaryKey = primaryKeyJsonValue ? primaryKeyJsonValue->toJSONStr
ing() : errorMessage; | 488 String primaryKey = primaryKeyJsonValue ? primaryKeyJsonValue->toJSONStr
ing() : errorMessage; |
| 502 RefPtr<DataEntry> dataEntry = DataEntry::create() | 489 OwnPtr<DataEntry> dataEntry = DataEntry::create() |
| 503 .setKey(key) | 490 .setKey(key) |
| 504 .setPrimaryKey(primaryKey) | 491 .setPrimaryKey(primaryKey) |
| 505 .setValue(value); | 492 .setValue(value).build(); |
| 506 m_result->addItem(dataEntry); | 493 m_result->addItem(dataEntry.release()); |
| 507 } | 494 } |
| 508 | 495 |
| 509 void end(bool hasMore) | 496 void end(bool hasMore) |
| 510 { | 497 { |
| 511 if (!m_requestCallback->isActive()) | 498 if (!m_requestCallback->isActive()) |
| 512 return; | 499 return; |
| 513 m_requestCallback->sendSuccess(m_result.release(), hasMore); | 500 m_requestCallback->sendSuccess(m_result.release(), hasMore); |
| 514 } | 501 } |
| 515 | 502 |
| 516 DEFINE_INLINE_VIRTUAL_TRACE() | 503 DEFINE_INLINE_VIRTUAL_TRACE() |
| 517 { | 504 { |
| 518 EventListener::trace(visitor); | 505 EventListener::trace(visitor); |
| 519 } | 506 } |
| 520 | 507 |
| 521 private: | 508 private: |
| 522 OpenCursorCallback(ScriptState* scriptState, PassRefPtr<RequestDataCallback>
requestCallback, int skipCount, unsigned pageSize) | 509 OpenCursorCallback(ScriptState* scriptState, PassRefPtr<RequestDataCallback>
requestCallback, int skipCount, unsigned pageSize) |
| 523 : EventListener(EventListener::CPPEventListenerType) | 510 : EventListener(EventListener::CPPEventListenerType) |
| 524 , m_scriptState(scriptState) | 511 , m_scriptState(scriptState) |
| 525 , m_requestCallback(requestCallback) | 512 , m_requestCallback(requestCallback) |
| 526 , m_skipCount(skipCount) | 513 , m_skipCount(skipCount) |
| 527 , m_pageSize(pageSize) | 514 , m_pageSize(pageSize) |
| 528 { | 515 { |
| 529 m_result = Array<DataEntry>::create(); | 516 m_result = Array<DataEntry>::create(); |
| 530 } | 517 } |
| 531 | 518 |
| 532 RefPtr<ScriptState> m_scriptState; | 519 RefPtr<ScriptState> m_scriptState; |
| 533 RefPtr<RequestDataCallback> m_requestCallback; | 520 RefPtr<RequestDataCallback> m_requestCallback; |
| 534 int m_skipCount; | 521 int m_skipCount; |
| 535 unsigned m_pageSize; | 522 unsigned m_pageSize; |
| 536 RefPtr<Array<DataEntry>> m_result; | 523 OwnPtr<Array<DataEntry>> m_result; |
| 537 }; | 524 }; |
| 538 | 525 |
| 539 class DataLoader final : public ExecutableWithDatabase { | 526 class DataLoader final : public ExecutableWithDatabase { |
| 540 public: | 527 public: |
| 541 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassRefPtr<Re
questDataCallback> requestCallback, const String& objectStoreName, const String&
indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize) | 528 static PassRefPtr<DataLoader> create(ScriptState* scriptState, PassRefPtr<Re
questDataCallback> requestCallback, const String& objectStoreName, const String&
indexName, IDBKeyRange* idbKeyRange, int skipCount, unsigned pageSize) |
| 542 { | 529 { |
| 543 return adoptRef(new DataLoader(scriptState, requestCallback, objectStore
Name, indexName, idbKeyRange, skipCount, pageSize)); | 530 return adoptRef(new DataLoader(scriptState, requestCallback, objectStore
Name, indexName, idbKeyRange, skipCount, pageSize)); |
| 544 } | 531 } |
| 545 | 532 |
| 546 ~DataLoader() override { } | 533 ~DataLoader() override { } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 return; | 679 return; |
| 693 | 680 |
| 694 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 681 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 695 if (!scriptState) | 682 if (!scriptState) |
| 696 return; | 683 return; |
| 697 ScriptState::Scope scope(scriptState); | 684 ScriptState::Scope scope(scriptState); |
| 698 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState,
requestCallback); | 685 RefPtr<DatabaseLoader> databaseLoader = DatabaseLoader::create(scriptState,
requestCallback); |
| 699 databaseLoader->start(idbFactory, document->securityOrigin(), databaseName); | 686 databaseLoader->start(idbFactory, document->securityOrigin(), databaseName); |
| 700 } | 687 } |
| 701 | 688 |
| 702 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, const String
& securityOrigin, const String& databaseName, const String& objectStoreName, con
st String& indexName, int skipCount, int pageSize, const RefPtr<JSONObject>* key
Range, const PassRefPtr<RequestDataCallback> requestCallback) | 689 void InspectorIndexedDBAgent::requestData(ErrorString* errorString, const String
& securityOrigin, const String& databaseName, const String& objectStoreName, con
st String& indexName, int skipCount, int pageSize, PassOwnPtr<protocol::IndexedD
B::KeyRange> keyRange, const PassRefPtr<RequestDataCallback> requestCallback) |
| 703 { | 690 { |
| 704 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi
n); | 691 LocalFrame* frame = m_inspectedFrames->frameWithSecurityOrigin(securityOrigi
n); |
| 705 Document* document = assertDocument(errorString, frame); | 692 Document* document = assertDocument(errorString, frame); |
| 706 if (!document) | 693 if (!document) |
| 707 return; | 694 return; |
| 708 IDBFactory* idbFactory = assertIDBFactory(errorString, document); | 695 IDBFactory* idbFactory = assertIDBFactory(errorString, document); |
| 709 if (!idbFactory) | 696 if (!idbFactory) |
| 710 return; | 697 return; |
| 711 | 698 |
| 712 IDBKeyRange* idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(keyRange->get(
)) : nullptr; | 699 IDBKeyRange* idbKeyRange = keyRange ? idbKeyRangeFromKeyRange(keyRange) : nu
llptr; |
| 713 if (keyRange && !idbKeyRange) { | 700 if (keyRange && !idbKeyRange) { |
| 714 *errorString = "Can not parse key range."; | 701 *errorString = "Can not parse key range."; |
| 715 return; | 702 return; |
| 716 } | 703 } |
| 717 | 704 |
| 718 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 705 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 719 if (!scriptState) | 706 if (!scriptState) |
| 720 return; | 707 return; |
| 721 ScriptState::Scope scope(scriptState); | 708 ScriptState::Scope scope(scriptState); |
| 722 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb
ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize); | 709 RefPtr<DataLoader> dataLoader = DataLoader::create(scriptState, requestCallb
ack, objectStoreName, indexName, idbKeyRange, skipCount, pageSize); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
); | 817 clearObjectStore->start(idbFactory, document->securityOrigin(), databaseName
); |
| 831 } | 818 } |
| 832 | 819 |
| 833 DEFINE_TRACE(InspectorIndexedDBAgent) | 820 DEFINE_TRACE(InspectorIndexedDBAgent) |
| 834 { | 821 { |
| 835 visitor->trace(m_inspectedFrames); | 822 visitor->trace(m_inspectedFrames); |
| 836 InspectorBaseAgent::trace(visitor); | 823 InspectorBaseAgent::trace(visitor); |
| 837 } | 824 } |
| 838 | 825 |
| 839 } // namespace blink | 826 } // namespace blink |
| OLD | NEW |