mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Adopt to connection token
- Add connection token to window configuration - Use it in window service while opening windows
This commit is contained in:
parent
74563de36d
commit
310cb67b0e
|
@ -13,22 +13,7 @@ export class SignService implements ISignService {
|
|||
private readonly _tkn: string | null;
|
||||
|
||||
constructor(token: string | undefined) {
|
||||
if (typeof token !== 'undefined') {
|
||||
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];
|
||||
this._tkn = token || null;
|
||||
}
|
||||
|
||||
async sign(value: string): Promise<string> {
|
||||
|
|
|
@ -444,6 +444,7 @@ export interface IWindowConfiguration extends ParsedArgs {
|
|||
filesToDiff?: IPath[];
|
||||
filesToWait?: IPathsToWaitFor;
|
||||
termProgram?: string;
|
||||
connectionToken?: string;
|
||||
}
|
||||
|
||||
export interface IRunActionInWindowRequest {
|
||||
|
|
|
@ -118,7 +118,8 @@ class CodeRendererMain extends Disposable {
|
|||
const environmentService = new BrowserWorkbenchEnvironmentService({
|
||||
workspaceId: payload.id,
|
||||
remoteAuthority: this.configuration.remoteAuthority,
|
||||
webviewEndpoint: this.configuration.webviewEndpoint
|
||||
webviewEndpoint: this.configuration.webviewEndpoint,
|
||||
connectionToken: this.configuration.connectionToken
|
||||
});
|
||||
serviceCollection.set(IWorkbenchEnvironmentService, environmentService);
|
||||
|
||||
|
@ -131,7 +132,7 @@ class CodeRendererMain extends Disposable {
|
|||
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);
|
||||
|
||||
// Signing
|
||||
const signService = new SignService(this.configuration.connectionToken);
|
||||
const signService = new SignService(environmentService.configuration.connectionToken);
|
||||
serviceCollection.set(ISignService, signService);
|
||||
|
||||
// Remote Agent
|
||||
|
|
|
@ -37,6 +37,7 @@ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteA
|
|||
// tslint:disable-next-line: import-patterns
|
||||
import { IExperimentService, IExperiment, ExperimentActionType, ExperimentState } from 'vs/workbench/contrib/experiments/common/experimentService';
|
||||
import { ExtensionHostDebugChannelClient, ExtensionHostDebugBroadcastChannel } from 'vs/platform/debug/common/extensionHostDebugIpc';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
|
||||
//#region Extension Tips
|
||||
|
||||
|
@ -293,7 +294,8 @@ export class SimpleWindowService extends Disposable implements IWindowService {
|
|||
@IConfigurationService private readonly configurationService: IConfigurationService,
|
||||
@IStorageService private readonly storageService: IStorageService,
|
||||
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
|
||||
@ILogService private readonly logService: ILogService
|
||||
@ILogService private readonly logService: ILogService,
|
||||
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
|
||||
) {
|
||||
super();
|
||||
|
||||
|
@ -489,7 +491,7 @@ export class SimpleWindowService extends Disposable implements IWindowService {
|
|||
for (let i = 0; i < _uris.length; i++) {
|
||||
const uri = _uris[i];
|
||||
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) {
|
||||
window.open(newAddress);
|
||||
} else {
|
||||
|
@ -608,6 +610,10 @@ export class SimpleWindowsService implements IWindowsService {
|
|||
readonly onWindowUnmaximize: Event<number> = Event.None;
|
||||
readonly onRecentlyOpenedChange: Event<void> = Event.None;
|
||||
|
||||
constructor(
|
||||
@IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService
|
||||
) {
|
||||
}
|
||||
isFocused(_windowId: number): Promise<boolean> {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
@ -778,6 +784,9 @@ export class SimpleWindowsService implements IWindowsService {
|
|||
newAddress += `&ibe=${encodeURIComponent(ibe)}`;
|
||||
}
|
||||
|
||||
// add connection token
|
||||
newAddress += `${this.workbenchEnvironmentService.configuration.connectionToken ? `tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`;
|
||||
|
||||
window.open(newAddress);
|
||||
|
||||
return Promise.resolve();
|
||||
|
|
|
@ -61,6 +61,7 @@ export interface IBrowserWindowConfiguration {
|
|||
workspaceId: string;
|
||||
remoteAuthority?: string;
|
||||
webviewEndpoint?: string;
|
||||
connectionToken?: string;
|
||||
}
|
||||
|
||||
export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
|
||||
|
@ -81,6 +82,7 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
|
|||
this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json');
|
||||
this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS);
|
||||
this.configuration.backupWorkspaceResource = joinPath(this.backupHome, configuration.workspaceId);
|
||||
this.configuration.connectionToken = configuration.connectionToken || this.getConnectionTokenFromLocation();
|
||||
|
||||
this.logsPath = '/web/logs';
|
||||
|
||||
|
@ -182,4 +184,21 @@ export class BrowserWorkbenchEnvironmentService implements IEnvironmentService {
|
|||
get webviewCspSource(): string {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue