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.
26 #ifndef IDBTransaction_h
27 #define IDBTransaction_h
29 #if ENABLE(INDEXED_DATABASE)
31 #include "ActiveDOMObject.h"
33 #include "DOMStringList.h"
35 #include "EventListener.h"
36 #include "EventNames.h"
37 #include "EventTarget.h"
38 #include "IDBMetadata.h"
39 #include "IDBTransactionBackendInterface.h"
40 #include "IDBTransactionCallbacks.h"
41 #include <wtf/HashSet.h>
42 #include <wtf/RefCounted.h>
50 class IDBTransaction : public IDBTransactionCallbacks, public EventTarget, public ActiveDOMObject {
58 static PassRefPtr<IDBTransaction> create(ScriptExecutionContext*, PassRefPtr<IDBTransactionBackendInterface>, Mode, IDBDatabase*);
59 virtual ~IDBTransaction();
61 static const AtomicString& modeReadOnly();
62 static const AtomicString& modeReadWrite();
63 static const AtomicString& modeVersionChange();
64 static const AtomicString& modeReadOnlyLegacy();
65 static const AtomicString& modeReadWriteLegacy();
67 static Mode stringToMode(const String&, ExceptionCode&);
68 static const AtomicString& modeToString(Mode, ExceptionCode&);
70 IDBTransactionBackendInterface* backend() const;
71 bool isActive() const { return m_active; }
72 bool isFinished() const;
73 bool isReadOnly() const { return m_mode == READ_ONLY; }
74 bool isVersionChange() const { return m_mode == VERSION_CHANGE; }
76 // Implement the IDBTransaction IDL
77 const String& mode() const;
78 IDBDatabase* db() const;
79 PassRefPtr<DOMError> error(ExceptionCode&) const;
80 void setError(PassRefPtr<DOMError>);
82 PassRefPtr<IDBObjectStore> objectStore(const String& name, ExceptionCode&);
85 class OpenCursorNotifier {
87 OpenCursorNotifier(PassRefPtr<IDBTransaction>, IDBCursor*);
88 ~OpenCursorNotifier();
90 RefPtr<IDBTransaction> m_transaction;
94 void registerRequest(IDBRequest*);
95 void unregisterRequest(IDBRequest*);
96 void objectStoreCreated(const String&, PassRefPtr<IDBObjectStore>);
97 void objectStoreDeleted(const String&);
99 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
100 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
101 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
103 // IDBTransactionCallbacks
104 virtual void onAbort();
105 virtual void onComplete();
108 virtual const AtomicString& interfaceName() const;
109 virtual ScriptExecutionContext* scriptExecutionContext() const;
110 virtual bool dispatchEvent(PassRefPtr<Event>);
111 bool dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) { return EventTarget::dispatchEvent(event, ec); }
114 virtual bool hasPendingActivity() const OVERRIDE;
115 virtual bool canSuspend() const OVERRIDE;
116 virtual void stop() OVERRIDE;
118 using RefCounted<IDBTransactionCallbacks>::ref;
119 using RefCounted<IDBTransactionCallbacks>::deref;
122 IDBTransaction(ScriptExecutionContext*, PassRefPtr<IDBTransactionBackendInterface>, Mode, IDBDatabase*);
124 void enqueueEvent(PassRefPtr<Event>);
125 void closeOpenCursors();
127 void registerOpenCursor(IDBCursor*);
128 void unregisterOpenCursor(IDBCursor*);
131 virtual void refEventTarget() { ref(); }
132 virtual void derefEventTarget() { deref(); }
133 virtual EventTargetData* eventTargetData();
134 virtual EventTargetData* ensureEventTargetData();
136 RefPtr<IDBTransactionBackendInterface> m_backend;
137 RefPtr<IDBDatabase> m_database;
140 bool m_transactionFinished; // Is it possible that we'll fire any more events or allow any new requests? If not, we're finished.
141 bool m_contextStopped;
142 RefPtr<DOMError> m_error;
144 ListHashSet<IDBRequest*> m_childRequests;
146 typedef HashMap<String, RefPtr<IDBObjectStore> > IDBObjectStoreMap;
147 IDBObjectStoreMap m_objectStoreMap;
149 typedef HashMap<RefPtr<IDBObjectStore>, IDBObjectStoreMetadata> IDBObjectStoreMetadataMap;
150 IDBObjectStoreMetadataMap m_objectStoreCleanupMap;
152 HashSet<IDBCursor*> m_openCursors;
154 EventTargetData m_eventTargetData;
157 } // namespace WebCore
159 #endif // ENABLE(INDEXED_DATABASE)
161 #endif // IDBTransaction_h