Skip to content

Commit 1ee616d

Browse files
committed
Don't duplicate external webview commit in so many places
1 parent 04da82c commit 1ee616d

6 files changed

Lines changed: 33 additions & 34 deletions

File tree

src/vs/workbench/api/common/extHostWebview.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ export class ExtHostWebview implements vscode.Webview {
4141

4242
public get cspSource(): string {
4343
return this._initData.webviewCspSource
44-
.replace('{{uuid}}', this._handle)
45-
.replace('{{commit}}', this._initData.commit || '211fa02efe8c041fd7baa8ec3dce199d5185aa44');
44+
.replace('{{uuid}}', this._handle);
4645
}
4746

4847
public get html(): string {

src/vs/workbench/api/common/shared/webview.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { URI } from 'vs/base/common/uri';
77
import * as vscode from 'vscode';
88

99
export interface WebviewInitData {
10-
readonly commit?: string;
1110
readonly webviewResourceRoot: string;
1211
readonly webviewCspSource: string;
1312
}
@@ -18,7 +17,6 @@ export function asWebviewUri(
1817
resource: vscode.Uri,
1918
): vscode.Uri {
2019
const uri = initData.webviewResourceRoot
21-
.replace('{{commit}}', initData.commit || '211fa02efe8c041fd7baa8ec3dce199d5185aa44')
2220
.replace('{{resource}}', resource.toString().replace(/^\S+?:/, ''))
2321
.replace('{{uuid}}', uuid);
2422
return URI.parse(uri);

src/vs/workbench/contrib/webview/browser/webviewElement.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import { addClass, addDisposableListener } from 'vs/base/browser/dom';
77
import { Emitter } from 'vs/base/common/event';
88
import { Disposable } from 'vs/base/common/lifecycle';
9+
import { isWeb } from 'vs/base/common/platform';
910
import { URI } from 'vs/base/common/uri';
1011
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1112
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
1213
import { IFileService } from 'vs/platform/files/common/files';
13-
import { IProductService } from 'vs/platform/product/common/productService';
1414
import { ITunnelService } from 'vs/platform/remote/common/tunnel';
1515
import { ITheme, IThemeService } from 'vs/platform/theme/common/themeService';
1616
import { Webview, WebviewContentOptions, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview';
@@ -19,7 +19,6 @@ import { WebviewPortMappingManager } from 'vs/workbench/contrib/webview/common/p
1919
import { loadLocalResource } from 'vs/workbench/contrib/webview/common/resourceLoader';
2020
import { getWebviewThemeData } from 'vs/workbench/contrib/webview/common/themeing';
2121
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
22-
import { isWeb } from 'vs/base/common/platform';
2322

2423
interface WebviewContent {
2524
readonly html: string;
@@ -46,11 +45,10 @@ export class IFrameWebview extends Disposable implements Webview {
4645
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
4746
@IFileService private readonly fileService: IFileService,
4847
@IConfigurationService private readonly _configurationService: IConfigurationService,
49-
@IProductService private readonly _productService: IProductService
5048
) {
5149
super();
52-
if (!this.useExternalEndpoint && (!environmentService.options || typeof environmentService.options.webviewEndpoint !== 'string')) {
53-
throw new Error('To use iframe based webviews, you must configure `environmentService.webviewEndpoint`');
50+
if (!this.useExternalEndpoint && (!environmentService.options || typeof environmentService.webviewExternalEndpoint !== 'string')) {
51+
throw new Error('To use iframe based webviews, you must configure `environmentService.webviewExternalEndpoint`');
5452
}
5553

5654
this._portMappingManager = this._register(new WebviewPortMappingManager(
@@ -67,7 +65,7 @@ export class IFrameWebview extends Disposable implements Webview {
6765

6866
this.element = document.createElement('iframe');
6967
this.element.sandbox.add('allow-scripts', 'allow-same-origin');
70-
this.element.setAttribute('src', `${this.endpoint}/index.html?id=${this.id}`);
68+
this.element.setAttribute('src', `${this.externalEndpoint}/index.html?id=${this.id}`);
7169
this.element.style.border = 'none';
7270
this.element.style.width = '100%';
7371
this.element.style.height = '100%';
@@ -145,24 +143,14 @@ export class IFrameWebview extends Disposable implements Webview {
145143
this._register(themeService.onThemeChange(this.style, this));
146144
}
147145

148-
private get endpoint(): string {
149-
const baseEndpoint = this.externalEndpoint || this.environmentService.options!.webviewEndpoint!;
150-
const endpoint = baseEndpoint.replace('{{uuid}}', this.id);
146+
private get externalEndpoint(): string {
147+
const endpoint = this.environmentService.webviewExternalEndpoint!.replace('{{uuid}}', this.id);
151148
if (endpoint[endpoint.length - 1] === '/') {
152149
return endpoint.slice(0, endpoint.length - 1);
153150
}
154151
return endpoint;
155152
}
156153

157-
private get externalEndpoint(): string | undefined {
158-
const useExternalEndpoint = this.useExternalEndpoint;
159-
if (!useExternalEndpoint) {
160-
return undefined;
161-
}
162-
const commit = this._productService.quality && this._productService.commit ? this._productService.commit : '211fa02efe8c041fd7baa8ec3dce199d5185aa44';
163-
return `https://{{uuid}}.vscode-webview-test.com/${commit}`;
164-
}
165-
166154
private get useExternalEndpoint(): boolean {
167155
return isWeb || this._configurationService.getValue<boolean>('webview.experimental.useExternalEndpoint');
168156
}
@@ -197,7 +185,7 @@ export class IFrameWebview extends Disposable implements Webview {
197185

198186
private preprocessHtml(value: string): string {
199187
return value.replace(/(["'])vscode-resource:([^\s'"]+?)(["'])/gi, (_, startQuote, path, endQuote) =>
200-
`${startQuote}${this.endpoint}/vscode-resource${path}${endQuote}`);
188+
`${startQuote}${this.externalEndpoint}/vscode-resource${path}${endQuote}`);
201189
}
202190

203191
public update(html: string, options: WebviewContentOptions, retainContextWhenHidden: boolean) {
@@ -217,7 +205,7 @@ export class IFrameWebview extends Disposable implements Webview {
217205
contents: this.content.html,
218206
options: this.content.options,
219207
state: this.content.state,
220-
endpoint: this.endpoint,
208+
endpoint: this.externalEndpoint,
221209
});
222210
}
223211

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IWindowConfiguration, IPath, IPathsToWaitFor } from 'vs/platform/windows/common/windows';
7-
import { IExtensionHostDebugParams, IDebugParams, BACKUPS } from 'vs/platform/environment/common/environment';
8-
import { URI } from 'vs/base/common/uri';
9-
import { IProcessEnvironment } from 'vs/base/common/platform';
10-
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
6+
import { Schemas } from 'vs/base/common/network';
117
import { ExportData } from 'vs/base/common/performance';
12-
import { LogLevel } from 'vs/platform/log/common/log';
8+
import { IProcessEnvironment } from 'vs/base/common/platform';
139
import { joinPath } from 'vs/base/common/resources';
14-
import { Schemas } from 'vs/base/common/network';
10+
import { URI } from 'vs/base/common/uri';
11+
import { generateUuid } from 'vs/base/common/uuid';
12+
import { BACKUPS, IDebugParams, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
13+
import { LogLevel } from 'vs/platform/log/common/log';
14+
import product from 'vs/platform/product/browser/product';
15+
import { IPath, IPathsToWaitFor, IWindowConfiguration } from 'vs/platform/windows/common/windows';
16+
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
1517
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
1618
import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api';
17-
import { generateUuid } from 'vs/base/common/uuid';
1819

1920
export class BrowserWindowConfiguration implements IWindowConfiguration {
2021

@@ -178,12 +179,18 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment
178179
galleryMachineIdResource?: URI;
179180
readonly logFile: URI;
180181

182+
get webviewExternalEndpoint(): string {
183+
// TODO: get fallback from product.json
184+
return this.options.webviewEndpoint || 'https://{{uuid}}.vscode-webview-test.com';
185+
}
186+
181187
get webviewResourceRoot(): string {
182-
return this.options.webviewEndpoint ? `${this.options.webviewEndpoint}/vscode-resource{{resource}}` : 'vscode-resource:{{resource}}';
188+
return `${this.webviewExternalEndpoint}/{{commit}}/vscode-resource{{resource}}`
189+
.replace('{{commit}}', product.commit || '211fa02efe8c041fd7baa8ec3dce199d5185aa44');
183190
}
184191

185192
get webviewCspSource(): string {
186-
return this.options.webviewEndpoint ? this.options.webviewEndpoint : 'vscode-resource:';
193+
return this.options.webviewEndpoint || `https://*.vscode-webview-test.com`;
187194
}
188195
}
189196

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface IWorkbenchEnvironmentService extends IEnvironmentService {
2424

2525
readonly debugSearch: IDebugParams;
2626

27+
readonly webviewExternalEndpoint: string;
2728
readonly webviewResourceRoot: string;
2829
readonly webviewCspSource: string;
2930

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ import { Schemas } from 'vs/base/common/network';
1212
import { toBackupWorkspaceResource } from 'vs/workbench/services/backup/common/backup';
1313
import { join } from 'vs/base/common/path';
1414
import { IDebugParams } from 'vs/platform/environment/common/environment';
15+
import product from 'vs/platform/product/node/product';
1516

1617
export class WorkbenchEnvironmentService extends EnvironmentService implements IWorkbenchEnvironmentService {
1718

1819
_serviceBrand: undefined;
1920

21+
get webviewExternalEndpoint(): string {
22+
const baseEndpoint = 'https://{{uuid}}.vscode-webview-test.com/{{commit}}';
23+
return baseEndpoint.replace('{{commit}}', product.commit || '211fa02efe8c041fd7baa8ec3dce199d5185aa44');
24+
}
25+
2026
readonly webviewResourceRoot = 'vscode-resource:{{resource}}';
2127
readonly webviewCspSource = 'vscode-resource:';
2228

0 commit comments

Comments
 (0)