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

Side by Side Diff: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 1455513002: [XHR] Decrease readyStateChange event dispatching during loading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years 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) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 { 481 {
482 if (!m_upload) 482 if (!m_upload)
483 m_upload = XMLHttpRequestUpload::create(this); 483 m_upload = XMLHttpRequestUpload::create(this);
484 return m_upload.get(); 484 return m_upload.get();
485 } 485 }
486 486
487 void XMLHttpRequest::trackProgress(long long length) 487 void XMLHttpRequest::trackProgress(long long length)
488 { 488 {
489 m_receivedLength += length; 489 m_receivedLength += length;
490 490
491 if (m_state != LOADING) { 491 changeState(LOADING);
492 changeState(LOADING); 492 if (m_async) {
493 } else { 493 // readyStateChange event is fired as well.
494 // Dispatch a readystatechange event because many applications use 494 dispatchProgressEventFromSnapshot(EventTypeNames::progress);
495 // it to track progress although this is not specified.
496 //
497 // FIXME: Stop dispatching this event for progress tracking.
498 dispatchReadyStateChangeEvent();
499 } 495 }
500 if (m_async)
501 dispatchProgressEventFromSnapshot(EventTypeNames::progress);
502 } 496 }
503 497
504 void XMLHttpRequest::changeState(State newState) 498 void XMLHttpRequest::changeState(State newState)
505 { 499 {
506 if (m_state != newState) { 500 if (m_state != newState) {
507 m_state = newState; 501 m_state = newState;
508 dispatchReadyStateChangeEvent(); 502 dispatchReadyStateChangeEvent();
509 } 503 }
510 } 504 }
511 505
512 void XMLHttpRequest::dispatchReadyStateChangeEvent() 506 void XMLHttpRequest::dispatchReadyStateChangeEvent()
513 { 507 {
514 if (!executionContext()) 508 if (!executionContext())
515 return; 509 return;
516 510
517 // We need this protection because dispatchReadyStateChangeEvent may
518 // dispatch multiple events.
519 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 511 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
520 if (m_async || (m_state <= OPENED || m_state == DONE)) { 512 if (m_async || (m_state <= OPENED || m_state == DONE)) {
521 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(executionContext(), this)); 513 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(executionContext(), this));
522 XMLHttpRequestProgressEventThrottle::DeferredEventAction action = XMLHtt pRequestProgressEventThrottle::Ignore; 514 XMLHttpRequestProgressEventThrottle::DeferredEventAction action = XMLHtt pRequestProgressEventThrottle::Ignore;
523 if (m_state == DONE) { 515 if (m_state == DONE) {
524 if (m_error) 516 if (m_error)
525 action = XMLHttpRequestProgressEventThrottle::Clear; 517 action = XMLHttpRequestProgressEventThrottle::Clear;
526 else 518 else
527 action = XMLHttpRequestProgressEventThrottle::Flush; 519 action = XMLHttpRequestProgressEventThrottle::Flush;
528 } 520 }
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1716 visitor->trace(m_responseDocumentParser); 1708 visitor->trace(m_responseDocumentParser);
1717 visitor->trace(m_progressEventThrottle); 1709 visitor->trace(m_progressEventThrottle);
1718 visitor->trace(m_upload); 1710 visitor->trace(m_upload);
1719 visitor->trace(m_blobLoader); 1711 visitor->trace(m_blobLoader);
1720 XMLHttpRequestEventTarget::trace(visitor); 1712 XMLHttpRequestEventTarget::trace(visitor);
1721 DocumentParserClient::trace(visitor); 1713 DocumentParserClient::trace(visitor);
1722 ActiveDOMObject::trace(visitor); 1714 ActiveDOMObject::trace(visitor);
1723 } 1715 }
1724 1716
1725 } // namespace blink 1717 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698