diff --git a/src/vs/code/browser/workbench/workbench.ts b/src/vs/code/browser/workbench/workbench.ts index 390e4d48637..ce98b6ee867 100644 --- a/src/vs/code/browser/workbench/workbench.ts +++ b/src/vs/code/browser/workbench/workbench.ts @@ -208,11 +208,11 @@ class WorkspaceProvider implements IWorkspaceProvider { constructor( public readonly workspace: IWorkspace, - public readonly environment: ReadonlyMap + public readonly payload: object ) { } - async open(workspace: IWorkspace, options?: { reuse?: boolean, environment?: Map }): Promise { - if (options && options.reuse && !options.environment && this.isSame(this.workspace, workspace)) { + async open(workspace: IWorkspace, options?: { reuse?: boolean, payload?: object }): Promise { + if (options && options.reuse && !options.payload && this.isSame(this.workspace, workspace)) { return; // return early if workspace and environment is not changing and we are reusing window } @@ -233,10 +233,8 @@ class WorkspaceProvider implements IWorkspaceProvider { } // Environment - if (options && options.environment) { - for (const [key, value] of options.environment) { - targetHref += `&${key}=${encodeURIComponent(value)}`; - } + if (options && options.payload) { + targetHref += `&payload=${encodeURIComponent(JSON.stringify(options.payload))}`; } if (targetHref) { @@ -290,8 +288,8 @@ class WorkspaceProvider implements IWorkspaceProvider { workspace = undefined; } - // Find environmental properties - const environment = new Map(); + // Find payload + let payload = Object.create(null); if (document && document.location && document.location.search) { const query = document.location.search.substring(1); const vars = query.split('&'); @@ -299,14 +297,15 @@ class WorkspaceProvider implements IWorkspaceProvider { const pair = p.split('='); if (pair.length === 2) { const [key, value] = pair; - if (key !== WorkspaceProvider.QUERY_PARAM_EMPTY_WINDOW && key !== WorkspaceProvider.QUERY_PARAM_FOLDER && key !== WorkspaceProvider.QUERY_PARAM_WORKSPACE) { - environment.set(key, decodeURIComponent(value)); + if (key === 'payload') { + payload = JSON.parse(decodeURIComponent(value)); + break; } } } } - options.workspaceProvider = new WorkspaceProvider(workspace, environment); + options.workspaceProvider = new WorkspaceProvider(workspace, payload); options.urlCallbackProvider = new PollingURLCallbackProvider(); options.credentialsProvider = new LocalStorageCredentialsProvider(); diff --git a/src/vs/workbench/contrib/debug/browser/extensionHostDebugService.ts b/src/vs/workbench/contrib/debug/browser/extensionHostDebugService.ts index d18940a05fe..c5897f06752 100644 --- a/src/vs/workbench/contrib/debug/browser/extensionHostDebugService.ts +++ b/src/vs/workbench/contrib/debug/browser/extensionHostDebugService.ts @@ -13,6 +13,7 @@ import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService' import { IChannel } from 'vs/base/parts/ipc/common/ipc'; import { Event } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; +import { mapToSerializable } from 'vs/base/common/map'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkspaceProvider, IWorkspace } from 'vs/workbench/services/host/browser/browserHostService'; @@ -64,7 +65,7 @@ class BrowserExtensionHostDebugService extends ExtensionHostDebugChannelClient i } async openExtensionDevelopmentHostWindow(args: string[]): Promise { - if (!this.workspaceProvider.environment) { + if (!this.workspaceProvider.payload) { // TODO@Ben remove me once environment is adopted return this.openExtensionDevelopmentHostWindowLegacy(args); } @@ -96,8 +97,8 @@ class BrowserExtensionHostDebugService extends ExtensionHostDebugChannelClient i // Open debug window as new window. Pass ParsedArgs over. this.workspaceProvider.open(debugWorkspace, { - reuse: false, // debugging always requires a new window - environment // mandatory properties to enable debugging + reuse: false, // debugging always requires a new window + payload: mapToSerializable(environment) // mandatory properties to enable debugging }); } diff --git a/src/vs/workbench/services/environment/browser/environmentService.ts b/src/vs/workbench/services/environment/browser/environmentService.ts index 7e3051f96d1..003830f4248 100644 --- a/src/vs/workbench/services/environment/browser/environmentService.ts +++ b/src/vs/workbench/services/environment/browser/environmentService.ts @@ -16,6 +16,7 @@ import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platf import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api'; import product from 'vs/platform/product/common/product'; +import { serializableToMap } from 'vs/base/common/map'; export class BrowserWindowConfiguration implements IWindowConfiguration { @@ -101,8 +102,8 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment this.untitledWorkspacesHome = URI.from({ scheme: Schemas.untitled, path: 'Workspaces' }); // Fill in selected extra environmental properties - if (options.workspaceProvider && options.workspaceProvider.environment) { - const environment = options.workspaceProvider.environment; + if (options.workspaceProvider && Array.isArray(options.workspaceProvider.payload)) { + const environment = serializableToMap(options.workspaceProvider.payload); for (const [key, value] of environment) { switch (key) { case 'extensionDevelopmentPath': diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts index a84472e399b..bb0afb31a5d 100644 --- a/src/vs/workbench/services/host/browser/browserHostService.ts +++ b/src/vs/workbench/services/host/browser/browserHostService.ts @@ -34,10 +34,9 @@ export interface IWorkspaceProvider { readonly workspace: IWorkspace; /** - * Optionally a set of environmental properties to be used - * as environment for the workspace to open. + * Arbitrary payload from the `IWorkspaceProvider.open` call. */ - readonly environment?: ReadonlyMap; + readonly payload?: object; /** * Asks to open a workspace in the current or a new window. @@ -45,10 +44,10 @@ export interface IWorkspaceProvider { * @param workspace the workspace to open. * @param options optional options for the workspace to open. * - `reuse`: wether to open inside the current window or a new window - * - `environment`: a map of environmental properties that should be - * filled into the environment of the workspace to open. + * - `payload`: arbitrary payload that should be made available + * to the opening window via the `IWorkspaceProvider.payload` property. */ - open(workspace: IWorkspace, options?: { reuse?: boolean, environment?: Map }): Promise; + open(workspace: IWorkspace, options?: { reuse?: boolean, payload?: object }): Promise; } export class BrowserHostService extends Disposable implements IHostService {