Skip to content

Commit f20f7ac

Browse files
committed
Move extension fetch to main thread
This makes the fetch work independently of the worker's origin which is no longer the same as the main thread (the main problem is the inability to send cookies without setting SameSite to None).
1 parent a7c43a8 commit f20f7ac

File tree

1 file changed

+39
-22
lines changed

1 file changed

+39
-22
lines changed

ci/dev/vscode.patch

+39-22
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,13 @@ index 0000000000000000000000000000000000000000..3c0703b7174ad792a4b42841e96ee937
929929
+};
930930
diff --git a/src/vs/server/browser/extHostNodeProxy.ts b/src/vs/server/browser/extHostNodeProxy.ts
931931
new file mode 100644
932-
index 0000000000000000000000000000000000000000..ed7c078077b0c375758529959b280e091436113a
932+
index 0000000000000000000000000000000000000000..6c6b87a05610417d73635c5a151845000f216d28
933933
--- /dev/null
934934
+++ b/src/vs/server/browser/extHostNodeProxy.ts
935-
@@ -0,0 +1,46 @@
935+
@@ -0,0 +1,52 @@
936+
+import { VSBuffer } from 'vs/base/common/buffer';
936937
+import { Emitter } from 'vs/base/common/event';
938+
+import { UriComponents } from 'vs/base/common/uri';
937939
+import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
938940
+import { ExtHostNodeProxyShape, MainContext, MainThreadNodeProxyShape } from 'vs/workbench/api/common/extHost.protocol';
939941
+import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
@@ -975,17 +977,24 @@ index 0000000000000000000000000000000000000000..ed7c078077b0c375758529959b280e09
975977
+ public send(message: string): void {
976978
+ this.proxy.$send(message);
977979
+ }
980+
+
981+
+ public async fetchExtension(extensionUri: UriComponents): Promise<Uint8Array> {
982+
+ return this.proxy.$fetchExtension(extensionUri).then(b => b.buffer);
983+
+ }
978984
+}
979985
+
980986
+export interface IExtHostNodeProxy extends ExtHostNodeProxy { }
981987
+export const IExtHostNodeProxy = createDecorator<IExtHostNodeProxy>('IExtHostNodeProxy');
982988
diff --git a/src/vs/server/browser/mainThreadNodeProxy.ts b/src/vs/server/browser/mainThreadNodeProxy.ts
983989
new file mode 100644
984-
index 0000000000000000000000000000000000000000..0d2e93edae2baf34d27b7b52be0bf4960f244531
990+
index 0000000000000000000000000000000000000000..21a139288e5b8f56016491879d69d01da929decb
985991
--- /dev/null
986992
+++ b/src/vs/server/browser/mainThreadNodeProxy.ts
987-
@@ -0,0 +1,37 @@
993+
@@ -0,0 +1,55 @@
994+
+import { VSBuffer } from 'vs/base/common/buffer';
988995
+import { IDisposable } from 'vs/base/common/lifecycle';
996+
+import { FileAccess } from 'vs/base/common/network';
997+
+import { URI, UriComponents } from 'vs/base/common/uri';
989998
+import { INodeProxyService } from 'vs/server/common/nodeProxy';
990999
+import { ExtHostContext, IExtHostContext, MainContext, MainThreadNodeProxyShape } from 'vs/workbench/api/common/extHost.protocol';
9911000
+import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
@@ -1016,6 +1025,21 @@ index 0000000000000000000000000000000000000000..0d2e93edae2baf34d27b7b52be0bf496
10161025
+ }
10171026
+ }
10181027
+
1028+
+ async $fetchExtension(extensionUri: UriComponents): Promise<VSBuffer> {
1029+
+ const fetchUri = URI.from({
1030+
+ scheme: window.location.protocol.replace(':', ''),
1031+
+ authority: window.location.host,
1032+
+ // Use FileAccess to get the static base path.
1033+
+ path: FileAccess.asBrowserUri("", require).path,
1034+
+ query: `tar=${encodeURIComponent(extensionUri.path)}`,
1035+
+ });
1036+
+ const response = await fetch(fetchUri.toString(true));
1037+
+ if (response.status !== 200) {
1038+
+ throw new Error(`Failed to download extension "${module}"`);
1039+
+ }
1040+
+ return VSBuffer.wrap(new Uint8Array(await response.arrayBuffer()));
1041+
+ }
1042+
+
10191043
+ dispose(): void {
10201044
+ this.disposables.forEach((d) => d.dispose());
10211045
+ this.disposables = [];
@@ -1024,10 +1048,10 @@ index 0000000000000000000000000000000000000000..0d2e93edae2baf34d27b7b52be0bf496
10241048
+}
10251049
diff --git a/src/vs/server/browser/worker.ts b/src/vs/server/browser/worker.ts
10261050
new file mode 100644
1027-
index 0000000000000000000000000000000000000000..5ae44cdc856bf81326a4c516b8be9afb2c746a67
1051+
index 0000000000000000000000000000000000000000..1d47ede49b76b1774329269ab5c86fedb5712c19
10281052
--- /dev/null
10291053
+++ b/src/vs/server/browser/worker.ts
1030-
@@ -0,0 +1,56 @@
1054+
@@ -0,0 +1,48 @@
10311055
+import { Client } from '@coder/node-browser';
10321056
+import { fromTar } from '@coder/requirefs';
10331057
+import { URI } from 'vs/base/common/uri';
@@ -1042,19 +1066,11 @@ index 0000000000000000000000000000000000000000..5ae44cdc856bf81326a4c516b8be9afb
10421066
+ logService: ILogService,
10431067
+ vscode: any,
10441068
+): Promise<T> => {
1045-
+ const fetchUri = URI.from({
1046-
+ scheme: self.location.protocol.replace(':', ''),
1047-
+ authority: self.location.host,
1048-
+ path: self.location.pathname.replace(/\/static\/([^\/]+)\/.*$/, '/static/$1\/'),
1049-
+ query: `tar=${encodeURIComponent(module.path)}`,
1050-
+ });
1051-
+ const response = await fetch(fetchUri.toString(true));
1052-
+ if (response.status !== 200) {
1053-
+ throw new Error(`Failed to download extension "${module}"`);
1054-
+ }
10551069
+ const client = new Client(nodeProxy, { logger: logService });
1056-
+ const init = await client.handshake();
1057-
+ const buffer = new Uint8Array(await response.arrayBuffer());
1070+
+ const [buffer, init] = await Promise.all([
1071+
+ nodeProxy.fetchExtension(module),
1072+
+ client.handshake(),
1073+
+ ]);
10581074
+ const rfs = fromTar(buffer);
10591075
+ (<any>self).global = self;
10601076
+ rfs.provide('vscode', vscode);
@@ -2895,15 +2911,16 @@ index 2a0576b68f943f63c010dd496e094311bdc149f0..357c63f0fec08ddfb06b3579460fe156
28952911
rpcProtocol.set(ExtHostContext.ExtHostWindow, extHostWindow);
28962912

28972913
diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts
2898-
index 3728f5602dffd0fd4b0cf326c5fa7d6d7c49c53e..233fbbce328094d014a375b1e9c11231ac9fafd9 100644
2914+
index 3728f5602dffd0fd4b0cf326c5fa7d6d7c49c53e..2521acff0e692e97b72deef758ce41b4cd54a724 100644
28992915
--- a/src/vs/workbench/api/common/extHost.protocol.ts
29002916
+++ b/src/vs/workbench/api/common/extHost.protocol.ts
2901-
@@ -807,6 +807,16 @@ export interface MainThreadLabelServiceShape extends IDisposable {
2917+
@@ -807,6 +807,17 @@ export interface MainThreadLabelServiceShape extends IDisposable {
29022918
$unregisterResourceLabelFormatter(handle: number): void;
29032919
}
29042920

29052921
+export interface MainThreadNodeProxyShape extends IDisposable {
29062922
+ $send(message: string): void;
2923+
+ $fetchExtension(extensionUri: UriComponents): Promise<VSBuffer>;
29072924
+}
29082925
+export interface ExtHostNodeProxyShape {
29092926
+ $onMessage(message: string): void;
@@ -2915,15 +2932,15 @@ index 3728f5602dffd0fd4b0cf326c5fa7d6d7c49c53e..233fbbce328094d014a375b1e9c11231
29152932
export interface MainThreadSearchShape extends IDisposable {
29162933
$registerFileSearchProvider(handle: number, scheme: string): void;
29172934
$registerTextSearchProvider(handle: number, scheme: string): void;
2918-
@@ -1784,6 +1794,7 @@ export const MainContext = {
2935+
@@ -1784,6 +1795,7 @@ export const MainContext = {
29192936
MainThreadWindow: createMainId<MainThreadWindowShape>('MainThreadWindow'),
29202937
MainThreadLabelService: createMainId<MainThreadLabelServiceShape>('MainThreadLabelService'),
29212938
MainThreadNotebook: createMainId<MainThreadNotebookShape>('MainThreadNotebook'),
29222939
+ MainThreadNodeProxy: createMainId<MainThreadNodeProxyShape>('MainThreadNodeProxy'),
29232940
MainThreadTheming: createMainId<MainThreadThemingShape>('MainThreadTheming'),
29242941
MainThreadTunnelService: createMainId<MainThreadTunnelServiceShape>('MainThreadTunnelService'),
29252942
MainThreadTimeline: createMainId<MainThreadTimelineShape>('MainThreadTimeline')
2926-
@@ -1826,6 +1837,7 @@ export const ExtHostContext = {
2943+
@@ -1826,6 +1838,7 @@ export const ExtHostContext = {
29272944
ExtHostOutputService: createMainId<ExtHostOutputServiceShape>('ExtHostOutputService'),
29282945
ExtHosLabelService: createMainId<ExtHostLabelServiceShape>('ExtHostLabelService'),
29292946
ExtHostNotebook: createMainId<ExtHostNotebookShape>('ExtHostNotebook'),

0 commit comments

Comments
 (0)