summaryrefslogtreecommitdiffstats
path: root/devtools/shared/DevToolsUtils.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 05:35:29 +0000
commit59203c63bb777a3bacec32fb8830fba33540e809 (patch)
tree58298e711c0ff0575818c30485b44a2f21bf28a0 /devtools/shared/DevToolsUtils.js
parentAdding upstream version 126.0.1. (diff)
downloadfirefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz
firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/DevToolsUtils.js')
-rw-r--r--devtools/shared/DevToolsUtils.js38
1 files changed, 15 insertions, 23 deletions
diff --git a/devtools/shared/DevToolsUtils.js b/devtools/shared/DevToolsUtils.js
index 9a38e4eed5..b5b6f7ddb3 100644
--- a/devtools/shared/DevToolsUtils.js
+++ b/devtools/shared/DevToolsUtils.js
@@ -730,11 +730,7 @@ function mainThreadFetch(
* @param {Object} options - The options object passed to @method fetch.
* @return {nsIChannel} - The newly created channel. Throws on failure.
*/
-function newChannelForURL(
- url,
- { policy, window, principal },
- recursing = false
-) {
+function newChannelForURL(url, { policy, window, principal }) {
const securityFlags =
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL;
@@ -747,6 +743,19 @@ function newChannelForURL(
// scheme to see if it helps.
uri = Services.io.newURI("file://" + url);
}
+
+ // In xpcshell tests on Windows, opening the channel
+ // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't
+ // supported by Windows, so we also need to handle that case here if
+ // parsing the URL above doesn't throw.
+ const handler = Services.io.getProtocolHandler(uri.scheme);
+ if (
+ handler instanceof Ci.nsIExternalProtocolHandler &&
+ !handler.externalAppExistsForScheme(uri.scheme)
+ ) {
+ uri = Services.io.newURI("file://" + url);
+ }
+
const channelOptions = {
contentPolicyType: policy,
securityFlags,
@@ -778,24 +787,7 @@ function newChannelForURL(
channelOptions.loadingPrincipal = prin;
}
- try {
- return NetUtil.newChannel(channelOptions);
- } catch (e) {
- // Don't infinitely recurse if newChannel keeps throwing.
- if (recursing) {
- throw e;
- }
-
- // In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel()
- // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't
- // supported by Windows, so we also need to handle the exception here if
- // parsing the URL above doesn't throw.
- return newChannelForURL(
- "file://" + url,
- { policy, window, principal },
- /* recursing */ true
- );
- }
+ return NetUtil.newChannel(channelOptions);
}
// Fetch is defined differently depending on whether we are on the main thread