| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "platform/SharedBuffer.h" | 45 #include "platform/SharedBuffer.h" |
| 46 #include "public/platform/WebBlobInfo.h" | 46 #include "public/platform/WebBlobInfo.h" |
| 47 | 47 |
| 48 using blink::WebIDBCursor; | 48 using blink::WebIDBCursor; |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 IDBRequest* IDBRequest::create(ScriptState* scriptState, IDBAny* source, IDBTran
saction* transaction) | 52 IDBRequest* IDBRequest::create(ScriptState* scriptState, IDBAny* source, IDBTran
saction* transaction) |
| 53 { | 53 { |
| 54 IDBRequest* request = new IDBRequest(scriptState, source, transaction); | 54 IDBRequest* request = new IDBRequest(scriptState, source, transaction); |
| 55 request->suspendIfNeeded(); | |
| 56 // Requests associated with IDBFactory (open/deleteDatabase/getDatabaseNames
) are not associated with transactions. | 55 // Requests associated with IDBFactory (open/deleteDatabase/getDatabaseNames
) are not associated with transactions. |
| 57 if (transaction) | 56 if (transaction) |
| 58 transaction->registerRequest(request); | 57 transaction->registerRequest(request); |
| 59 return request; | 58 return request; |
| 60 } | 59 } |
| 61 | 60 |
| 62 IDBRequest::IDBRequest(ScriptState* scriptState, IDBAny* source, IDBTransaction*
transaction) | 61 IDBRequest::IDBRequest(ScriptState* scriptState, IDBAny* source, IDBTransaction*
transaction) |
| 63 : ActiveDOMObject(scriptState->executionContext()) | 62 : ContextLifecycleObserver(scriptState->executionContext()) |
| 64 , m_transaction(transaction) | 63 , m_transaction(transaction) |
| 65 , m_scriptState(scriptState) | 64 , m_scriptState(scriptState) |
| 66 , m_source(source) | 65 , m_source(source) |
| 67 { | 66 { |
| 68 } | 67 } |
| 69 | 68 |
| 70 IDBRequest::~IDBRequest() | 69 IDBRequest::~IDBRequest() |
| 71 { | 70 { |
| 72 ASSERT(m_readyState == DONE || m_readyState == EarlyDeath || !executionConte
xt()); | 71 ASSERT(m_readyState == DONE || m_readyState == EarlyDeath || !executionConte
xt()); |
| 73 } | 72 } |
| 74 | 73 |
| 75 DEFINE_TRACE(IDBRequest) | 74 DEFINE_TRACE(IDBRequest) |
| 76 { | 75 { |
| 77 visitor->trace(m_transaction); | 76 visitor->trace(m_transaction); |
| 78 visitor->trace(m_source); | 77 visitor->trace(m_source); |
| 79 visitor->trace(m_result); | 78 visitor->trace(m_result); |
| 80 visitor->trace(m_error); | 79 visitor->trace(m_error); |
| 81 visitor->trace(m_enqueuedEvents); | 80 visitor->trace(m_enqueuedEvents); |
| 82 visitor->trace(m_pendingCursor); | 81 visitor->trace(m_pendingCursor); |
| 83 visitor->trace(m_cursorKey); | 82 visitor->trace(m_cursorKey); |
| 84 visitor->trace(m_cursorPrimaryKey); | 83 visitor->trace(m_cursorPrimaryKey); |
| 85 RefCountedGarbageCollectedEventTargetWithInlineData<IDBRequest>::trace(visit
or); | 84 RefCountedGarbageCollectedEventTargetWithInlineData<IDBRequest>::trace(visit
or); |
| 86 ActiveDOMObject::trace(visitor); | 85 ContextLifecycleObserver::trace(visitor); |
| 87 } | 86 } |
| 88 | 87 |
| 89 ScriptValue IDBRequest::result(ExceptionState& exceptionState) | 88 ScriptValue IDBRequest::result(ExceptionState& exceptionState) |
| 90 { | 89 { |
| 91 if (m_readyState != DONE) { | 90 if (m_readyState != DONE) { |
| 92 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::request
NotFinishedErrorMessage); | 91 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::request
NotFinishedErrorMessage); |
| 93 return ScriptValue(); | 92 return ScriptValue(); |
| 94 } | 93 } |
| 95 if (m_contextStopped || !executionContext()) | 94 if (!executionContext()) |
| 96 return ScriptValue(); | 95 return ScriptValue(); |
| 97 m_resultDirty = false; | 96 m_resultDirty = false; |
| 98 ScriptValue value = ScriptValue::from(m_scriptState.get(), m_result); | 97 ScriptValue value = ScriptValue::from(m_scriptState.get(), m_result); |
| 99 return value; | 98 return value; |
| 100 } | 99 } |
| 101 | 100 |
| 102 DOMException* IDBRequest::error(ExceptionState& exceptionState) const | 101 DOMException* IDBRequest::error(ExceptionState& exceptionState) const |
| 103 { | 102 { |
| 104 if (m_readyState != DONE) { | 103 if (m_readyState != DONE) { |
| 105 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::request
NotFinishedErrorMessage); | 104 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::request
NotFinishedErrorMessage); |
| 106 return nullptr; | 105 return nullptr; |
| 107 } | 106 } |
| 108 return m_error; | 107 return m_error; |
| 109 } | 108 } |
| 110 | 109 |
| 111 ScriptValue IDBRequest::source() const | 110 ScriptValue IDBRequest::source() const |
| 112 { | 111 { |
| 113 if (m_contextStopped || !executionContext()) | 112 if (!executionContext()) |
| 114 return ScriptValue(); | 113 return ScriptValue(); |
| 115 | 114 |
| 116 return ScriptValue::from(m_scriptState.get(), m_source); | 115 return ScriptValue::from(m_scriptState.get(), m_source); |
| 117 } | 116 } |
| 118 | 117 |
| 119 const String& IDBRequest::readyState() const | 118 const String& IDBRequest::readyState() const |
| 120 { | 119 { |
| 121 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 120 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
| 122 | 121 |
| 123 if (m_readyState == PENDING) | 122 if (m_readyState == PENDING) |
| 124 return IndexedDBNames::pending; | 123 return IndexedDBNames::pending; |
| 125 | 124 |
| 126 return IndexedDBNames::done; | 125 return IndexedDBNames::done; |
| 127 } | 126 } |
| 128 | 127 |
| 129 void IDBRequest::abort() | 128 void IDBRequest::abort() |
| 130 { | 129 { |
| 131 ASSERT(!m_requestAborted); | 130 ASSERT(!m_requestAborted); |
| 132 if (m_contextStopped || !executionContext()) | 131 if (!executionContext()) |
| 133 return; | 132 return; |
| 134 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 133 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
| 135 if (m_readyState == DONE) | 134 if (m_readyState == DONE) |
| 136 return; | 135 return; |
| 137 | 136 |
| 138 EventQueue* eventQueue = executionContext()->eventQueue(); | 137 EventQueue* eventQueue = executionContext()->eventQueue(); |
| 139 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 138 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
| 140 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); | 139 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); |
| 141 ASSERT_UNUSED(removed, removed); | 140 ASSERT_UNUSED(removed, removed); |
| 142 } | 141 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 203 } |
| 205 | 204 |
| 206 void IDBRequest::ackReceivedBlobs(const Vector<RefPtr<IDBValue>>& values) | 205 void IDBRequest::ackReceivedBlobs(const Vector<RefPtr<IDBValue>>& values) |
| 207 { | 206 { |
| 208 for (size_t i = 0; i < values.size(); ++i) | 207 for (size_t i = 0; i < values.size(); ++i) |
| 209 ackReceivedBlobs(values[i].get()); | 208 ackReceivedBlobs(values[i].get()); |
| 210 } | 209 } |
| 211 | 210 |
| 212 bool IDBRequest::shouldEnqueueEvent() const | 211 bool IDBRequest::shouldEnqueueEvent() const |
| 213 { | 212 { |
| 214 if (m_contextStopped || !executionContext()) | 213 if (!executionContext()) |
| 215 return false; | 214 return false; |
| 216 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 215 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
| 217 if (m_requestAborted) | 216 if (m_requestAborted) |
| 218 return false; | 217 return false; |
| 219 ASSERT(m_readyState == PENDING); | 218 ASSERT(m_readyState == PENDING); |
| 220 ASSERT(!m_error && !m_result); | 219 ASSERT(!m_error && !m_result); |
| 221 return true; | 220 return true; |
| 222 } | 221 } |
| 223 | 222 |
| 224 void IDBRequest::onError(DOMException* error) | 223 void IDBRequest::onError(DOMException* error) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void IDBRequest::onSuccess() | 338 void IDBRequest::onSuccess() |
| 340 { | 339 { |
| 341 IDB_TRACE("IDBRequest::onSuccess()"); | 340 IDB_TRACE("IDBRequest::onSuccess()"); |
| 342 if (!shouldEnqueueEvent()) | 341 if (!shouldEnqueueEvent()) |
| 343 return; | 342 return; |
| 344 onSuccessInternal(IDBAny::createUndefined()); | 343 onSuccessInternal(IDBAny::createUndefined()); |
| 345 } | 344 } |
| 346 | 345 |
| 347 void IDBRequest::onSuccessInternal(IDBAny* result) | 346 void IDBRequest::onSuccessInternal(IDBAny* result) |
| 348 { | 347 { |
| 349 ASSERT(!m_contextStopped); | 348 ASSERT(executionContext()); |
| 350 ASSERT(!m_pendingCursor); | 349 ASSERT(!m_pendingCursor); |
| 351 setResult(result); | 350 setResult(result); |
| 352 enqueueEvent(Event::create(EventTypeNames::success)); | 351 enqueueEvent(Event::create(EventTypeNames::success)); |
| 353 } | 352 } |
| 354 | 353 |
| 355 void IDBRequest::setResult(IDBAny* result) | 354 void IDBRequest::setResult(IDBAny* result) |
| 356 { | 355 { |
| 357 m_result = result; | 356 m_result = result; |
| 358 m_resultDirty = true; | 357 m_resultDirty = true; |
| 359 } | 358 } |
| 360 | 359 |
| 361 void IDBRequest::onSuccess(IDBKey* key, IDBKey* primaryKey, PassRefPtr<IDBValue>
value) | 360 void IDBRequest::onSuccess(IDBKey* key, IDBKey* primaryKey, PassRefPtr<IDBValue>
value) |
| 362 { | 361 { |
| 363 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); | 362 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); |
| 364 if (!shouldEnqueueEvent()) | 363 if (!shouldEnqueueEvent()) |
| 365 return; | 364 return; |
| 366 | 365 |
| 367 ASSERT(m_pendingCursor); | 366 ASSERT(m_pendingCursor); |
| 368 setResultCursor(m_pendingCursor.release(), key, primaryKey, value); | 367 setResultCursor(m_pendingCursor.release(), key, primaryKey, value); |
| 369 } | 368 } |
| 370 | 369 |
| 371 bool IDBRequest::hasPendingActivity() const | 370 bool IDBRequest::hasPendingActivity() const |
| 372 { | 371 { |
| 373 // FIXME: In an ideal world, we should return true as long as anyone has a o
r can | 372 // FIXME: In an ideal world, we should return true as long as anyone has a o
r can |
| 374 // get a handle to us and we have event listeners. This is order to h
andle | 373 // get a handle to us and we have event listeners. This is order to h
andle |
| 375 // user generated events properly. | 374 // user generated events properly. |
| 376 return m_hasPendingActivity && !m_contextStopped; | 375 return m_hasPendingActivity && executionContext(); |
| 377 } | 376 } |
| 378 | 377 |
| 379 void IDBRequest::stop() | 378 void IDBRequest::contextDestroyed() |
| 380 { | 379 { |
| 381 if (m_contextStopped) | |
| 382 return; | |
| 383 | |
| 384 m_contextStopped = true; | |
| 385 | |
| 386 if (m_readyState == PENDING) { | 380 if (m_readyState == PENDING) { |
| 387 m_readyState = EarlyDeath; | 381 m_readyState = EarlyDeath; |
| 388 if (m_transaction) { | 382 if (m_transaction) { |
| 389 m_transaction->unregisterRequest(this); | 383 m_transaction->unregisterRequest(this); |
| 390 m_transaction.clear(); | 384 m_transaction.clear(); |
| 391 } | 385 } |
| 392 } | 386 } |
| 393 | 387 |
| 394 m_enqueuedEvents.clear(); | 388 m_enqueuedEvents.clear(); |
| 395 if (m_source) | 389 if (m_source) |
| 396 m_source->contextWillBeDestroyed(); | 390 m_source->contextWillBeDestroyed(); |
| 397 if (m_result) | 391 if (m_result) |
| 398 m_result->contextWillBeDestroyed(); | 392 m_result->contextWillBeDestroyed(); |
| 399 if (m_pendingCursor) | 393 if (m_pendingCursor) |
| 400 m_pendingCursor->contextWillBeDestroyed(); | 394 m_pendingCursor->contextWillBeDestroyed(); |
| 401 } | 395 } |
| 402 | 396 |
| 403 const AtomicString& IDBRequest::interfaceName() const | 397 const AtomicString& IDBRequest::interfaceName() const |
| 404 { | 398 { |
| 405 return EventTargetNames::IDBRequest; | 399 return EventTargetNames::IDBRequest; |
| 406 } | 400 } |
| 407 | 401 |
| 408 ExecutionContext* IDBRequest::executionContext() const | 402 ExecutionContext* IDBRequest::executionContext() const |
| 409 { | 403 { |
| 410 return ActiveDOMObject::executionContext(); | 404 return ContextLifecycleObserver::executionContext(); |
| 411 } | 405 } |
| 412 | 406 |
| 413 DispatchEventResult IDBRequest::dispatchEventInternal(PassRefPtrWillBeRawPtr<Eve
nt> event) | 407 DispatchEventResult IDBRequest::dispatchEventInternal(PassRefPtrWillBeRawPtr<Eve
nt> event) |
| 414 { | 408 { |
| 415 IDB_TRACE("IDBRequest::dispatchEvent"); | 409 IDB_TRACE("IDBRequest::dispatchEvent"); |
| 416 if (m_contextStopped || !executionContext()) | 410 if (!executionContext()) |
| 417 return DispatchEventResult::CanceledBeforeDispatch; | 411 return DispatchEventResult::CanceledBeforeDispatch; |
| 418 ASSERT(m_readyState == PENDING); | 412 ASSERT(m_readyState == PENDING); |
| 419 ASSERT(m_hasPendingActivity); | 413 ASSERT(m_hasPendingActivity); |
| 420 ASSERT(m_enqueuedEvents.size()); | 414 ASSERT(m_enqueuedEvents.size()); |
| 421 ASSERT(event->target() == this); | 415 ASSERT(event->target() == this); |
| 422 | 416 |
| 423 ScriptState::Scope scope(m_scriptState.get()); | 417 ScriptState::Scope scope(m_scriptState.get()); |
| 424 | 418 |
| 425 if (event->type() != EventTypeNames::blocked) | 419 if (event->type() != EventTypeNames::blocked) |
| 426 m_readyState = DONE; | 420 m_readyState = DONE; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 490 |
| 497 void IDBRequest::transactionDidFinishAndDispatch() | 491 void IDBRequest::transactionDidFinishAndDispatch() |
| 498 { | 492 { |
| 499 ASSERT(m_transaction); | 493 ASSERT(m_transaction); |
| 500 ASSERT(m_transaction->isVersionChange()); | 494 ASSERT(m_transaction->isVersionChange()); |
| 501 ASSERT(m_didFireUpgradeNeededEvent); | 495 ASSERT(m_didFireUpgradeNeededEvent); |
| 502 ASSERT(m_readyState == DONE); | 496 ASSERT(m_readyState == DONE); |
| 503 ASSERT(executionContext()); | 497 ASSERT(executionContext()); |
| 504 m_transaction.clear(); | 498 m_transaction.clear(); |
| 505 | 499 |
| 506 if (m_contextStopped) | 500 if (!executionContext()) |
| 507 return; | 501 return; |
| 508 | 502 |
| 509 m_readyState = PENDING; | 503 m_readyState = PENDING; |
| 510 } | 504 } |
| 511 | 505 |
| 512 void IDBRequest::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) | 506 void IDBRequest::enqueueEvent(PassRefPtrWillBeRawPtr<Event> event) |
| 513 { | 507 { |
| 514 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 508 ASSERT(m_readyState == PENDING || m_readyState == DONE); |
| 515 | 509 |
| 516 if (m_contextStopped || !executionContext()) | 510 if (!executionContext()) |
| 517 return; | 511 return; |
| 518 | 512 |
| 519 ASSERT_WITH_MESSAGE(m_readyState == PENDING || m_didFireUpgradeNeededEvent,
"When queueing event %s, m_readyState was %d", event->type().utf8().data(), m_re
adyState); | 513 ASSERT_WITH_MESSAGE(m_readyState == PENDING || m_didFireUpgradeNeededEvent,
"When queueing event %s, m_readyState was %d", event->type().utf8().data(), m_re
adyState); |
| 520 | 514 |
| 521 EventQueue* eventQueue = executionContext()->eventQueue(); | 515 EventQueue* eventQueue = executionContext()->eventQueue(); |
| 522 event->setTarget(this); | 516 event->setTarget(this); |
| 523 | 517 |
| 524 // Keep track of enqueued events in case we need to abort prior to dispatch, | 518 // Keep track of enqueued events in case we need to abort prior to dispatch, |
| 525 // in which case these must be cancelled. If the events not dispatched for | 519 // in which case these must be cancelled. If the events not dispatched for |
| 526 // other reasons they must be removed from this list via dequeueEvent(). | 520 // other reasons they must be removed from this list via dequeueEvent(). |
| 527 if (eventQueue->enqueueEvent(event.get())) | 521 if (eventQueue->enqueueEvent(event.get())) |
| 528 m_enqueuedEvents.append(event); | 522 m_enqueuedEvents.append(event); |
| 529 } | 523 } |
| 530 | 524 |
| 531 void IDBRequest::dequeueEvent(Event* event) | 525 void IDBRequest::dequeueEvent(Event* event) |
| 532 { | 526 { |
| 533 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 527 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
| 534 if (m_enqueuedEvents[i].get() == event) | 528 if (m_enqueuedEvents[i].get() == event) |
| 535 m_enqueuedEvents.remove(i); | 529 m_enqueuedEvents.remove(i); |
| 536 } | 530 } |
| 537 } | 531 } |
| 538 | 532 |
| 539 } // namespace blink | 533 } // namespace blink |
| OLD | NEW |