Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: Source/WebCore/Modules/indexeddb/IDBRequest.cpp

Issue 11348011: Revert 128789 - IndexedDB: Use ScriptValue instead of SerializedScriptValue for get/openCursor (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1271/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 { 207 {
208 if (!m_result) 208 if (!m_result)
209 return 0; 209 return 0;
210 if (m_result->type() == IDBAny::IDBCursorType) 210 if (m_result->type() == IDBAny::IDBCursorType)
211 return m_result->idbCursor(); 211 return m_result->idbCursor();
212 if (m_result->type() == IDBAny::IDBCursorWithValueType) 212 if (m_result->type() == IDBAny::IDBCursorWithValueType)
213 return m_result->idbCursorWithValue(); 213 return m_result->idbCursorWithValue();
214 return 0; 214 return 0;
215 } 215 }
216 216
217 void IDBRequest::setResultCursor(PassRefPtr<IDBCursor> cursor, PassRefPtr<IDBKey > key, PassRefPtr<IDBKey> primaryKey, const ScriptValue& value) 217 void IDBRequest::setResultCursor(PassRefPtr<IDBCursor> cursor, PassRefPtr<IDBKey > key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SerializedScriptValue> value)
218 { 218 {
219 ASSERT(m_readyState == PENDING); 219 ASSERT(m_readyState == PENDING);
220 m_cursorKey = key; 220 m_cursorKey = key;
221 m_cursorPrimaryKey = primaryKey; 221 m_cursorPrimaryKey = primaryKey;
222 m_cursorValue = value; 222 m_cursorValue = value;
223 223
224 if (m_cursorType == IDBCursorBackendInterface::IndexKeyCursor) { 224 if (m_cursorType == IDBCursorBackendInterface::IndexKeyCursor) {
225 m_result = IDBAny::create(cursor); 225 m_result = IDBAny::create(cursor);
226 return; 226 return;
227 } 227 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 void IDBRequest::onSuccess(PassRefPtr<DOMStringList> domStringList) 269 void IDBRequest::onSuccess(PassRefPtr<DOMStringList> domStringList)
270 { 270 {
271 IDB_TRACE("IDBRequest::onSuccess(DOMStringList)"); 271 IDB_TRACE("IDBRequest::onSuccess(DOMStringList)");
272 if (!shouldEnqueueEvent()) 272 if (!shouldEnqueueEvent())
273 return; 273 return;
274 274
275 m_result = IDBAny::create(domStringList); 275 m_result = IDBAny::create(domStringList);
276 enqueueEvent(createSuccessEvent()); 276 enqueueEvent(createSuccessEvent());
277 } 277 }
278 278
279 void IDBRequest::onSuccess(PassRefPtr<IDBCursorBackendInterface> backend, PassRe fPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SerializedScriptValu e> serializedValue) 279 void IDBRequest::onSuccess(PassRefPtr<IDBCursorBackendInterface> backend, PassRe fPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SerializedScriptValu e> value)
280 { 280 {
281 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); 281 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)");
282 if (!shouldEnqueueEvent()) 282 if (!shouldEnqueueEvent())
283 return; 283 return;
284 284
285 ScriptValue value = deserializeIDBValue(scriptExecutionContext(), serialized Value);
286 ASSERT(m_cursorType != IDBCursorBackendInterface::InvalidCursorType); 285 ASSERT(m_cursorType != IDBCursorBackendInterface::InvalidCursorType);
287 RefPtr<IDBCursor> cursor; 286 RefPtr<IDBCursor> cursor;
288 if (m_cursorType == IDBCursorBackendInterface::IndexKeyCursor) 287 if (m_cursorType == IDBCursorBackendInterface::IndexKeyCursor)
289 cursor = IDBCursor::create(backend, m_cursorDirection, this, m_source.ge t(), m_transaction.get()); 288 cursor = IDBCursor::create(backend, m_cursorDirection, this, m_source.ge t(), m_transaction.get());
290 else 289 else
291 cursor = IDBCursorWithValue::create(backend, m_cursorDirection, this, m_ source.get(), m_transaction.get()); 290 cursor = IDBCursorWithValue::create(backend, m_cursorDirection, this, m_ source.get(), m_transaction.get());
292 setResultCursor(cursor, key, primaryKey, value); 291 setResultCursor(cursor, key, primaryKey, value);
293 292
294 enqueueEvent(createSuccessEvent()); 293 enqueueEvent(createSuccessEvent());
295 } 294 }
296 295
297 void IDBRequest::onSuccess(PassRefPtr<IDBKey> idbKey) 296 void IDBRequest::onSuccess(PassRefPtr<IDBKey> idbKey)
298 { 297 {
299 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); 298 IDB_TRACE("IDBRequest::onSuccess(IDBKey)");
300 if (!shouldEnqueueEvent()) 299 if (!shouldEnqueueEvent())
301 return; 300 return;
302 301
303 if (idbKey && idbKey->isValid()) 302 if (idbKey && idbKey->isValid())
304 m_result = IDBAny::create(idbKey); 303 m_result = IDBAny::create(idbKey);
305 else 304 else
306 m_result = IDBAny::createInvalid(); 305 m_result = IDBAny::create(SerializedScriptValue::undefinedValue());
307 enqueueEvent(createSuccessEvent()); 306 enqueueEvent(createSuccessEvent());
308 } 307 }
309 308
310 void IDBRequest::onSuccess(PassRefPtr<IDBTransactionBackendInterface> prpBackend ) 309 void IDBRequest::onSuccess(PassRefPtr<IDBTransactionBackendInterface> prpBackend )
311 { 310 {
312 IDB_TRACE("IDBRequest::onSuccess(IDBTransaction)"); 311 IDB_TRACE("IDBRequest::onSuccess(IDBTransaction)");
313 RefPtr<IDBTransactionBackendInterface> backend = prpBackend; 312 RefPtr<IDBTransactionBackendInterface> backend = prpBackend;
314 313
315 if (m_contextStopped || !scriptExecutionContext()) { 314 if (m_contextStopped || !scriptExecutionContext()) {
316 // Should only be null in tests. 315 // Should only be null in tests.
(...skipping 14 matching lines...) Expand all
331 m_result = IDBAny::create(frontend.release()); 330 m_result = IDBAny::create(frontend.release());
332 enqueueEvent(createSuccessEvent()); 331 enqueueEvent(createSuccessEvent());
333 } 332 }
334 333
335 void IDBRequest::onSuccess(PassRefPtr<SerializedScriptValue> serializedScriptVal ue) 334 void IDBRequest::onSuccess(PassRefPtr<SerializedScriptValue> serializedScriptVal ue)
336 { 335 {
337 IDB_TRACE("IDBRequest::onSuccess(SerializedScriptValue)"); 336 IDB_TRACE("IDBRequest::onSuccess(SerializedScriptValue)");
338 if (!shouldEnqueueEvent()) 337 if (!shouldEnqueueEvent())
339 return; 338 return;
340 339
341 ScriptValue value = deserializeIDBValue(scriptExecutionContext(), serialized ScriptValue); 340 m_result = IDBAny::create(serializedScriptValue);
342 onSuccessInternal(value); 341 m_pendingCursor.clear();
342 enqueueEvent(createSuccessEvent());
343 } 343 }
344 344
345 #ifndef NDEBUG 345 #ifndef NDEBUG
346 static PassRefPtr<IDBObjectStore> effectiveObjectStore(PassRefPtr<IDBAny> source ) 346 static PassRefPtr<IDBObjectStore> effectiveObjectStore(PassRefPtr<IDBAny> source )
347 { 347 {
348 if (source->type() == IDBAny::IDBObjectStoreType) 348 if (source->type() == IDBAny::IDBObjectStoreType)
349 return source->idbObjectStore(); 349 return source->idbObjectStore();
350 if (source->type() == IDBAny::IDBIndexType) 350 if (source->type() == IDBAny::IDBIndexType)
351 return source->idbIndex()->objectStore(); 351 return source->idbIndex()->objectStore();
352 352
353 ASSERT_NOT_REACHED(); 353 ASSERT_NOT_REACHED();
354 return 0; 354 return 0;
355 } 355 }
356 #endif 356 #endif
357 357
358 void IDBRequest::onSuccess(PassRefPtr<SerializedScriptValue> prpSerializedScript Value, PassRefPtr<IDBKey> prpPrimaryKey, const IDBKeyPath& keyPath) 358 void IDBRequest::onSuccess(PassRefPtr<SerializedScriptValue> prpSerializedScript Value, PassRefPtr<IDBKey> prpPrimaryKey, const IDBKeyPath& keyPath)
359 { 359 {
360 IDB_TRACE("IDBRequest::onSuccess(SerializedScriptValue, IDBKey, IDBKeyPath)" ); 360 IDB_TRACE("IDBRequest::onSuccess(SerializedScriptValue, IDBKey, IDBKeyPath)" );
361 if (!shouldEnqueueEvent()) 361 if (!shouldEnqueueEvent())
362 return; 362 return;
363 363
364 #ifndef NDEBUG 364 #ifndef NDEBUG
365 ASSERT(keyPath == effectiveObjectStore(m_source)->keyPath()); 365 ASSERT(keyPath == effectiveObjectStore(m_source)->keyPath());
366 #endif 366 #endif
367 ScriptValue value = deserializeIDBValue(scriptExecutionContext(), prpSeriali zedScriptValue); 367 RefPtr<SerializedScriptValue> value = prpSerializedScriptValue;
368 368
369 RefPtr<IDBKey> primaryKey = prpPrimaryKey; 369 RefPtr<IDBKey> primaryKey = prpPrimaryKey;
370 #ifndef NDEBUG 370 #ifndef NDEBUG
371 RefPtr<IDBKey> expectedKey = createIDBKeyFromScriptValueAndKeyPath(value, ke yPath); 371 RefPtr<IDBKey> expectedKey = createIDBKeyFromSerializedValueAndKeyPath(value , keyPath);
372 ASSERT(!expectedKey || expectedKey->isEqual(primaryKey.get())); 372 ASSERT(!expectedKey || expectedKey->isEqual(primaryKey.get()));
373 #endif 373 #endif
374 bool injected = injectIDBKeyIntoScriptValue(primaryKey, value, keyPath); 374 RefPtr<SerializedScriptValue> valueAfterInjection = injectIDBKeyIntoSerializ edValue(primaryKey, value, keyPath);
375 ASSERT_UNUSED(injected, injected); 375 ASSERT(valueAfterInjection);
376 onSuccessInternal(value); 376 if (!valueAfterInjection) {
377 // Checks in put() ensure this should only happen if I/O error occurs.
378 onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Int ernal error inserting generated key into the object."));
379 return;
380 }
381 value = valueAfterInjection;
382 onSuccess(value.release());
377 } 383 }
378 384
379 void IDBRequest::onSuccessInternal(const ScriptValue& value) 385 void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey , PassRefPtr<SerializedScriptValue> value)
380 {
381 m_result = IDBAny::create(value);
382 m_pendingCursor.clear();
383 enqueueEvent(createSuccessEvent());
384 }
385
386 void IDBRequest::onSuccess(PassRefPtr<IDBKey> key, PassRefPtr<IDBKey> primaryKey , PassRefPtr<SerializedScriptValue> serializedValue)
387 { 386 {
388 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); 387 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)");
389 if (!shouldEnqueueEvent()) 388 if (!shouldEnqueueEvent())
390 return; 389 return;
391 390
392 ScriptValue value = deserializeIDBValue(scriptExecutionContext(), serialized Value);
393 ASSERT(m_pendingCursor); 391 ASSERT(m_pendingCursor);
394 setResultCursor(m_pendingCursor.release(), key, primaryKey, value); 392 setResultCursor(m_pendingCursor.release(), key, primaryKey, value);
395 enqueueEvent(createSuccessEvent()); 393 enqueueEvent(createSuccessEvent());
396 } 394 }
397 395
398 bool IDBRequest::hasPendingActivity() const 396 bool IDBRequest::hasPendingActivity() const
399 { 397 {
400 // FIXME: In an ideal world, we should return true as long as anyone has a o r can 398 // FIXME: In an ideal world, we should return true as long as anyone has a o r can
401 // get a handle to us and we have event listeners. This is order to h andle 399 // get a handle to us and we have event listeners. This is order to h andle
402 // user generated events properly. 400 // user generated events properly.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 // this object to actually hold a reference to the database (to ensure 449 // this object to actually hold a reference to the database (to ensure
452 // it stays alive). 450 // it stays alive).
453 targets.append(m_transaction->db()); 451 targets.append(m_transaction->db());
454 } 452 }
455 453
456 // Cursor properties should not updated until the success event is being dis patched. 454 // Cursor properties should not updated until the success event is being dis patched.
457 RefPtr<IDBCursor> cursorToNotify; 455 RefPtr<IDBCursor> cursorToNotify;
458 if (event->type() == eventNames().successEvent) { 456 if (event->type() == eventNames().successEvent) {
459 cursorToNotify = getResultCursor(); 457 cursorToNotify = getResultCursor();
460 if (cursorToNotify) 458 if (cursorToNotify)
461 cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimary Key.release(), m_cursorValue); 459 cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimary Key.release(), m_cursorValue.release());
462 } 460 }
463 461
464 if (event->type() == eventNames().upgradeneededEvent) { 462 if (event->type() == eventNames().upgradeneededEvent) {
465 ASSERT(!m_didFireUpgradeNeededEvent); 463 ASSERT(!m_didFireUpgradeNeededEvent);
466 m_didFireUpgradeNeededEvent = true; 464 m_didFireUpgradeNeededEvent = true;
467 } 465 }
468 466
469 // FIXME: When we allow custom event dispatching, this will probably need to change. 467 // FIXME: When we allow custom event dispatching, this will probably need to change.
470 ASSERT_WITH_MESSAGE(event->type() == eventNames().successEvent || event->typ e() == eventNames().errorEvent || event->type() == eventNames().blockedEvent || event->type() == eventNames().upgradeneededEvent, "event type was %s", event->ty pe().string().utf8().data()); 468 ASSERT_WITH_MESSAGE(event->type() == eventNames().successEvent || event->typ e() == eventNames().errorEvent || event->type() == eventNames().blockedEvent || event->type() == eventNames().upgradeneededEvent, "event type was %s", event->ty pe().string().utf8().data());
471 const bool setTransactionActive = m_transaction && (event->type() == eventNa mes().successEvent || event->type() == eventNames().upgradeneededEvent || (event ->type() == eventNames().errorEvent && m_errorCode != IDBDatabaseException::IDB_ ABORT_ERR)); 469 const bool setTransactionActive = m_transaction && (event->type() == eventNa mes().successEvent || event->type() == eventNames().upgradeneededEvent || (event ->type() == eventNames().errorEvent && m_errorCode != IDBDatabaseException::IDB_ ABORT_ERR));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 539 }
542 540
543 EventTargetData* IDBRequest::ensureEventTargetData() 541 EventTargetData* IDBRequest::ensureEventTargetData()
544 { 542 {
545 return &m_eventTargetData; 543 return &m_eventTargetData;
546 } 544 }
547 545
548 } // namespace WebCore 546 } // namespace WebCore
549 547
550 #endif 548 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/Modules/indexeddb/IDBRequest.h ('k') | Source/WebCore/Modules/indexeddb/IDBTransactionCallbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698