forked from mirrors/gecko-dev
Bug 1883693 - Fix devtools expectation that newChannel throws for unsupported external handlers r=nika,devtools-reviewers,ochameau
Depends on D205296 Differential Revision: https://phabricator.services.mozilla.com/D206754
This commit is contained in:
parent
b74a2369f2
commit
a79b4fefa9
1 changed files with 15 additions and 23 deletions
|
|
@ -730,11 +730,7 @@ function mainThreadFetch(
|
||||||
* @param {Object} options - The options object passed to @method fetch.
|
* @param {Object} options - The options object passed to @method fetch.
|
||||||
* @return {nsIChannel} - The newly created channel. Throws on failure.
|
* @return {nsIChannel} - The newly created channel. Throws on failure.
|
||||||
*/
|
*/
|
||||||
function newChannelForURL(
|
function newChannelForURL(url, { policy, window, principal }) {
|
||||||
url,
|
|
||||||
{ policy, window, principal },
|
|
||||||
recursing = false
|
|
||||||
) {
|
|
||||||
const securityFlags =
|
const securityFlags =
|
||||||
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL;
|
Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL;
|
||||||
|
|
||||||
|
|
@ -747,6 +743,19 @@ function newChannelForURL(
|
||||||
// scheme to see if it helps.
|
// scheme to see if it helps.
|
||||||
uri = Services.io.newURI("file://" + url);
|
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 = {
|
const channelOptions = {
|
||||||
contentPolicyType: policy,
|
contentPolicyType: policy,
|
||||||
securityFlags,
|
securityFlags,
|
||||||
|
|
@ -778,24 +787,7 @@ function newChannelForURL(
|
||||||
channelOptions.loadingPrincipal = prin;
|
channelOptions.loadingPrincipal = prin;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
return NetUtil.newChannel(channelOptions);
|
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch is defined differently depending on whether we are on the main thread
|
// Fetch is defined differently depending on whether we are on the main thread
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue