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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 PassRefPtrWillBeRawPtr<DOMStringList> IDBObjectStore::indexNames() const | 77 PassRefPtrWillBeRawPtr<DOMStringList> IDBObjectStore::indexNames() const |
78 { | 78 { |
79 IDB_TRACE("IDBObjectStore::indexNames"); | 79 IDB_TRACE("IDBObjectStore::indexNames"); |
80 RefPtrWillBeRawPtr<DOMStringList> indexNames = DOMStringList::create(); | 80 RefPtrWillBeRawPtr<DOMStringList> indexNames = DOMStringList::create(); |
81 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) | 81 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) |
82 indexNames->append(it->value.name); | 82 indexNames->append(it->value.name); |
83 indexNames->sort(); | 83 indexNames->sort(); |
84 return indexNames.release(); | 84 return indexNames.release(); |
85 } | 85 } |
86 | 86 |
87 IDBRequest* IDBObjectStore::get(ExecutionContext* context, const ScriptValue& ke
y, ExceptionState& exceptionState) | 87 IDBRequest* IDBObjectStore::get(ScriptState* scriptState, const ScriptValue& key
, ExceptionState& exceptionState) |
88 { | 88 { |
89 IDB_TRACE("IDBObjectStore::get"); | 89 IDB_TRACE("IDBObjectStore::get"); |
90 if (isDeleted()) { | 90 if (isDeleted()) { |
91 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 91 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
92 return 0; | 92 return 0; |
93 } | 93 } |
94 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 94 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
95 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 95 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
96 return 0; | 96 return 0; |
97 } | 97 } |
98 if (!m_transaction->isActive()) { | 98 if (!m_transaction->isActive()) { |
99 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 99 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
100 return 0; | 100 return 0; |
101 } | 101 } |
102 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(context, key, exception
State); | 102 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), key, exceptionState); |
103 if (exceptionState.hadException()) | 103 if (exceptionState.hadException()) |
104 return 0; | 104 return 0; |
105 if (!keyRange) { | 105 if (!keyRange) { |
106 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 106 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
107 return 0; | 107 return 0; |
108 } | 108 } |
109 if (!backendDB()) { | 109 if (!backendDB()) { |
110 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 110 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
111 return 0; | 111 return 0; |
112 } | 112 } |
113 | 113 |
114 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); | 114 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
115 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key
Range, false, WebIDBCallbacksImpl::create(request).leakPtr()); | 115 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key
Range, false, WebIDBCallbacksImpl::create(request).leakPtr()); |
116 return request; | 116 return request; |
117 } | 117 } |
118 | 118 |
119 static void generateIndexKeysForValue(v8::Isolate* isolate, const IDBIndexMetada
ta& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::IndexKeys* in
dexKeys) | 119 static void generateIndexKeysForValue(v8::Isolate* isolate, const IDBIndexMetada
ta& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::IndexKeys* in
dexKeys) |
120 { | 120 { |
121 ASSERT(indexKeys); | 121 ASSERT(indexKeys); |
122 IDBKey* indexKey = createIDBKeyFromScriptValueAndKeyPath(isolate, objectValu
e, indexMetadata.keyPath); | 122 IDBKey* indexKey = createIDBKeyFromScriptValueAndKeyPath(isolate, objectValu
e, indexMetadata.keyPath); |
123 | 123 |
124 if (!indexKey) | 124 if (!indexKey) |
125 return; | 125 return; |
126 | 126 |
127 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) { | 127 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) { |
128 if (!indexKey->isValid()) | 128 if (!indexKey->isValid()) |
129 return; | 129 return; |
130 | 130 |
131 indexKeys->append(indexKey); | 131 indexKeys->append(indexKey); |
132 } else { | 132 } else { |
133 ASSERT(indexMetadata.multiEntry); | 133 ASSERT(indexMetadata.multiEntry); |
134 ASSERT(indexKey->type() == IDBKey::ArrayType); | 134 ASSERT(indexKey->type() == IDBKey::ArrayType); |
135 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); | 135 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); |
136 | 136 |
137 for (size_t i = 0; i < indexKey->array().size(); ++i) | 137 for (size_t i = 0; i < indexKey->array().size(); ++i) |
138 indexKeys->append(indexKey->array()[i]); | 138 indexKeys->append(indexKey->array()[i]); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 IDBRequest* IDBObjectStore::add(ExecutionContext* executionContext, ScriptValue&
value, const ScriptValue& key, ExceptionState& exceptionState) | 142 IDBRequest* IDBObjectStore::add(ScriptState* scriptState, ScriptValue& value, co
nst ScriptValue& key, ExceptionState& exceptionState) |
143 { | 143 { |
144 IDB_TRACE("IDBObjectStore::add"); | 144 IDB_TRACE("IDBObjectStore::add"); |
145 return put(executionContext, WebIDBDatabase::AddOnly, IDBAny::create(this),
value, key, exceptionState); | 145 return put(scriptState, WebIDBDatabase::AddOnly, IDBAny::create(this), value
, key, exceptionState); |
146 } | 146 } |
147 | 147 |
148 IDBRequest* IDBObjectStore::put(ExecutionContext* executionContext, ScriptValue&
value, const ScriptValue& key, ExceptionState& exceptionState) | 148 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, ScriptValue& value, co
nst ScriptValue& key, ExceptionState& exceptionState) |
149 { | 149 { |
150 IDB_TRACE("IDBObjectStore::put"); | 150 IDB_TRACE("IDBObjectStore::put"); |
151 return put(executionContext, WebIDBDatabase::AddOrUpdate, IDBAny::create(thi
s), value, key, exceptionState); | 151 return put(scriptState, WebIDBDatabase::AddOrUpdate, IDBAny::create(this), v
alue, key, exceptionState); |
152 } | 152 } |
153 | 153 |
154 IDBRequest* IDBObjectStore::put(ExecutionContext* executionContext, WebIDBDataba
se::PutMode putMode, IDBAny* source, ScriptValue& value, const ScriptValue& keyV
alue, ExceptionState& exceptionState) | 154 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, WebIDBDatabase::PutMod
e putMode, IDBAny* source, ScriptValue& value, const ScriptValue& keyValue, Exce
ptionState& exceptionState) |
155 { | 155 { |
156 IDBKey* key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(toIsolate(exe
cutionContext), keyValue); | 156 IDBKey* key = keyValue.isUndefined() ? nullptr : scriptValueToIDBKey(scriptS
tate->isolate(), keyValue); |
157 return put(executionContext, putMode, source, value, key, exceptionState); | 157 return put(scriptState, putMode, source, value, key, exceptionState); |
158 } | 158 } |
159 | 159 |
160 IDBRequest* IDBObjectStore::put(ExecutionContext* executionContext, WebIDBDataba
se::PutMode putMode, IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionS
tate& exceptionState) | 160 IDBRequest* IDBObjectStore::put(ScriptState* scriptState, WebIDBDatabase::PutMod
e putMode, IDBAny* source, ScriptValue& value, IDBKey* key, ExceptionState& exce
ptionState) |
161 { | 161 { |
162 if (isDeleted()) { | 162 if (isDeleted()) { |
163 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 163 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
164 return 0; | 164 return 0; |
165 } | 165 } |
166 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 166 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
167 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 167 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
168 return 0; | 168 return 0; |
169 } | 169 } |
170 if (!m_transaction->isActive()) { | 170 if (!m_transaction->isActive()) { |
171 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 171 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
172 return 0; | 172 return 0; |
173 } | 173 } |
174 if (m_transaction->isReadOnly()) { | 174 if (m_transaction->isReadOnly()) { |
175 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction
ReadOnlyErrorMessage); | 175 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction
ReadOnlyErrorMessage); |
176 return 0; | 176 return 0; |
177 } | 177 } |
178 | 178 |
179 Vector<WebBlobInfo> blobInfo; | 179 Vector<WebBlobInfo> blobInfo; |
180 | 180 |
181 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat
e(value, &blobInfo, exceptionState, toIsolate(executionContext)); | 181 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat
e(value, &blobInfo, exceptionState, scriptState->isolate()); |
182 if (exceptionState.hadException()) | 182 if (exceptionState.hadException()) |
183 return 0; | 183 return 0; |
184 | 184 |
185 if (serializedValue->containsBlobs()) { | 185 if (serializedValue->containsBlobs()) { |
186 // FIXME: Add Blob/File/FileList support | 186 // FIXME: Add Blob/File/FileList support |
187 exceptionState.throwDOMException(DataCloneError, "The object store curre
ntly does not support blob values."); | 187 exceptionState.throwDOMException(DataCloneError, "The object store curre
ntly does not support blob values."); |
188 return 0; | 188 return 0; |
189 } | 189 } |
190 ASSERT(blobInfo.isEmpty()); | 190 ASSERT(blobInfo.isEmpty()); |
191 | 191 |
192 const IDBKeyPath& keyPath = m_metadata.keyPath; | 192 const IDBKeyPath& keyPath = m_metadata.keyPath; |
193 const bool usesInLineKeys = !keyPath.isNull(); | 193 const bool usesInLineKeys = !keyPath.isNull(); |
194 const bool hasKeyGenerator = autoIncrement(); | 194 const bool hasKeyGenerator = autoIncrement(); |
195 | 195 |
196 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { | 196 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) { |
197 exceptionState.throwDOMException(DataError, "The object store uses in-li
ne keys and the key parameter was provided."); | 197 exceptionState.throwDOMException(DataError, "The object store uses in-li
ne keys and the key parameter was provided."); |
198 return 0; | 198 return 0; |
199 } | 199 } |
200 if (!usesInLineKeys && !hasKeyGenerator && !key) { | 200 if (!usesInLineKeys && !hasKeyGenerator && !key) { |
201 exceptionState.throwDOMException(DataError, "The object store uses out-o
f-line keys and has no key generator and the key parameter was not provided."); | 201 exceptionState.throwDOMException(DataError, "The object store uses out-o
f-line keys and has no key generator and the key parameter was not provided."); |
202 return 0; | 202 return 0; |
203 } | 203 } |
204 if (usesInLineKeys) { | 204 if (usesInLineKeys) { |
205 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(toIsolate(exe
cutionContext), value, keyPath); | 205 IDBKey* keyPathKey = createIDBKeyFromScriptValueAndKeyPath(scriptState->
isolate(), value, keyPath); |
206 if (keyPathKey && !keyPathKey->isValid()) { | 206 if (keyPathKey && !keyPathKey->isValid()) { |
207 exceptionState.throwDOMException(DataError, "Evaluating the object s
tore's key path yielded a value that is not a valid key."); | 207 exceptionState.throwDOMException(DataError, "Evaluating the object s
tore's key path yielded a value that is not a valid key."); |
208 return 0; | 208 return 0; |
209 } | 209 } |
210 if (!hasKeyGenerator && !keyPathKey) { | 210 if (!hasKeyGenerator && !keyPathKey) { |
211 exceptionState.throwDOMException(DataError, "Evaluating the object s
tore's key path did not yield a value."); | 211 exceptionState.throwDOMException(DataError, "Evaluating the object s
tore's key path did not yield a value."); |
212 return 0; | 212 return 0; |
213 } | 213 } |
214 if (hasKeyGenerator && !keyPathKey) { | 214 if (hasKeyGenerator && !keyPathKey) { |
215 if (!canInjectIDBKeyIntoScriptValue(toIsolate(executionContext), val
ue, keyPath)) { | 215 if (!canInjectIDBKeyIntoScriptValue(scriptState->isolate(), value, k
eyPath)) { |
216 exceptionState.throwDOMException(DataError, "A generated key cou
ld not be inserted into the value."); | 216 exceptionState.throwDOMException(DataError, "A generated key cou
ld not be inserted into the value."); |
217 return 0; | 217 return 0; |
218 } | 218 } |
219 } | 219 } |
220 if (keyPathKey) | 220 if (keyPathKey) |
221 key = keyPathKey; | 221 key = keyPathKey; |
222 } | 222 } |
223 if (key && !key->isValid()) { | 223 if (key && !key->isValid()) { |
224 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 224 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
225 return 0; | 225 return 0; |
226 } | 226 } |
227 | 227 |
228 if (!backendDB()) { | 228 if (!backendDB()) { |
229 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 229 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
230 return 0; | 230 return 0; |
231 } | 231 } |
232 | 232 |
233 Vector<int64_t> indexIds; | 233 Vector<int64_t> indexIds; |
234 HeapVector<IndexKeys> indexKeys; | 234 HeapVector<IndexKeys> indexKeys; |
235 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 235 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { |
236 IndexKeys keys; | 236 IndexKeys keys; |
237 generateIndexKeysForValue(toIsolate(executionContext), it->value, value,
&keys); | 237 generateIndexKeysForValue(scriptState->isolate(), it->value, value, &key
s); |
238 indexIds.append(it->key); | 238 indexIds.append(it->key); |
239 indexKeys.append(keys); | 239 indexKeys.append(keys); |
240 } | 240 } |
241 | 241 |
242 IDBRequest* request = IDBRequest::create(executionContext, source, m_transac
tion.get()); | 242 IDBRequest* request = IDBRequest::create(scriptState, source, m_transaction.
get()); |
243 Vector<char> wireBytes; | 243 Vector<char> wireBytes; |
244 serializedValue->toWireBytes(wireBytes); | 244 serializedValue->toWireBytes(wireBytes); |
245 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); | 245 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); |
246 | 246 |
247 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo
bInfo, key, static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl::
create(request).leakPtr(), indexIds, indexKeys); | 247 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), blo
bInfo, key, static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl::
create(request).leakPtr(), indexIds, indexKeys); |
248 return request; | 248 return request; |
249 } | 249 } |
250 | 250 |
251 IDBRequest* IDBObjectStore::deleteFunction(ExecutionContext* context, const Scri
ptValue& key, ExceptionState& exceptionState) | 251 IDBRequest* IDBObjectStore::deleteFunction(ScriptState* scriptState, const Scrip
tValue& key, ExceptionState& exceptionState) |
252 { | 252 { |
253 IDB_TRACE("IDBObjectStore::delete"); | 253 IDB_TRACE("IDBObjectStore::delete"); |
254 if (isDeleted()) { | 254 if (isDeleted()) { |
255 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 255 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
256 return 0; | 256 return 0; |
257 } | 257 } |
258 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 258 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
259 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 259 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
260 return 0; | 260 return 0; |
261 } | 261 } |
262 if (!m_transaction->isActive()) { | 262 if (!m_transaction->isActive()) { |
263 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 263 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
264 return 0; | 264 return 0; |
265 } | 265 } |
266 if (m_transaction->isReadOnly()) { | 266 if (m_transaction->isReadOnly()) { |
267 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction
ReadOnlyErrorMessage); | 267 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction
ReadOnlyErrorMessage); |
268 return 0; | 268 return 0; |
269 } | 269 } |
270 | 270 |
271 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(context, key, exception
State); | 271 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), key, exceptionState); |
272 if (exceptionState.hadException()) | 272 if (exceptionState.hadException()) |
273 return 0; | 273 return 0; |
274 if (!keyRange) { | 274 if (!keyRange) { |
275 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); | 275 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange
ErrorMessage); |
276 return 0; | 276 return 0; |
277 } | 277 } |
278 if (!backendDB()) { | 278 if (!backendDB()) { |
279 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 279 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
280 return 0; | 280 return 0; |
281 } | 281 } |
282 | 282 |
283 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); | 283 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
284 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, WebIDBCallback
sImpl::create(request).leakPtr()); | 284 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, WebIDBCallback
sImpl::create(request).leakPtr()); |
285 return request; | 285 return request; |
286 } | 286 } |
287 | 287 |
288 IDBRequest* IDBObjectStore::clear(ExecutionContext* context, ExceptionState& exc
eptionState) | 288 IDBRequest* IDBObjectStore::clear(ScriptState* scriptState, ExceptionState& exce
ptionState) |
289 { | 289 { |
290 IDB_TRACE("IDBObjectStore::clear"); | 290 IDB_TRACE("IDBObjectStore::clear"); |
291 if (isDeleted()) { | 291 if (isDeleted()) { |
292 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 292 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
293 return 0; | 293 return 0; |
294 } | 294 } |
295 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 295 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
296 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 296 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
297 return 0; | 297 return 0; |
298 } | 298 } |
299 if (!m_transaction->isActive()) { | 299 if (!m_transaction->isActive()) { |
300 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 300 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
301 return 0; | 301 return 0; |
302 } | 302 } |
303 if (m_transaction->isReadOnly()) { | 303 if (m_transaction->isReadOnly()) { |
304 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction
ReadOnlyErrorMessage); | 304 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transaction
ReadOnlyErrorMessage); |
305 return 0; | 305 return 0; |
306 } | 306 } |
307 if (!backendDB()) { | 307 if (!backendDB()) { |
308 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 308 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
309 return 0; | 309 return 0; |
310 } | 310 } |
311 | 311 |
312 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); | 312 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
313 backendDB()->clear(m_transaction->id(), id(), WebIDBCallbacksImpl::create(re
quest).leakPtr()); | 313 backendDB()->clear(m_transaction->id(), id(), WebIDBCallbacksImpl::create(re
quest).leakPtr()); |
314 return request; | 314 return request; |
315 } | 315 } |
316 | 316 |
317 namespace { | 317 namespace { |
318 // This class creates the index keys for a given index by extracting | 318 // This class creates the index keys for a given index by extracting |
319 // them from the SerializedScriptValue, for all the existing values in | 319 // them from the SerializedScriptValue, for all the existing values in |
320 // the objectStore. It only needs to be kept alive by virtue of being | 320 // the objectStore. It only needs to be kept alive by virtue of being |
321 // a listener on an IDBRequest object, in the same way that JavaScript | 321 // a listener on an IDBRequest object, in the same way that JavaScript |
322 // cursor success handlers are kept alive. | 322 // cursor success handlers are kept alive. |
(...skipping 13 matching lines...) Expand all Loading... |
336 IndexPopulator(ScriptState* scriptState, IDBDatabase* database, int64_t tran
sactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata) | 336 IndexPopulator(ScriptState* scriptState, IDBDatabase* database, int64_t tran
sactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata) |
337 : EventListener(CPPEventListenerType) | 337 : EventListener(CPPEventListenerType) |
338 , m_scriptState(scriptState) | 338 , m_scriptState(scriptState) |
339 , m_database(database) | 339 , m_database(database) |
340 , m_transactionId(transactionId) | 340 , m_transactionId(transactionId) |
341 , m_objectStoreId(objectStoreId) | 341 , m_objectStoreId(objectStoreId) |
342 , m_indexMetadata(indexMetadata) | 342 , m_indexMetadata(indexMetadata) |
343 { | 343 { |
344 } | 344 } |
345 | 345 |
346 virtual void handleEvent(ExecutionContext* context, Event* event) OVERRIDE | 346 virtual void handleEvent(ExecutionContext* executionContext, Event* event) O
VERRIDE |
347 { | 347 { |
| 348 ASSERT(m_scriptState->executionContext() == executionContext); |
348 ASSERT(event->type() == EventTypeNames::success); | 349 ASSERT(event->type() == EventTypeNames::success); |
349 EventTarget* target = event->target(); | 350 EventTarget* target = event->target(); |
350 IDBRequest* request = static_cast<IDBRequest*>(target); | 351 IDBRequest* request = static_cast<IDBRequest*>(target); |
351 | 352 |
352 if (!m_database->backend()) // If database is stopped? | 353 if (!m_database->backend()) // If database is stopped? |
353 return; | 354 return; |
354 | 355 |
355 IDBAny* cursorAny = request->resultAsAny(); | 356 IDBAny* cursorAny = request->resultAsAny(); |
356 IDBCursorWithValue* cursor = 0; | 357 IDBCursorWithValue* cursor = 0; |
357 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) | 358 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) |
358 cursor = cursorAny->idbCursorWithValue(); | 359 cursor = cursorAny->idbCursorWithValue(); |
359 | 360 |
360 Vector<int64_t> indexIds; | 361 Vector<int64_t> indexIds; |
361 indexIds.append(m_indexMetadata.id); | 362 indexIds.append(m_indexMetadata.id); |
362 if (cursor && !cursor->isDeleted()) { | 363 if (cursor && !cursor->isDeleted()) { |
363 cursor->continueFunction(static_cast<IDBKey*>(0), static_cast<IDBKey
*>(0), ASSERT_NO_EXCEPTION); | 364 cursor->continueFunction(static_cast<IDBKey*>(0), static_cast<IDBKey
*>(0), ASSERT_NO_EXCEPTION); |
364 | 365 |
365 IDBKey* primaryKey = cursor->idbPrimaryKey(); | 366 IDBKey* primaryKey = cursor->idbPrimaryKey(); |
366 ScriptValue value = cursor->value(m_scriptState.get()); | 367 ScriptValue value = cursor->value(m_scriptState.get()); |
367 | 368 |
368 IDBObjectStore::IndexKeys indexKeys; | 369 IDBObjectStore::IndexKeys indexKeys; |
369 generateIndexKeysForValue(toIsolate(context), m_indexMetadata, value
, &indexKeys); | 370 generateIndexKeysForValue(m_scriptState->isolate(), m_indexMetadata,
value, &indexKeys); |
370 | 371 |
371 HeapVector<IDBObjectStore::IndexKeys> indexKeysList; | 372 HeapVector<IDBObjectStore::IndexKeys> indexKeysList; |
372 indexKeysList.append(indexKeys); | 373 indexKeysList.append(indexKeys); |
373 | 374 |
374 m_database->backend()->setIndexKeys(m_transactionId, m_objectStoreId
, primaryKey, indexIds, indexKeysList); | 375 m_database->backend()->setIndexKeys(m_transactionId, m_objectStoreId
, primaryKey, indexIds, indexKeysList); |
375 } else { | 376 } else { |
376 // Now that we are done indexing, tell the backend to go | 377 // Now that we are done indexing, tell the backend to go |
377 // back to processing tasks of type NormalTask. | 378 // back to processing tasks of type NormalTask. |
378 m_database->backend()->setIndexesReady(m_transactionId, m_objectStor
eId, indexIds); | 379 m_database->backend()->setIndexesReady(m_transactionId, m_objectStor
eId, indexIds); |
379 m_database.clear(); | 380 m_database.clear(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); | 450 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); |
450 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get()); | 451 IDBIndex* index = IDBIndex::create(metadata, this, m_transaction.get()); |
451 m_indexMap.set(name, index); | 452 m_indexMap.set(name, index); |
452 m_metadata.indexes.set(indexId, metadata); | 453 m_metadata.indexes.set(indexId, metadata); |
453 m_transaction->db()->indexCreated(id(), metadata); | 454 m_transaction->db()->indexCreated(id(), metadata); |
454 | 455 |
455 ASSERT(!exceptionState.hadException()); | 456 ASSERT(!exceptionState.hadException()); |
456 if (exceptionState.hadException()) | 457 if (exceptionState.hadException()) |
457 return 0; | 458 return 0; |
458 | 459 |
459 IDBRequest* indexRequest = openCursor(scriptState->executionContext(), stati
c_cast<IDBKeyRange*>(0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTa
sk); | 460 IDBRequest* indexRequest = openCursor(scriptState, static_cast<IDBKeyRange*>
(0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask); |
460 indexRequest->preventPropagation(); | 461 indexRequest->preventPropagation(); |
461 | 462 |
462 // This is kept alive by being the success handler of the request, which is
in turn kept alive by the owning transaction. | 463 // This is kept alive by being the success handler of the request, which is
in turn kept alive by the owning transaction. |
463 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState,
transaction()->db(), m_transaction->id(), id(), metadata); | 464 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(scriptState,
transaction()->db(), m_transaction->id(), id(), metadata); |
464 indexRequest->setOnsuccess(indexPopulator); | 465 indexRequest->setOnsuccess(indexPopulator); |
465 return index; | 466 return index; |
466 } | 467 } |
467 | 468 |
468 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta
te) | 469 IDBIndex* IDBObjectStore::index(const String& name, ExceptionState& exceptionSta
te) |
469 { | 470 { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 536 |
536 m_metadata.indexes.remove(indexId); | 537 m_metadata.indexes.remove(indexId); |
537 m_transaction->db()->indexDeleted(id(), indexId); | 538 m_transaction->db()->indexDeleted(id(), indexId); |
538 IDBIndexMap::iterator it = m_indexMap.find(name); | 539 IDBIndexMap::iterator it = m_indexMap.find(name); |
539 if (it != m_indexMap.end()) { | 540 if (it != m_indexMap.end()) { |
540 it->value->markDeleted(); | 541 it->value->markDeleted(); |
541 m_indexMap.remove(name); | 542 m_indexMap.remove(name); |
542 } | 543 } |
543 } | 544 } |
544 | 545 |
545 IDBRequest* IDBObjectStore::openCursor(ExecutionContext* context, const ScriptVa
lue& range, const String& directionString, ExceptionState& exceptionState) | 546 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, const ScriptVal
ue& range, const String& directionString, ExceptionState& exceptionState) |
546 { | 547 { |
547 IDB_TRACE("IDBObjectStore::openCursor"); | 548 IDB_TRACE("IDBObjectStore::openCursor"); |
548 if (isDeleted()) { | 549 if (isDeleted()) { |
549 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 550 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
550 return 0; | 551 return 0; |
551 } | 552 } |
552 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 553 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
553 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 554 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
554 return 0; | 555 return 0; |
555 } | 556 } |
556 if (!m_transaction->isActive()) { | 557 if (!m_transaction->isActive()) { |
557 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 558 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
558 return 0; | 559 return 0; |
559 } | 560 } |
560 | 561 |
561 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); | 562 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); |
562 if (exceptionState.hadException()) | 563 if (exceptionState.hadException()) |
563 return 0; | 564 return 0; |
564 | 565 |
565 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(context, range, excepti
onState); | 566 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); |
566 if (exceptionState.hadException()) | 567 if (exceptionState.hadException()) |
567 return 0; | 568 return 0; |
568 | 569 |
569 if (!backendDB()) { | 570 if (!backendDB()) { |
570 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 571 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
571 return 0; | 572 return 0; |
572 } | 573 } |
573 | 574 |
574 return openCursor(context, keyRange, direction, WebIDBDatabase::NormalTask); | 575 return openCursor(scriptState, keyRange, direction, WebIDBDatabase::NormalTa
sk); |
575 } | 576 } |
576 | 577 |
577 IDBRequest* IDBObjectStore::openCursor(ExecutionContext* context, IDBKeyRange* r
ange, WebIDBCursor::Direction direction, WebIDBDatabase::TaskType taskType) | 578 IDBRequest* IDBObjectStore::openCursor(ScriptState* scriptState, IDBKeyRange* ra
nge, WebIDBCursor::Direction direction, WebIDBDatabase::TaskType taskType) |
578 { | 579 { |
579 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); | 580 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
580 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 581 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
581 | 582 |
582 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak
Ptr()); | 583 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leak
Ptr()); |
583 return request; | 584 return request; |
584 } | 585 } |
585 | 586 |
586 IDBRequest* IDBObjectStore::openKeyCursor(ExecutionContext* context, const Scrip
tValue& range, const String& directionString, ExceptionState& exceptionState) | 587 IDBRequest* IDBObjectStore::openKeyCursor(ScriptState* scriptState, const Script
Value& range, const String& directionString, ExceptionState& exceptionState) |
587 { | 588 { |
588 IDB_TRACE("IDBObjectStore::openKeyCursor"); | 589 IDB_TRACE("IDBObjectStore::openKeyCursor"); |
589 if (isDeleted()) { | 590 if (isDeleted()) { |
590 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 591 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
591 return 0; | 592 return 0; |
592 } | 593 } |
593 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 594 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
594 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 595 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
595 return 0; | 596 return 0; |
596 } | 597 } |
597 if (!m_transaction->isActive()) { | 598 if (!m_transaction->isActive()) { |
598 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 599 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
599 return 0; | 600 return 0; |
600 } | 601 } |
601 | 602 |
602 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); | 603 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionSt
ring, exceptionState); |
603 if (exceptionState.hadException()) | 604 if (exceptionState.hadException()) |
604 return 0; | 605 return 0; |
605 | 606 |
606 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(context, range, excepti
onState); | 607 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); |
607 if (exceptionState.hadException()) | 608 if (exceptionState.hadException()) |
608 return 0; | 609 return 0; |
609 | 610 |
610 if (!backendDB()) { | 611 if (!backendDB()) { |
611 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 612 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
612 return 0; | 613 return 0; |
613 } | 614 } |
614 | 615 |
615 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); | 616 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
616 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 617 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
617 | 618 |
618 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, keyRange, direction, true, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl::
create(request).leakPtr()); | 619 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid
Id, keyRange, direction, true, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl::
create(request).leakPtr()); |
619 return request; | 620 return request; |
620 } | 621 } |
621 | 622 |
622 IDBRequest* IDBObjectStore::count(ExecutionContext* context, const ScriptValue&
range, ExceptionState& exceptionState) | 623 IDBRequest* IDBObjectStore::count(ScriptState* scriptState, const ScriptValue& r
ange, ExceptionState& exceptionState) |
623 { | 624 { |
624 IDB_TRACE("IDBObjectStore::count"); | 625 IDB_TRACE("IDBObjectStore::count"); |
625 if (isDeleted()) { | 626 if (isDeleted()) { |
626 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); | 627 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS
toreDeletedErrorMessage); |
627 return 0; | 628 return 0; |
628 } | 629 } |
629 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 630 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
630 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 631 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
631 return 0; | 632 return 0; |
632 } | 633 } |
633 if (!m_transaction->isActive()) { | 634 if (!m_transaction->isActive()) { |
634 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 635 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
635 return 0; | 636 return 0; |
636 } | 637 } |
637 | 638 |
638 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(context, range, excepti
onState); | 639 IDBKeyRange* keyRange = IDBKeyRange::fromScriptValue(scriptState->executionC
ontext(), range, exceptionState); |
639 if (exceptionState.hadException()) | 640 if (exceptionState.hadException()) |
640 return 0; | 641 return 0; |
641 | 642 |
642 if (!backendDB()) { | 643 if (!backendDB()) { |
643 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 644 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
644 return 0; | 645 return 0; |
645 } | 646 } |
646 | 647 |
647 IDBRequest* request = IDBRequest::create(context, IDBAny::create(this), m_tr
ansaction.get()); | 648 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
648 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k
eyRange, WebIDBCallbacksImpl::create(request).leakPtr()); | 649 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k
eyRange, WebIDBCallbacksImpl::create(request).leakPtr()); |
649 return request; | 650 return request; |
650 } | 651 } |
651 | 652 |
652 void IDBObjectStore::transactionFinished() | 653 void IDBObjectStore::transactionFinished() |
653 { | 654 { |
654 ASSERT(m_transaction->isFinished()); | 655 ASSERT(m_transaction->isFinished()); |
655 | 656 |
656 // Break reference cycles. | 657 // Break reference cycles. |
657 m_indexMap.clear(); | 658 m_indexMap.clear(); |
658 } | 659 } |
659 | 660 |
660 int64_t IDBObjectStore::findIndexId(const String& name) const | 661 int64_t IDBObjectStore::findIndexId(const String& name) const |
661 { | 662 { |
662 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { | 663 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe
s.begin(); it != m_metadata.indexes.end(); ++it) { |
663 if (it->value.name == name) { | 664 if (it->value.name == name) { |
664 ASSERT(it->key != IDBIndexMetadata::InvalidId); | 665 ASSERT(it->key != IDBIndexMetadata::InvalidId); |
665 return it->key; | 666 return it->key; |
666 } | 667 } |
667 } | 668 } |
668 return IDBIndexMetadata::InvalidId; | 669 return IDBIndexMetadata::InvalidId; |
669 } | 670 } |
670 | 671 |
671 WebIDBDatabase* IDBObjectStore::backendDB() const | 672 WebIDBDatabase* IDBObjectStore::backendDB() const |
672 { | 673 { |
673 return m_transaction->backendDB(); | 674 return m_transaction->backendDB(); |
674 } | 675 } |
675 | 676 |
676 } // namespace WebCore | 677 } // namespace WebCore |
OLD | NEW |