| 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 ASSERT(m_loadingState == LoadingStatePending); | 315 ASSERT(m_loadingState == LoadingStatePending); |
| 316 m_loadingState = LoadingStateLoading; | 316 m_loadingState = LoadingStateLoading; |
| 317 | 317 |
| 318 m_loader = FileReaderLoader::create(m_readType, this); | 318 m_loader = FileReaderLoader::create(m_readType, this); |
| 319 m_loader->setEncoding(m_encoding); | 319 m_loader->setEncoding(m_encoding); |
| 320 m_loader->setDataType(m_blobType); | 320 m_loader->setDataType(m_blobType); |
| 321 m_loader->start(getExecutionContext(), m_blobDataHandle); | 321 m_loader->start(getExecutionContext(), m_blobDataHandle); |
| 322 m_blobDataHandle = nullptr; | 322 m_blobDataHandle = nullptr; |
| 323 } | 323 } |
| 324 | 324 |
| 325 static void delayedAbort(FileReader* reader) { | |
| 326 reader->doAbort(); | |
| 327 } | |
| 328 | |
| 329 void FileReader::abort() { | 325 void FileReader::abort() { |
| 330 DVLOG(1) << "aborting"; | 326 DVLOG(1) << "aborting"; |
| 331 | 327 |
| 332 if (m_loadingState != LoadingStateLoading && | 328 if (m_loadingState != LoadingStateLoading && |
| 333 m_loadingState != LoadingStatePending) { | 329 m_loadingState != LoadingStatePending) { |
| 334 return; | 330 return; |
| 335 } | 331 } |
| 336 m_loadingState = LoadingStateAborted; | 332 m_loadingState = LoadingStateAborted; |
| 337 | 333 |
| 338 // Schedule to have the abort done later since abort() might be called from | 334 DCHECK_NE(kDone, m_state); |
| 339 // the event handler and we do not want the resource loading code to be in the | 335 m_state = kDone; |
| 340 // stack. | |
| 341 getExecutionContext()->postTask( | |
| 342 BLINK_FROM_HERE, | |
| 343 createSameThreadTask(&delayedAbort, wrapPersistent(this))); | |
| 344 } | |
| 345 | 336 |
| 346 void FileReader::doAbort() { | |
| 347 DCHECK_NE(kDone, m_state); | |
| 348 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); | 337 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); |
| 349 | 338 |
| 350 terminate(); | 339 // Setting error implicitly makes |result| return null. |
| 351 | |
| 352 m_error = FileError::createDOMException(FileError::kAbortErr); | 340 m_error = FileError::createDOMException(FileError::kAbortErr); |
| 353 | 341 |
| 354 // Unregister the reader. | 342 // Unregister the reader. |
| 355 ThrottlingController::FinishReaderType finalStep = | 343 ThrottlingController::FinishReaderType finalStep = |
| 356 ThrottlingController::removeReader(getExecutionContext(), this); | 344 ThrottlingController::removeReader(getExecutionContext(), this); |
| 357 | 345 |
| 358 fireEvent(EventTypeNames::error); | 346 fireEvent(EventTypeNames::error); |
| 359 fireEvent(EventTypeNames::abort); | 347 fireEvent(EventTypeNames::abort); |
| 360 fireEvent(EventTypeNames::loadend); | 348 fireEvent(EventTypeNames::loadend); |
| 361 | 349 |
| 362 // All possible events have fired and we're done, no more pending activity. | 350 // All possible events have fired and we're done, no more pending activity. |
| 363 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); | 351 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); |
| 352 |
| 353 // ..but perform the loader cancellation asynchronously as abort() could be |
| 354 // called from the event handler and we do not want the resource loading code |
| 355 // to be on the stack when doing so. The persistent reference keeps the |
| 356 // reader alive until the task has completed. |
| 357 getExecutionContext()->postTask( |
| 358 BLINK_FROM_HERE, |
| 359 createSameThreadTask(&FileReader::terminate, wrapPersistent(this))); |
| 364 } | 360 } |
| 365 | 361 |
| 366 void FileReader::result(StringOrArrayBuffer& resultAttribute) const { | 362 void FileReader::result(StringOrArrayBuffer& resultAttribute) const { |
| 367 if (!m_loader || m_error) | 363 if (m_error || !m_loader) |
| 368 return; | 364 return; |
| 369 | 365 |
| 370 if (m_readType == FileReaderLoader::ReadAsArrayBuffer) | 366 if (m_readType == FileReaderLoader::ReadAsArrayBuffer) |
| 371 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult()); | 367 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult()); |
| 372 else | 368 else |
| 373 resultAttribute.setString(m_loader->stringResult()); | 369 resultAttribute.setString(m_loader->stringResult()); |
| 374 } | 370 } |
| 375 | 371 |
| 376 void FileReader::terminate() { | 372 void FileReader::terminate() { |
| 377 if (m_loader) { | 373 if (m_loader) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 return; | 434 return; |
| 439 | 435 |
| 440 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); | 436 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); |
| 441 | 437 |
| 442 DCHECK_EQ(LoadingStateLoading, m_loadingState); | 438 DCHECK_EQ(LoadingStateLoading, m_loadingState); |
| 443 m_loadingState = LoadingStateNone; | 439 m_loadingState = LoadingStateNone; |
| 444 | 440 |
| 445 DCHECK_NE(kDone, m_state); | 441 DCHECK_NE(kDone, m_state); |
| 446 m_state = kDone; | 442 m_state = kDone; |
| 447 | 443 |
| 448 m_error = FileError::createDOMException( | 444 m_error = FileError::createDOMException(errorCode); |
| 449 static_cast<FileError::ErrorCode>(errorCode)); | |
| 450 | 445 |
| 451 // Unregister the reader. | 446 // Unregister the reader. |
| 452 ThrottlingController::FinishReaderType finalStep = | 447 ThrottlingController::FinishReaderType finalStep = |
| 453 ThrottlingController::removeReader(getExecutionContext(), this); | 448 ThrottlingController::removeReader(getExecutionContext(), this); |
| 454 | 449 |
| 455 fireEvent(EventTypeNames::error); | 450 fireEvent(EventTypeNames::error); |
| 456 fireEvent(EventTypeNames::loadend); | 451 fireEvent(EventTypeNames::loadend); |
| 457 | 452 |
| 458 // All possible events have fired and we're done, no more pending activity. | 453 // All possible events have fired and we're done, no more pending activity. |
| 459 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); | 454 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 474 ProgressEvent::create(type, false, m_loader->bytesLoaded(), 0)); | 469 ProgressEvent::create(type, false, m_loader->bytesLoaded(), 0)); |
| 475 } | 470 } |
| 476 | 471 |
| 477 DEFINE_TRACE(FileReader) { | 472 DEFINE_TRACE(FileReader) { |
| 478 visitor->trace(m_error); | 473 visitor->trace(m_error); |
| 479 EventTargetWithInlineData::trace(visitor); | 474 EventTargetWithInlineData::trace(visitor); |
| 480 ActiveDOMObject::trace(visitor); | 475 ActiveDOMObject::trace(visitor); |
| 481 } | 476 } |
| 482 | 477 |
| 483 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |