Chromium Code Reviews| Index: third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp |
| diff --git a/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp b/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp |
| index 819155622e869f3e962f706d9c1ac332fe786bc2..5d74f68be76f62fec0bf6b256f0ed2cc8106b4e5 100644 |
| --- a/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp |
| +++ b/third_party/WebKit/Source/modules/indexeddb/InspectorIndexedDBAgent.cpp |
| @@ -88,6 +88,7 @@ static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled"; |
| namespace { |
| static const char indexedDBObjectGroup[] = "indexeddb"; |
|
dgozman
2016/11/02 17:49:36
Please change these to use kConstantName style.
kozy
2016/11/02 18:28:02
Done.
|
| +static const char noDocumentError[] = "No document for given frame found"; |
| class GetDatabaseNamesCallback final : public EventListener { |
| WTF_MAKE_NONCOPYABLE(GetDatabaseNamesCallback); |
| @@ -108,14 +109,15 @@ class GetDatabaseNamesCallback final : public EventListener { |
| void handleEvent(ExecutionContext*, Event* event) override { |
| if (event->type() != EventTypeNames::success) { |
| - m_requestCallback->sendFailure("Unexpected event type."); |
| + m_requestCallback->sendFailure(Response::Error("Unexpected event type.")); |
| return; |
| } |
| IDBRequest* idbRequest = static_cast<IDBRequest*>(event->target()); |
| IDBAny* requestResult = idbRequest->resultAsAny(); |
| if (requestResult->getType() != IDBAny::DOMStringListType) { |
| - m_requestCallback->sendFailure("Unexpected result type."); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Unexpected result type.")); |
| return; |
| } |
| @@ -163,7 +165,8 @@ class ExecutableWithDatabase |
| IDBOpenDBRequest* idbOpenDBRequest = |
| idbFactory->open(getScriptState(), databaseName, exceptionState); |
| if (exceptionState.hadException()) { |
| - getRequestCallback()->sendFailure("Could not open database."); |
| + getRequestCallback()->sendFailure( |
| + Response::Error("Could not open database.")); |
| return; |
| } |
| idbOpenDBRequest->addEventListener(EventTypeNames::upgradeneeded, |
| @@ -199,7 +202,7 @@ class OpenDatabaseCallback final : public EventListener { |
| void handleEvent(ExecutionContext* context, Event* event) override { |
| if (event->type() != EventTypeNames::success) { |
| m_executableWithDatabase->getRequestCallback()->sendFailure( |
| - "Unexpected event type."); |
| + Response::Error("Unexpected event type.")); |
| return; |
| } |
| @@ -208,7 +211,7 @@ class OpenDatabaseCallback final : public EventListener { |
| IDBAny* requestResult = idbOpenDBRequest->resultAsAny(); |
| if (requestResult->getType() != IDBAny::IDBDatabaseType) { |
| m_executableWithDatabase->getRequestCallback()->sendFailure( |
| - "Unexpected result type."); |
| + Response::Error("Unexpected result type.")); |
| return; |
| } |
| @@ -245,7 +248,7 @@ class UpgradeDatabaseCallback final : public EventListener { |
| void handleEvent(ExecutionContext* context, Event* event) override { |
| if (event->type() != EventTypeNames::upgradeneeded) { |
| m_executableWithDatabase->getRequestCallback()->sendFailure( |
| - "Unexpected event type."); |
| + Response::Error("Unexpected event type.")); |
| return; |
| } |
| @@ -257,7 +260,7 @@ class UpgradeDatabaseCallback final : public EventListener { |
| NonThrowableExceptionState exceptionState; |
| idbOpenDBRequest->transaction()->abort(exceptionState); |
| m_executableWithDatabase->getRequestCallback()->sendFailure( |
| - "Aborted upgrade."); |
| + Response::Error("Aborted upgrade.")); |
| } |
| private: |
| @@ -483,7 +486,7 @@ class OpenCursorCallback final : public EventListener { |
| void handleEvent(ExecutionContext*, Event* event) override { |
| if (event->type() != EventTypeNames::success) { |
| - m_requestCallback->sendFailure("Unexpected event type."); |
| + m_requestCallback->sendFailure(Response::Error("Unexpected event type.")); |
| return; |
| } |
| @@ -494,7 +497,8 @@ class OpenCursorCallback final : public EventListener { |
| return; |
| } |
| if (requestResult->getType() != IDBAny::IDBCursorWithValueType) { |
| - m_requestCallback->sendFailure("Unexpected result type."); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Unexpected result type.")); |
| return; |
| } |
| @@ -503,8 +507,10 @@ class OpenCursorCallback final : public EventListener { |
| if (m_skipCount) { |
| TrackExceptionState exceptionState; |
| idbCursor->advance(m_skipCount, exceptionState); |
| - if (exceptionState.hadException()) |
| - m_requestCallback->sendFailure("Could not advance cursor."); |
| + if (exceptionState.hadException()) { |
| + m_requestCallback->sendFailure( |
| + Response::Error("Could not advance cursor.")); |
| + } |
| m_skipCount = 0; |
| return; |
| } |
| @@ -519,7 +525,8 @@ class OpenCursorCallback final : public EventListener { |
| TrackExceptionState exceptionState; |
| idbCursor->continueFunction(nullptr, nullptr, exceptionState); |
| if (exceptionState.hadException()) { |
| - m_requestCallback->sendFailure("Could not continue cursor."); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Could not continue cursor.")); |
| return; |
| } |
| @@ -595,13 +602,15 @@ class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> { |
| IDBTransaction* idbTransaction = transactionForDatabase( |
| getScriptState(), idbDatabase, m_objectStoreName); |
| if (!idbTransaction) { |
| - m_requestCallback->sendFailure("Could not get transaction"); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Could not get transaction")); |
| return; |
| } |
| IDBObjectStore* idbObjectStore = |
| objectStoreForTransaction(idbTransaction, m_objectStoreName); |
| if (!idbObjectStore) { |
| - m_requestCallback->sendFailure("Could not get object store"); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Could not get object store")); |
| return; |
| } |
| @@ -609,7 +618,7 @@ class DataLoader final : public ExecutableWithDatabase<RequestDataCallback> { |
| if (!m_indexName.isEmpty()) { |
| IDBIndex* idbIndex = indexForObjectStore(idbObjectStore, m_indexName); |
| if (!idbIndex) { |
| - m_requestCallback->sendFailure("Could not get index"); |
| + m_requestCallback->sendFailure(Response::Error("Could not get index")); |
| return; |
| } |
| @@ -668,8 +677,7 @@ InspectorIndexedDBAgent::~InspectorIndexedDBAgent() {} |
| void InspectorIndexedDBAgent::restore() { |
| if (m_state->booleanProperty(IndexedDBAgentState::indexedDBAgentEnabled, |
| false)) { |
| - ErrorString error; |
| - enable(&error); |
| + enable(); |
| } |
| } |
| @@ -679,38 +687,28 @@ void InspectorIndexedDBAgent::didCommitLoadForLocalFrame(LocalFrame* frame) { |
| toV8InspectorStringView(indexedDBObjectGroup)); |
| } |
| -void InspectorIndexedDBAgent::enable(ErrorString*) { |
| +Response InspectorIndexedDBAgent::enable() { |
| m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, true); |
| + return Response::OK(); |
| } |
| -void InspectorIndexedDBAgent::disable(ErrorString*) { |
| +Response InspectorIndexedDBAgent::disable() { |
| m_state->setBoolean(IndexedDBAgentState::indexedDBAgentEnabled, false); |
| m_v8Session->releaseObjectGroup( |
| toV8InspectorStringView(indexedDBObjectGroup)); |
| + return Response::OK(); |
| } |
| -static Document* assertDocument(ErrorString* errorString, LocalFrame* frame) { |
| - Document* document = frame ? frame->document() : nullptr; |
| - |
| - if (!document) |
| - *errorString = "No document for given frame found"; |
| - |
| - return document; |
| -} |
| - |
| -static IDBFactory* assertIDBFactory(ErrorString* errorString, |
| - Document* document) { |
| +static Response assertIDBFactory(Document* document, IDBFactory*& result) { |
| LocalDOMWindow* domWindow = document->domWindow(); |
| - if (!domWindow) { |
| - *errorString = "No IndexedDB factory for given frame found"; |
| - return nullptr; |
| - } |
| + if (!domWindow) |
| + return Response::Error("No IndexedDB factory for given frame found"); |
| IDBFactory* idbFactory = GlobalIndexedDB::indexedDB(*domWindow); |
| if (!idbFactory) |
| - *errorString = "No IndexedDB factory for given frame found"; |
| - |
| - return idbFactory; |
| + return Response::Error("No IndexedDB factory for given frame found"); |
| + result = idbFactory; |
| + return Response::OK(); |
| } |
| void InspectorIndexedDBAgent::requestDatabaseNames( |
| @@ -719,26 +717,30 @@ void InspectorIndexedDBAgent::requestDatabaseNames( |
| LocalFrame* frame = |
| m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| ErrorString errorString; |
| - Document* document = assertDocument(&errorString, frame); |
| + Document* document = frame ? frame->document() : nullptr; |
| if (!document) { |
| - requestCallback->sendFailure(errorString); |
| + requestCallback->sendFailure(Response::Error(noDocumentError)); |
| return; |
| } |
| - IDBFactory* idbFactory = assertIDBFactory(&errorString, document); |
| - if (!idbFactory) { |
| - requestCallback->sendFailure(errorString); |
| + IDBFactory* idbFactory = nullptr; |
| + Response response = assertIDBFactory(document, idbFactory); |
| + if (!response.isSuccess()) { |
| + requestCallback->sendFailure(response); |
| return; |
| } |
| ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| - if (!scriptState) |
| + if (!scriptState) { |
| + requestCallback->sendFailure(Response::InternalError()); |
| return; |
| + } |
| ScriptState::Scope scope(scriptState); |
| TrackExceptionState exceptionState; |
| IDBRequest* idbRequest = |
| idbFactory->getDatabaseNames(scriptState, exceptionState); |
| if (exceptionState.hadException()) { |
| - requestCallback->sendFailure("Could not obtain database names."); |
| + requestCallback->sendFailure( |
| + Response::Error("Could not obtain database names.")); |
| return; |
| } |
| idbRequest->addEventListener( |
| @@ -756,20 +758,24 @@ void InspectorIndexedDBAgent::requestDatabase( |
| LocalFrame* frame = |
| m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| ErrorString errorString; |
| - Document* document = assertDocument(&errorString, frame); |
| + Document* document = frame ? frame->document() : nullptr; |
| if (!document) { |
| - requestCallback->sendFailure(errorString); |
| + requestCallback->sendFailure(Response::Error(noDocumentError)); |
| return; |
| } |
| - IDBFactory* idbFactory = assertIDBFactory(&errorString, document); |
| - if (!idbFactory) { |
| - requestCallback->sendFailure(errorString); |
| + IDBFactory* idbFactory = nullptr; |
| + Response response = assertIDBFactory(document, idbFactory); |
| + if (!response.isSuccess()) { |
| + requestCallback->sendFailure(response); |
| return; |
| } |
| ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| - if (!scriptState) |
| + if (!scriptState) { |
| + requestCallback->sendFailure(Response::InternalError()); |
| return; |
| + } |
| + |
| ScriptState::Scope scope(scriptState); |
| RefPtr<DatabaseLoader> databaseLoader = |
| DatabaseLoader::create(scriptState, std::move(requestCallback)); |
| @@ -784,19 +790,20 @@ void InspectorIndexedDBAgent::requestData( |
| const String& indexName, |
| int skipCount, |
| int pageSize, |
| - const Maybe<protocol::IndexedDB::KeyRange>& keyRange, |
| + Maybe<protocol::IndexedDB::KeyRange> keyRange, |
| std::unique_ptr<RequestDataCallback> requestCallback) { |
| LocalFrame* frame = |
| m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| ErrorString errorString; |
| - Document* document = assertDocument(&errorString, frame); |
| + Document* document = frame ? frame->document() : nullptr; |
| if (!document) { |
| - requestCallback->sendFailure(errorString); |
| + requestCallback->sendFailure(Response::Error(noDocumentError)); |
| return; |
| } |
| - IDBFactory* idbFactory = assertIDBFactory(&errorString, document); |
| - if (!idbFactory) { |
| - requestCallback->sendFailure(errorString); |
| + IDBFactory* idbFactory = nullptr; |
| + Response response = assertIDBFactory(document, idbFactory); |
| + if (!response.isSuccess()) { |
| + requestCallback->sendFailure(response); |
| return; |
| } |
| @@ -804,13 +811,16 @@ void InspectorIndexedDBAgent::requestData( |
| ? idbKeyRangeFromKeyRange(keyRange.fromJust()) |
| : nullptr; |
| if (keyRange.isJust() && !idbKeyRange) { |
| - requestCallback->sendFailure("Can not parse key range."); |
| + requestCallback->sendFailure(Response::Error("Can not parse key range.")); |
| return; |
| } |
| ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| - if (!scriptState) |
| + if (!scriptState) { |
| + requestCallback->sendFailure(Response::InternalError()); |
| return; |
| + } |
| + |
| ScriptState::Scope scope(scriptState); |
| RefPtr<DataLoader> dataLoader = DataLoader::create( |
| m_v8Session, scriptState, std::move(requestCallback), objectStoreName, |
| @@ -835,7 +845,7 @@ class ClearObjectStoreListener final : public EventListener { |
| void handleEvent(ExecutionContext*, Event* event) override { |
| if (event->type() != EventTypeNames::complete) { |
| - m_requestCallback->sendFailure("Unexpected event type."); |
| + m_requestCallback->sendFailure(Response::Error("Unexpected event type.")); |
| return; |
| } |
| @@ -876,13 +886,15 @@ class ClearObjectStore final |
| transactionForDatabase(getScriptState(), idbDatabase, m_objectStoreName, |
| IndexedDBNames::readwrite); |
| if (!idbTransaction) { |
| - m_requestCallback->sendFailure("Could not get transaction"); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Could not get transaction")); |
| return; |
| } |
| IDBObjectStore* idbObjectStore = |
| objectStoreForTransaction(idbTransaction, m_objectStoreName); |
| if (!idbObjectStore) { |
| - m_requestCallback->sendFailure("Could not get object store"); |
| + m_requestCallback->sendFailure( |
| + Response::Error("Could not get object store")); |
| return; |
| } |
| @@ -891,9 +903,9 @@ class ClearObjectStore final |
| ASSERT(!exceptionState.hadException()); |
| if (exceptionState.hadException()) { |
| ExceptionCode ec = exceptionState.code(); |
| - m_requestCallback->sendFailure( |
| + m_requestCallback->sendFailure(Response::Error( |
| String::format("Could not clear object store '%s': %d", |
| - m_objectStoreName.utf8().data(), ec)); |
| + m_objectStoreName.utf8().data(), ec))); |
| return; |
| } |
| idbTransaction->addEventListener( |
| @@ -918,20 +930,24 @@ void InspectorIndexedDBAgent::clearObjectStore( |
| LocalFrame* frame = |
| m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| ErrorString errorString; |
| - Document* document = assertDocument(&errorString, frame); |
| + Document* document = frame ? frame->document() : nullptr; |
| if (!document) { |
| - requestCallback->sendFailure(errorString); |
| + requestCallback->sendFailure(Response::Error(noDocumentError)); |
| return; |
| } |
| - IDBFactory* idbFactory = assertIDBFactory(&errorString, document); |
| - if (!idbFactory) { |
| - requestCallback->sendFailure(errorString); |
| + IDBFactory* idbFactory = nullptr; |
| + Response response = assertIDBFactory(document, idbFactory); |
| + if (!response.isSuccess()) { |
| + requestCallback->sendFailure(response); |
| return; |
| } |
| ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| - if (!scriptState) |
| + if (!scriptState) { |
| + requestCallback->sendFailure(Response::InternalError()); |
| return; |
| + } |
| + |
| ScriptState::Scope scope(scriptState); |
| RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create( |
| scriptState, objectStoreName, std::move(requestCallback)); |