| 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 16 matching lines...) Expand all Loading... |
| 27 #define IDBDatabase_h | 27 #define IDBDatabase_h |
| 28 | 28 |
| 29 #include "bindings/core/v8/ActiveScriptWrappable.h" | 29 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 30 #include "bindings/core/v8/ScriptState.h" | 30 #include "bindings/core/v8/ScriptState.h" |
| 31 #include "bindings/modules/v8/StringOrStringSequenceOrDOMStringList.h" | 31 #include "bindings/modules/v8/StringOrStringSequenceOrDOMStringList.h" |
| 32 #include "core/dom/ActiveDOMObject.h" | 32 #include "core/dom/ActiveDOMObject.h" |
| 33 #include "core/dom/DOMStringList.h" | 33 #include "core/dom/DOMStringList.h" |
| 34 #include "modules/EventModules.h" | 34 #include "modules/EventModules.h" |
| 35 #include "modules/EventTargetModules.h" | 35 #include "modules/EventTargetModules.h" |
| 36 #include "modules/ModulesExport.h" | 36 #include "modules/ModulesExport.h" |
| 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" | |
| 38 #include "modules/indexeddb/IDBHistograms.h" | 37 #include "modules/indexeddb/IDBHistograms.h" |
| 39 #include "modules/indexeddb/IDBMetadata.h" | 38 #include "modules/indexeddb/IDBMetadata.h" |
| 40 #include "modules/indexeddb/IDBObjectStore.h" | 39 #include "modules/indexeddb/IDBObjectStore.h" |
| 41 #include "modules/indexeddb/IDBObjectStoreParameters.h" | 40 #include "modules/indexeddb/IDBObjectStoreParameters.h" |
| 42 #include "modules/indexeddb/IDBTransaction.h" | 41 #include "modules/indexeddb/IDBTransaction.h" |
| 43 #include "modules/indexeddb/IndexedDB.h" | 42 #include "modules/indexeddb/IndexedDB.h" |
| 44 #include "platform/heap/Handle.h" | 43 #include "platform/heap/Handle.h" |
| 45 #include "public/platform/modules/indexeddb/WebIDBDatabase.h" | |
| 46 #include "wtf/PassRefPtr.h" | 44 #include "wtf/PassRefPtr.h" |
| 47 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
| 48 #include <memory> | 46 #include <memory> |
| 49 | 47 |
| 50 namespace blink { | 48 namespace blink { |
| 51 | 49 |
| 52 class DOMException; | 50 class DOMException; |
| 53 class ExceptionState; | 51 class ExceptionState; |
| 54 class ExecutionContext; | 52 class ExecutionContext; |
| 53 class IDBDatabaseProxy; |
| 55 | 54 |
| 56 class MODULES_EXPORT IDBDatabase final | 55 class MODULES_EXPORT IDBDatabase final |
| 57 : public EventTargetWithInlineData | 56 : public EventTargetWithInlineData |
| 58 , public ActiveScriptWrappable | 57 , public ActiveScriptWrappable |
| 59 , public ActiveDOMObject { | 58 , public ActiveDOMObject { |
| 60 USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); | 59 USING_GARBAGE_COLLECTED_MIXIN(IDBDatabase); |
| 61 DEFINE_WRAPPERTYPEINFO(); | 60 DEFINE_WRAPPERTYPEINFO(); |
| 62 public: | 61 public: |
| 63 static IDBDatabase* create(ExecutionContext*, std::unique_ptr<WebIDBDatabase
>, IDBDatabaseCallbacks*); | 62 static IDBDatabase* create(ExecutionContext*, std::unique_ptr<IDBDatabasePro
xy>); |
| 64 ~IDBDatabase() override; | 63 ~IDBDatabase() override; |
| 65 DECLARE_VIRTUAL_TRACE(); | 64 DECLARE_VIRTUAL_TRACE(); |
| 66 | 65 |
| 67 void setMetadata(const IDBDatabaseMetadata& metadata) { m_metadata = metadat
a; } | 66 void setMetadata(const IDBDatabaseMetadata& metadata) { m_metadata = metadat
a; } |
| 68 void indexCreated(int64_t objectStoreId, const IDBIndexMetadata&); | 67 void indexCreated(int64_t objectStoreId, const IDBIndexMetadata&); |
| 69 void indexDeleted(int64_t objectStoreId, int64_t indexId); | 68 void indexDeleted(int64_t objectStoreId, int64_t indexId); |
| 70 void transactionCreated(IDBTransaction*); | 69 void transactionCreated(IDBTransaction*); |
| 71 void transactionFinished(const IDBTransaction*); | 70 void transactionFinished(const IDBTransaction*); |
| 72 const String& getObjectStoreName(int64_t objectStoreId) const; | 71 const String& getObjectStoreName(int64_t objectStoreId) const; |
| 73 | 72 |
| 74 // Implement the IDL | 73 // Implement the IDL |
| 75 const String& name() const { return m_metadata.name; } | 74 const String& name() const { return m_metadata.name; } |
| 76 unsigned long long version() const { return m_metadata.version; } | 75 unsigned long long version() const { return m_metadata.version; } |
| 77 DOMStringList* objectStoreNames() const; | 76 DOMStringList* objectStoreNames() const; |
| 78 | 77 |
| 79 IDBObjectStore* createObjectStore(const String& name, const IDBObjectStorePa
rameters& options, ExceptionState& exceptionState) { return createObjectStore(na
me, IDBKeyPath(options.keyPath()), options.autoIncrement(), exceptionState); } | 78 IDBObjectStore* createObjectStore(const String& name, const IDBObjectStorePa
rameters& options, ExceptionState& exceptionState) { return createObjectStore(na
me, IDBKeyPath(options.keyPath()), options.autoIncrement(), exceptionState); } |
| 80 IDBTransaction* transaction(ScriptState*, const StringOrStringSequenceOrDOMS
tringList&, const String& mode, ExceptionState&); | 79 IDBTransaction* transaction(ScriptState*, const StringOrStringSequenceOrDOMS
tringList&, const String& mode, ExceptionState&); |
| 81 void deleteObjectStore(const String& name, ExceptionState&); | 80 void deleteObjectStore(const String& name, ExceptionState&); |
| 82 void close(); | 81 void close(); |
| 83 | 82 |
| 84 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); | 83 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort); |
| 85 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); | 84 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); |
| 86 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 85 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 87 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange); | 86 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange); |
| 88 | 87 |
| 89 // IDBDatabaseCallbacks | |
| 90 void onVersionChange(int64_t oldVersion, int64_t newVersion); | 88 void onVersionChange(int64_t oldVersion, int64_t newVersion); |
| 91 void onAbort(int64_t, DOMException*); | 89 void onAbort(int64_t, DOMException*); |
| 92 void onComplete(int64_t); | 90 void onComplete(int64_t); |
| 93 | 91 |
| 94 // ActiveScriptWrappable | 92 // ActiveScriptWrappable |
| 95 bool hasPendingActivity() const final; | 93 bool hasPendingActivity() const final; |
| 96 | 94 |
| 97 // ActiveDOMObject | 95 // ActiveDOMObject |
| 98 void stop() override; | 96 void stop() override; |
| 99 | 97 |
| 100 // EventTarget | 98 // EventTarget |
| 101 const AtomicString& interfaceName() const override; | 99 const AtomicString& interfaceName() const override; |
| 102 ExecutionContext* getExecutionContext() const override; | 100 ExecutionContext* getExecutionContext() const override; |
| 103 | 101 |
| 104 bool isClosePending() const { return m_closePending; } | 102 bool isClosePending() const { return m_closePending; } |
| 105 void forceClose(); | 103 void forceClose(); |
| 106 const IDBDatabaseMetadata& metadata() const { return m_metadata; } | 104 const IDBDatabaseMetadata& metadata() const { return m_metadata; } |
| 107 void enqueueEvent(Event*); | 105 void enqueueEvent(Event*); |
| 108 | 106 |
| 109 int64_t findObjectStoreId(const String& name) const; | 107 int64_t findObjectStoreId(const String& name) const; |
| 110 bool containsObjectStore(const String& name) const | 108 bool containsObjectStore(const String& name) const |
| 111 { | 109 { |
| 112 return findObjectStoreId(name) != IDBObjectStoreMetadata::InvalidId; | 110 return findObjectStoreId(name) != IDBObjectStoreMetadata::InvalidId; |
| 113 } | 111 } |
| 114 | 112 |
| 115 // Will return nullptr if this database is stopped. | 113 // Will return nullptr if this database is stopped. |
| 116 WebIDBDatabase* backend() const { return m_backend.get(); } | 114 IDBDatabaseProxy* backend() const { return m_backend.get(); } |
| 117 | 115 |
| 118 static int64_t nextTransactionId(); | 116 static int64_t nextTransactionId(); |
| 119 | 117 |
| 120 static const char indexDeletedErrorMessage[]; | 118 static const char indexDeletedErrorMessage[]; |
| 121 static const char isKeyCursorErrorMessage[]; | 119 static const char isKeyCursorErrorMessage[]; |
| 122 static const char noKeyOrKeyRangeErrorMessage[]; | 120 static const char noKeyOrKeyRangeErrorMessage[]; |
| 123 static const char noSuchIndexErrorMessage[]; | 121 static const char noSuchIndexErrorMessage[]; |
| 124 static const char noSuchObjectStoreErrorMessage[]; | 122 static const char noSuchObjectStoreErrorMessage[]; |
| 125 static const char noValueErrorMessage[]; | 123 static const char noValueErrorMessage[]; |
| 126 static const char notValidKeyErrorMessage[]; | 124 static const char notValidKeyErrorMessage[]; |
| 127 static const char notVersionChangeTransactionErrorMessage[]; | 125 static const char notVersionChangeTransactionErrorMessage[]; |
| 128 static const char objectStoreDeletedErrorMessage[]; | 126 static const char objectStoreDeletedErrorMessage[]; |
| 129 static const char requestNotFinishedErrorMessage[]; | 127 static const char requestNotFinishedErrorMessage[]; |
| 130 static const char sourceDeletedErrorMessage[]; | 128 static const char sourceDeletedErrorMessage[]; |
| 131 static const char transactionFinishedErrorMessage[]; | 129 static const char transactionFinishedErrorMessage[]; |
| 132 static const char transactionInactiveErrorMessage[]; | 130 static const char transactionInactiveErrorMessage[]; |
| 133 static const char transactionReadOnlyErrorMessage[]; | 131 static const char transactionReadOnlyErrorMessage[]; |
| 134 static const char databaseClosedErrorMessage[]; | 132 static const char databaseClosedErrorMessage[]; |
| 135 | 133 |
| 136 static void recordApiCallsHistogram(IndexedDatabaseMethods); | 134 static void recordApiCallsHistogram(IndexedDatabaseMethods); |
| 137 | 135 |
| 138 protected: | 136 protected: |
| 139 // EventTarget | 137 // EventTarget |
| 140 DispatchEventResult dispatchEventInternal(Event*) override; | 138 DispatchEventResult dispatchEventInternal(Event*) override; |
| 141 | 139 |
| 142 private: | 140 private: |
| 143 IDBDatabase(ExecutionContext*, std::unique_ptr<WebIDBDatabase>, IDBDatabaseC
allbacks*); | 141 IDBDatabase(ExecutionContext*, std::unique_ptr<IDBDatabaseProxy>); |
| 144 | 142 |
| 145 IDBObjectStore* createObjectStore(const String& name, const IDBKeyPath&, boo
l autoIncrement, ExceptionState&); | 143 IDBObjectStore* createObjectStore(const String& name, const IDBKeyPath&, boo
l autoIncrement, ExceptionState&); |
| 146 void closeConnection(); | 144 void closeConnection(); |
| 147 | 145 |
| 148 IDBDatabaseMetadata m_metadata; | 146 IDBDatabaseMetadata m_metadata; |
| 149 std::unique_ptr<WebIDBDatabase> m_backend; | 147 std::unique_ptr<IDBDatabaseProxy> m_backend; |
| 150 Member<IDBTransaction> m_versionChangeTransaction; | 148 Member<IDBTransaction> m_versionChangeTransaction; |
| 151 HeapHashMap<int64_t, Member<IDBTransaction>> m_transactions; | 149 HeapHashMap<int64_t, Member<IDBTransaction>> m_transactions; |
| 152 | 150 |
| 153 bool m_closePending = false; | 151 bool m_closePending = false; |
| 154 bool m_contextStopped = false; | 152 bool m_contextStopped = false; |
| 155 | 153 |
| 156 // Keep track of the versionchange events waiting to be fired on this | 154 // Keep track of the versionchange events waiting to be fired on this |
| 157 // database so that we can cancel them if the database closes. | 155 // database so that we can cancel them if the database closes. |
| 158 HeapVector<Member<Event>> m_enqueuedEvents; | 156 HeapVector<Member<Event>> m_enqueuedEvents; |
| 159 | |
| 160 Member<IDBDatabaseCallbacks> m_databaseCallbacks; | |
| 161 }; | 157 }; |
| 162 | 158 |
| 163 } // namespace blink | 159 } // namespace blink |
| 164 | 160 |
| 165 #endif // IDBDatabase_h | 161 #endif // IDBDatabase_h |
| OLD | NEW |