2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "ActiveDOMObject.h"
30 #include "DOMStringList.h"
32 #include "EventTarget.h"
33 #include "ExceptionCode.h"
34 #include "IDBDatabaseBackendInterface.h"
35 #include "IDBDatabaseCallbacksImpl.h"
36 #include "IDBObjectStore.h"
37 #include "IDBTransaction.h"
38 #include "OptionsObject.h"
39 #include <wtf/PassRefPtr.h>
40 #include <wtf/RefCounted.h>
41 #include <wtf/RefPtr.h>
43 #if ENABLE(INDEXED_DATABASE)
47 class IDBVersionChangeRequest;
48 class ScriptExecutionContext;
50 class IDBDatabase : public RefCounted<IDBDatabase>, public EventTarget, public ActiveDOMObject {
52 static PassRefPtr<IDBDatabase> create(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendInterface>);
55 void setSetVersionTransaction(IDBTransaction*);
58 String name() const { return m_backend->name(); }
59 String version() const { return m_backend->version(); }
60 PassRefPtr<DOMStringList> objectStoreNames() const { return m_backend->objectStoreNames(); }
62 // FIXME: Try to modify the code generator so this is unneeded.
63 PassRefPtr<IDBObjectStore> createObjectStore(const String& name, ExceptionCode& ec) { return createObjectStore(name, OptionsObject(), ec); }
64 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext* context, ExceptionCode& ec) { return transaction(context, 0, ec); }
65 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext* context, PassRefPtr<DOMStringList> storeNames, ExceptionCode& ec) { return transaction(context, storeNames, IDBTransaction::READ_ONLY, ec); }
66 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, PassRefPtr<DOMStringList>, unsigned short mode, ExceptionCode&);
68 PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const OptionsObject&, ExceptionCode&);
69 void deleteObjectStore(const String& name, ExceptionCode&);
70 PassRefPtr<IDBVersionChangeRequest> setVersion(ScriptExecutionContext*, const String& version, ExceptionCode&);
73 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
74 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
75 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange);
77 // IDBDatabaseCallbacks
78 virtual void onVersionChange(const String& requestedVersion);
81 virtual bool hasPendingActivity() const;
85 virtual IDBDatabase* toIDBDatabase() { return this; }
86 virtual ScriptExecutionContext* scriptExecutionContext() const;
90 void enqueueEvent(PassRefPtr<Event>);
91 bool dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) { return EventTarget::dispatchEvent(event, ec); }
92 virtual bool dispatchEvent(PassRefPtr<Event>);
94 using RefCounted<IDBDatabase>::ref;
95 using RefCounted<IDBDatabase>::deref;
98 IDBDatabase(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendInterface>);
101 virtual void refEventTarget() { ref(); }
102 virtual void derefEventTarget() { deref(); }
103 virtual EventTargetData* eventTargetData();
104 virtual EventTargetData* ensureEventTargetData();
106 RefPtr<IDBDatabaseBackendInterface> m_backend;
107 RefPtr<IDBTransaction> m_setVersionTransaction;
109 bool m_noNewTransactions;
112 EventTargetData m_eventTargetData;
114 // Keep track of the versionchange events waiting to be fired on this
115 // database so that we can cancel them if the database closes.
116 Vector<RefPtr<Event> > m_enqueuedEvents;
118 RefPtr<IDBDatabaseCallbacksImpl> m_databaseCallbacks;
121 } // namespace WebCore
125 #endif // IDBDatabase_h