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

Side by Side Diff: third_party/WebKit/Source/core/fileapi/FileReader.cpp

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 months 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 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 FileReader* FileReader::create(ExecutionContext* context) 191 FileReader* FileReader::create(ExecutionContext* context)
192 { 192 {
193 FileReader* fileReader = new FileReader(context); 193 FileReader* fileReader = new FileReader(context);
194 fileReader->suspendIfNeeded(); 194 fileReader->suspendIfNeeded();
195 return fileReader; 195 return fileReader;
196 } 196 }
197 197
198 FileReader::FileReader(ExecutionContext* context) 198 FileReader::FileReader(ExecutionContext* context)
199 : ActiveScriptWrappable(this) 199 : ActiveScriptWrappable(this)
200 , ActiveDOMObject(context) 200 , ActiveDOMObject(context)
201 , m_state(EMPTY) 201 , m_state(kEmpty)
202 , m_loadingState(LoadingStateNone) 202 , m_loadingState(LoadingStateNone)
203 , m_stillFiringEvents(false) 203 , m_stillFiringEvents(false)
204 , m_readType(FileReaderLoader::ReadAsBinaryString) 204 , m_readType(FileReaderLoader::ReadAsBinaryString)
205 , m_lastProgressNotificationTimeMS(0) 205 , m_lastProgressNotificationTimeMS(0)
206 { 206 {
207 } 207 }
208 208
209 FileReader::~FileReader() 209 FileReader::~FileReader()
210 { 210 {
211 terminate(); 211 terminate();
(...skipping 10 matching lines...) Expand all
222 if (m_loadingState == LoadingStateAborted) 222 if (m_loadingState == LoadingStateAborted)
223 return; 223 return;
224 224
225 if (hasPendingActivity()) 225 if (hasPendingActivity())
226 ThrottlingController::finishReader(getExecutionContext(), this, Throttli ngController::removeReader(getExecutionContext(), this)); 226 ThrottlingController::finishReader(getExecutionContext(), this, Throttli ngController::removeReader(getExecutionContext(), this));
227 terminate(); 227 terminate();
228 } 228 }
229 229
230 bool FileReader::hasPendingActivity() const 230 bool FileReader::hasPendingActivity() const
231 { 231 {
232 return m_state == LOADING || m_stillFiringEvents; 232 return m_state == kLoading || m_stillFiringEvents;
233 } 233 }
234 234
235 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) 235 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState)
236 { 236 {
237 ASSERT(blob); 237 ASSERT(blob);
238 DVLOG(1) << "reading as array buffer: " << utf8BlobUUID(blob).data() << " " << utf8FilePath(blob).data(); 238 DVLOG(1) << "reading as array buffer: " << utf8BlobUUID(blob).data() << " " << utf8FilePath(blob).data();
239 239
240 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState); 240 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState);
241 } 241 }
242 242
(...skipping 22 matching lines...) Expand all
265 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) 265 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState)
266 { 266 {
267 ASSERT(blob); 267 ASSERT(blob);
268 DVLOG(1) << "reading as data URL: " << utf8BlobUUID(blob).data() << " " << u tf8FilePath(blob).data(); 268 DVLOG(1) << "reading as data URL: " << utf8BlobUUID(blob).data() << " " << u tf8FilePath(blob).data();
269 269
270 readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); 270 readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState);
271 } 271 }
272 272
273 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep tionState& exceptionState) 273 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep tionState& exceptionState)
274 { 274 {
275 // If multiple concurrent read methods are called on the same FileReader, In validStateError should be thrown when the state is LOADING. 275 // If multiple concurrent read methods are called on the same FileReader, In validStateError should be thrown when the state is kLoading.
276 if (m_state == LOADING) { 276 if (m_state == kLoading) {
277 exceptionState.throwDOMException(InvalidStateError, "The object is alrea dy busy reading Blobs."); 277 exceptionState.throwDOMException(InvalidStateError, "The object is alrea dy busy reading Blobs.");
278 return; 278 return;
279 } 279 }
280 280
281 if (blob->isClosed()) { 281 if (blob->isClosed()) {
282 exceptionState.throwDOMException(InvalidStateError, String(blob->isFile( ) ? "File" : "Blob") + " has been closed."); 282 exceptionState.throwDOMException(InvalidStateError, String(blob->isFile( ) ? "File" : "Blob") + " has been closed.");
283 return; 283 return;
284 } 284 }
285 285
286 ExecutionContext* context = getExecutionContext(); 286 ExecutionContext* context = getExecutionContext();
287 if (!context) { 287 if (!context) {
288 exceptionState.throwDOMException(AbortError, "Reading from a detached Fi leReader is not supported."); 288 exceptionState.throwDOMException(AbortError, "Reading from a detached Fi leReader is not supported.");
289 return; 289 return;
290 } 290 }
291 291
292 // A document loader will not load new resources once the Document has detac hed from its frame. 292 // A document loader will not load new resources once the Document has detac hed from its frame.
293 if (context->isDocument() && !toDocument(context)->frame()) { 293 if (context->isDocument() && !toDocument(context)->frame()) {
294 exceptionState.throwDOMException(AbortError, "Reading from a Document-de tached FileReader is not supported."); 294 exceptionState.throwDOMException(AbortError, "Reading from a Document-de tached FileReader is not supported.");
295 return; 295 return;
296 } 296 }
297 297
298 // "Snapshot" the Blob data rather than the Blob itself as ongoing 298 // "Snapshot" the Blob data rather than the Blob itself as ongoing
299 // read operations should not be affected if close() is called on 299 // read operations should not be affected if close() is called on
300 // the Blob being read. 300 // the Blob being read.
301 m_blobDataHandle = blob->blobDataHandle(); 301 m_blobDataHandle = blob->blobDataHandle();
302 m_blobType = blob->type(); 302 m_blobType = blob->type();
303 m_readType = type; 303 m_readType = type;
304 m_state = LOADING; 304 m_state = kLoading;
305 m_loadingState = LoadingStatePending; 305 m_loadingState = LoadingStatePending;
306 m_error = nullptr; 306 m_error = nullptr;
307 ASSERT(ThrottlingController::from(context)); 307 ASSERT(ThrottlingController::from(context));
308 ThrottlingController::pushReader(context, this); 308 ThrottlingController::pushReader(context, this);
309 } 309 }
310 310
311 void FileReader::executePendingRead() 311 void FileReader::executePendingRead()
312 { 312 {
313 ASSERT(m_loadingState == LoadingStatePending); 313 ASSERT(m_loadingState == LoadingStatePending);
314 m_loadingState = LoadingStateLoading; 314 m_loadingState = LoadingStateLoading;
(...skipping 20 matching lines...) Expand all
335 } 335 }
336 m_loadingState = LoadingStateAborted; 336 m_loadingState = LoadingStateAborted;
337 337
338 // 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. 338 // 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.
339 getExecutionContext()->postTask( 339 getExecutionContext()->postTask(
340 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, wrapPersistent(this ))); 340 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, wrapPersistent(this )));
341 } 341 }
342 342
343 void FileReader::doAbort() 343 void FileReader::doAbort()
344 { 344 {
345 ASSERT(m_state != DONE); 345 DCHECK_NE(kDone, m_state);
346 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); 346 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
347 347
348 terminate(); 348 terminate();
349 349
350 m_error = FileError::createDOMException(FileError::ABORT_ERR); 350 m_error = FileError::createDOMException(FileError::kAbortErr);
351 351
352 // Unregister the reader. 352 // Unregister the reader.
353 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this); 353 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this);
354 354
355 fireEvent(EventTypeNames::error); 355 fireEvent(EventTypeNames::error);
356 fireEvent(EventTypeNames::abort); 356 fireEvent(EventTypeNames::abort);
357 fireEvent(EventTypeNames::loadend); 357 fireEvent(EventTypeNames::loadend);
358 358
359 // All possible events have fired and we're done, no more pending activity. 359 // All possible events have fired and we're done, no more pending activity.
360 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); 360 ThrottlingController::finishReader(getExecutionContext(), this, finalStep);
361 } 361 }
362 362
363 void FileReader::result(StringOrArrayBuffer& resultAttribute) const 363 void FileReader::result(StringOrArrayBuffer& resultAttribute) const
364 { 364 {
365 if (!m_loader || m_error) 365 if (!m_loader || m_error)
366 return; 366 return;
367 367
368 if (m_readType == FileReaderLoader::ReadAsArrayBuffer) 368 if (m_readType == FileReaderLoader::ReadAsArrayBuffer)
369 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult()); 369 resultAttribute.setArrayBuffer(m_loader->arrayBufferResult());
370 else 370 else
371 resultAttribute.setString(m_loader->stringResult()); 371 resultAttribute.setString(m_loader->stringResult());
372 } 372 }
373 373
374 void FileReader::terminate() 374 void FileReader::terminate()
375 { 375 {
376 if (m_loader) { 376 if (m_loader) {
377 m_loader->cancel(); 377 m_loader->cancel();
378 m_loader = nullptr; 378 m_loader = nullptr;
379 } 379 }
380 m_state = DONE; 380 m_state = kDone;
381 m_loadingState = LoadingStateNone; 381 m_loadingState = LoadingStateNone;
382 } 382 }
383 383
384 void FileReader::didStartLoading() 384 void FileReader::didStartLoading()
385 { 385 {
386 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); 386 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
387 fireEvent(EventTypeNames::loadstart); 387 fireEvent(EventTypeNames::loadstart);
388 } 388 }
389 389
390 void FileReader::didReceiveData() 390 void FileReader::didReceiveData()
(...skipping 22 matching lines...) Expand all
413 // the stack. 413 // the stack.
414 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); 414 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
415 415
416 // It's important that we change m_loadingState before firing any events 416 // It's important that we change m_loadingState before firing any events
417 // since any of the events could call abort(), which internally checks 417 // since any of the events could call abort(), which internally checks
418 // if we're still loading (therefore we need abort process) or not. 418 // if we're still loading (therefore we need abort process) or not.
419 m_loadingState = LoadingStateNone; 419 m_loadingState = LoadingStateNone;
420 420
421 fireEvent(EventTypeNames::progress); 421 fireEvent(EventTypeNames::progress);
422 422
423 ASSERT(m_state != DONE); 423 DCHECK_NE(kDone, m_state);
424 m_state = DONE; 424 m_state = kDone;
425 425
426 // Unregister the reader. 426 // Unregister the reader.
427 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this); 427 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this);
428 428
429 fireEvent(EventTypeNames::load); 429 fireEvent(EventTypeNames::load);
430 fireEvent(EventTypeNames::loadend); 430 fireEvent(EventTypeNames::loadend);
431 431
432 // All possible events have fired and we're done, no more pending activity. 432 // All possible events have fired and we're done, no more pending activity.
433 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); 433 ThrottlingController::finishReader(getExecutionContext(), this, finalStep);
434 } 434 }
435 435
436 void FileReader::didFail(FileError::ErrorCode errorCode) 436 void FileReader::didFail(FileError::ErrorCode errorCode)
437 { 437 {
438 if (m_loadingState == LoadingStateAborted) 438 if (m_loadingState == LoadingStateAborted)
439 return; 439 return;
440 440
441 AutoReset<bool> firingEvents(&m_stillFiringEvents, true); 441 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
442 442
443 ASSERT(m_loadingState == LoadingStateLoading); 443 DCHECK_EQ(LoadingStateLoading, m_loadingState);
444 m_loadingState = LoadingStateNone; 444 m_loadingState = LoadingStateNone;
445 445
446 ASSERT(m_state != DONE); 446 DCHECK_NE(kDone, m_state);
447 m_state = DONE; 447 m_state = kDone;
448 448
449 m_error = FileError::createDOMException(static_cast<FileError::ErrorCode>(er rorCode)); 449 m_error = FileError::createDOMException(static_cast<FileError::ErrorCode>(er rorCode));
450 450
451 // Unregister the reader. 451 // Unregister the reader.
452 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this); 452 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this);
453 453
454 fireEvent(EventTypeNames::error); 454 fireEvent(EventTypeNames::error);
455 fireEvent(EventTypeNames::loadend); 455 fireEvent(EventTypeNames::loadend);
456 456
457 // All possible events have fired and we're done, no more pending activity. 457 // All possible events have fired and we're done, no more pending activity.
(...skipping 15 matching lines...) Expand all
473 } 473 }
474 474
475 DEFINE_TRACE(FileReader) 475 DEFINE_TRACE(FileReader)
476 { 476 {
477 visitor->trace(m_error); 477 visitor->trace(m_error);
478 EventTargetWithInlineData::trace(visitor); 478 EventTargetWithInlineData::trace(visitor);
479 ActiveDOMObject::trace(visitor); 479 ActiveDOMObject::trace(visitor);
480 } 480 }
481 481
482 } // namespace blink 482 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReader.h ('k') | third_party/WebKit/Source/core/fileapi/FileReaderLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698