@@ -43,26 +43,37 @@ self.close = () => console.trace(`'close' has been blocked`);
43
43
const nativePostMessage = postMessage . bind ( self ) ;
44
44
self . postMessage = ( ) => console . trace ( `'postMessage' has been blocked` ) ;
45
45
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
+
46
53
const 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
+ }
50
63
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
+ } ;
57
65
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
+ } ) ( ) ;
62
74
}
63
- return super . open ( method , url , async ?? true , username , password ) ;
64
- }
65
- } ;
75
+ } ;
76
+ }
66
77
67
78
self . importScripts = ( ) => { throw new Error ( `'importScripts' has been blocked` ) ; } ;
68
79
@@ -85,6 +96,11 @@ if ((<any>self).Worker) {
85
96
Worker = < any > function ( stringUrl : string | URL , options ?: WorkerOptions ) {
86
97
if ( / ^ f i l e : / i. test ( stringUrl . toString ( ) ) ) {
87
98
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.` ) ;
88
104
}
89
105
90
106
// 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 } {
244
260
message . data
245
261
) ;
246
262
263
+ patchFetching ( uri => extHostMain . asBrowserUri ( uri ) ) ;
264
+
247
265
onTerminate = ( reason : string ) => extHostMain . terminate ( reason ) ;
248
266
} ) ;
249
267
}
0 commit comments