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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/fileapi/FileReader.h" | 32 #include "core/fileapi/FileReader.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "bindings/core/v8/UnionTypesCore.h" |
35 #include "core/dom/CrossThreadTask.h" | 36 #include "core/dom/CrossThreadTask.h" |
36 #include "core/dom/DOMArrayBuffer.h" | 37 #include "core/dom/DOMArrayBuffer.h" |
37 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
38 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
39 #include "core/dom/ExecutionContext.h" | 40 #include "core/dom/ExecutionContext.h" |
40 #include "core/events/ProgressEvent.h" | 41 #include "core/events/ProgressEvent.h" |
41 #include "core/fileapi/File.h" | 42 #include "core/fileapi/File.h" |
42 #include "core/inspector/InspectorInstrumentation.h" | 43 #include "core/inspector/InspectorInstrumentation.h" |
43 #include "platform/Logging.h" | 44 #include "platform/Logging.h" |
44 #include "platform/Supplementable.h" | 45 #include "platform/Supplementable.h" |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(executionContext(), this); | 358 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(executionContext(), this); |
358 | 359 |
359 fireEvent(EventTypeNames::error); | 360 fireEvent(EventTypeNames::error); |
360 fireEvent(EventTypeNames::abort); | 361 fireEvent(EventTypeNames::abort); |
361 fireEvent(EventTypeNames::loadend); | 362 fireEvent(EventTypeNames::loadend); |
362 | 363 |
363 // All possible events have fired and we're done, no more pending activity. | 364 // All possible events have fired and we're done, no more pending activity. |
364 ThrottlingController::finishReader(executionContext(), this, finalStep); | 365 ThrottlingController::finishReader(executionContext(), this, finalStep); |
365 } | 366 } |
366 | 367 |
| 368 void FileReader::result(StringOrArrayBuffer& resultAttribute) const |
| 369 { |
| 370 if (!m_loader || m_error) |
| 371 return; |
| 372 |
| 373 if (m_readType == FileReaderLoader::ReadAsArrayBuffer) |
| 374 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult()); |
| 375 else |
| 376 resultAttribute.setString(m_loader->stringResult()); |
| 377 } |
| 378 |
367 void FileReader::terminate() | 379 void FileReader::terminate() |
368 { | 380 { |
369 if (m_loader) { | 381 if (m_loader) { |
370 m_loader->cancel(); | 382 m_loader->cancel(); |
371 m_loader = nullptr; | 383 m_loader = nullptr; |
372 } | 384 } |
373 m_state = DONE; | 385 m_state = DONE; |
374 m_loadingState = LoadingStateNone; | 386 m_loadingState = LoadingStateNone; |
375 } | 387 } |
376 | 388 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 461 } |
450 | 462 |
451 if (m_loader->totalBytes() >= 0) | 463 if (m_loader->totalBytes() >= 0) |
452 dispatchEvent(ProgressEvent::create(type, true, m_loader->bytesLoaded(),
m_loader->totalBytes())); | 464 dispatchEvent(ProgressEvent::create(type, true, m_loader->bytesLoaded(),
m_loader->totalBytes())); |
453 else | 465 else |
454 dispatchEvent(ProgressEvent::create(type, false, m_loader->bytesLoaded()
, 0)); | 466 dispatchEvent(ProgressEvent::create(type, false, m_loader->bytesLoaded()
, 0)); |
455 | 467 |
456 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | 468 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); |
457 } | 469 } |
458 | 470 |
459 PassRefPtr<DOMArrayBuffer> FileReader::arrayBufferResult() const | |
460 { | |
461 if (!m_loader || m_error) | |
462 return nullptr; | |
463 return m_loader->arrayBufferResult(); | |
464 } | |
465 | |
466 String FileReader::stringResult() | |
467 { | |
468 if (!m_loader || m_error) | |
469 return String(); | |
470 return m_loader->stringResult(); | |
471 } | |
472 | |
473 void FileReader::trace(Visitor* visitor) | 471 void FileReader::trace(Visitor* visitor) |
474 { | 472 { |
475 visitor->trace(m_error); | 473 visitor->trace(m_error); |
476 RefCountedGarbageCollectedEventTargetWithInlineData<FileReader>::trace(visit
or); | 474 RefCountedGarbageCollectedEventTargetWithInlineData<FileReader>::trace(visit
or); |
477 ActiveDOMObject::trace(visitor); | 475 ActiveDOMObject::trace(visitor); |
478 } | 476 } |
479 | 477 |
480 } // namespace blink | 478 } // namespace blink |
OLD | NEW |