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 "IDBDatabaseBackendInterface.h"
34 #include "IDBDatabaseCallbacksImpl.h"
35 #include "IDBObjectStore.h"
36 #include "IDBTransaction.h"
37 #include "OptionsObject.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 setVersionChangeTransaction(IDBTransaction*);
57 void clearVersionChangeTransaction(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, OptionsObject(), ec); }
66 PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const OptionsObject&, ExceptionCode&);
67 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, PassRefPtr<DOMStringList>, unsigned short mode, ExceptionCode&);
68 PassRefPtr<IDBTransaction> transaction(ScriptExecutionContext*, const String&, unsigned short mode, 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 OVERRIDE;
82 virtual void stop() OVERRIDE;
85 virtual const AtomicString& interfaceName() const;
86 virtual ScriptExecutionContext* scriptExecutionContext() const;
89 void enqueueEvent(PassRefPtr<Event>);
90 bool dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) { return EventTarget::dispatchEvent(event, ec); }
91 virtual bool dispatchEvent(PassRefPtr<Event>);
93 using RefCounted<IDBDatabase>::ref;
94 using RefCounted<IDBDatabase>::deref;
97 IDBDatabase(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendInterface>);
100 virtual void refEventTarget() { ref(); }
101 virtual void derefEventTarget() { deref(); }
102 virtual EventTargetData* eventTargetData();
103 virtual EventTargetData* ensureEventTargetData();
105 RefPtr<IDBDatabaseBackendInterface> m_backend;
106 RefPtr<IDBTransaction> m_versionChangeTransaction;
109 bool m_contextStopped;
111 EventTargetData m_eventTargetData;
113 // Keep track of the versionchange events waiting to be fired on this
114 // database so that we can cancel them if the database closes.
115 Vector<RefPtr<Event> > m_enqueuedEvents;
117 RefPtr<IDBDatabaseCallbacksImpl> m_databaseCallbacks;
120 } // namespace WebCore
124 #endif // IDBDatabase_h