tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / storage / IDBDatabase.h
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
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.
13  *
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.
24  */
25
26 #ifndef IDBDatabase_h
27 #define IDBDatabase_h
28
29 #include "ActiveDOMObject.h"
30 #include "DOMStringList.h"
31 #include "Event.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>
41
42 #if ENABLE(INDEXED_DATABASE)
43
44 namespace WebCore {
45
46 class IDBVersionChangeRequest;
47 class ScriptExecutionContext;
48
49 typedef int ExceptionCode;
50
51 class IDBDatabase : public RefCounted<IDBDatabase>, public EventTarget, public ActiveDOMObject {
52 public:
53     static PassRefPtr<IDBDatabase> create(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendInterface>);
54     ~IDBDatabase();
55
56     void setVersionChangeTransaction(IDBTransaction*);
57     void clearVersionChangeTransaction(IDBTransaction*);
58
59     // Implement the IDL
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(); }
63
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&);
71     void close();
72
73     DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
74     DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
75     DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange);
76
77     // IDBDatabaseCallbacks
78     virtual void onVersionChange(const String& requestedVersion);
79
80     // ActiveDOMObject
81     virtual bool hasPendingActivity() const OVERRIDE;
82     virtual void stop() OVERRIDE;
83
84     // EventTarget
85     virtual const AtomicString& interfaceName() const;
86     virtual ScriptExecutionContext* scriptExecutionContext() const;
87
88     void open();
89     void enqueueEvent(PassRefPtr<Event>);
90     bool dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) { return EventTarget::dispatchEvent(event, ec); }
91     virtual bool dispatchEvent(PassRefPtr<Event>);
92
93     using RefCounted<IDBDatabase>::ref;
94     using RefCounted<IDBDatabase>::deref;
95
96 private:
97     IDBDatabase(ScriptExecutionContext*, PassRefPtr<IDBDatabaseBackendInterface>);
98
99     // EventTarget
100     virtual void refEventTarget() { ref(); }
101     virtual void derefEventTarget() { deref(); }
102     virtual EventTargetData* eventTargetData();
103     virtual EventTargetData* ensureEventTargetData();
104
105     RefPtr<IDBDatabaseBackendInterface> m_backend;
106     RefPtr<IDBTransaction> m_versionChangeTransaction;
107
108     bool m_closePending;
109     bool m_contextStopped;
110
111     EventTargetData m_eventTargetData;
112
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;
116
117     RefPtr<IDBDatabaseCallbacksImpl> m_databaseCallbacks;
118 };
119
120 } // namespace WebCore
121
122 #endif
123
124 #endif // IDBDatabase_h