Skip to content

Commit b58579c

Browse files
committed
Use cookie for connection token, align fetching of remote resources
1 parent 19a5bd6 commit b58579c

10 files changed

Lines changed: 42 additions & 69 deletions

File tree

src/vs/base/browser/dom.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,22 +1186,14 @@ export function animate(fn: () => void): IDisposable {
11861186
return toDisposable(() => stepDisposable.dispose());
11871187
}
11881188

1189-
1190-
1191-
const _location = URI.parse(window.location.href);
1189+
RemoteAuthorities.setPreferredWebSchema(/^https:/.test(window.location.href) ? 'https' : 'http');
11921190

11931191
export function asDomUri(uri: URI): URI {
11941192
if (!uri) {
11951193
return uri;
11961194
}
11971195
if (Schemas.vscodeRemote === uri.scheme) {
1198-
if (platform.isWeb) {
1199-
// rewrite vscode-remote-uris to uris of the window location
1200-
// so that they can be intercepted by the service worker
1201-
return _location.with({ path: '/vscode-remote', query: JSON.stringify(uri) });
1202-
} else {
1203-
return RemoteAuthorities.rewrite(uri.authority, uri.path);
1204-
}
1196+
return RemoteAuthorities.rewrite(uri.authority, uri.path);
12051197
}
12061198
return uri;
12071199
}

src/vs/base/common/network.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { URI } from 'vs/base/common/uri';
7+
import * as platform from 'vs/base/common/platform';
78

