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"
32 #include "DOMStringList.h"
34 #include "EventListener.h"
35 #include "EventNames.h"
36 #include "EventTarget.h"
37 #include "IDBTransactionBackendInterface.h"
38 #include "IDBTransactionCallbacks.h"
39 #include <wtf/RefCounted.h>
46 class IDBTransaction : public IDBTransactionCallbacks, public EventTarget, public ActiveDOMObject {
48 static PassRefPtr<IDBTransaction> create(ScriptExecutionContext*, PassRefPtr<IDBTransactionBackendInterface>, IDBDatabase*);
49 virtual ~IDBTransaction();
57 IDBTransactionBackendInterface* backend() const;
58 bool finished() const;
60 unsigned short mode() const;
61 IDBDatabase* db() const;
62 PassRefPtr<IDBObjectStore> objectStore(const String& name, ExceptionCode&);
65 void registerRequest(IDBRequest*);
66 void unregisterRequest(IDBRequest*);
68 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
69 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
70 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
72 // IDBTransactionCallbacks
73 virtual void onAbort();
74 virtual void onComplete();
77 virtual IDBTransaction* toIDBTransaction() { return this; }
78 virtual ScriptExecutionContext* scriptExecutionContext() const;
79 virtual bool dispatchEvent(PassRefPtr<Event>);
80 bool dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) { return EventTarget::dispatchEvent(event, ec); }
83 virtual bool hasPendingActivity() const;
84 virtual bool canSuspend() const;
85 virtual void contextDestroyed();
87 using RefCounted<IDBTransactionCallbacks>::ref;
88 using RefCounted<IDBTransactionCallbacks>::deref;
91 IDBTransaction(ScriptExecutionContext*, PassRefPtr<IDBTransactionBackendInterface>, IDBDatabase*);
93 void enqueueEvent(PassRefPtr<Event>);
96 virtual void refEventTarget() { ref(); }
97 virtual void derefEventTarget() { deref(); }
98 virtual EventTargetData* eventTargetData();
99 virtual EventTargetData* ensureEventTargetData();
101 RefPtr<IDBTransactionBackendInterface> m_backend;
102 RefPtr<IDBDatabase> m_database;
103 unsigned short m_mode;
104 bool m_finished; // Is it possible that we'll fire any more events or allow any new transactions? If not, we're finished.
106 ListHashSet<IDBRequest*> m_childRequests;
108 EventTargetData m_eventTargetData;
111 } // namespace WebCore
113 #endif // ENABLE(INDEXED_DATABASE)
115 #endif // IDBTransaction_h