# HG changeset patch # User xKhorasan # Date 1369483986 -32400 # Node ID d5b4ef5d5d2936ce0118c78dd95baba11ca42600 # Parent 8ca260fe91e31a2b19d5ed90079db3a4d71d1c82 Bug 859095: set proper documentURI and baseURI for cross origin loaded XHR documents diff --git a/content/base/src/nsXMLHttpRequest.cpp b/content/base/src/nsXMLHttpRequest.cpp --- a/content/base/src/nsXMLHttpRequest.cpp +++ b/content/base/src/nsXMLHttpRequest.cpp @@ -2005,25 +2005,19 @@ nsXMLHttpRequest::OnStartRequest(nsIRequ } } else { // The request failed, so we shouldn't be parsing anyway mState &= ~XML_HTTP_REQUEST_PARSEBODY; } if (mState & XML_HTTP_REQUEST_PARSEBODY) { nsCOMPtr baseURI, docURI; - nsIScriptContext* sc = GetContextForEventHandlers(&rv); + rv = mChannel->GetURI(getter_AddRefs(docURI)); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr doc = - nsContentUtils::GetDocumentFromScriptContext(sc); - - if (doc) { - docURI = doc->GetDocumentURI(); - baseURI = doc->GetBaseURI(); - } + baseURI = docURI; // Create an empty document from it. Here we have to cheat a little bit... // Setting the base URI to |baseURI| won't work if the document has a null // principal, so use mPrincipal when creating the document, then reset the // principal. const nsAString& emptyStr = EmptyString(); nsCOMPtr responseDoc; nsIGlobalObject* global = nsDOMEventTargetHelper::GetParentObject(); diff --git a/content/base/test/Makefile.in b/content/base/test/Makefile.in --- a/content/base/test/Makefile.in +++ b/content/base/test/Makefile.in @@ -222,16 +222,18 @@ MOCHITEST_FILES_A = \ file_CrossSiteXHR_server.sjs \ test_CrossSiteXHR_cache.html \ file_CrossSiteXHR_cache_server.sjs \ test_XHRDocURI.html \ file_XHRDocURI.xml \ file_XHRDocURI.xml^headers^ \ file_XHRDocURI.text \ file_XHRDocURI.text^headers^ \ + file_XHRDocURI_redirect.html \ + file_XHRDocURI_redirect.html^headers^ \ test_DOMException.html \ test_domparsing.html \ test_meta_viewport0.html \ test_meta_viewport1.html \ test_meta_viewport2.html \ test_meta_viewport3.html \ test_meta_viewport4.html \ test_meta_viewport5.html \ diff --git a/content/base/test/file_XHRDocURI_redirect.html b/content/base/test/file_XHRDocURI_redirect.html new file mode 100644 --- /dev/null +++ b/content/base/test/file_XHRDocURI_redirect.html @@ -0,0 +1,13 @@ + + + + + + XMLHttpRequest return document URIs for cross origin redirect + + +

redirect to http://example.com/tests/content/base/test/file_XHRDocURI.xml

+ + diff --git a/content/base/test/file_XHRDocURI_redirect.html^headers^ b/content/base/test/file_XHRDocURI_redirect.html^headers^ new file mode 100644 --- /dev/null +++ b/content/base/test/file_XHRDocURI_redirect.html^headers^ @@ -0,0 +1,2 @@ +HTTP 302 Found +Location: http://example.com/tests/content/base/test/file_XHRDocURI.xml diff --git a/content/base/test/test_XHRDocURI.html b/content/base/test/test_XHRDocURI.html --- a/content/base/test/test_XHRDocURI.html +++ b/content/base/test/test_XHRDocURI.html @@ -1,22 +1,24 @@ XMLHttpRequest return document URIs Mozilla Bug 459470 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=459470">Mozilla Bug 459470
+Mozilla Bug 859095