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 23 matching lines...) Expand all Loading... |
34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
35 #include "core/dom/ExecutionContext.h" | 35 #include "core/dom/ExecutionContext.h" |
36 #include "modules/indexeddb/IDBAny.h" | 36 #include "modules/indexeddb/IDBAny.h" |
37 #include "modules/indexeddb/IDBCursorWithValue.h" | 37 #include "modules/indexeddb/IDBCursorWithValue.h" |
38 #include "modules/indexeddb/IDBDatabase.h" | 38 #include "modules/indexeddb/IDBDatabase.h" |
39 #include "modules/indexeddb/IDBKeyPath.h" | 39 #include "modules/indexeddb/IDBKeyPath.h" |
40 #include "modules/indexeddb/IDBTracing.h" | 40 #include "modules/indexeddb/IDBTracing.h" |
41 #include "modules/indexeddb/IDBTransaction.h" | 41 #include "modules/indexeddb/IDBTransaction.h" |
42 #include "modules/indexeddb/WebIDBCallbacksImpl.h" | 42 #include "modules/indexeddb/WebIDBCallbacksImpl.h" |
43 #include "platform/SharedBuffer.h" | 43 #include "platform/SharedBuffer.h" |
| 44 #include "platform/blob/BlobInfo.h" |
| 45 #include "public/platform/WebBlobInfo.h" |
44 #include "public/platform/WebData.h" | 46 #include "public/platform/WebData.h" |
45 #include "public/platform/WebIDBKey.h" | 47 #include "public/platform/WebIDBKey.h" |
46 #include "public/platform/WebIDBKeyRange.h" | 48 #include "public/platform/WebIDBKeyRange.h" |
| 49 #include "public/platform/WebVector.h" |
47 | 50 |
| 51 using blink::WebBlobInfo; |
48 using blink::WebIDBDatabase; | 52 using blink::WebIDBDatabase; |
49 using blink::WebIDBCallbacks; | 53 using blink::WebIDBCallbacks; |
| 54 using blink::WebVector; |
50 | 55 |
51 namespace WebCore { | 56 namespace WebCore { |
52 | 57 |
53 IDBObjectStore::IDBObjectStore(const IDBObjectStoreMetadata& metadata, IDBTransa
ction* transaction) | 58 IDBObjectStore::IDBObjectStore(const IDBObjectStoreMetadata& metadata, IDBTransa
ction* transaction) |
54 : m_metadata(metadata) | 59 : m_metadata(metadata) |
55 , m_transaction(transaction) | 60 , m_transaction(transaction) |
56 , m_deleted(false) | 61 , m_deleted(false) |
57 { | 62 { |
58 ASSERT(m_transaction); | 63 ASSERT(m_transaction); |
59 // We pass a reference to this object before it can be adopted. | 64 // We pass a reference to this object before it can be adopted. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 162 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
158 return 0; | 163 return 0; |
159 } | 164 } |
160 if (m_transaction->isReadOnly()) { | 165 if (m_transaction->isReadOnly()) { |
161 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError); | 166 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError); |
162 return 0; | 167 return 0; |
163 } | 168 } |
164 | 169 |
165 // FIXME: Make SerializedScriptValue::create etc take an ExceptionState or u
se ScriptState::setDOMException. | 170 // FIXME: Make SerializedScriptValue::create etc take an ExceptionState or u
se ScriptState::setDOMException. |
166 bool didThrow = false; | 171 bool didThrow = false; |
167 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat
e(value, didThrow, state); | 172 Vector<BlobInfo> blobInfo; |
| 173 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat
e(value, &blobInfo, didThrow, state); |
168 if (didThrow) | 174 if (didThrow) |
169 return 0; | 175 return 0; |
170 | 176 |
171 if (serializedValue->containsBlobs()) { | |
172 // FIXME: Add Blob/File/FileList support | |
173 exceptionState.throwUninformativeAndGenericDOMException(DataCloneError); | |
174 return 0; | |
175 } | |
176 | |
177 const IDBKeyPath& keyPath = m_metadata.keyPath; | 177 const IDBKeyPath& keyPath = m_metadata.keyPath; |
178 const bool usesInLineKeys = !keyPath.isNull(); | 178 const bool usesInLineKeys = !keyPath.isNull(); |
179 const bool hasKeyGenerator = autoIncrement(); | 179 const bool hasKeyGenerator = autoIncrement(); |
180 | 180 |
181 ExecutionContext* context = state->executionContext(); | 181 ExecutionContext* context = state->executionContext(); |
182 DOMRequestState requestState(context); | 182 DOMRequestState requestState(context); |
183 | 183 |
184 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { | 184 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { |
185 exceptionState.throwDOMException(DataError, "The object store uses in-li
ne keys and the key parameter was provided."); | 185 exceptionState.throwDOMException(DataError, "The object store uses in-li
ne keys and the key parameter was provided."); |
186 return 0; | 186 return 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 IndexKeys keys; | 219 IndexKeys keys; |
220 generateIndexKeysForValue(&requestState, it->value, value, &keys); | 220 generateIndexKeysForValue(&requestState, it->value, value, &keys); |
221 indexIds.append(it->key); | 221 indexIds.append(it->key); |
222 indexKeys.append(keys); | 222 indexKeys.append(keys); |
223 } | 223 } |
224 | 224 |
225 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti
on.get()); | 225 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti
on.get()); |
226 Vector<char> wireBytes; | 226 Vector<char> wireBytes; |
227 serializedValue->toWireBytes(wireBytes); | 227 serializedValue->toWireBytes(wireBytes); |
228 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 228 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
229 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), key
.release(), static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl::
create(request).leakPtr(), indexIds, indexKeys); | 229 |
| 230 WebVector<WebBlobInfo> webBlobInfo(blobInfo.size()); |
| 231 for (size_t i = 0; i < blobInfo.size(); ++i) { |
| 232 const WebCore::BlobInfo& info = blobInfo[i]; |
| 233 if (info.isFile()) |
| 234 webBlobInfo[i] = WebBlobInfo(info.uuid(), info.filePath(), info.file
Name(), info.type()); |
| 235 else |
| 236 webBlobInfo[i] = WebBlobInfo(info.uuid(), info.type(), info.size()); |
| 237 } |
| 238 |
| 239 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), web
BlobInfo, key.release(), static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCa
llbacksImpl::create(request).leakPtr(), indexIds, indexKeys); |
230 return request.release(); | 240 return request.release(); |
231 } | 241 } |
232 | 242 |
233 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context,
const ScriptValue& key, ExceptionState& exceptionState) | 243 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context,
const ScriptValue& key, ExceptionState& exceptionState) |
234 { | 244 { |
235 IDB_TRACE("IDBObjectStore::delete"); | 245 IDB_TRACE("IDBObjectStore::delete"); |
236 if (isDeleted()) { | 246 if (isDeleted()) { |
237 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 247 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
238 return 0; | 248 return 0; |
239 } | 249 } |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 624 } |
615 return IDBIndexMetadata::InvalidId; | 625 return IDBIndexMetadata::InvalidId; |
616 } | 626 } |
617 | 627 |
618 WebIDBDatabase* IDBObjectStore::backendDB() const | 628 WebIDBDatabase* IDBObjectStore::backendDB() const |
619 { | 629 { |
620 return m_transaction->backendDB(); | 630 return m_transaction->backendDB(); |
621 } | 631 } |
622 | 632 |
623 } // namespace WebCore | 633 } // namespace WebCore |
OLD | NEW |