Bug 1411725 - have XHR responseURL use the final channel URL so the expected URLs for substituted protocols like web-extension: are returned; r=mayhemer
authorThomas Wisniewski <twisniewski@mozilla.com>
Sun, 31 Mar 2019 01:31:12 +0000
changeset 466960 9b129ff965d75b364c9bdb4d737542cb4d1c40d1
parent 466959 6b173cb60b92471a6d04361de084fc4328e14af9
child 466998 c06dfc552c647a6ce96f35cd84c32a589dc85608
child 466999 ff52b92809090ffb61272e0f7474226e271c1211
push id35788
push userbtara@mozilla.com
push dateSun, 31 Mar 2019 08:58:22 +0000
treeherdermozilla-central@9b129ff965d7 [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
@@ -778,19 +778,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();
+  });
+});