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"
31 #include "Dictionary.h"
33 #include "EventTarget.h"
34 #include "IDBDatabaseBackendInterface.h"
35 #include "IDBDatabaseCallbacksImpl.h"
36 #include "IDBObjectStore.h"
37 #include "IDBTransaction.h"
38 #include <wtf/PassRefPtr.h>
39 #include <wtf/RefCounted.h>
40 #include <wtf/RefPtr.h>
42 #if ENABLE(INDEXED_DATABASE)
46 class IDBVersionChangeRequest;
47 class ScriptExecutionContext;
49 typedef int ExceptionCode;
51 class IDBDatabase : public RefCounted<IDBDatabase>, public EventTarget, public ActiveDOMObject {
53 static PassRefPtr<IDBDatabase> create(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendInterface>);
56 void transactionCreated(IDBTransaction*);
57 void transactionFinished(IDBTransaction*);
60 String name() const { return m_backend->name(); }
61 String version() const { return m_backend->version(); }
62 PassRefPtr<DOMStringList> objectStoreNames() const { return m_backend->objectStoreNames(); }
64 // FIXME: Try to modify the code generator so this is unneeded.
65 PassRefPtr<IDBObjectStore> createObjectStore(const String& name, ExceptionCode& ec) { return createObjectStore(name, Dictionary(), ec); }
66 PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const Dictionary&, ExceptionCode&);
67 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, PassRefPtr<DOMStringList>, const String& mode, ExceptionCode&);
68 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const String&, const String& mode, ExceptionCode&);
69 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, PassRefPtr<DOMStringList>, unsigned short mode, ExceptionCode&);
70 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const String&, unsigned short mode, ExceptionCode&);
71 void deleteObjectStore(const String& name, ExceptionCode&);
72 PassRefPtr<IDBVersionChangeRequest> setVersion(ScriptExecutionContext*, const String& version, ExceptionCode&);
75 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
76 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
77 DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange);
79 // IDBDatabaseCallbacks
80 virtual void onVersionChange(const String& requestedVersion);
83 virtual void stop() OVERRIDE;
86 virtual const AtomicString& interfaceName() const;
87 virtual ScriptExecutionContext* scriptExecutionContext() const;
89 void registerFrontendCallbacks();
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 void closeConnection();
108 RefPtr<IDBDatabaseBackendInterface> m_backend;
109 RefPtr<IDBTransaction> m_versionChangeTransaction;
110 HashSet<IDBTransaction*> m_transactions;
113 bool m_contextStopped;
115 EventTargetData m_eventTargetData;
117 // Keep track of the versionchange events waiting to be fired on this
118 // database so that we can cancel them if the database closes.
119 Vector<RefPtr<Event> > m_enqueuedEvents;
121 RefPtr<IDBDatabaseCallbacksImpl> m_databaseCallbacks;
124 } // namespace WebCore
128 #endif // IDBDatabase_h