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

Side by Side Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 75103006: Factor out delivery of throttled progress event. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 947 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 void XMLHttpRequest::dispatchEventAndLoadEnd(const AtomicString& type) 958 void XMLHttpRequest::dispatchEventAndLoadEnd(const AtomicString& type)
959 { 959 {
960 if (!m_uploadComplete) { 960 if (!m_uploadComplete) {
961 m_uploadComplete = true; 961 m_uploadComplete = true;
962 if (m_upload && m_uploadEventsAllowed) 962 if (m_upload && m_uploadEventsAllowed)
963 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(type)); 963 m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::creat e(type));
964 } 964 }
965 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(type)); 965 m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent: :create(type));
966 } 966 }
967 967
968 void XMLHttpRequest::dispatchThrottledProgressEvent()
969 {
970 long long expectedLength = m_response.expectedContentLength();
971 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLe ngth;
972 unsigned long long total = lengthComputable ? expectedLength : 0;
973
974 m_progressEventThrottle.dispatchProgressEvent(lengthComputable, m_receivedLe ngth, total);
975 }
976
968 void XMLHttpRequest::handleNetworkError() 977 void XMLHttpRequest::handleNetworkError()
969 { 978 {
970 LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); 979 LOG(Network, "XMLHttpRequest %p handleNetworkError()", this);
971 980
972 m_exceptionCode = NetworkError; 981 m_exceptionCode = NetworkError;
973 982
974 handleDidFailGeneric(); 983 handleDidFailGeneric();
975 984
976 if (m_async) { 985 if (m_async) {
977 changeState(DONE); 986 changeState(DONE);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 if (!m_responseStream) 1300 if (!m_responseStream)
1292 m_responseStream = Stream::create(executionContext(), responseMIMETy pe()); 1301 m_responseStream = Stream::create(executionContext(), responseMIMETy pe());
1293 m_responseStream->addData(data, len); 1302 m_responseStream->addData(data, len);
1294 } 1303 }
1295 1304
1296 if (m_error) 1305 if (m_error)
1297 return; 1306 return;
1298 1307
1299 m_receivedLength += len; 1308 m_receivedLength += len;
1300 1309
1301 if (m_async) { 1310 if (m_async)
1302 long long expectedLength = m_response.expectedContentLength(); 1311 dispatchThrottledProgressEvent();
1303 bool lengthComputable = expectedLength > 0 && m_receivedLength <= expect edLength;
1304 unsigned long long total = lengthComputable ? expectedLength : 0;
1305
1306 m_progressEventThrottle.dispatchProgressEvent(lengthComputable, m_receiv edLength, total);
1307 }
1308 1312
1309 if (m_state != LOADING) { 1313 if (m_state != LOADING) {
1310 changeState(LOADING); 1314 changeState(LOADING);
1311 } else { 1315 } else {
1312 // Firefox calls readyStateChanged every time it receives data. Do 1316 // Firefox calls readyStateChanged every time it receives data. Do
1313 // the same to align with Firefox. 1317 // the same to align with Firefox.
1314 // 1318 //
1315 // FIXME: Make our implementation and the spec consistent. This 1319 // FIXME: Make our implementation and the spec consistent. This
1316 // behavior was needed when the progress event was not available. 1320 // behavior was needed when the progress event was not available.
1317 dispatchReadyStateChangeEvent(); 1321 dispatchReadyStateChangeEvent();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 { 1370 {
1367 return EventTargetNames::XMLHttpRequest; 1371 return EventTargetNames::XMLHttpRequest;
1368 } 1372 }
1369 1373
1370 ExecutionContext* XMLHttpRequest::executionContext() const 1374 ExecutionContext* XMLHttpRequest::executionContext() const
1371 { 1375 {
1372 return ActiveDOMObject::executionContext(); 1376 return ActiveDOMObject::executionContext();
1373 } 1377 }
1374 1378
1375 } // namespace WebCore 1379 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698