Adopt to connection token

- Add connection token to window configuration
- Use it in window service while opening windows
This commit is contained in:
Sandeep Somavarapu 2019-08-02 15:56:29 +05:30
parent 74563de36d
commit 310cb67b0e
5 changed files with 35 additions and 20 deletions

View file

@ -13,22 +13,7 @@ export class SignService implements ISignService {
private readonly _tkn: string | null; private readonly _tkn: string | null;
constructor(token: string | undefined) { constructor(token: string | undefined) {
if (typeof token !== 'undefined') { this._tkn = token || null;
this._tkn = token;
} else {
this._tkn = SignService._readTokenFromURL();
}
}
private static _readTokenFromURL(): string | null {
if (!document.location.hash) {
return null;
}
const m = document.location.hash.match(/[#&]tkn=([^&]+)/);
if (!m) {
return null;
}
return m[1];
} }
async sign(value: string): Promise<string> { async sign(value: string): Promise<string> {

View file

@ -444,6 +444,7 @@ export interface IWindowConfiguration extends ParsedArgs {
filesToDiff?: IPath[]; filesToDiff?: IPath[];
filesToWait?: IPathsToWaitFor; filesToWait?: IPathsToWaitFor;
termProgram?: string; termProgram?: string;
connectionToken?: string;
} }
export interface IRunActionInWindowRequest { export interface IRunActionInWindowRequest {

View file

@ -118,7 +118,8 @@ class CodeRendererMain extends Disposable {
const environmentService = new BrowserWorkbenchEnvironmentService({ const environmentService = new BrowserWorkbenchEnvironmentService({
workspaceId: payload.id, workspaceId: payload.id,
remoteAuthority: this.configuration.remoteAuthority, remoteAuthority: this.configuration.remoteAuthority,
webviewEndpoint: this.configuration.webviewEndpoint webviewEndpoint: this.configuration.webviewEndpoint,
connectionToken: this.configuration.connectionToken
}); });
serviceCollection.set(IWorkbenchEnvironmentService, environmentService); serviceCollection.set(IWorkbenchEnvironmentService, environmentService);
@ -131,7 +132,7 @@ class CodeRendererMain extends Disposable {
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService); serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);
// Signing // Signing
const signService = new SignService(this.configuration.connectionToken); const signService = new SignService(environmentService.configuration.connectionToken);
serviceCollection.set(ISignService, signService); serviceCollection.set(ISignService, signService);
// Remote Agent // Remote Agent

View file

@ -37,6 +37,7 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
// tslint:disable-next-line: import-patterns // tslint:disable-next-line: import-patterns
import { IExperimentService, IExperiment, ExperimentActionType, ExperimentState } from 'vs/workbench/contrib/experiments/common/experimentService'; import { IExperimentService, IExperiment, ExperimentActionType, ExperimentState } from 'vs/workbench/contrib/experiments/common/experimentService';
import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc'; import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
//#region Extension Tips //#region Extension Tips
@ -293,7 +294,8 @@ export class SimpleWindowService extends Disposable implements IWindowService {
@IConfigurationService private readonly configurationService: IConfigurationService, @IConfigurationService private readonly configurationService: IConfigurationService,
@IStorageService private readonly storageService: IStorageService, @IStorageService private readonly storageService: IStorageService,
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService, @IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
@ILogService private readonly logService: ILogService @ILogService private readonly logService: ILogService,
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
) { ) {
super(); super();
@ -489,7 +491,7 @@ export class SimpleWindowService extends Disposable implements IWindowService {
for (let i = 0; i < _uris.length; i++) { for (let i = 0; i < _uris.length; i++) {
const uri = _uris[i]; const uri = _uris[i];
if ('folderUri' in uri) { if ('folderUri' in uri) {
const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}`; const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}${this.workbenchEnvironmentService.configuration.connectionToken ? `&tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
if (openFolderInNewWindow) { if (openFolderInNewWindow) {
window.open(newAddress); window.open(newAddress);
} else { } else {
@ -608,6 +610,10 @@ export class SimpleWindowsService implements IWindowsService {
readonly onWindowUnmaximize: Event<number> = Event.None; readonly onWindowUnmaximize: Event<number> = Event.None;
readonly onRecentlyOpenedChange: Event<void> = Event.None; readonly onRecentlyOpenedChange: Event<void> = Event.None;
constructor(
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
) {
}
isFocused(_windowId: number): Promise<boolean> { isFocused(_windowId: number): Promise<boolean> {
return Promise.resolve(true); return Promise.resolve(true);
} }
@ -778,6 +784,9 @@ export class SimpleWindowsService implements IWindowsService {
newAddress += `&ibe=${encodeURIComponent(ibe)}`; newAddress += `&ibe=${encodeURIComponent(ibe)}`;
} }
// add connection token
newAddress += `${this.workbenchEnvironmentService.configuration.connectionToken ? `tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
window.open(newAddress); window.open(newAddress);
return Promise.resolve(); return Promise.resolve();

View file

@ -61,6 +61,7 @@ export interface IBrowserWindowConfiguration {
workspaceId: string; workspaceId: string;
remoteAuthority?: string; remoteAuthority?: string;
webviewEndpoint?: string; webviewEndpoint?: string;
connectionToken?: string;
} }
export class BrowserWorkbenchEnvironmentService implements IEnvironmentService { export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
@ -81,6 +82,7 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json'); this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS); this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
this.configuration.backupWorkspaceResource = joinPath(this.backupHome, configuration.workspaceId); this.configuration.backupWorkspaceResource = joinPath(this.backupHome, configuration.workspaceId);
this.configuration.connectionToken = configuration.connectionToken || this.getConnectionTokenFromLocation();
this.logsPath = '/web/logs'; this.logsPath = '/web/logs';
@ -182,4 +184,21 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
get webviewCspSource(): string { get webviewCspSource(): string {
return this.webviewEndpoint ? this.webviewEndpoint : 'vscode-resource:'; return this.webviewEndpoint ? this.webviewEndpoint : 'vscode-resource:';
} }
private getConnectionTokenFromLocation(): string | undefined {
// TODO: Check with @alexd where the token will be: search or hash?
let connectionToken: string | undefined = undefined;
if (document.location.search) {
connectionToken = this.getConnectionToken(document.location.search);
}
if (!connectionToken && document.location.hash) {
connectionToken = this.getConnectionToken(document.location.hash);
}
return connectionToken;
}
private getConnectionToken(str: string): string | undefined {
const m = str.match(/[#&]tkn=([^&]+)/);
return m ? m[1] : undefined;
}
} }