| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
RefPtr<IDBKey> key, ExceptionCode& ec) | 98 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass
RefPtr<IDBKey> key, ExceptionCode& ec) |
| 99 { | 99 { |
| 100 IDB_TRACE("IDBObjectStore::get"); | 100 IDB_TRACE("IDBObjectStore::get"); |
| 101 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(key, ec); | 101 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(key, ec); |
| 102 if (ec) | 102 if (ec) |
| 103 return 0; | 103 return 0; |
| 104 return get(context, keyRange.release(), ec); | 104 return get(context, keyRange.release(), ec); |
| 105 } | 105 } |
| 106 | 106 |
| 107 static void generateIndexKeysForValue(const IDBIndexMetadata& indexMetadata, | 107 static void generateIndexKeysForValue(const IDBIndexMetadata& indexMetadata, |
| 108 const ScriptValue& objectValue, | 108 PassRefPtr<SerializedScriptValue> objectVa
lue, |
| 109 IDBObjectStore::IndexKeys* indexKeys) | 109 IDBObjectStore::IndexKeys* indexKeys) |
| 110 { | 110 { |
| 111 ASSERT(indexKeys); | 111 ASSERT(indexKeys); |
| 112 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(objectValue,
indexMetadata.keyPath); | 112 RefPtr<IDBKey> indexKey = createIDBKeyFromSerializedValueAndKeyPath(objectVa
lue, indexMetadata.keyPath); |
| 113 | 113 |
| 114 if (!indexKey) | 114 if (!indexKey) |
| 115 return; | 115 return; |
| 116 | 116 |
| 117 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) { | 117 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) { |
| 118 if (!indexKey->isValid()) | 118 if (!indexKey->isValid()) |
| 119 return; | 119 return; |
| 120 | 120 |
| 121 indexKeys->append(indexKey); | 121 indexKeys->append(indexKey); |
| 122 } else { | 122 } else { |
| 123 ASSERT(indexMetadata.multiEntry); | 123 ASSERT(indexMetadata.multiEntry); |
| 124 ASSERT(indexKey->type() == IDBKey::ArrayType); | 124 ASSERT(indexKey->type() == IDBKey::ArrayType); |
| 125 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); | 125 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); |
| 126 | 126 |
| 127 for (size_t i = 0; i < indexKey->array().size(); ++i) | 127 for (size_t i = 0; i < indexKey->array().size(); ++i) |
| 128 indexKeys->append(indexKey->array()[i]); | 128 indexKeys->append(indexKey->array()[i]); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptExecutionContext* context, Scri
ptValue& value, PassRefPtr<IDBKey> key, ExceptionCode& ec) | 132 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptExecutionContext* context, Pass
RefPtr<SerializedScriptValue> value, PassRefPtr<IDBKey> key, ExceptionCode& ec) |
| 133 { | 133 { |
| 134 IDB_TRACE("IDBObjectStore::add"); | 134 IDB_TRACE("IDBObjectStore::add"); |
| 135 return put(IDBObjectStoreBackendInterface::AddOnly, IDBAny::create(this), co
ntext, value, key, ec); | 135 return put(IDBObjectStoreBackendInterface::AddOnly, IDBAny::create(this), co
ntext, value, key, ec); |
| 136 } | 136 } |
| 137 | 137 |
| 138 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptExecutionContext* context, Scri
ptValue& value, PassRefPtr<IDBKey> key, ExceptionCode& ec) | 138 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptExecutionContext* context, Pass
RefPtr<SerializedScriptValue> value, PassRefPtr<IDBKey> key, ExceptionCode& ec) |
| 139 { | 139 { |
| 140 IDB_TRACE("IDBObjectStore::put"); | 140 IDB_TRACE("IDBObjectStore::put"); |
| 141 return put(IDBObjectStoreBackendInterface::AddOrUpdate, IDBAny::create(this)
, context, value, key, ec); | 141 return put(IDBObjectStoreBackendInterface::AddOrUpdate, IDBAny::create(this)
, context, value, key, ec); |
| 142 } | 142 } |
| 143 | 143 |
| 144 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBObjectStoreBackendInterface::PutMo
de putMode, PassRefPtr<IDBAny> source, ScriptExecutionContext* context, ScriptVa
lue& value, PassRefPtr<IDBKey> prpKey, ExceptionCode& ec) | 144 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBObjectStoreBackendInterface::PutMo
de putMode, PassRefPtr<IDBAny> source, ScriptExecutionContext* context, PassRefP
tr<SerializedScriptValue> prpValue, PassRefPtr<IDBKey> prpKey, ExceptionCode& ec
) |
| 145 { | 145 { |
| 146 IDB_TRACE("IDBObjectStore::put"); | 146 IDB_TRACE("IDBObjectStore::put"); |
| 147 RefPtr<SerializedScriptValue> value = prpValue; |
| 147 RefPtr<IDBKey> key = prpKey; | 148 RefPtr<IDBKey> key = prpKey; |
| 148 if (m_deleted) { | 149 if (m_deleted) { |
| 149 ec = IDBDatabaseException::IDB_INVALID_STATE_ERR; | 150 ec = IDBDatabaseException::IDB_INVALID_STATE_ERR; |
| 150 return 0; | 151 return 0; |
| 151 } | 152 } |
| 152 if (!m_transaction->isActive()) { | 153 if (!m_transaction->isActive()) { |
| 153 ec = IDBDatabaseException::TRANSACTION_INACTIVE_ERR; | 154 ec = IDBDatabaseException::TRANSACTION_INACTIVE_ERR; |
| 154 return 0; | 155 return 0; |
| 155 } | 156 } |
| 156 if (m_transaction->isReadOnly()) { | 157 if (m_transaction->isReadOnly()) { |
| 157 ec = IDBDatabaseException::READ_ONLY_ERR; | 158 ec = IDBDatabaseException::READ_ONLY_ERR; |
| 158 return 0; | 159 return 0; |
| 159 } | 160 } |
| 160 | 161 if (value->blobURLs().size() > 0) { |
| 161 ScriptState* state = ScriptState::current(); | |
| 162 RefPtr<SerializedScriptValue> serializedValue = value.serialize(state); | |
| 163 if (state->hadException()) { | |
| 164 ec = IDBDatabaseException::IDB_DATA_CLONE_ERR; | |
| 165 return 0; | |
| 166 } | |
| 167 | |
| 168 if (serializedValue->blobURLs().size() > 0) { | |
| 169 // FIXME: Add Blob/File/FileList support | 162 // FIXME: Add Blob/File/FileList support |
| 170 ec = IDBDatabaseException::IDB_DATA_CLONE_ERR; | 163 ec = IDBDatabaseException::IDB_DATA_CLONE_ERR; |
| 171 return 0; | 164 return 0; |
| 172 } | 165 } |
| 173 | 166 |
| 174 const IDBKeyPath& keyPath = m_metadata.keyPath; | 167 const IDBKeyPath& keyPath = m_metadata.keyPath; |
| 175 const bool usesInLineKeys = !keyPath.isNull(); | 168 const bool usesInLineKeys = !keyPath.isNull(); |
| 176 const bool hasKeyGenerator = autoIncrement(); | 169 const bool hasKeyGenerator = autoIncrement(); |
| 177 | 170 |
| 178 if (putMode != IDBObjectStoreBackendInterface::CursorUpdate && usesInLineKey
s && key) { | 171 if (putMode != IDBObjectStoreBackendInterface::CursorUpdate && usesInLineKey
s && key) { |
| 179 ec = IDBDatabaseException::DATA_ERR; | 172 ec = IDBDatabaseException::DATA_ERR; |
| 180 return 0; | 173 return 0; |
| 181 } | 174 } |
| 182 if (!usesInLineKeys && !hasKeyGenerator && !key) { | 175 if (!usesInLineKeys && !hasKeyGenerator && !key) { |
| 183 ec = IDBDatabaseException::DATA_ERR; | 176 ec = IDBDatabaseException::DATA_ERR; |
| 184 return 0; | 177 return 0; |
| 185 } | 178 } |
| 186 if (usesInLineKeys) { | 179 if (usesInLineKeys) { |
| 187 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(value,
keyPath); | 180 RefPtr<IDBKey> keyPathKey = createIDBKeyFromSerializedValueAndKeyPath(va
lue, keyPath); |
| 188 if (keyPathKey && !keyPathKey->isValid()) { | 181 if (keyPathKey && !keyPathKey->isValid()) { |
| 189 ec = IDBDatabaseException::DATA_ERR; | 182 ec = IDBDatabaseException::DATA_ERR; |
| 190 return 0; | 183 return 0; |
| 191 } | 184 } |
| 192 if (!hasKeyGenerator && !keyPathKey) { | 185 if (!hasKeyGenerator && !keyPathKey) { |
| 193 ec = IDBDatabaseException::DATA_ERR; | 186 ec = IDBDatabaseException::DATA_ERR; |
| 194 return 0; | 187 return 0; |
| 195 } | 188 } |
| 196 if (hasKeyGenerator && !keyPathKey) { | 189 if (hasKeyGenerator && !keyPathKey) { |
| 197 if (!canInjectIDBKeyIntoScriptValue(value, keyPath)) { | 190 RefPtr<IDBKey> dummyKey = IDBKey::createNumber(-1); |
| 191 RefPtr<SerializedScriptValue> valueAfterInjection = injectIDBKeyInto
SerializedValue(dummyKey, value, keyPath); |
| 192 if (!valueAfterInjection) { |
| 198 ec = IDBDatabaseException::DATA_ERR; | 193 ec = IDBDatabaseException::DATA_ERR; |
| 199 return 0; | 194 return 0; |
| 200 } | 195 } |
| 201 } | 196 } |
| 202 if (keyPathKey) | 197 if (keyPathKey) |
| 203 key = keyPathKey; | 198 key = keyPathKey; |
| 204 } | 199 } |
| 205 if (key && !key->isValid()) { | 200 if (key && !key->isValid()) { |
| 206 ec = IDBDatabaseException::DATA_ERR; | 201 ec = IDBDatabaseException::DATA_ERR; |
| 207 return 0; | 202 return 0; |
| 208 } | 203 } |
| 209 | 204 |
| 210 Vector<String> indexNames; | 205 Vector<String> indexNames; |
| 211 Vector<IndexKeys> indexKeys; | 206 Vector<IndexKeys> indexKeys; |
| 212 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 207 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { |
| 213 IndexKeys keys; | 208 IndexKeys keys; |
| 214 generateIndexKeysForValue(it->second, value, &keys); | 209 generateIndexKeysForValue(it->second, value, &keys); |
| 215 indexNames.append(it->first); | 210 indexNames.append(it->first); |
| 216 indexKeys.append(keys); | 211 indexKeys.append(keys); |
| 217 } | 212 } |
| 218 ASSERT(indexKeys.size() == indexNames.size()); | 213 ASSERT(indexKeys.size() == indexNames.size()); |
| 219 | 214 |
| 220 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti
on.get()); | 215 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti
on.get()); |
| 221 m_backend->putWithIndexKeys(serializedValue.release(), key.release(), putMod
e, request, m_transaction->backend(), indexNames, indexKeys, ec); | 216 m_backend->putWithIndexKeys(value.release(), key.release(), putMode, request
, m_transaction->backend(), indexNames, indexKeys, ec); |
| 222 if (ec) { | 217 if (ec) { |
| 223 request->markEarlyDeath(); | 218 request->markEarlyDeath(); |
| 224 return 0; | 219 return 0; |
| 225 } | 220 } |
| 226 return request.release(); | 221 return request.release(); |
| 227 } | 222 } |
| 228 | 223 |
| 229 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) | 224 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co
ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) |
| 230 { | 225 { |
| 231 IDB_TRACE("IDBObjectStore::delete"); | 226 IDB_TRACE("IDBObjectStore::delete"); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 IndexPopulator(PassRefPtr<IDBObjectStoreBackendInterface> backend, | 306 IndexPopulator(PassRefPtr<IDBObjectStoreBackendInterface> backend, |
| 312 PassRefPtr<IDBTransactionBackendInterface> transaction, | 307 PassRefPtr<IDBTransactionBackendInterface> transaction, |
| 313 const IDBIndexMetadata& indexMetadata) | 308 const IDBIndexMetadata& indexMetadata) |
| 314 : EventListener(CPPEventListenerType) | 309 : EventListener(CPPEventListenerType) |
| 315 , m_objectStoreBackend(backend) | 310 , m_objectStoreBackend(backend) |
| 316 , m_transaction(transaction) | 311 , m_transaction(transaction) |
| 317 , m_indexMetadata(indexMetadata) | 312 , m_indexMetadata(indexMetadata) |
| 318 { | 313 { |
| 319 } | 314 } |
| 320 | 315 |
| 321 virtual void handleEvent(ScriptExecutionContext* context, Event* event) | 316 virtual void handleEvent(ScriptExecutionContext*, Event* event) |
| 322 { | 317 { |
| 323 ASSERT(event->type() == eventNames().successEvent); | 318 ASSERT(event->type() == eventNames().successEvent); |
| 324 EventTarget* target = event->target(); | 319 EventTarget* target = event->target(); |
| 325 IDBRequest* request = static_cast<IDBRequest*>(target); | 320 IDBRequest* request = static_cast<IDBRequest*>(target); |
| 326 | 321 |
| 327 ExceptionCode ec = 0; | 322 ExceptionCode ec = 0; |
| 328 RefPtr<IDBAny> cursorAny = request->result(ec); | 323 RefPtr<IDBAny> cursorAny = request->result(ec); |
| 329 ASSERT(!ec); | 324 ASSERT(!ec); |
| 330 RefPtr<IDBCursorWithValue> cursor; | 325 RefPtr<IDBCursorWithValue> cursor; |
| 331 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) | 326 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) |
| 332 cursor = cursorAny->idbCursorWithValue(); | 327 cursor = cursorAny->idbCursorWithValue(); |
| 333 | 328 |
| 334 Vector<String, 1> indexNames; | 329 Vector<String, 1> indexNames; |
| 335 indexNames.append(m_indexMetadata.name); | 330 indexNames.append(m_indexMetadata.name); |
| 336 if (cursor) { | 331 if (cursor) { |
| 337 cursor->continueFunction(ec); | 332 cursor->continueFunction(ec); |
| 338 ASSERT(!ec); | 333 ASSERT(!ec); |
| 339 | 334 |
| 340 RefPtr<IDBKey> primaryKey = cursor->primaryKey(); | 335 RefPtr<IDBKey> primaryKey = cursor->primaryKey(); |
| 341 RefPtr<IDBAny> valueAny = cursor->value(); | 336 RefPtr<IDBAny> valueAny = cursor->value(); |
| 342 | 337 |
| 343 ASSERT(valueAny->type() == IDBAny::SerializedScriptValueType); | 338 ASSERT(valueAny->type() == IDBAny::SerializedScriptValueType); |
| 344 RefPtr<SerializedScriptValue> serializedValue = valueAny->serialized
ScriptValue(); | 339 RefPtr<SerializedScriptValue> value = valueAny->serializedScriptValu
e(); |
| 345 ScriptValue value(deserializeIDBValue(context, serializedValue)); | |
| 346 | 340 |
| 347 IDBObjectStore::IndexKeys indexKeys; | 341 IDBObjectStore::IndexKeys indexKeys; |
| 348 generateIndexKeysForValue(m_indexMetadata, value, &indexKeys); | 342 generateIndexKeysForValue(m_indexMetadata, value, &indexKeys); |
| 349 | 343 |
| 350 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList; | 344 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList; |
| 351 indexKeysList.append(indexKeys); | 345 indexKeysList.append(indexKeys); |
| 352 | 346 |
| 353 m_objectStoreBackend->setIndexKeys(primaryKey, indexNames, indexKeys
List, m_transaction.get()); | 347 m_objectStoreBackend->setIndexKeys(primaryKey, indexNames, indexKeys
List, m_transaction.get()); |
| 354 | 348 |
| 355 } else { | 349 } else { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 ASSERT(m_transaction->isFinished()); | 580 ASSERT(m_transaction->isFinished()); |
| 587 | 581 |
| 588 // Break reference cycles. | 582 // Break reference cycles. |
| 589 m_indexMap.clear(); | 583 m_indexMap.clear(); |
| 590 } | 584 } |
| 591 | 585 |
| 592 | 586 |
| 593 } // namespace WebCore | 587 } // namespace WebCore |
| 594 | 588 |
| 595 #endif // ENABLE(INDEXED_DATABASE) | 589 #endif // ENABLE(INDEXED_DATABASE) |
| OLD | NEW |