Skip to content

Commit 310cb67

Browse files
committed
Adopt to connection token
- Add connection token to window configuration - Use it in window service while opening windows
1 parent 74563de commit 310cb67

5 files changed

Lines changed: 35 additions & 20 deletions

File tree

src/vs/platform/sign/browser/signService.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,7 @@ export class SignService implements ISignService {
1313
private readonly _tkn: string | null;
1414

1515
constructor(token: string | undefined) {
16-
if (typeof token !== 'undefined') {
17-
this._tkn = token;
18-
} else {
19-
this._tkn = SignService._readTokenFromURL();
20-
}
21-
}
22-
23-
private static _readTokenFromURL(): string | null {
24-
if (!document.location.hash) {
25-
return null;
26-
}
27-
const m = document.location.hash.match(/[#&]tkn=([^&]+)/);
28-
if (!m) {
29-
return null;
30-
}
31-
return m[1];
16+
this._tkn = token || null;
3217
}
3318

3419
async sign(value: string): Promise<string> {

src/vs/platform/windows/common/windows.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export interface IWindowConfiguration extends ParsedArgs {
444444
filesToDiff?: IPath[];
445445
filesToWait?: IPathsToWaitFor;
446446
termProgram?: string;
447+
connectionToken?: string;
447448
}
448449

449450
export interface IRunActionInWindowRequest {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ class CodeRendererMain extends Disposable {
118118
const environmentService = new BrowserWorkbenchEnvironmentService({
119119
workspaceId: payload.id,
120120
remoteAuthority: this.configuration.remoteAuthority,
121-
webviewEndpoint: this.configuration.webviewEndpoint
121+
webviewEndpoint: this.configuration.webviewEndpoint,
122+
connectionToken: this.configuration.connectionToken
122123
});
123124
serviceCollection.set(IWorkbenchEnvironmentService, environmentService);
124125

@@ -131,7 +132,7 @@ class CodeRendererMain extends Disposable {
131132
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);
132133

133134
// Signing
134-
const signService = new SignService(this.configuration.connectionToken);
135+
const signService = new SignService(environmentService.configuration.connectionToken);
135136
serviceCollection.set(ISignService, signService);
136137

137138
// Remote Agent

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
3737
// tslint:disable-next-line: import-patterns
3838
import { IExperimentService, IExperiment, ExperimentActionType, ExperimentState } from 'vs/workbench/contrib/experiments/common/experimentService';
3939
import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc';
40+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
4041

4142
//#region Extension Tips
4243

@@ -293,7 +294,8 @@ export class SimpleWindowService extends Disposable implements IWindowService {
293294
@IConfigurationService private readonly configurationService: IConfigurationService,
294295
@IStorageService private readonly storageService: IStorageService,
295296
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
296-
@ILogService private readonly logService: ILogService
297+
@ILogService private readonly logService: ILogService,
298+
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
297299
) {
298300
super();
299301

@@ -489,7 +491,7 @@ export class SimpleWindowService extends Disposable implements IWindowService {
489491
for (let i = 0; i < _uris.length; i++) {
490492
const uri = _uris[i];
491493
if ('folderUri' in uri) {
492-
const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}`;
494+
const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}${this.workbenchEnvironmentService.configuration.connectionToken ? `&tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
493495
if (openFolderInNewWindow) {
494496
window.open(newAddress);
495497
} else {
@@ -608,6 +610,10 @@ export class SimpleWindowsService implements IWindowsService {
608610
readonly onWindowUnmaximize: Event<number> = Event.None;
609611
readonly onRecentlyOpenedChange: Event<void> = Event.None;
610612

613+
constructor(
614+
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
615+
) {
616+
}
611617
isFocused(_windowId: number): Promise<boolean> {
612618
return Promise.resolve(true);
613619
}
@@ -778,6 +784,9 @@ export class SimpleWindowsService implements IWindowsService {
778784
newAddress += `&ibe=${encodeURIComponent(ibe)}`;
779785
}
780786

787+
// add connection token
788+
newAddress += `${this.workbenchEnvironmentService.configuration.connectionToken ? `tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
789+
781790
window.open(newAddress);
782791

783792
return Promise.resolve();

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface IBrowserWindowConfiguration {
6161
workspaceId: string;
6262
remoteAuthority?: string;
6363
webviewEndpoint?: string;
64+
connectionToken?: string;
6465
}
6566

6667
export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
@@ -81,6 +82,7 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
8182
this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
8283
this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
8384
this.configuration.backupWorkspaceResource = joinPath(this.backupHome, configuration.workspaceId);
85+
this.configuration.connectionToken = configuration.connectionToken || this.getConnectionTokenFromLocation();
8486

8587
this.logsPath = '/web/logs';
8688

@@ -182,4 +184,21 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
182184
get webviewCspSource(): string {
183185
return this.webviewEndpoint ? this.webviewEndpoint : 'vscode-resource:';
184186
}
187+
188+
private getConnectionTokenFromLocation(): string | undefined {
189+
// TODO: Check with @alexd where the token will be: search or hash?
190+
let connectionToken: string | undefined = undefined;
191+
if (document.location.search) {
192+
connectionToken = this.getConnectionToken(document.location.search);
193+
}
194+
if (!connectionToken && document.location.hash) {
195+
connectionToken = this.getConnectionToken(document.location.hash);
196+
}
197+
return connectionToken;
198+
}
199+
200+
private getConnectionToken(str: string): string | undefined {
201+
const m = str.match(/[#&]tkn=([^&]+)/);
202+
return m ? m[1] : undefined;
203+
}
185204
}

0 commit comments

Comments
 (0)