Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / indexeddb / IDBAny.cpp
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 #include "config.h"
27 #include "modules/indexeddb/IDBAny.h"
28
29 #include "core/dom/DOMStringList.h"
30 #include "modules/indexeddb/IDBCursorWithValue.h"
31 #include "modules/indexeddb/IDBDatabase.h"
32 #include "modules/indexeddb/IDBIndex.h"
33 #include "modules/indexeddb/IDBObjectStore.h"
34
35 namespace WebCore {
36
37 PassRefPtrWillBeRawPtr<IDBAny> IDBAny::createUndefined()
38 {
39     return adoptRefWillBeNoop(new IDBAny(UndefinedType));
40 }
41
42 PassRefPtrWillBeRawPtr<IDBAny> IDBAny::createNull()
43 {
44     return adoptRefWillBeNoop(new IDBAny(NullType));
45 }
46
47 PassRefPtrWillBeRawPtr<IDBAny> IDBAny::createString(const String& value)
48 {
49     return adoptRefWillBeNoop(new IDBAny(value));
50 }
51
52 IDBAny::IDBAny(Type type)
53     : m_type(type)
54     , m_integer(0)
55 {
56     ASSERT(type == UndefinedType || type == NullType);
57 }
58
59 IDBAny::~IDBAny()
60 {
61 }
62
63 void IDBAny::contextWillBeDestroyed()
64 {
65     if (m_idbCursor)
66         m_idbCursor->contextWillBeDestroyed();
67 }
68
69 DOMStringList* IDBAny::domStringList() const
70 {
71     ASSERT(m_type == DOMStringListType);
72     return m_domStringList.get();
73 }
74
75 IDBCursor* IDBAny::idbCursor() const
76 {
77     ASSERT(m_type == IDBCursorType);
78     ASSERT_WITH_SECURITY_IMPLICATION(m_idbCursor->isKeyCursor());
79     return m_idbCursor.get();
80 }
81
82 IDBCursorWithValue* IDBAny::idbCursorWithValue() const
83 {
84     ASSERT(m_type == IDBCursorWithValueType);
85     ASSERT_WITH_SECURITY_IMPLICATION(m_idbCursor->isCursorWithValue());
86     return toIDBCursorWithValue(m_idbCursor.get());
87 }
88
89 IDBDatabase* IDBAny::idbDatabase() const
90 {
91     ASSERT(m_type == IDBDatabaseType);
92     return m_idbDatabase.get();
93 }
94
95 IDBIndex* IDBAny::idbIndex() const
96 {
97     ASSERT(m_type == IDBIndexType);
98     return m_idbIndex.get();
99 }
100
101 IDBObjectStore* IDBAny::idbObjectStore() const
102 {
103     ASSERT(m_type == IDBObjectStoreType);
104     return m_idbObjectStore.get();
105 }
106
107 IDBTransaction* IDBAny::idbTransaction() const
108 {
109     ASSERT(m_type == IDBTransactionType);
110     return m_idbTransaction.get();
111 }
112
113 const IDBKey* IDBAny::key() const
114 {
115     ASSERT(m_type == KeyType || m_type == BufferKeyAndKeyPathType);
116     return m_idbKey.get();
117 }
118
119 const IDBKeyPath& IDBAny::keyPath() const
120 {
121     ASSERT(m_type == KeyPathType || m_type == BufferKeyAndKeyPathType);
122     return m_idbKeyPath;
123 }
124
125 SharedBuffer* IDBAny::buffer() const
126 {
127     ASSERT(m_type == BufferType || m_type == BufferKeyAndKeyPathType);
128     return m_buffer.get();
129 }
130
131 const Vector<blink::WebBlobInfo>* IDBAny::blobInfo() const
132 {
133     ASSERT(m_type == BufferType || m_type == BufferKeyAndKeyPathType);
134     return m_blobInfo;
135 }
136
137 const String& IDBAny::string() const
138 {
139     ASSERT(m_type == StringType);
140     return m_string;
141 }
142
143 int64_t IDBAny::integer() const
144 {
145     ASSERT(m_type == IntegerType);
146     return m_integer;
147 }
148
149 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<DOMStringList> value)
150     : m_type(DOMStringListType)
151     , m_domStringList(value)
152     , m_integer(0)
153 {
154 }
155
156 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBCursor> value)
157     : m_type(value->isCursorWithValue() ? IDBCursorWithValueType : IDBCursorType)
158     , m_idbCursor(value)
159     , m_integer(0)
160 {
161 }
162
163 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBDatabase> value)
164     : m_type(IDBDatabaseType)
165     , m_idbDatabase(value)
166     , m_integer(0)
167 {
168 }
169
170 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBIndex> value)
171     : m_type(IDBIndexType)
172     , m_idbIndex(value)
173     , m_integer(0)
174 {
175 }
176
177 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBTransaction> value)
178     : m_type(IDBTransactionType)
179     , m_idbTransaction(value)
180     , m_integer(0)
181 {
182 }
183
184 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBObjectStore> value)
185     : m_type(IDBObjectStoreType)
186     , m_idbObjectStore(value)
187     , m_integer(0)
188 {
189 }
190
191 IDBAny::IDBAny(PassRefPtr<SharedBuffer> value, const Vector<blink::WebBlobInfo>* blobInfo)
192     : m_type(BufferType)
193     , m_buffer(value)
194     , m_blobInfo(blobInfo)
195     , m_integer(0)
196 {
197 }
198
199 IDBAny::IDBAny(PassRefPtr<SharedBuffer> value, const Vector<blink::WebBlobInfo>* blobInfo, PassRefPtrWillBeRawPtr<IDBKey> key, const IDBKeyPath& keyPath)
200     : m_type(BufferKeyAndKeyPathType)
201     , m_idbKey(key)
202     , m_idbKeyPath(keyPath)
203     , m_buffer(value)
204     , m_blobInfo(blobInfo)
205     , m_integer(0)
206 {
207 }
208
209 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBKey> key)
210     : m_type(KeyType)
211     , m_idbKey(key)
212     , m_integer(0)
213 {
214 }
215
216 IDBAny::IDBAny(const IDBKeyPath& value)
217     : m_type(KeyPathType)
218     , m_idbKeyPath(value)
219     , m_integer(0)
220 {
221 }
222
223 IDBAny::IDBAny(const String& value)
224     : m_type(StringType)
225     , m_string(value)
226     , m_integer(0)
227 {
228 }
229
230 IDBAny::IDBAny(int64_t value)
231     : m_type(IntegerType)
232     , m_integer(value)
233 {
234 }
235
236 void IDBAny::trace(Visitor* visitor)
237 {
238     visitor->trace(m_domStringList);
239     visitor->trace(m_idbCursor);
240     visitor->trace(m_idbDatabase);
241     visitor->trace(m_idbIndex);
242     visitor->trace(m_idbObjectStore);
243     visitor->trace(m_idbTransaction);
244     visitor->trace(m_idbKey);
245 }
246
247 } // namespace WebCore