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

Unified Diff: Source/core/xml/XMLHttpRequest.cpp

Issue 24225002: Don't dispatch events when XHR is set to sync mode (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Revert change on network-preflight-options.html Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/xml/XMLHttpRequest.cpp
diff --git a/Source/core/xml/XMLHttpRequest.cpp b/Source/core/xml/XMLHttpRequest.cpp
index 4b041d4ec7e998a3f5e89b9c8366a8f3dc2c5a54..64d947a8482c5d52788ae5f955b181dee4b86a36 100644
--- a/Source/core/xml/XMLHttpRequest.cpp
+++ b/Source/core/xml/XMLHttpRequest.cpp
@@ -890,36 +890,53 @@ void XMLHttpRequest::clearRequest()
m_requestEntityBody = 0;
}
-void XMLHttpRequest::genericError()
+void XMLHttpRequest::handleDidFailGeneric()
{
clearResponse();
clearRequest();
- m_error = true;
- changeState(DONE);
+ m_error = true;
}
-void XMLHttpRequest::networkError()
+void XMLHttpRequest::dispatchEventAndLoadEnd(const AtomicString& type)
{
- genericError();
if (!m_uploadComplete) {
m_uploadComplete = true;
if (m_upload && m_uploadEventsAllowed)
- m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().errorEvent));
+ m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(type));
+ }
+ m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(type));
+}
+
+void XMLHttpRequest::handleNetworkError()
+{
+ m_exceptionCode = NetworkError;
+
+ handleDidFailGeneric();
+
+ if (m_async) {
+ changeState(DONE);
+ dispatchEventAndLoadEnd(eventNames().errorEvent);
+ } else {
+ m_state = DONE;
}
- m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().errorEvent));
+
internalAbort();
}
-void XMLHttpRequest::abortError()
+void XMLHttpRequest::handleDidCancel()
{
- genericError();
- if (!m_uploadComplete) {
- m_uploadComplete = true;
- if (m_upload && m_uploadEventsAllowed)
- m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent));
+ m_exceptionCode = AbortError;
+
+ handleDidFailGeneric();
+
+ if (!m_async) {
+ m_state = DONE;
+ return;
}
- m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().abortEvent));
+ changeState(DONE);
+
+ dispatchEventAndLoadEnd(eventNames().abortEvent);
}
void XMLHttpRequest::dropProtectionSoon()
@@ -1087,19 +1104,17 @@ String XMLHttpRequest::statusText(ExceptionState& es) const
void XMLHttpRequest::didFail(const ResourceError& error)
{
-
// If we are already in an error state, for instance we called abort(), bail out early.
if (m_error)
return;
if (error.isCancellation()) {
- m_exceptionCode = AbortError;
- abortError();
+ handleDidCancel();
return;
}
if (error.isTimeout()) {
- didTimeout();
+ handleDidTimeout();
return;
}
@@ -1107,13 +1122,12 @@ void XMLHttpRequest::didFail(const ResourceError& error)
if (error.domain() == errorDomainWebKitInternal)
logConsoleError(scriptExecutionContext(), "XMLHttpRequest cannot load " + error.failingURL() + ". " + error.localizedDescription());
- m_exceptionCode = NetworkError;
- networkError();
+ handleNetworkError();
}
void XMLHttpRequest::didFailRedirectCheck()
{
- networkError();
+ handleNetworkError();
}
void XMLHttpRequest::didFinishLoading(unsigned long identifier, double)
@@ -1237,32 +1251,23 @@ void XMLHttpRequest::didReceiveData(const char* data, int len)
}
}
-void XMLHttpRequest::didTimeout()
+void XMLHttpRequest::handleDidTimeout()
{
// internalAbort() calls dropProtection(), which may release the last reference.
RefPtr<XMLHttpRequest> protect(this);
internalAbort();
- clearResponse();
- clearRequest();
-
- m_error = true;
m_exceptionCode = TimeoutError;
+ handleDidFailGeneric();
+
if (!m_async) {
m_state = DONE;
- m_exceptionCode = TimeoutError;
return;
}
-
changeState(DONE);
- if (!m_uploadComplete) {
- m_uploadComplete = true;
- if (m_upload && m_uploadEventsAllowed)
- m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent));
- }
- m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent));
+ dispatchEventAndLoadEnd(eventNames().timeoutEvent);
}
bool XMLHttpRequest::canSuspend() const
« 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