@@ -43,26 +43,37 @@ self.close = () => console.trace(`'close' has been blocked`);
4343const nativePostMessage = postMessage . bind ( self ) ;
4444self . postMessage = ( ) => console . trace ( `'postMessage' has been blocked` ) ;
4545
46+ function shouldTransformUri ( uri : string ) : boolean {
47+ // In principle, we could convert any URI, but we have concerns
48+ // that parsing https URIs might end up decoding escape characters
49+ // and result in an unintended transformation
50+ return / ^ ( f i l e | v s c o d e - r e m o t e ) : / i. test ( uri ) ;
51+ }
52+
4653const nativeFetch = fetch . bind ( self ) ;
47- self . fetch = function ( input , init ) {
48- if ( input instanceof Request ) {
49- // Request object - massage not supported
54+ function patchFetching ( asBrowserUri : ( uri : URI ) => Promise < URI > ) {
55+ self . fetch = async function ( input , init ) {
56+ if ( input instanceof Request ) {
57+ // Request object - massage not supported
58+ return nativeFetch ( input , init ) ;
59+ }
60+ if ( shouldTransformUri ( String ( input ) ) ) {
61+ input = ( await asBrowserUri ( URI . parse ( String ( input ) ) ) ) . toString ( true ) ;
62+ }
5063 return nativeFetch ( input , init ) ;
51- }
52- if ( / ^ f i l e : / i. test ( String ( input ) ) ) {
53- input = FileAccess . asBrowserUri ( URI . parse ( String ( input ) ) ) . toString ( true ) ;
54- }
55- return nativeFetch ( input , init ) ;
56- } ;
64+ } ;
5765
58- self . XMLHttpRequest = class extends XMLHttpRequest {
59- override open ( method : string , url : string | URL , async ?: boolean , username ?: string | null , password ?: string | null ) : void {
60- if ( / ^ f i l e : / i. test ( url . toString ( ) ) ) {
61- url = FileAccess . asBrowserUri ( URI . parse ( url . toString ( ) ) ) . toString ( true ) ;
66+ self . XMLHttpRequest = class extends XMLHttpRequest {
67+ override open ( method : string , url : string | URL , async ?: boolean , username ?: string | null , password ?: string | null ) : void {
68+ ( async ( ) => {
69+ if ( shouldTransformUri ( url . toString ( ) ) ) {
70+ url = ( await asBrowserUri ( URI . parse ( url . toString ( ) ) ) ) . toString ( true ) ;
71+ }
72+ super . open ( method , url , async ?? true , username , password ) ;
73+ } ) ( ) ;
6274 }
63- return super . open ( method , url , async ?? true , username , password ) ;
64- }
65- } ;
75+ } ;
76+ }
6677
6778self . importScripts = ( ) => { throw new Error ( `'importScripts' has been blocked` ) ; } ;
6879
@@ -85,6 +96,11 @@ if ((<any>self).Worker) {
8596 Worker = < any > function ( stringUrl : string | URL , options ?: WorkerOptions ) {
8697 if ( / ^ f i l e : / i. test ( stringUrl . toString ( ) ) ) {
8798 stringUrl = FileAccess . asBrowserUri ( URI . parse ( stringUrl . toString ( ) ) ) . toString ( true ) ;
99+ } else if ( / ^ v s c o d e - r e m o t e : / i. test ( stringUrl . toString ( ) ) ) {
100+ // Supporting transformation of vscode-remote URIs requires an async call to the main thread,
101+ // but we cannot do this call from within the embedded Worker, and the only way out would be
102+ // to use templating instead of a function in the web api (`resourceUriProvider`)
103+ throw new Error ( `Creating workers from remote extensions is currently not supported.` ) ;
88104 }
89105
90106 // IMPORTANT: bootstrapFn is stringified and injected as worker blob-url. Because of that it CANNOT
@@ -244,6 +260,8 @@ export function create(): { onmessage: (message: any) => void } {
244260 message . data
245261 ) ;
246262
263+ patchFetching ( uri => extHostMain . asBrowserUri ( uri ) ) ;
264+
247265 onTerminate = ( reason : string ) => extHostMain . terminate ( reason ) ;
248266 } ) ;
249267 }
0 commit comments