Skip to content

Commit a02a205

Browse files
committedApr 28, 2024
Bug 1883693 - Fix devtools expectation that newChannel throws for unsupported external handlers r=nika,devtools-reviewers,ochameau
Differential Revision: https://phabricator.services.mozilla.com/D206754
1 parent 1eec464 commit a02a205

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed
 

‎devtools/shared/DevToolsUtils.js

+13-22
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,7 @@ function mainThreadFetch(
730730
* @param {Object} options - The options object passed to @method fetch.
731731
* @return {nsIChannel} - The newly created channel. Throws on failure.
732732
*/
733-
function newChannelForURL(
734-
url,
735-
{ policy, window, principal },
736-
recursing = false
737-
) {
733+
function newChannelForURL(url, { policy, window, principal }) {
738734
const securityFlags =
739735
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL;
740736

@@ -778,24 +774,19 @@ function newChannelForURL(
778774
channelOptions.loadingPrincipal = prin;
779775
}
780776

781-
try {
782-
return NetUtil.newChannel(channelOptions);
783-
} catch (e) {
784-
// Don't infinitely recurse if newChannel keeps throwing.
785-
if (recursing) {
786-
throw e;
787-
}
788-
789-
// In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel()
790-
// can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't
791-
// supported by Windows, so we also need to handle the exception here if
792-
// parsing the URL above doesn't throw.
793-
return newChannelForURL(
794-
"file://" + url,
795-
{ policy, window, principal },
796-
/* recursing */ true
797-
);
777+
// In xpcshell tests on Windows, opening the channel
778+
// can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't
779+
// supported by Windows, so we also need to handle that case here if
780+
// parsing the URL above doesn't throw.
781+
const handler = Services.io.getProtocolHandler(uri.scheme);
782+
if (
783+
handler instanceof Ci.nsIExternalProtocolHandler &&
784+
!handler.externalAppExistsForScheme(uri.scheme)
785+
) {
786+
uri = Services.io.newURI("file://" + url);
798787
}
788+
789+
return NetUtil.newChannel(channelOptions);
799790
}
800791

801792
// Fetch is defined differently depending on whether we are on the main thread

0 commit comments

Comments
 (0)
Failed to load comments.