89
export namespace Schemas {
910

@@ -58,11 +59,17 @@ class RemoteAuthoritiesImpl {
5859
private readonly _hosts: { [authority: string]: string; };
5960
private readonly _ports: { [authority: string]: number; };
6061
private readonly _connectionTokens: { [authority: string]: string; };
62+
private _preferredWebSchema: 'http' | 'https';
6163

6264
constructor() {
6365
this._hosts = Object.create(null);
6466
this._ports = Object.create(null);
6567
this._connectionTokens = Object.create(null);
68+
this._preferredWebSchema = 'http';
69+
}
70+
71+
public setPreferredWebSchema(schema: 'http' | 'https') {
72+
this._preferredWebSchema = schema;
6673
}
6774

6875
public set(authority: string, host: string, port: number): void {
@@ -79,9 +86,9 @@ class RemoteAuthoritiesImpl {
7986
const port = this._ports[authority];
8087
const connectionToken = this._connectionTokens[authority];
8188
return URI.from({
82-
scheme: Schemas.vscodeRemoteResource,
89+
scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
8390
authority: `${host}:${port}`,
84-
path: `/vscode-remote2`,
91+
path: `/vscode-remote-resource`,
8592
query: `path=${encodeURIComponent(path)}&tkn=${encodeURIComponent(connectionToken)}`
8693
});
8794
}

src/vs/code/browser/workbench/workbench.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
</body>
2626

2727
<!-- Require our AMD loader -->
28-
<script src="./out/vs/loader.js"></script>
28+
<script src="./static/out/vs/loader.js"></script>
2929

3030
<!-- Startup via workbench.js -->
31-
<script src="./out/vs/code/browser/workbench/workbench.js"></script>
31+
<script src="./static/out/vs/code/browser/workbench/workbench.js"></script>
3232
</html>

src/vs/code/browser/workbench/workbench.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
(function () {
99

1010
require.config({
11-
baseUrl: `${window.location.origin}/out`,
11+
baseUrl: `${window.location.origin}/static/out`,
1212
paths: {
13-
'vscode-textmate': `${window.location.origin}/node_modules/vscode-textmate/release/main`,
14-
'onigasm-umd': `${window.location.origin}/node_modules/onigasm-umd/release/main`,
15-
'xterm': `${window.location.origin}/node_modules/xterm/lib/xterm.js`,
16-
'xterm-addon-search': `${window.location.origin}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
17-
'xterm-addon-web-links': `${window.location.origin}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`,
18-
'semver-umd': `${window.location.origin}/node_modules/semver-umd/lib/semver-umd.js`,
19-
'@microsoft/applicationinsights-web': `${window.location.origin}/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js`,
13+
'vscode-textmate': `${window.location.origin}/static/node_modules/vscode-textmate/release/main`,
14+
'onigasm-umd': `${window.location.origin}/static/node_modules/onigasm-umd/release/main`,
15+
'xterm': `${window.location.origin}/static/node_modules/xterm/lib/xterm.js`,
16+
'xterm-addon-search': `${window.location.origin}/static/node_modules/xterm-addon-search/lib/xterm-addon-search.js`,
17+
'xterm-addon-web-links': `${window.location.origin}/static/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`,
18+
'semver-umd': `${window.location.origin}/static/node_modules/semver-umd/lib/semver-umd.js`,
19+
'@microsoft/applicationinsights-web': `${window.location.origin}/static/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js`,
2020
}
2121
});
2222

src/vs/platform/remote/browser/remoteAuthorityResolverService.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ResolvedAuthority, IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/remote/common/remoteAuthorityResolver';
7+
import { RemoteAuthorities } from 'vs/base/common/network';
78

89
export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService {
910

@@ -15,13 +16,14 @@ export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverS
1516
resolveAuthority(authority: string): Promise<ResolverResult> {
1617
if (authority.indexOf(':') >= 0) {
1718
const pieces = authority.split(':');
18-
return Promise.resolve({
19-
authority: { authority, host: pieces[0], port: parseInt(pieces[1], 10) }
20-
});
19+
return Promise.resolve(this._createResolvedAuthority(authority, pieces[0], parseInt(pieces[1], 10)));
2120
}
22-
return Promise.resolve({
23-
authority: { authority, host: authority, port: 80 }
24-
});
21+
return Promise.resolve(this._createResolvedAuthority(authority, authority, 80));
22+
}
23+
24+
private _createResolvedAuthority(authority: string, host: string, port: number): ResolverResult {
25+
RemoteAuthorities.set(authority, host, port);
26+
return { authority: { authority, host, port } };
2527
}
2628

2729
clearResolvedAuthority(authority: string): void {

src/vs/workbench/api/worker/extHostExtensionService.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ExtensionActivationTimesBuilder } from 'vs/workbench/api/common/extHost
88
import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService';
99
import { endsWith, startsWith } from 'vs/base/common/strings';
1010
import { URI } from 'vs/base/common/uri';
11-
import { Schemas } from 'vs/base/common/network';
1211
import { joinPath } from 'vs/base/common/resources';
1312
import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor';
1413

@@ -128,7 +127,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
128127
const next = joinPath(parent, '..', ensureSuffix(mod, '.js'));
129128
moduleStack.push(next);
130129
const trap = ExportsTrap.Instance.add(next.toString());
131-
importScripts(asDomUri(next).toString(true));
130+
importScripts(next.toString(true));
132131
moduleStack.pop();
133132

134133
return trap.claim();
@@ -139,7 +138,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
139138
module = module.with({ path: ensureSuffix(module.path, '.js') });
140139
moduleStack.push(module);
141140
const trap = ExportsTrap.Instance.add(module.toString());
142-
importScripts(asDomUri(module).toString(true));
141+
importScripts(module.toString(true));
143142
moduleStack.pop();
144143
return Promise.resolve<T>(trap.claim());
145144

@@ -153,16 +152,6 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService {
153152
}
154153
}
155154

156-
// todo@joh this is a copy of `dom.ts#asDomUri`
157-
function asDomUri(uri: URI): URI {
158-
if (Schemas.vscodeRemote === uri.scheme) {
159-
// rewrite vscode-remote-uris to uris of the window location
160-
// so that they can be intercepted by the service worker
161-
return URI.parse(window.location.href).with({ path: '/vscode-remote', query: JSON.stringify(uri) });
162-
}
163-
return uri;
164-
}
165-
166155
function ensureSuffix(path: string, suffix: string): string {
167156
return endsWith(path, suffix) ? path : path + suffix;
168157
}

src/vs/workbench/browser/web.simpleservices.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
3131
import { ParsedArgs } from 'vs/platform/environment/common/environment';
3232
import { IProcessEnvironment } from 'vs/base/common/platform';
3333
import { toStoreData, restoreRecentlyOpened } from 'vs/platform/history/common/historyStorage';
34-
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
3534
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
3635
import { IProductService } from 'vs/platform/product/common/product';
3736
import Severity from 'vs/base/common/severity';
@@ -176,7 +175,6 @@ export class SimpleWindowService extends Disposable implements IWindowService {
176175
@IStorageService private readonly storageService: IStorageService,
177176
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
178177
@ILogService private readonly logService: ILogService,
179-
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
180178
) {
181179
super();
182180

@@ -372,7 +370,7 @@ export class SimpleWindowService extends Disposable implements IWindowService {
372370
for (let i = 0; i < _uris.length; i++) {
373371
const uri = _uris[i];
374372
if ('folderUri' in uri) {
375-
const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}${this.workbenchEnvironmentService.configuration.connectionToken ? `&tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
373+
const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}`;
376374
if (openFolderInNewWindow) {
377375
window.open(newAddress);
378376
} else {
@@ -459,7 +457,6 @@ export class SimpleWindowsService implements IWindowsService {
459457
readonly onRecentlyOpenedChange: Event<void> = Event.None;
460458

461459
constructor(
462-
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService,
463460
@IDialogService private readonly dialogService: IDialogService,
464461
@IProductService private readonly productService: IProductService,
465462
@IClipboardService private readonly clipboardService: IClipboardService
@@ -651,11 +648,6 @@ export class SimpleWindowsService implements IWindowsService {
651648
addQueryParameter('ibe', ibe);
652649
}
653650

654-
// add connection token
655-
if (this.workbenchEnvironmentService.configuration.connectionToken) {
656-
addQueryParameter('tkn', this.workbenchEnvironmentService.configuration.connectionToken);
657-
}
658-
659651
window.open(newAddress);
660652

661653
return Promise.resolve();

src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ self.addEventListener('activate', event => {
3434
//#region --- fetching/caching
3535

3636
const _cacheName = 'vscode-extension-resources';
37-
const _resourcePrefix = '/vscode-remote';
37+
const _resourcePrefix = '/vscode-remote-resource';
3838
const _pendingFetch = new Map<string, Function>();
3939

4040
self.addEventListener('message', event => {

src/vs/workbench/contrib/resources/browser/resourceServiceWorkerMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// statement.
1111

1212
// trigger service worker updates
13-
const _tag = '52278406-3ca9-48af-a8fb-8495add5bb4e';
13+
const _tag = '23549971-9b8d-41bb-92ae-d7f6a68c9702';
1414

1515
// loader world
1616
const baseUrl = '../../../../../';

src/vs/workbench/services/environment/browser/environmentService.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
8888
this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
8989
this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
9090
this.configuration.backupWorkspaceResource = joinPath(this.backupHome, options.workspaceId);
91-
this.configuration.connectionToken = options.connectionToken || this.getConnectionTokenFromLocation();
91+
this.configuration.connectionToken = options.connectionToken || getCookieValue('vscode-tkn');
9292

9393
this.logsPath = '/web/logs';
9494

@@ -191,21 +191,12 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
191191
get webviewCspSource(): string {
192192
return this.webviewEndpoint ? this.webviewEndpoint : 'vscode-resource:';
193193
}
194+
}
194195

195-
private getConnectionTokenFromLocation(): string | undefined {
196-
// TODO: Check with @alexd where the token will be: search or hash?
197-
let connectionToken: string | undefined = undefined;
198-
if (document.location.search) {
199-
connectionToken = this.getConnectionToken(document.location.search);
200-
}
201-
if (!connectionToken && document.location.hash) {
202-
connectionToken = this.getConnectionToken(document.location.hash);
203-
}
204-
return connectionToken;
205-
}
206-
207-
private getConnectionToken(str: string): string | undefined {
208-
const m = str.match(/[#&?]tkn=([^&]+)/);
209-
return m ? m[1] : undefined;
210-
}
196+
/**
197+
* See https://stackoverflow.com/a/25490531
198+
*/
199+
function getCookieValue(name: string): string | undefined {
200+
const m = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)');
201+
return m ? m.pop() : undefined;
211202
}

0 commit comments

Comments
 (0)