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.
27 #include "modules/indexeddb/IDBAny.h"
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"
37 PassRefPtrWillBeRawPtr<IDBAny> IDBAny::createUndefined()
39 return adoptRefWillBeNoop(new IDBAny(UndefinedType));
42 PassRefPtrWillBeRawPtr<IDBAny> IDBAny::createNull()
44 return adoptRefWillBeNoop(new IDBAny(NullType));
47 PassRefPtrWillBeRawPtr<IDBAny> IDBAny::createString(const String& value)
49 return adoptRefWillBeNoop(new IDBAny(value));
52 IDBAny::IDBAny(Type type)
56 ASSERT(type == UndefinedType || type == NullType);
63 void IDBAny::contextWillBeDestroyed()
66 m_idbCursor->contextWillBeDestroyed();
69 DOMStringList* IDBAny::domStringList() const
71 ASSERT(m_type == DOMStringListType);
72 return m_domStringList.get();
75 IDBCursor* IDBAny::idbCursor() const
77 ASSERT(m_type == IDBCursorType);
78 ASSERT_WITH_SECURITY_IMPLICATION(m_idbCursor->isKeyCursor());
79 return m_idbCursor.get();
82 IDBCursorWithValue* IDBAny::idbCursorWithValue() const
84 ASSERT(m_type == IDBCursorWithValueType);
85 ASSERT_WITH_SECURITY_IMPLICATION(m_idbCursor->isCursorWithValue());
86 return toIDBCursorWithValue(m_idbCursor.get());
89 IDBDatabase* IDBAny::idbDatabase() const
91 ASSERT(m_type == IDBDatabaseType);
92 return m_idbDatabase.get();
95 IDBIndex* IDBAny::idbIndex() const
97 ASSERT(m_type == IDBIndexType);
98 return m_idbIndex.get();
101 IDBObjectStore* IDBAny::idbObjectStore() const
103 ASSERT(m_type == IDBObjectStoreType);
104 return m_idbObjectStore.get();
107 IDBTransaction* IDBAny::idbTransaction() const
109 ASSERT(m_type == IDBTransactionType);
110 return m_idbTransaction.get();
113 const IDBKey* IDBAny::key() const
115 ASSERT(m_type == KeyType || m_type == BufferKeyAndKeyPathType);
116 return m_idbKey.get();
119 const IDBKeyPath& IDBAny::keyPath() const
121 ASSERT(m_type == KeyPathType || m_type == BufferKeyAndKeyPathType);
125 SharedBuffer* IDBAny::buffer() const
127 ASSERT(m_type == BufferType || m_type == BufferKeyAndKeyPathType);
128 return m_buffer.get();
131 const Vector<blink::WebBlobInfo>* IDBAny::blobInfo() const
133 ASSERT(m_type == BufferType || m_type == BufferKeyAndKeyPathType);
137 const String& IDBAny::string() const
139 ASSERT(m_type == StringType);
143 int64_t IDBAny::integer() const
145 ASSERT(m_type == IntegerType);
149 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<DOMStringList> value)
150 : m_type(DOMStringListType)
151 , m_domStringList(value)
156 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBCursor> value)
157 : m_type(value->isCursorWithValue() ? IDBCursorWithValueType : IDBCursorType)
163 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBDatabase> value)
164 : m_type(IDBDatabaseType)
165 , m_idbDatabase(value)
170 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBIndex> value)
171 : m_type(IDBIndexType)
177 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBTransaction> value)
178 : m_type(IDBTransactionType)
179 , m_idbTransaction(value)
184 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBObjectStore> value)
185 : m_type(IDBObjectStoreType)
186 , m_idbObjectStore(value)
191 IDBAny::IDBAny(PassRefPtr<SharedBuffer> value, const Vector<blink::WebBlobInfo>* blobInfo)
194 , m_blobInfo(blobInfo)
199 IDBAny::IDBAny(PassRefPtr<SharedBuffer> value, const Vector<blink::WebBlobInfo>* blobInfo, PassRefPtrWillBeRawPtr<IDBKey> key, const IDBKeyPath& keyPath)
200 : m_type(BufferKeyAndKeyPathType)
202 , m_idbKeyPath(keyPath)
204 , m_blobInfo(blobInfo)
209 IDBAny::IDBAny(PassRefPtrWillBeRawPtr<IDBKey> key)
216 IDBAny::IDBAny(const IDBKeyPath& value)
217 : m_type(KeyPathType)
218 , m_idbKeyPath(value)
223 IDBAny::IDBAny(const String& value)
230 IDBAny::IDBAny(int64_t value)
231 : m_type(IntegerType)
236 void IDBAny::trace(Visitor* visitor)
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);
247 } // namespace WebCore