diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp index e0f7adfd0468..5539991ef225 100644 --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -2633,12 +2633,6 @@ nsXMLHttpRequest::Send(nsIVariant *aBody) return rv; } - // Now that we've successfully opened the channel, we can change state. Note - // that this needs to come after the AsyncOpen() and rv check, because this - // can run script that would try to restart this request, and that could end - // up doing our AsyncOpen on a null channel if the reentered AsyncOpen fails. - ChangeState(XML_HTTP_REQUEST_SENT); - // If we're synchronous, spin an event loop here and wait if (!(mState & XML_HTTP_REQUEST_ASYNC)) { mState |= XML_HTTP_REQUEST_SYNCLOOPING; @@ -2661,6 +2655,9 @@ nsXMLHttpRequest::Send(nsIVariant *aBody) } } + ChangeState(XML_HTTP_REQUEST_SENT); + // Note, calling ChangeState may have cleared + // XML_HTTP_REQUEST_SYNCLOOPING flag. nsIThread *thread = NS_GetCurrentThread(); while (mState & XML_HTTP_REQUEST_SYNCLOOPING) { if (!NS_ProcessNextEvent(thread)) { @@ -2677,6 +2674,11 @@ nsXMLHttpRequest::Send(nsIVariant *aBody) NS_DispatchToCurrentThread(resumeTimeoutRunnable); } } else { + // Now that we've successfully opened the channel, we can change state. Note + // that this needs to come after the AsyncOpen() and rv check, because this + // can run script that would try to restart this request, and that could end + // up doing our AsyncOpen on a null channel if the reentered AsyncOpen fails. + ChangeState(XML_HTTP_REQUEST_SENT); if (!mUploadComplete && HasListenersFor(NS_LITERAL_STRING(UPLOADPROGRESS_STR)) || (mUpload && mUpload->HasListenersFor(NS_LITERAL_STRING(PROGRESS_STR)))) { @@ -2993,9 +2995,11 @@ nsXMLHttpRequest::ChangeState(PRUint32 aState, PRBool aBroadcast) mProgressNotifier->Cancel(); } - if ((mState & XML_HTTP_REQUEST_ASYNC) && - (aState & XML_HTTP_REQUEST_LOADSTATES) && // Broadcast load states only - aBroadcast) { + if ((aState & XML_HTTP_REQUEST_LOADSTATES) && // Broadcast load states only + aBroadcast && + (mState & XML_HTTP_REQUEST_ASYNC || + aState & XML_HTTP_REQUEST_OPENED || + aState & XML_HTTP_REQUEST_COMPLETED)) { nsCOMPtr event; rv = CreateReadystatechangeEvent(getter_AddRefs(event)); NS_ENSURE_SUCCESS(rv, rv); diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in index 8a1b90aa9f52..94bb68493ff4 100644 --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -310,6 +310,8 @@ _TEST_FILES2 = \ file_xhtmlserializer_2_latin1.xhtml \ test_bug500937.html \ test_htmlcopyencoder.html \ + test_bug313646.html \ + bug313646.txt \ test_htmlcopyencoder.xhtml \ test_bug270145.xhtml \ test_elementTraversal.html \ diff --git a/content/base/test/bug313646.txt b/content/base/test/bug313646.txt new file mode 100644 index 000000000000..150f5ea6d1de --- /dev/null +++ b/content/base/test/bug313646.txt @@ -0,0 +1 @@ +Nothing to see here. Just need to request this file via XHR. diff --git a/content/base/test/test_bug313646.html b/content/base/test/test_bug313646.html new file mode 100644 index 000000000000..8e9cd4bd44e1 --- /dev/null +++ b/content/base/test/test_bug313646.html @@ -0,0 +1,63 @@ + + + + + Test for Bug 313646 + + + + + +Mozilla Bug 313646 +

+ +
+
+
+ +