Bug 1411725 - have XHR responseURL use the final channel URL so the expected URLs for substituted protocols like web-extension: are returned; r=mayhemer
☠☠ backed out by bd6678635951 ☠ ☠
authorThomas Wisniewski <twisniewski@mozilla.com>
Thu, 21 Mar 2019 23:43:52 +0000
changeset 465564 5dc08ac77984b6ccf679aebada2f59b16acc3d2d
parent 465563 9fa430d66dab280abe459d16c728708e0d2edf52
child 465565 5ef6c41911e53e0d24ec6fad6aa81c235cdff800
push id35744
push userapavel@mozilla.com
push dateFri, 22 Mar 2019 16:44:08 +0000
treeherdermozilla-central@e66a2b59914d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1411725
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1411725 - have XHR responseURL use the final channel URL so the expected URLs for substituted protocols like web-extension: are returned; r=mayhemer have XHR responseURL use the final channel URL so the expected URLs for substituted protocols like web-extension: are returned Differential Revision: https://phabricator.services.mozilla.com/D23811
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/tests/browser.ini
dom/xhr/tests/browser_xhr_substituted_protocol_responseURL.js
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -776,19 +776,17 @@ void XMLHttpRequestMainThread::GetRespon
 
   // Make sure we don't leak responseURL information from denied cross-site
   // requests.
   if (IsDeniedCrossSiteCORSRequest()) {
     return;
   }
 
   nsCOMPtr<nsIURI> responseUrl;
-  mChannel->GetURI(getter_AddRefs(responseUrl));
-
-  if (!responseUrl) {
+  if (NS_FAILED(NS_GetFinalChannelURI(mChannel, getter_AddRefs(responseUrl)))) {
     return;
   }
 
   nsAutoCString temp;
   responseUrl->GetSpecIgnoringRef(temp);
   CopyUTF8toUTF16(temp, aUrl);
 }
 
--- a/dom/xhr/tests/browser.ini
+++ b/dom/xhr/tests/browser.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 support-files =
   browser_xhr_onchange_leak.html
 [browser_blobFromFile.js]
 [browser_xhr_onchange_leak.js]
+[browser_xhr_substituted_protocol_responseURL.js]
 [browser_temporaryFile.js]
 support-files =  temporaryFileBlob.sjs
new file mode 100644
--- /dev/null
+++ b/dom/xhr/tests/browser_xhr_substituted_protocol_responseURL.js
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// Bug 1411725 - An XHR using a SubstitutingProtocolHandler channel
+// (web-extension:, resource:, etc) should return the original URL,
+// not the jar/file it was actually substituted for.
+
+const TEST_URL = "resource://gre/modules/XPCOMUtils.jsm";
+
+add_task(async function test() {
+  await new Promise(resolve => {
+    const xhr = new XMLHttpRequest();
+    xhr.responseType = "text";
+    xhr.open("get", TEST_URL);
+    xhr.addEventListener("loadend", () => {
+      is(xhr.responseURL, TEST_URL, "original URL is given instead of substitution");
+      resolve();
+    });
+    xhr.send();
+  });
+});