| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 ClearObjectStoreCallback; | 80 ClearObjectStoreCallback; |
| 81 | 81 |
| 82 namespace blink { | 82 namespace blink { |
| 83 | 83 |
| 84 namespace IndexedDBAgentState { | 84 namespace IndexedDBAgentState { |
| 85 static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled"; | 85 static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled"; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 namespace { | 88 namespace { |
| 89 | 89 |
| 90 static const char indexedDBObjectGroup[] = "indexeddb"; | 90 static const char kIndexedDBObjectGroup[] = "indexeddb"; |
| 91 static const char kNoDocumentError[] = "No document for given frame found"; |
| 91 | 92 |
| 92 class GetDatabaseNamesCallback final : public EventListener { | 93 class GetDatabaseNamesCallback final : public EventListener { |
| 93 WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback); | 94 WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback); |
| 94 | 95 |
| 95 public: | 96 public: |
| 96 static GetDatabaseNamesCallback* create( | 97 static GetDatabaseNamesCallback* create( |
| 97 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback, | 98 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback, |
| 98 const String& securityOrigin) { | 99 const String& securityOrigin) { |
| 99 return new GetDatabaseNamesCallback(std::move(requestCallback), | 100 return new GetDatabaseNamesCallback(std::move(requestCallback), |
| 100 securityOrigin); | 101 securityOrigin); |
| 101 } | 102 } |
| 102 | 103 |
| 103 ~GetDatabaseNamesCallback() override {} | 104 ~GetDatabaseNamesCallback() override {} |
| 104 | 105 |
| 105 bool operator==(const EventListener& other) const override { | 106 bool operator==(const EventListener& other) const override { |
| 106 return this == &other; | 107 return this == &other; |
| 107 } | 108 } |
| 108 | 109 |
| 109 void handleEvent(ExecutionContext*, Event* event) override { | 110 void handleEvent(ExecutionContext*, Event* event) override { |
| 110 if (event->type() != EventTypeNames::success) { | 111 if (event->type() != EventTypeNames::success) { |
| 111 m_requestCallback->sendFailure("Unexpected event type."); | 112 m_requestCallback->sendFailure(Response::Error("Unexpected event type.")); |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 | 115 |
| 115 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); | 116 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); |
| 116 IDBAny* requestResult = idbRequest->resultAsAny(); | 117 IDBAny* requestResult = idbRequest->resultAsAny(); |
| 117 if (requestResult->getType() != IDBAny::DOMStringListType) { | 118 if (requestResult->getType() != IDBAny::DOMStringListType) { |
| 118 m_requestCallback->sendFailure("Unexpected result type."); | 119 m_requestCallback->sendFailure( |
| 120 Response::Error("Unexpected result type.")); |
| 119 return; | 121 return; |
| 120 } | 122 } |
| 121 | 123 |
| 122 DOMStringList* databaseNamesList = requestResult->domStringList(); | 124 DOMStringList* databaseNamesList = requestResult->domStringList(); |
| 123 std::unique_ptr<protocol::Array<String>> databaseNames = | 125 std::unique_ptr<protocol::Array<String>> databaseNames = |
| 124 protocol::Array<String>::create(); | 126 protocol::Array<String>::create(); |
| 125 for (size_t i = 0; i < databaseNamesList->length(); ++i) | 127 for (size_t i = 0; i < databaseNamesList->length(); ++i) |
| 126 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i)); | 128 databaseNames->addItem(databaseNamesList->anonymousIndexedGetter(i)); |
| 127 m_requestCallback->sendSuccess(std::move(databaseNames)); | 129 m_requestCallback->sendSuccess(std::move(databaseNames)); |
| 128 } | 130 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 156 SecurityOrigin*, | 158 SecurityOrigin*, |
| 157 const String& databaseName) { | 159 const String& databaseName) { |
| 158 OpenDatabaseCallback<RequestCallback>* openCallback = | 160 OpenDatabaseCallback<RequestCallback>* openCallback = |
| 159 OpenDatabaseCallback<RequestCallback>::create(this); | 161 OpenDatabaseCallback<RequestCallback>::create(this); |
| 160 UpgradeDatabaseCallback<RequestCallback>* upgradeCallback = | 162 UpgradeDatabaseCallback<RequestCallback>* upgradeCallback = |
| 161 UpgradeDatabaseCallback<RequestCallback>::create(this); | 163 UpgradeDatabaseCallback<RequestCallback>::create(this); |
| 162 TrackExceptionState exceptionState; | 164 TrackExceptionState exceptionState; |
| 163 IDBOpenDBRequest* idbOpenDBRequest = | 165 IDBOpenDBRequest* idbOpenDBRequest = |
| 164 idbFactory->open(getScriptState(), databaseName, exceptionState); | 166 idbFactory->open(getScriptState(), databaseName, exceptionState); |
| 165 if (exceptionState.hadException()) { | 167 if (exceptionState.hadException()) { |
| 166 getRequestCallback()->sendFailure("Could not open database."); | 168 getRequestCallback()->sendFailure( |
| 169 Response::Error("Could not open database.")); |
| 167 return; | 170 return; |
| 168 } | 171 } |
| 169 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, | 172 idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, |
| 170 upgradeCallback, false); | 173 upgradeCallback, false); |
| 171 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback, | 174 idbOpenDBRequest->addEventListener(EventTypeNames::success, openCallback, |
| 172 false); | 175 false); |
| 173 } | 176 } |
| 174 virtual void execute(IDBDatabase*) = 0; | 177 virtual void execute(IDBDatabase*) = 0; |
| 175 virtual RequestCallback* getRequestCallback() = 0; | 178 virtual RequestCallback* getRequestCallback() = 0; |
| 176 ExecutionContext* context() const { | 179 ExecutionContext* context() const { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 192 | 195 |
| 193 ~OpenDatabaseCallback() override {} | 196 ~OpenDatabaseCallback() override {} |
| 194 | 197 |
| 195 bool operator==(const EventListener& other) const override { | 198 bool operator==(const EventListener& other) const override { |
| 196 return this == &other; | 199 return this == &other; |
| 197 } | 200 } |
| 198 | 201 |
| 199 void handleEvent(ExecutionContext* context, Event* event) override { | 202 void handleEvent(ExecutionContext* context, Event* event) override { |
| 200 if (event->type() != EventTypeNames::success) { | 203 if (event->type() != EventTypeNames::success) { |
| 201 m_executableWithDatabase->getRequestCallback()->sendFailure( | 204 m_executableWithDatabase->getRequestCallback()->sendFailure( |
| 202 "Unexpected event type."); | 205 Response::Error("Unexpected event type.")); |
| 203 return; | 206 return; |
| 204 } | 207 } |
| 205 | 208 |
| 206 IDBOpenDBRequest* idbOpenDBRequest = | 209 IDBOpenDBRequest* idbOpenDBRequest = |
| 207 static_cast<IDBOpenDBRequest*>(event->target()); | 210 static_cast<IDBOpenDBRequest*>(event->target()); |
| 208 IDBAny* requestResult = idbOpenDBRequest->resultAsAny(); | 211 IDBAny* requestResult = idbOpenDBRequest->resultAsAny(); |
| 209 if (requestResult->getType() != IDBAny::IDBDatabaseType) { | 212 if (requestResult->getType() != IDBAny::IDBDatabaseType) { |
| 210 m_executableWithDatabase->getRequestCallback()->sendFailure( | 213 m_executableWithDatabase->getRequestCallback()->sendFailure( |
| 211 "Unexpected result type."); | 214 Response::Error("Unexpected result type.")); |
| 212 return; | 215 return; |
| 213 } | 216 } |
| 214 | 217 |
| 215 IDBDatabase* idbDatabase = requestResult->idbDatabase(); | 218 IDBDatabase* idbDatabase = requestResult->idbDatabase(); |
| 216 m_executableWithDatabase->execute(idbDatabase); | 219 m_executableWithDatabase->execute(idbDatabase); |
| 217 V8PerIsolateData::from( | 220 V8PerIsolateData::from( |
| 218 m_executableWithDatabase->getScriptState()->isolate()) | 221 m_executableWithDatabase->getScriptState()->isolate()) |
| 219 ->runEndOfScopeTasks(); | 222 ->runEndOfScopeTasks(); |
| 220 idbDatabase->close(); | 223 idbDatabase->close(); |
| 221 } | 224 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 238 | 241 |
| 239 ~UpgradeDatabaseCallback() override {} | 242 ~UpgradeDatabaseCallback() override {} |
| 240 | 243 |
| 241 bool operator==(const EventListener& other) const override { | 244 bool operator==(const EventListener& other) const override { |
| 242 return this == &other; | 245 return this == &other; |
| 243 } | 246 } |
| 244 | 247 |
| 245 void handleEvent(ExecutionContext* context, Event* event) override { | 248 void handleEvent(ExecutionContext* context, Event* event) override { |
| 246 if (event->type() != EventTypeNames::upgradeneeded) { | 249 if (event->type() != EventTypeNames::upgradeneeded) { |
| 247 m_executableWithDatabase->getRequestCallback()->sendFailure( | 250 m_executableWithDatabase->getRequestCallback()->sendFailure( |
| 248 "Unexpected event type."); | 251 Response::Error("Unexpected event type.")); |
| 249 return; | 252 return; |
| 250 } | 253 } |
| 251 | 254 |
| 252 // If an "upgradeneeded" event comes through then the database that | 255 // If an "upgradeneeded" event comes through then the database that |
| 253 // had previously been enumerated was deleted. We don't want to | 256 // had previously been enumerated was deleted. We don't want to |
| 254 // implicitly re-create it here, so abort the transaction. | 257 // implicitly re-create it here, so abort the transaction. |
| 255 IDBOpenDBRequest* idbOpenDBRequest = | 258 IDBOpenDBRequest* idbOpenDBRequest = |
| 256 static_cast<IDBOpenDBRequest*>(event->target()); | 259 static_cast<IDBOpenDBRequest*>(event->target()); |
| 257 NonThrowableExceptionState exceptionState; | 260 NonThrowableExceptionState exceptionState; |
| 258 idbOpenDBRequest->transaction()->abort(exceptionState); | 261 idbOpenDBRequest->transaction()->abort(exceptionState); |
| 259 m_executableWithDatabase->getRequestCallback()->sendFailure( | 262 m_executableWithDatabase->getRequestCallback()->sendFailure( |
| 260 "Aborted upgrade."); | 263 Response::Error("Aborted upgrade.")); |
| 261 } | 264 } |
| 262 | 265 |
| 263 private: | 266 private: |
| 264 UpgradeDatabaseCallback( | 267 UpgradeDatabaseCallback( |
| 265 ExecutableWithDatabase<RequestCallback>* executableWithDatabase) | 268 ExecutableWithDatabase<RequestCallback>* executableWithDatabase) |
| 266 : EventListener(EventListener::CPPEventListenerType), | 269 : EventListener(EventListener::CPPEventListenerType), |
| 267 m_executableWithDatabase(executableWithDatabase) {} | 270 m_executableWithDatabase(executableWithDatabase) {} |
| 268 RefPtr<ExecutableWithDatabase<RequestCallback>> m_executableWithDatabase; | 271 RefPtr<ExecutableWithDatabase<RequestCallback>> m_executableWithDatabase; |
| 269 }; | 272 }; |
| 270 | 273 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } | 479 } |
| 477 | 480 |
| 478 ~OpenCursorCallback() override {} | 481 ~OpenCursorCallback() override {} |
| 479 | 482 |
| 480 bool operator==(const EventListener& other) const override { | 483 bool operator==(const EventListener& other) const override { |
| 481 return this == &other; | 484 return this == &other; |
| 482 } | 485 } |
| 483 | 486 |
| 484 void handleEvent(ExecutionContext*, Event* event) override { | 487 void handleEvent(ExecutionContext*, Event* event) override { |
| 485 if (event->type() != EventTypeNames::success) { | 488 if (event->type() != EventTypeNames::success) { |
| 486 m_requestCallback->sendFailure("Unexpected event type."); | 489 m_requestCallback->sendFailure(Response::Error("Unexpected event type.")); |
| 487 return; | 490 return; |
| 488 } | 491 } |
| 489 | 492 |
| 490 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); | 493 IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); |
| 491 IDBAny* requestResult = idbRequest->resultAsAny(); | 494 IDBAny* requestResult = idbRequest->resultAsAny(); |
| 492 if (requestResult->getType() == IDBAny::IDBValueType) { | 495 if (requestResult->getType() == IDBAny::IDBValueType) { |
| 493 end(false); | 496 end(false); |
| 494 return; | 497 return; |
| 495 } | 498 } |
| 496 if (requestResult->getType() != IDBAny::IDBCursorWithValueType) { | 499 if (requestResult->getType() != IDBAny::IDBCursorWithValueType) { |
| 497 m_requestCallback->sendFailure("Unexpected result type."); | 500 m_requestCallback->sendFailure( |
| 501 Response::Error("Unexpected result type.")); |
| 498 return; | 502 return; |
| 499 } | 503 } |
| 500 | 504 |
| 501 IDBCursorWithValue* idbCursor = requestResult->idbCursorWithValue(); | 505 IDBCursorWithValue* idbCursor = requestResult->idbCursorWithValue(); |
| 502 | 506 |
| 503 if (m_skipCount) { | 507 if (m_skipCount) { |
| 504 TrackExceptionState exceptionState; | 508 TrackExceptionState exceptionState; |
| 505 idbCursor->advance(m_skipCount, exceptionState); | 509 idbCursor->advance(m_skipCount, exceptionState); |
| 506 if (exceptionState.hadException()) | 510 if (exceptionState.hadException()) { |
| 507 m_requestCallback->sendFailure("Could not advance cursor."); | 511 m_requestCallback->sendFailure( |
| 512 Response::Error("Could not advance cursor.")); |
| 513 } |
| 508 m_skipCount = 0; | 514 m_skipCount = 0; |
| 509 return; | 515 return; |
| 510 } | 516 } |
| 511 | 517 |
| 512 if (m_result->length() == m_pageSize) { | 518 if (m_result->length() == m_pageSize) { |
| 513 end(true); | 519 end(true); |
| 514 return; | 520 return; |
| 515 } | 521 } |
| 516 | 522 |
| 517 // Continue cursor before making injected script calls, otherwise | 523 // Continue cursor before making injected script calls, otherwise |
| 518 // transaction might be finished. | 524 // transaction might be finished. |
| 519 TrackExceptionState exceptionState; | 525 TrackExceptionState exceptionState; |
| 520 idbCursor->continueFunction(nullptr, nullptr, exceptionState); | 526 idbCursor->continueFunction(nullptr, nullptr, exceptionState); |
| 521 if (exceptionState.hadException()) { | 527 if (exceptionState.hadException()) { |
| 522 m_requestCallback->sendFailure("Could not continue cursor."); | 528 m_requestCallback->sendFailure( |
| 529 Response::Error("Could not continue cursor.")); |
| 523 return; | 530 return; |
| 524 } | 531 } |
| 525 | 532 |
| 526 Document* document = toDocument(m_scriptState->getExecutionContext()); | 533 Document* document = toDocument(m_scriptState->getExecutionContext()); |
| 527 if (!document) | 534 if (!document) |
| 528 return; | 535 return; |
| 529 ScriptState* scriptState = m_scriptState.get(); | 536 ScriptState* scriptState = m_scriptState.get(); |
| 530 ScriptState::Scope scope(scriptState); | 537 ScriptState::Scope scope(scriptState); |
| 531 v8::Local<v8::Context> context = scriptState->context(); | 538 v8::Local<v8::Context> context = scriptState->context(); |
| 532 v8_inspector::StringView objectGroup = | 539 v8_inspector::StringView objectGroup = |
| 533 toV8InspectorStringView(indexedDBObjectGroup); | 540 toV8InspectorStringView(kIndexedDBObjectGroup); |
| 534 std::unique_ptr<DataEntry> dataEntry = | 541 std::unique_ptr<DataEntry> dataEntry = |
| 535 DataEntry::create() | 542 DataEntry::create() |
| 536 .setKey(m_v8Session->wrapObject( | 543 .setKey(m_v8Session->wrapObject( |
| 537 context, idbCursor->key(scriptState).v8Value(), objectGroup)) | 544 context, idbCursor->key(scriptState).v8Value(), objectGroup)) |
| 538 .setPrimaryKey(m_v8Session->wrapObject( | 545 .setPrimaryKey(m_v8Session->wrapObject( |
| 539 context, idbCursor->primaryKey(scriptState).v8Value(), | 546 context, idbCursor->primaryKey(scriptState).v8Value(), |
| 540 objectGroup)) | 547 objectGroup)) |
| 541 .setValue(m_v8Session->wrapObject( | 548 .setValue(m_v8Session->wrapObject( |
| 542 context, idbCursor->value(scriptState).v8Value(), objectGroup)) | 549 context, idbCursor->value(scriptState).v8Value(), objectGroup)) |
| 543 .build(); | 550 .build(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 v8Session, scriptState, std::move(requestCallback), objectStoreName, | 595 v8Session, scriptState, std::move(requestCallback), objectStoreName, |
| 589 indexName, idbKeyRange, skipCount, pageSize)); | 596 indexName, idbKeyRange, skipCount, pageSize)); |
| 590 } | 597 } |
| 591 | 598 |
| 592 ~DataLoader() override {} | 599 ~DataLoader() override {} |
| 593 | 600 |
| 594 void execute(IDBDatabase* idbDatabase) override { | 601 void execute(IDBDatabase* idbDatabase) override { |
| 595 IDBTransaction* idbTransaction = transactionForDatabase( | 602 IDBTransaction* idbTransaction = transactionForDatabase( |
| 596 getScriptState(), idbDatabase, m_objectStoreName); | 603 getScriptState(), idbDatabase, m_objectStoreName); |
| 597 if (!idbTransaction) { | 604 if (!idbTransaction) { |
| 598 m_requestCallback->sendFailure("Could not get transaction"); | 605 m_requestCallback->sendFailure( |
| 606 Response::Error("Could not get transaction")); |
| 599 return; | 607 return; |
| 600 } | 608 } |
| 601 IDBObjectStore* idbObjectStore = | 609 IDBObjectStore* idbObjectStore = |
| 602 objectStoreForTransaction(idbTransaction, m_objectStoreName); | 610 objectStoreForTransaction(idbTransaction, m_objectStoreName); |
| 603 if (!idbObjectStore) { | 611 if (!idbObjectStore) { |
| 604 m_requestCallback->sendFailure("Could not get object store"); | 612 m_requestCallback->sendFailure( |
| 613 Response::Error("Could not get object store")); |
| 605 return; | 614 return; |
| 606 } | 615 } |
| 607 | 616 |
| 608 IDBRequest* idbRequest; | 617 IDBRequest* idbRequest; |
| 609 if (!m_indexName.isEmpty()) { | 618 if (!m_indexName.isEmpty()) { |
| 610 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName); | 619 IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName); |
| 611 if (!idbIndex) { | 620 if (!idbIndex) { |
| 612 m_requestCallback->sendFailure("Could not get index"); | 621 m_requestCallback->sendFailure(Response::Error("Could not get index")); |
| 613 return; | 622 return; |
| 614 } | 623 } |
| 615 | 624 |
| 616 idbRequest = idbIndex->openCursor(getScriptState(), m_idbKeyRange.get(), | 625 idbRequest = idbIndex->openCursor(getScriptState(), m_idbKeyRange.get(), |
| 617 WebIDBCursorDirectionNext); | 626 WebIDBCursorDirectionNext); |
| 618 } else { | 627 } else { |
| 619 idbRequest = idbObjectStore->openCursor( | 628 idbRequest = idbObjectStore->openCursor( |
| 620 getScriptState(), m_idbKeyRange.get(), WebIDBCursorDirectionNext); | 629 getScriptState(), m_idbKeyRange.get(), WebIDBCursorDirectionNext); |
| 621 } | 630 } |
| 622 OpenCursorCallback* openCursorCallback = OpenCursorCallback::create( | 631 OpenCursorCallback* openCursorCallback = OpenCursorCallback::create( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 InspectorIndexedDBAgent::InspectorIndexedDBAgent( | 670 InspectorIndexedDBAgent::InspectorIndexedDBAgent( |
| 662 InspectedFrames* inspectedFrames, | 671 InspectedFrames* inspectedFrames, |
| 663 v8_inspector::V8InspectorSession* v8Session) | 672 v8_inspector::V8InspectorSession* v8Session) |
| 664 : m_inspectedFrames(inspectedFrames), m_v8Session(v8Session) {} | 673 : m_inspectedFrames(inspectedFrames), m_v8Session(v8Session) {} |
| 665 | 674 |
| 666 InspectorIndexedDBAgent::~InspectorIndexedDBAgent() {} | 675 InspectorIndexedDBAgent::~InspectorIndexedDBAgent() {} |
| 667 | 676 |
| 668 void InspectorIndexedDBAgent::restore() { | 677 void InspectorIndexedDBAgent::restore() { |
| 669 if (m_state->booleanProperty(IndexedDBAgentState::indexedDBAgentEnabled, | 678 if (m_state->booleanProperty(IndexedDBAgentState::indexedDBAgentEnabled, |
| 670 false)) { | 679 false)) { |
| 671 ErrorString error; | 680 enable(); |
| 672 enable(&error); | |
| 673 } | 681 } |
| 674 } | 682 } |
| 675 | 683 |
| 676 void InspectorIndexedDBAgent::didCommitLoadForLocalFrame(LocalFrame* frame) { | 684 void InspectorIndexedDBAgent::didCommitLoadForLocalFrame(LocalFrame* frame) { |
| 677 if (frame == m_inspectedFrames->root()) | 685 if (frame == m_inspectedFrames->root()) { |
| 678 m_v8Session->releaseObjectGroup( | 686 m_v8Session->releaseObjectGroup( |
| 679 toV8InspectorStringView(indexedDBObjectGroup)); | 687 toV8InspectorStringView(kIndexedDBObjectGroup)); |
| 688 } |
| 680 } | 689 } |
| 681 | 690 |
| 682 void InspectorIndexedDBAgent::enable(ErrorString*) { | 691 Response InspectorIndexedDBAgent::enable() { |
| 683 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, true); | 692 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, true); |
| 693 return Response::OK(); |
| 684 } | 694 } |
| 685 | 695 |
| 686 void InspectorIndexedDBAgent::disable(ErrorString*) { | 696 Response InspectorIndexedDBAgent::disable() { |
| 687 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, false); | 697 m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, false); |
| 688 m_v8Session->releaseObjectGroup( | 698 m_v8Session->releaseObjectGroup( |
| 689 toV8InspectorStringView(indexedDBObjectGroup)); | 699 toV8InspectorStringView(kIndexedDBObjectGroup)); |
| 700 return Response::OK(); |
| 690 } | 701 } |
| 691 | 702 |
| 692 static Document* assertDocument(ErrorString* errorString, LocalFrame* frame) { | 703 static Response assertIDBFactory(Document* document, IDBFactory*& result) { |
| 693 Document* document = frame ? frame->document() : nullptr; | |
| 694 | |
| 695 if (!document) | |
| 696 *errorString = "No document for given frame found"; | |
| 697 | |
| 698 return document; | |
| 699 } | |
| 700 | |
| 701 static IDBFactory* assertIDBFactory(ErrorString* errorString, | |
| 702 Document* document) { | |
| 703 LocalDOMWindow* domWindow = document->domWindow(); | 704 LocalDOMWindow* domWindow = document->domWindow(); |
| 704 if (!domWindow) { | 705 if (!domWindow) |
| 705 *errorString = "No IndexedDB factory for given frame found"; | 706 return Response::Error("No IndexedDB factory for given frame found"); |
| 706 return nullptr; | |
| 707 } | |
| 708 IDBFactory* idbFactory = GlobalIndexedDB::indexedDB(*domWindow); | 707 IDBFactory* idbFactory = GlobalIndexedDB::indexedDB(*domWindow); |
| 709 | 708 |
| 710 if (!idbFactory) | 709 if (!idbFactory) |
| 711 *errorString = "No IndexedDB factory for given frame found"; | 710 return Response::Error("No IndexedDB factory for given frame found"); |
| 712 | 711 result = idbFactory; |
| 713 return idbFactory; | 712 return Response::OK(); |
| 714 } | 713 } |
| 715 | 714 |
| 716 void InspectorIndexedDBAgent::requestDatabaseNames( | 715 void InspectorIndexedDBAgent::requestDatabaseNames( |
| 717 const String& securityOrigin, | 716 const String& securityOrigin, |
| 718 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback) { | 717 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback) { |
| 719 LocalFrame* frame = | 718 LocalFrame* frame = |
| 720 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); | 719 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| 721 ErrorString errorString; | 720 ErrorString errorString; |
| 722 Document* document = assertDocument(&errorString, frame); | 721 Document* document = frame ? frame->document() : nullptr; |
| 723 if (!document) { | 722 if (!document) { |
| 724 requestCallback->sendFailure(errorString); | 723 requestCallback->sendFailure(Response::Error(kNoDocumentError)); |
| 725 return; | 724 return; |
| 726 } | 725 } |
| 727 IDBFactory* idbFactory = assertIDBFactory(&errorString, document); | 726 IDBFactory* idbFactory = nullptr; |
| 728 if (!idbFactory) { | 727 Response response = assertIDBFactory(document, idbFactory); |
| 729 requestCallback->sendFailure(errorString); | 728 if (!response.isSuccess()) { |
| 729 requestCallback->sendFailure(response); |
| 730 return; | 730 return; |
| 731 } | 731 } |
| 732 | 732 |
| 733 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 733 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 734 if (!scriptState) | 734 if (!scriptState) { |
| 735 requestCallback->sendFailure(Response::InternalError()); |
| 735 return; | 736 return; |
| 737 } |
| 736 ScriptState::Scope scope(scriptState); | 738 ScriptState::Scope scope(scriptState); |
| 737 TrackExceptionState exceptionState; | 739 TrackExceptionState exceptionState; |
| 738 IDBRequest* idbRequest = | 740 IDBRequest* idbRequest = |
| 739 idbFactory->getDatabaseNames(scriptState, exceptionState); | 741 idbFactory->getDatabaseNames(scriptState, exceptionState); |
| 740 if (exceptionState.hadException()) { | 742 if (exceptionState.hadException()) { |
| 741 requestCallback->sendFailure("Could not obtain database names."); | 743 requestCallback->sendFailure( |
| 744 Response::Error("Could not obtain database names.")); |
| 742 return; | 745 return; |
| 743 } | 746 } |
| 744 idbRequest->addEventListener( | 747 idbRequest->addEventListener( |
| 745 EventTypeNames::success, | 748 EventTypeNames::success, |
| 746 GetDatabaseNamesCallback::create( | 749 GetDatabaseNamesCallback::create( |
| 747 std::move(requestCallback), | 750 std::move(requestCallback), |
| 748 document->getSecurityOrigin()->toRawString()), | 751 document->getSecurityOrigin()->toRawString()), |
| 749 false); | 752 false); |
| 750 } | 753 } |
| 751 | 754 |
| 752 void InspectorIndexedDBAgent::requestDatabase( | 755 void InspectorIndexedDBAgent::requestDatabase( |
| 753 const String& securityOrigin, | 756 const String& securityOrigin, |
| 754 const String& databaseName, | 757 const String& databaseName, |
| 755 std::unique_ptr<RequestDatabaseCallback> requestCallback) { | 758 std::unique_ptr<RequestDatabaseCallback> requestCallback) { |
| 756 LocalFrame* frame = | 759 LocalFrame* frame = |
| 757 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); | 760 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| 758 ErrorString errorString; | 761 ErrorString errorString; |
| 759 Document* document = assertDocument(&errorString, frame); | 762 Document* document = frame ? frame->document() : nullptr; |
| 760 if (!document) { | 763 if (!document) { |
| 761 requestCallback->sendFailure(errorString); | 764 requestCallback->sendFailure(Response::Error(kNoDocumentError)); |
| 762 return; | 765 return; |
| 763 } | 766 } |
| 764 IDBFactory* idbFactory = assertIDBFactory(&errorString, document); | 767 IDBFactory* idbFactory = nullptr; |
| 765 if (!idbFactory) { | 768 Response response = assertIDBFactory(document, idbFactory); |
| 766 requestCallback->sendFailure(errorString); | 769 if (!response.isSuccess()) { |
| 770 requestCallback->sendFailure(response); |
| 767 return; | 771 return; |
| 768 } | 772 } |
| 769 | 773 |
| 770 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 774 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 771 if (!scriptState) | 775 if (!scriptState) { |
| 776 requestCallback->sendFailure(Response::InternalError()); |
| 772 return; | 777 return; |
| 778 } |
| 779 |
| 773 ScriptState::Scope scope(scriptState); | 780 ScriptState::Scope scope(scriptState); |
| 774 RefPtr<DatabaseLoader> databaseLoader = | 781 RefPtr<DatabaseLoader> databaseLoader = |
| 775 DatabaseLoader::create(scriptState, std::move(requestCallback)); | 782 DatabaseLoader::create(scriptState, std::move(requestCallback)); |
| 776 databaseLoader->start(idbFactory, document->getSecurityOrigin(), | 783 databaseLoader->start(idbFactory, document->getSecurityOrigin(), |
| 777 databaseName); | 784 databaseName); |
| 778 } | 785 } |
| 779 | 786 |
| 780 void InspectorIndexedDBAgent::requestData( | 787 void InspectorIndexedDBAgent::requestData( |
| 781 const String& securityOrigin, | 788 const String& securityOrigin, |
| 782 const String& databaseName, | 789 const String& databaseName, |
| 783 const String& objectStoreName, | 790 const String& objectStoreName, |
| 784 const String& indexName, | 791 const String& indexName, |
| 785 int skipCount, | 792 int skipCount, |
| 786 int pageSize, | 793 int pageSize, |
| 787 const Maybe<protocol::IndexedDB::KeyRange>& keyRange, | 794 Maybe<protocol::IndexedDB::KeyRange> keyRange, |
| 788 std::unique_ptr<RequestDataCallback> requestCallback) { | 795 std::unique_ptr<RequestDataCallback> requestCallback) { |
| 789 LocalFrame* frame = | 796 LocalFrame* frame = |
| 790 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); | 797 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| 791 ErrorString errorString; | 798 ErrorString errorString; |
| 792 Document* document = assertDocument(&errorString, frame); | 799 Document* document = frame ? frame->document() : nullptr; |
| 793 if (!document) { | 800 if (!document) { |
| 794 requestCallback->sendFailure(errorString); | 801 requestCallback->sendFailure(Response::Error(kNoDocumentError)); |
| 795 return; | 802 return; |
| 796 } | 803 } |
| 797 IDBFactory* idbFactory = assertIDBFactory(&errorString, document); | 804 IDBFactory* idbFactory = nullptr; |
| 798 if (!idbFactory) { | 805 Response response = assertIDBFactory(document, idbFactory); |
| 799 requestCallback->sendFailure(errorString); | 806 if (!response.isSuccess()) { |
| 807 requestCallback->sendFailure(response); |
| 800 return; | 808 return; |
| 801 } | 809 } |
| 802 | 810 |
| 803 IDBKeyRange* idbKeyRange = keyRange.isJust() | 811 IDBKeyRange* idbKeyRange = keyRange.isJust() |
| 804 ? idbKeyRangeFromKeyRange(keyRange.fromJust()) | 812 ? idbKeyRangeFromKeyRange(keyRange.fromJust()) |
| 805 : nullptr; | 813 : nullptr; |
| 806 if (keyRange.isJust() && !idbKeyRange) { | 814 if (keyRange.isJust() && !idbKeyRange) { |
| 807 requestCallback->sendFailure("Can not parse key range."); | 815 requestCallback->sendFailure(Response::Error("Can not parse key range.")); |
| 808 return; | 816 return; |
| 809 } | 817 } |
| 810 | 818 |
| 811 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 819 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 812 if (!scriptState) | 820 if (!scriptState) { |
| 821 requestCallback->sendFailure(Response::InternalError()); |
| 813 return; | 822 return; |
| 823 } |
| 824 |
| 814 ScriptState::Scope scope(scriptState); | 825 ScriptState::Scope scope(scriptState); |
| 815 RefPtr<DataLoader> dataLoader = DataLoader::create( | 826 RefPtr<DataLoader> dataLoader = DataLoader::create( |
| 816 m_v8Session, scriptState, std::move(requestCallback), objectStoreName, | 827 m_v8Session, scriptState, std::move(requestCallback), objectStoreName, |
| 817 indexName, idbKeyRange, skipCount, pageSize); | 828 indexName, idbKeyRange, skipCount, pageSize); |
| 818 dataLoader->start(idbFactory, document->getSecurityOrigin(), databaseName); | 829 dataLoader->start(idbFactory, document->getSecurityOrigin(), databaseName); |
| 819 } | 830 } |
| 820 | 831 |
| 821 class ClearObjectStoreListener final : public EventListener { | 832 class ClearObjectStoreListener final : public EventListener { |
| 822 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); | 833 WTF_MAKE_NONCOPYABLE(ClearObjectStoreListener); |
| 823 | 834 |
| 824 public: | 835 public: |
| 825 static ClearObjectStoreListener* create( | 836 static ClearObjectStoreListener* create( |
| 826 std::unique_ptr<ClearObjectStoreCallback> requestCallback) { | 837 std::unique_ptr<ClearObjectStoreCallback> requestCallback) { |
| 827 return new ClearObjectStoreListener(std::move(requestCallback)); | 838 return new ClearObjectStoreListener(std::move(requestCallback)); |
| 828 } | 839 } |
| 829 | 840 |
| 830 ~ClearObjectStoreListener() override {} | 841 ~ClearObjectStoreListener() override {} |
| 831 | 842 |
| 832 bool operator==(const EventListener& other) const override { | 843 bool operator==(const EventListener& other) const override { |
| 833 return this == &other; | 844 return this == &other; |
| 834 } | 845 } |
| 835 | 846 |
| 836 void handleEvent(ExecutionContext*, Event* event) override { | 847 void handleEvent(ExecutionContext*, Event* event) override { |
| 837 if (event->type() != EventTypeNames::complete) { | 848 if (event->type() != EventTypeNames::complete) { |
| 838 m_requestCallback->sendFailure("Unexpected event type."); | 849 m_requestCallback->sendFailure(Response::Error("Unexpected event type.")); |
| 839 return; | 850 return; |
| 840 } | 851 } |
| 841 | 852 |
| 842 m_requestCallback->sendSuccess(); | 853 m_requestCallback->sendSuccess(); |
| 843 } | 854 } |
| 844 | 855 |
| 845 DEFINE_INLINE_VIRTUAL_TRACE() { EventListener::trace(visitor); } | 856 DEFINE_INLINE_VIRTUAL_TRACE() { EventListener::trace(visitor); } |
| 846 | 857 |
| 847 private: | 858 private: |
| 848 ClearObjectStoreListener( | 859 ClearObjectStoreListener( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 869 std::unique_ptr<ClearObjectStoreCallback> requestCallback) | 880 std::unique_ptr<ClearObjectStoreCallback> requestCallback) |
| 870 : ExecutableWithDatabase(scriptState), | 881 : ExecutableWithDatabase(scriptState), |
| 871 m_objectStoreName(objectStoreName), | 882 m_objectStoreName(objectStoreName), |
| 872 m_requestCallback(std::move(requestCallback)) {} | 883 m_requestCallback(std::move(requestCallback)) {} |
| 873 | 884 |
| 874 void execute(IDBDatabase* idbDatabase) override { | 885 void execute(IDBDatabase* idbDatabase) override { |
| 875 IDBTransaction* idbTransaction = | 886 IDBTransaction* idbTransaction = |
| 876 transactionForDatabase(getScriptState(), idbDatabase, m_objectStoreName, | 887 transactionForDatabase(getScriptState(), idbDatabase, m_objectStoreName, |
| 877 IndexedDBNames::readwrite); | 888 IndexedDBNames::readwrite); |
| 878 if (!idbTransaction) { | 889 if (!idbTransaction) { |
| 879 m_requestCallback->sendFailure("Could not get transaction"); | 890 m_requestCallback->sendFailure( |
| 891 Response::Error("Could not get transaction")); |
| 880 return; | 892 return; |
| 881 } | 893 } |
| 882 IDBObjectStore* idbObjectStore = | 894 IDBObjectStore* idbObjectStore = |
| 883 objectStoreForTransaction(idbTransaction, m_objectStoreName); | 895 objectStoreForTransaction(idbTransaction, m_objectStoreName); |
| 884 if (!idbObjectStore) { | 896 if (!idbObjectStore) { |
| 885 m_requestCallback->sendFailure("Could not get object store"); | 897 m_requestCallback->sendFailure( |
| 898 Response::Error("Could not get object store")); |
| 886 return; | 899 return; |
| 887 } | 900 } |
| 888 | 901 |
| 889 TrackExceptionState exceptionState; | 902 TrackExceptionState exceptionState; |
| 890 idbObjectStore->clear(getScriptState(), exceptionState); | 903 idbObjectStore->clear(getScriptState(), exceptionState); |
| 891 ASSERT(!exceptionState.hadException()); | 904 ASSERT(!exceptionState.hadException()); |
| 892 if (exceptionState.hadException()) { | 905 if (exceptionState.hadException()) { |
| 893 ExceptionCode ec = exceptionState.code(); | 906 ExceptionCode ec = exceptionState.code(); |
| 894 m_requestCallback->sendFailure( | 907 m_requestCallback->sendFailure(Response::Error( |
| 895 String::format("Could not clear object store '%s': %d", | 908 String::format("Could not clear object store '%s': %d", |
| 896 m_objectStoreName.utf8().data(), ec)); | 909 m_objectStoreName.utf8().data(), ec))); |
| 897 return; | 910 return; |
| 898 } | 911 } |
| 899 idbTransaction->addEventListener( | 912 idbTransaction->addEventListener( |
| 900 EventTypeNames::complete, | 913 EventTypeNames::complete, |
| 901 ClearObjectStoreListener::create(std::move(m_requestCallback)), false); | 914 ClearObjectStoreListener::create(std::move(m_requestCallback)), false); |
| 902 } | 915 } |
| 903 | 916 |
| 904 ClearObjectStoreCallback* getRequestCallback() override { | 917 ClearObjectStoreCallback* getRequestCallback() override { |
| 905 return m_requestCallback.get(); | 918 return m_requestCallback.get(); |
| 906 } | 919 } |
| 907 | 920 |
| 908 private: | 921 private: |
| 909 const String m_objectStoreName; | 922 const String m_objectStoreName; |
| 910 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback; | 923 std::unique_ptr<ClearObjectStoreCallback> m_requestCallback; |
| 911 }; | 924 }; |
| 912 | 925 |
| 913 void InspectorIndexedDBAgent::clearObjectStore( | 926 void InspectorIndexedDBAgent::clearObjectStore( |
| 914 const String& securityOrigin, | 927 const String& securityOrigin, |
| 915 const String& databaseName, | 928 const String& databaseName, |
| 916 const String& objectStoreName, | 929 const String& objectStoreName, |
| 917 std::unique_ptr<ClearObjectStoreCallback> requestCallback) { | 930 std::unique_ptr<ClearObjectStoreCallback> requestCallback) { |
| 918 LocalFrame* frame = | 931 LocalFrame* frame = |
| 919 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); | 932 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| 920 ErrorString errorString; | 933 ErrorString errorString; |
| 921 Document* document = assertDocument(&errorString, frame); | 934 Document* document = frame ? frame->document() : nullptr; |
| 922 if (!document) { | 935 if (!document) { |
| 923 requestCallback->sendFailure(errorString); | 936 requestCallback->sendFailure(Response::Error(kNoDocumentError)); |
| 924 return; | 937 return; |
| 925 } | 938 } |
| 926 IDBFactory* idbFactory = assertIDBFactory(&errorString, document); | 939 IDBFactory* idbFactory = nullptr; |
| 927 if (!idbFactory) { | 940 Response response = assertIDBFactory(document, idbFactory); |
| 928 requestCallback->sendFailure(errorString); | 941 if (!response.isSuccess()) { |
| 942 requestCallback->sendFailure(response); |
| 929 return; | 943 return; |
| 930 } | 944 } |
| 931 | 945 |
| 932 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 946 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 933 if (!scriptState) | 947 if (!scriptState) { |
| 948 requestCallback->sendFailure(Response::InternalError()); |
| 934 return; | 949 return; |
| 950 } |
| 951 |
| 935 ScriptState::Scope scope(scriptState); | 952 ScriptState::Scope scope(scriptState); |
| 936 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create( | 953 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create( |
| 937 scriptState, objectStoreName, std::move(requestCallback)); | 954 scriptState, objectStoreName, std::move(requestCallback)); |
| 938 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), | 955 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), |
| 939 databaseName); | 956 databaseName); |
| 940 } | 957 } |
| 941 | 958 |
| 942 DEFINE_TRACE(InspectorIndexedDBAgent) { | 959 DEFINE_TRACE(InspectorIndexedDBAgent) { |
| 943 visitor->trace(m_inspectedFrames); | 960 visitor->trace(m_inspectedFrames); |
| 944 InspectorBaseAgent::trace(visitor); | 961 InspectorBaseAgent::trace(visitor); |
| 945 } | 962 } |
| 946 | 963 |
| 947 } // namespace blink | 964 } // namespace blink |
| OLD | NEW |