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 PassRefPtr<IDBAny> IDBAny::createUndefined() 38 { 39 return adoptRef(new IDBAny(UndefinedType)); 40 } 41 42 PassRefPtr<IDBAny> IDBAny::createNull() 43 { 44 return adoptRef(new IDBAny(NullType)); 45 } 46 47 PassRefPtr<IDBAny> IDBAny::createString(const String& value) 48 { 49 return adoptRef(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 DOMStringList* IDBAny::domStringList() const 64 { 65 ASSERT(m_type == DOMStringListType); 66 return m_domStringList.get(); 67 } 68 69 IDBCursor* IDBAny::idbCursor() const 70 { 71 ASSERT(m_type == IDBCursorType); 72 ASSERT_WITH_SECURITY_IMPLICATION(m_idbCursor->isKeyCursor()); 73 return m_idbCursor.get(); 74 } 75 76 IDBCursorWithValue* IDBAny::idbCursorWithValue() const 77 { 78 ASSERT(m_type == IDBCursorWithValueType); 79 ASSERT_WITH_SECURITY_IMPLICATION(m_idbCursor->isCursorWithValue()); 80 return toIDBCursorWithValue(m_idbCursor.get()); 81 } 82 83 IDBDatabase* IDBAny::idbDatabase() const 84 { 85 ASSERT(m_type == IDBDatabaseType); 86 return m_idbDatabase.get(); 87 } 88 89 IDBIndex* IDBAny::idbIndex() const 90 { 91 ASSERT(m_type == IDBIndexType); 92 return m_idbIndex.get(); 93 } 94 95 IDBObjectStore* IDBAny::idbObjectStore() const 96 { 97 ASSERT(m_type == IDBObjectStoreType); 98 return m_idbObjectStore.get(); 99 } 100 101 IDBTransaction* IDBAny::idbTransaction() const 102 { 103 ASSERT(m_type == IDBTransactionType); 104 return m_idbTransaction.get(); 105 } 106 107 const IDBKey* IDBAny::key() const 108 { 109 ASSERT(m_type == KeyType || m_type == BufferKeyAndKeyPathType); 110 return m_idbKey.get(); 111 } 112 113 const IDBKeyPath& IDBAny::keyPath() const 114 { 115 ASSERT(m_type == KeyPathType || m_type == BufferKeyAndKeyPathType); 116 return m_idbKeyPath; 117 } 118 119 SharedBuffer* IDBAny::buffer() const 120 { 121 ASSERT(m_type == BufferType || m_type == BufferKeyAndKeyPathType); 122 return m_buffer.get(); 123 } 124 125 const String& IDBAny::string() const 126 { 127 ASSERT(m_type == StringType); 128 return m_string; 129 } 130 131 int64_t IDBAny::integer() const 132 { 133 ASSERT(m_type == IntegerType); 134 return m_integer; 135 } 136 137 IDBAny::IDBAny(PassRefPtr<DOMStringList> value) 138 : m_type(DOMStringListType) 139 , m_domStringList(value) 140 , m_integer(0) 141 { 142 } 143 144 IDBAny::IDBAny(PassRefPtr<IDBCursor> value) 145 : m_type(value->isCursorWithValue() ? IDBCursorWithValueType : IDBCursorType) 146 , m_idbCursor(value) 147 , m_integer(0) 148 { 149 } 150 151 IDBAny::IDBAny(PassRefPtr<IDBDatabase> value) 152 : m_type(IDBDatabaseType) 153 , m_idbDatabase(value) 154 , m_integer(0) 155 { 156 } 157 158 IDBAny::IDBAny(PassRefPtr<IDBIndex> value) 159 : m_type(IDBIndexType) 160 , m_idbIndex(value) 161 , m_integer(0) 162 { 163 } 164 165 IDBAny::IDBAny(PassRefPtr<IDBTransaction> value) 166 : m_type(IDBTransactionType) 167 , m_idbTransaction(value) 168 , m_integer(0) 169 { 170 } 171 172 IDBAny::IDBAny(PassRefPtr<IDBObjectStore> value) 173 : m_type(IDBObjectStoreType) 174 , m_idbObjectStore(value) 175 , m_integer(0) 176 { 177 } 178 179 IDBAny::IDBAny(PassRefPtr<SharedBuffer> value) 180 : m_type(BufferType) 181 , m_buffer(value) 182 , m_integer(0) 183 { 184 } 185 186 IDBAny::IDBAny(PassRefPtr<SharedBuffer> value, PassRefPtr<IDBKey> key, const IDBKeyPath& keyPath) 187 : m_type(BufferKeyAndKeyPathType) 188 , m_idbKey(key) 189 , m_idbKeyPath(keyPath) 190 , m_buffer(value) 191 , m_integer(0) 192 { 193 } 194 195 IDBAny::IDBAny(PassRefPtr<IDBKey> key) 196 : m_type(KeyType) 197 , m_idbKey(key) 198 , m_integer(0) 199 { 200 } 201 202 IDBAny::IDBAny(const IDBKeyPath& value) 203 : m_type(KeyPathType) 204 , m_idbKeyPath(value) 205 , m_integer(0) 206 { 207 } 208 209 IDBAny::IDBAny(const String& value) 210 : m_type(StringType) 211 , m_string(value) 212 , m_integer(0) 213 { 214 } 215 216 IDBAny::IDBAny(int64_t value) 217 : m_type(IntegerType) 218 , m_integer(value) 219 { 220 } 221 222 } // namespace WebCore 223