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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return EventTargetNames::FileReader; | 219 return EventTargetNames::FileReader; |
220 } | 220 } |
221 | 221 |
222 void FileReader::contextDestroyed() | 222 void FileReader::contextDestroyed() |
223 { | 223 { |
224 // The delayed abort task tidies up and advances to the DONE state. | 224 // The delayed abort task tidies up and advances to the DONE state. |
225 if (m_loadingState == LoadingStateAborted) | 225 if (m_loadingState == LoadingStateAborted) |
226 return; | 226 return; |
227 | 227 |
228 if (hasPendingActivity()) | 228 if (hasPendingActivity()) |
229 ThrottlingController::finishReader(executionContext(), this, ThrottlingC
ontroller::removeReader(executionContext(), this)); | 229 ThrottlingController::finishReader(getExecutionContext(), this, Throttli
ngController::removeReader(getExecutionContext(), this)); |
230 terminate(); | 230 terminate(); |
231 } | 231 } |
232 | 232 |
233 bool FileReader::hasPendingActivity() const | 233 bool FileReader::hasPendingActivity() const |
234 { | 234 { |
235 return m_state == LOADING; | 235 return m_state == LOADING; |
236 } | 236 } |
237 | 237 |
238 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) | 238 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) |
239 { | 239 { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (m_state == LOADING) { | 279 if (m_state == LOADING) { |
280 exceptionState.throwDOMException(InvalidStateError, "The object is alrea
dy busy reading Blobs."); | 280 exceptionState.throwDOMException(InvalidStateError, "The object is alrea
dy busy reading Blobs."); |
281 return; | 281 return; |
282 } | 282 } |
283 | 283 |
284 if (blob->hasBeenClosed()) { | 284 if (blob->hasBeenClosed()) { |
285 exceptionState.throwDOMException(InvalidStateError, String(blob->isFile(
) ? "File" : "Blob") + " has been closed."); | 285 exceptionState.throwDOMException(InvalidStateError, String(blob->isFile(
) ? "File" : "Blob") + " has been closed."); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 ExecutionContext* context = executionContext(); | 289 ExecutionContext* context = getExecutionContext(); |
290 if (!context) { | 290 if (!context) { |
291 exceptionState.throwDOMException(AbortError, "Reading from a detached Fi
leReader is not supported."); | 291 exceptionState.throwDOMException(AbortError, "Reading from a detached Fi
leReader is not supported."); |
292 return; | 292 return; |
293 } | 293 } |
294 | 294 |
295 // A document loader will not load new resources once the Document has detac
hed from its frame. | 295 // A document loader will not load new resources once the Document has detac
hed from its frame. |
296 if (context->isDocument() && !toDocument(context)->frame()) { | 296 if (context->isDocument() && !toDocument(context)->frame()) { |
297 exceptionState.throwDOMException(AbortError, "Reading from a Document-de
tached FileReader is not supported."); | 297 exceptionState.throwDOMException(AbortError, "Reading from a Document-de
tached FileReader is not supported."); |
298 return; | 298 return; |
299 } | 299 } |
(...skipping 12 matching lines...) Expand all Loading... |
312 } | 312 } |
313 | 313 |
314 void FileReader::executePendingRead() | 314 void FileReader::executePendingRead() |
315 { | 315 { |
316 ASSERT(m_loadingState == LoadingStatePending); | 316 ASSERT(m_loadingState == LoadingStatePending); |
317 m_loadingState = LoadingStateLoading; | 317 m_loadingState = LoadingStateLoading; |
318 | 318 |
319 m_loader = FileReaderLoader::create(m_readType, this); | 319 m_loader = FileReaderLoader::create(m_readType, this); |
320 m_loader->setEncoding(m_encoding); | 320 m_loader->setEncoding(m_encoding); |
321 m_loader->setDataType(m_blobType); | 321 m_loader->setDataType(m_blobType); |
322 m_loader->start(executionContext(), m_blobDataHandle); | 322 m_loader->start(getExecutionContext(), m_blobDataHandle); |
323 m_blobDataHandle = nullptr; | 323 m_blobDataHandle = nullptr; |
324 } | 324 } |
325 | 325 |
326 static void delayedAbort(FileReader* reader) | 326 static void delayedAbort(FileReader* reader) |
327 { | 327 { |
328 reader->doAbort(); | 328 reader->doAbort(); |
329 } | 329 } |
330 | 330 |
331 void FileReader::abort() | 331 void FileReader::abort() |
332 { | 332 { |
333 WTF_LOG(FileAPI, "FileReader: aborting\n"); | 333 WTF_LOG(FileAPI, "FileReader: aborting\n"); |
334 | 334 |
335 if (m_loadingState != LoadingStateLoading | 335 if (m_loadingState != LoadingStateLoading |
336 && m_loadingState != LoadingStatePending) { | 336 && m_loadingState != LoadingStatePending) { |
337 return; | 337 return; |
338 } | 338 } |
339 m_loadingState = LoadingStateAborted; | 339 m_loadingState = LoadingStateAborted; |
340 | 340 |
341 // Schedule to have the abort done later since abort() might be called from
the event handler and we do not want the resource loading code to be in the stac
k. | 341 // Schedule to have the abort done later since abort() might be called from
the event handler and we do not want the resource loading code to be in the stac
k. |
342 executionContext()->postTask( | 342 getExecutionContext()->postTask( |
343 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, this)); | 343 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, this)); |
344 } | 344 } |
345 | 345 |
346 void FileReader::doAbort() | 346 void FileReader::doAbort() |
347 { | 347 { |
348 ASSERT(m_state != DONE); | 348 ASSERT(m_state != DONE); |
349 | 349 |
350 terminate(); | 350 terminate(); |
351 | 351 |
352 m_error = FileError::create(FileError::ABORT_ERR); | 352 m_error = FileError::create(FileError::ABORT_ERR); |
353 | 353 |
354 // Unregister the reader. | 354 // Unregister the reader. |
355 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(executionContext(), this); | 355 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(getExecutionContext(), this); |
356 | 356 |
357 fireEvent(EventTypeNames::error); | 357 fireEvent(EventTypeNames::error); |
358 fireEvent(EventTypeNames::abort); | 358 fireEvent(EventTypeNames::abort); |
359 fireEvent(EventTypeNames::loadend); | 359 fireEvent(EventTypeNames::loadend); |
360 | 360 |
361 // All possible events have fired and we're done, no more pending activity. | 361 // All possible events have fired and we're done, no more pending activity. |
362 ThrottlingController::finishReader(executionContext(), this, finalStep); | 362 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); |
363 } | 363 } |
364 | 364 |
365 void FileReader::result(StringOrArrayBuffer& resultAttribute) const | 365 void FileReader::result(StringOrArrayBuffer& resultAttribute) const |
366 { | 366 { |
367 if (!m_loader || m_error) | 367 if (!m_loader || m_error) |
368 return; | 368 return; |
369 | 369 |
370 if (m_readType == FileReaderLoader::ReadAsArrayBuffer) | 370 if (m_readType == FileReaderLoader::ReadAsArrayBuffer) |
371 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult()); | 371 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult()); |
372 else | 372 else |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 // since any of the events could call abort(), which internally checks | 410 // since any of the events could call abort(), which internally checks |
411 // if we're still loading (therefore we need abort process) or not. | 411 // if we're still loading (therefore we need abort process) or not. |
412 m_loadingState = LoadingStateNone; | 412 m_loadingState = LoadingStateNone; |
413 | 413 |
414 fireEvent(EventTypeNames::progress); | 414 fireEvent(EventTypeNames::progress); |
415 | 415 |
416 ASSERT(m_state != DONE); | 416 ASSERT(m_state != DONE); |
417 m_state = DONE; | 417 m_state = DONE; |
418 | 418 |
419 // Unregister the reader. | 419 // Unregister the reader. |
420 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(executionContext(), this); | 420 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(getExecutionContext(), this); |
421 | 421 |
422 fireEvent(EventTypeNames::load); | 422 fireEvent(EventTypeNames::load); |
423 fireEvent(EventTypeNames::loadend); | 423 fireEvent(EventTypeNames::loadend); |
424 | 424 |
425 // All possible events have fired and we're done, no more pending activity. | 425 // All possible events have fired and we're done, no more pending activity. |
426 ThrottlingController::finishReader(executionContext(), this, finalStep); | 426 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); |
427 } | 427 } |
428 | 428 |
429 void FileReader::didFail(FileError::ErrorCode errorCode) | 429 void FileReader::didFail(FileError::ErrorCode errorCode) |
430 { | 430 { |
431 if (m_loadingState == LoadingStateAborted) | 431 if (m_loadingState == LoadingStateAborted) |
432 return; | 432 return; |
433 ASSERT(m_loadingState == LoadingStateLoading); | 433 ASSERT(m_loadingState == LoadingStateLoading); |
434 m_loadingState = LoadingStateNone; | 434 m_loadingState = LoadingStateNone; |
435 | 435 |
436 ASSERT(m_state != DONE); | 436 ASSERT(m_state != DONE); |
437 m_state = DONE; | 437 m_state = DONE; |
438 | 438 |
439 m_error = FileError::create(static_cast<FileError::ErrorCode>(errorCode)); | 439 m_error = FileError::create(static_cast<FileError::ErrorCode>(errorCode)); |
440 | 440 |
441 // Unregister the reader. | 441 // Unregister the reader. |
442 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(executionContext(), this); | 442 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem
oveReader(getExecutionContext(), this); |
443 | 443 |
444 fireEvent(EventTypeNames::error); | 444 fireEvent(EventTypeNames::error); |
445 fireEvent(EventTypeNames::loadend); | 445 fireEvent(EventTypeNames::loadend); |
446 | 446 |
447 // All possible events have fired and we're done, no more pending activity. | 447 // All possible events have fired and we're done, no more pending activity. |
448 ThrottlingController::finishReader(executionContext(), this, finalStep); | 448 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); |
449 } | 449 } |
450 | 450 |
451 void FileReader::fireEvent(const AtomicString& type) | 451 void FileReader::fireEvent(const AtomicString& type) |
452 { | 452 { |
453 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
CallbackStarting(executionContext(), m_asyncOperationId); | 453 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
CallbackStarting(getExecutionContext(), m_asyncOperationId); |
454 if (!m_loader) { | 454 if (!m_loader) { |
455 dispatchEvent(ProgressEvent::create(type, false, 0, 0)); | 455 dispatchEvent(ProgressEvent::create(type, false, 0, 0)); |
456 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | 456 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); |
457 return; | 457 return; |
458 } | 458 } |
459 | 459 |
460 if (m_loader->totalBytes() >= 0) | 460 if (m_loader->totalBytes() >= 0) |
461 dispatchEvent(ProgressEvent::create(type, true, m_loader->bytesLoaded(),
m_loader->totalBytes())); | 461 dispatchEvent(ProgressEvent::create(type, true, m_loader->bytesLoaded(),
m_loader->totalBytes())); |
462 else | 462 else |
463 dispatchEvent(ProgressEvent::create(type, false, m_loader->bytesLoaded()
, 0)); | 463 dispatchEvent(ProgressEvent::create(type, false, m_loader->bytesLoaded()
, 0)); |
464 | 464 |
465 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | 465 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); |
466 } | 466 } |
467 | 467 |
468 DEFINE_TRACE(FileReader) | 468 DEFINE_TRACE(FileReader) |
469 { | 469 { |
470 visitor->trace(m_error); | 470 visitor->trace(m_error); |
471 RefCountedGarbageCollectedEventTargetWithInlineData<FileReader>::trace(visit
or); | 471 RefCountedGarbageCollectedEventTargetWithInlineData<FileReader>::trace(visit
or); |
472 ContextLifecycleObserver::trace(visitor); | 472 ContextLifecycleObserver::trace(visitor); |
473 } | 473 } |
474 | 474 |
475 } // namespace blink | 475 } // namespace blink |
OLD | NEW |