| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 using blink::protocol::IndexedDB::ObjectStoreIndex; | 70 using blink::protocol::IndexedDB::ObjectStoreIndex; |
| 71 | 71 |
| 72 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseNamesCallback | 72 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseNamesCallback |
| 73 RequestDatabaseNamesCallback; | 73 RequestDatabaseNamesCallback; |
| 74 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseCallback | 74 typedef blink::protocol::IndexedDB::Backend::RequestDatabaseCallback |
| 75 RequestDatabaseCallback; | 75 RequestDatabaseCallback; |
| 76 typedef blink::protocol::IndexedDB::Backend::RequestDataCallback | 76 typedef blink::protocol::IndexedDB::Backend::RequestDataCallback |
| 77 RequestDataCallback; | 77 RequestDataCallback; |
| 78 typedef blink::protocol::IndexedDB::Backend::ClearObjectStoreCallback | 78 typedef blink::protocol::IndexedDB::Backend::ClearObjectStoreCallback |
| 79 ClearObjectStoreCallback; | 79 ClearObjectStoreCallback; |
| 80 typedef blink::protocol::IndexedDB::Backend::DeleteDatabaseCallback |
| 81 DeleteDatabaseCallback; |
| 80 | 82 |
| 81 namespace blink { | 83 namespace blink { |
| 82 | 84 |
| 83 namespace IndexedDBAgentState { | 85 namespace IndexedDBAgentState { |
| 84 static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled"; | 86 static const char indexedDBAgentEnabled[] = "indexedDBAgentEnabled"; |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 namespace { | 89 namespace { |
| 88 | 90 |
| 89 static const char kIndexedDBObjectGroup[] = "indexeddb"; | 91 static const char kIndexedDBObjectGroup[] = "indexeddb"; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 GetDatabaseNamesCallback( | 136 GetDatabaseNamesCallback( |
| 135 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback, | 137 std::unique_ptr<RequestDatabaseNamesCallback> requestCallback, |
| 136 const String& securityOrigin) | 138 const String& securityOrigin) |
| 137 : EventListener(EventListener::CPPEventListenerType), | 139 : EventListener(EventListener::CPPEventListenerType), |
| 138 m_requestCallback(std::move(requestCallback)), | 140 m_requestCallback(std::move(requestCallback)), |
| 139 m_securityOrigin(securityOrigin) {} | 141 m_securityOrigin(securityOrigin) {} |
| 140 std::unique_ptr<RequestDatabaseNamesCallback> m_requestCallback; | 142 std::unique_ptr<RequestDatabaseNamesCallback> m_requestCallback; |
| 141 String m_securityOrigin; | 143 String m_securityOrigin; |
| 142 }; | 144 }; |
| 143 | 145 |
| 146 class DeleteCallback final : public EventListener { |
| 147 WTF_MAKE_NONCOPYABLE(DeleteCallback); |
| 148 |
| 149 public: |
| 150 static DeleteCallback* create( |
| 151 std::unique_ptr<DeleteDatabaseCallback> requestCallback, |
| 152 const String& securityOrigin) { |
| 153 return new DeleteCallback(std::move(requestCallback), securityOrigin); |
| 154 } |
| 155 |
| 156 ~DeleteCallback() override {} |
| 157 |
| 158 bool operator==(const EventListener& other) const override { |
| 159 return this == &other; |
| 160 } |
| 161 |
| 162 void handleEvent(ExecutionContext*, Event* event) override { |
| 163 if (event->type() != EventTypeNames::success) { |
| 164 m_requestCallback->sendFailure( |
| 165 Response::Error("Failed to delete database.")); |
| 166 return; |
| 167 } |
| 168 m_requestCallback->sendSuccess(); |
| 169 } |
| 170 |
| 171 DEFINE_INLINE_VIRTUAL_TRACE() { EventListener::trace(visitor); } |
| 172 |
| 173 private: |
| 174 DeleteCallback(std::unique_ptr<DeleteDatabaseCallback> requestCallback, |
| 175 const String& securityOrigin) |
| 176 : EventListener(EventListener::CPPEventListenerType), |
| 177 m_requestCallback(std::move(requestCallback)), |
| 178 m_securityOrigin(securityOrigin) {} |
| 179 std::unique_ptr<DeleteDatabaseCallback> m_requestCallback; |
| 180 String m_securityOrigin; |
| 181 }; |
| 182 |
| 144 template <typename RequestCallback> | 183 template <typename RequestCallback> |
| 145 class OpenDatabaseCallback; | 184 class OpenDatabaseCallback; |
| 146 template <typename RequestCallback> | 185 template <typename RequestCallback> |
| 147 class UpgradeDatabaseCallback; | 186 class UpgradeDatabaseCallback; |
| 148 | 187 |
| 149 template <typename RequestCallback> | 188 template <typename RequestCallback> |
| 150 class ExecutableWithDatabase | 189 class ExecutableWithDatabase |
| 151 : public RefCounted<ExecutableWithDatabase<RequestCallback>> { | 190 : public RefCounted<ExecutableWithDatabase<RequestCallback>> { |
| 152 public: | 191 public: |
| 153 ExecutableWithDatabase(ScriptState* scriptState) | 192 ExecutableWithDatabase(ScriptState* scriptState) |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 return; | 983 return; |
| 945 } | 984 } |
| 946 | 985 |
| 947 ScriptState::Scope scope(scriptState); | 986 ScriptState::Scope scope(scriptState); |
| 948 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create( | 987 RefPtr<ClearObjectStore> clearObjectStore = ClearObjectStore::create( |
| 949 scriptState, objectStoreName, std::move(requestCallback)); | 988 scriptState, objectStoreName, std::move(requestCallback)); |
| 950 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), | 989 clearObjectStore->start(idbFactory, document->getSecurityOrigin(), |
| 951 databaseName); | 990 databaseName); |
| 952 } | 991 } |
| 953 | 992 |
| 993 void InspectorIndexedDBAgent::deleteDatabase( |
| 994 const String& securityOrigin, |
| 995 const String& databaseName, |
| 996 std::unique_ptr<DeleteDatabaseCallback> requestCallback) { |
| 997 LocalFrame* frame = |
| 998 m_inspectedFrames->frameWithSecurityOrigin(securityOrigin); |
| 999 Document* document = frame ? frame->document() : nullptr; |
| 1000 if (!document) { |
| 1001 requestCallback->sendFailure(Response::Error(kNoDocumentError)); |
| 1002 return; |
| 1003 } |
| 1004 IDBFactory* idbFactory = nullptr; |
| 1005 Response response = assertIDBFactory(document, idbFactory); |
| 1006 if (!response.isSuccess()) { |
| 1007 requestCallback->sendFailure(response); |
| 1008 return; |
| 1009 } |
| 1010 |
| 1011 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 1012 if (!scriptState) { |
| 1013 requestCallback->sendFailure(Response::InternalError()); |
| 1014 return; |
| 1015 } |
| 1016 ScriptState::Scope scope(scriptState); |
| 1017 DummyExceptionStateForTesting exceptionState; |
| 1018 IDBRequest* idbRequest = idbFactory->closeConnectionsAndDeleteDatabase( |
| 1019 scriptState, databaseName, exceptionState); |
| 1020 if (exceptionState.hadException()) { |
| 1021 requestCallback->sendFailure(Response::Error("Could not delete database.")); |
| 1022 return; |
| 1023 } |
| 1024 idbRequest->addEventListener( |
| 1025 EventTypeNames::success, |
| 1026 DeleteCallback::create(std::move(requestCallback), |
| 1027 document->getSecurityOrigin()->toRawString()), |
| 1028 false); |
| 1029 } |
| 1030 |
| 954 DEFINE_TRACE(InspectorIndexedDBAgent) { | 1031 DEFINE_TRACE(InspectorIndexedDBAgent) { |
| 955 visitor->trace(m_inspectedFrames); | 1032 visitor->trace(m_inspectedFrames); |
| 956 InspectorBaseAgent::trace(visitor); | 1033 InspectorBaseAgent::trace(visitor); |
| 957 } | 1034 } |
| 958 | 1035 |
| 959 } // namespace blink | 1036 } // namespace blink |
| OLD | NEW |