Unreviewed, rolling out r243551.
[WebKit-https.git] / Source / WebCore / xml / XMLHttpRequest.cpp
index d868ddf..0af9244 100644 (file)
@@ -626,7 +626,7 @@ ExceptionOr<void> XMLHttpRequest::createRequest()
     if (m_async) {
         m_progressEventThrottle.dispatchProgressEvent(eventNames().loadstartEvent);
         if (!m_uploadComplete && m_uploadListenerFlag)
-            m_upload->dispatchProgressEvent(eventNames().loadstartEvent, 0, request.httpBody()->lengthInBytes());
+            m_upload->dispatchProgressEvent(eventNames().loadstartEvent);
 
         if (readyState() != OPENED || !m_sendFlag || m_loader)
             return { };
@@ -714,7 +714,6 @@ bool XMLHttpRequest::internalAbort()
 void XMLHttpRequest::clearResponse()
 {
     m_response = ResourceResponse();
-    m_didReceiveResponseHandler = nullptr;
     clearResponseBuffers();
 }
 
@@ -946,22 +945,14 @@ void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
     if (!m_upload)
         return;
 
-    if (m_response.isNull()) {
-        // We should not notify of progress until we've received a response from the server.
-        m_didReceiveResponseHandler = [this, bytesSent, totalBytesToBeSent] {
-            didSendData(bytesSent, totalBytesToBeSent);
-        };
-        return;
-    }
-
     if (m_uploadListenerFlag)
-        m_upload->dispatchProgressEvent(eventNames().progressEvent, bytesSent, totalBytesToBeSent);
+        m_upload->dispatchThrottledProgressEvent(true, bytesSent, totalBytesToBeSent);
 
     if (bytesSent == totalBytesToBeSent && !m_uploadComplete) {
         m_uploadComplete = true;
         if (m_uploadListenerFlag) {
-            m_upload->dispatchProgressEvent(eventNames().loadEvent, bytesSent, totalBytesToBeSent);
-            m_upload->dispatchProgressEvent(eventNames().loadendEvent, bytesSent, totalBytesToBeSent);
+            m_upload->dispatchProgressEvent(eventNames().loadEvent);
+            m_upload->dispatchProgressEvent(eventNames().loadendEvent);
         }
     }
 }
@@ -969,8 +960,6 @@ void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon
 void XMLHttpRequest::didReceiveResponse(unsigned long, const ResourceResponse& response)
 {
     m_response = response;
-    if (auto didReceiveResponseHandler = WTFMove(m_didReceiveResponseHandler))
-        didReceiveResponseHandler();
 }
 
 static inline bool shouldDecodeResponse(XMLHttpRequest::ResponseType type)
@@ -1058,19 +1047,18 @@ void XMLHttpRequest::didReceiveData(const char* data, int len)
     if (!m_error) {
         m_receivedLength += len;
 
-        if (readyState() != LOADING)
-            changeState(LOADING);
-        else {
-            // Firefox calls readyStateChanged every time it receives data, 4449442
-            callReadyStateChangeListener();
-        }
-
         if (m_async) {
             long long expectedLength = m_response.expectedContentLength();
             bool lengthComputable = expectedLength > 0 && m_receivedLength <= expectedLength;
             unsigned long long total = lengthComputable ? expectedLength : 0;
             m_progressEventThrottle.dispatchThrottledProgressEvent(lengthComputable, m_receivedLength, total);
         }
+
+        if (readyState() != LOADING)
+            changeState(LOADING);
+        else
+            // Firefox calls readyStateChanged every time it receives data, 4449442
+            callReadyStateChangeListener();
     }
 }
 
@@ -1079,8 +1067,8 @@ void XMLHttpRequest::dispatchErrorEvents(const AtomicString& type)
     if (!m_uploadComplete) {
         m_uploadComplete = true;
         if (m_upload && m_uploadListenerFlag) {
-            m_upload->dispatchProgressEvent(type, 0, 0);
-            m_upload->dispatchProgressEvent(eventNames().loadendEvent, 0, 0);
+            m_upload->dispatchProgressEvent(type);
+            m_upload->dispatchProgressEvent(eventNames().loadendEvent);
         }
     }
     m_progressEventThrottle.dispatchProgressEvent(type);