@@ -730,11 +730,7 @@ function mainThreadFetch(
730
730
* @param {Object } options - The options object passed to @method fetch.
731
731
* @return {nsIChannel } - The newly created channel. Throws on failure.
732
732
*/
733
- function newChannelForURL (
734
- url ,
735
- { policy, window, principal } ,
736
- recursing = false
737
- ) {
733
+ function newChannelForURL ( url , { policy, window, principal } ) {
738
734
const securityFlags =
739
735
Ci . nsILoadInfo . SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL ;
740
736
@@ -778,24 +774,19 @@ function newChannelForURL(
778
774
channelOptions . loadingPrincipal = prin ;
779
775
}
780
776
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 ) ;
798
787
}
788
+
789
+ return NetUtil . newChannel ( channelOptions ) ;
799
790
}
800
791
801
792
// Fetch is defined differently depending on whether we are on the main thread
0 commit comments