Skip to content

Commit d5fd351

Browse files
committed
Add setting that enables using a dynamic endpoint for hosting the static webview content
For microsoft#77132
1 parent b330068 commit d5fd351

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/vs/code/browser/workbench/workbench.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
1111

1212
<meta http-equiv="Content-Security-Policy"
13-
content="default-src 'none'; img-src 'self' https: data: blob: vscode-remote:; media-src 'none'; child-src 'self' {{WEBVIEW_ENDPOINT}}; script-src 'self' https://az416426.vo.msecnd.net 'unsafe-eval'; style-src 'self' 'unsafe-inline'; connect-src 'self' ws: wss: https:; font-src 'self' blob: vscode-remote:;">
13+
content="default-src 'none'; img-src 'self' https: data: blob: vscode-remote:; media-src 'none'; frame-src 'self' {{WEBVIEW_ENDPOINT}} https://*.vscode-webview-test.com; script-src 'self' https://az416426.vo.msecnd.net 'unsafe-eval'; style-src 'self' 'unsafe-inline'; connect-src 'self' ws: wss: https:; font-src 'self' blob: vscode-remote:;">
1414

1515
<meta id="vscode-workbench-web-configuration" data-settings="{{WORKBENCH_WEB_CONGIGURATION}}">
1616

src/vs/code/electron-browser/workbench/workbench.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html>
44
<head>
55
<meta charset="utf-8" />
6-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data: blob: vscode-remote:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https: vscode-remote:;">
6+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data: blob: vscode-remote:; media-src 'none'; frame-src 'self' https://*.vscode-webview-test.com; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https: vscode-remote:;">
77
</head>
88
<body class="vs-dark" aria-label="">
99
</body>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export class IFrameWebview extends Disposable implements Webview {
4545
@IConfigurationService private readonly _configurationService: IConfigurationService,
4646
) {
4747
super();
48-
if (typeof environmentService.webviewEndpoint !== 'string') {
48+
const useExternalEndpoint = this._configurationService.getValue<string>('webview.experimental.useExternalEndpoint');
49+
50+
if (typeof environmentService.webviewEndpoint !== 'string' && !useExternalEndpoint) {
4951
throw new Error('To use iframe based webviews, you must configure `environmentService.webviewEndpoint`');
5052
}
5153

@@ -142,7 +144,9 @@ export class IFrameWebview extends Disposable implements Webview {
142144
}
143145

144146
private get endpoint(): string {
145-
const endpoint = this.environmentService.webviewEndpoint!.replace('{{uuid}}', this.id);
147+
const useExternalEndpoint = this._configurationService.getValue<string>('webview.experimental.useExternalEndpoint');
148+
const baseEndpoint = useExternalEndpoint ? 'https://{{uuid}}.vscode-webview-test.com/8fa811108f0f0524c473020ef57b6620f6c201e1' : this.environmentService.webviewEndpoint!;
149+
const endpoint = baseEndpoint.replace('{{uuid}}', this.id);
146150
if (endpoint[endpoint.length - 1] === '/') {
147151
return endpoint.slice(0, endpoint.length - 1);
148152
}

src/vs/workbench/contrib/webview/electron-browser/webviewService.ts

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

6+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
67
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
78
import { DynamicWebviewEditorOverlay } from 'vs/workbench/contrib/webview/browser/DynamicWebviewEditorOverlay';
9+
import { IFrameWebview } from 'vs/workbench/contrib/webview/browser/webviewElement';
810
import { IWebviewService, WebviewContentOptions, WebviewEditorOverlay, WebviewElement, WebviewOptions } from 'vs/workbench/contrib/webview/common/webview';
911
import { ElectronWebviewBasedWebview } from 'vs/workbench/contrib/webview/electron-browser/webviewElement';
1012

@@ -13,14 +15,20 @@ export class ElectronWebviewService implements IWebviewService {
1315

1416
constructor(
1517
@IInstantiationService private readonly _instantiationService: IInstantiationService,
18+
@IConfigurationService private readonly _configService: IConfigurationService,
1619
) { }
1720

1821
createWebview(
19-
_id: string,
22+
id: string,
2023
options: WebviewOptions,
2124
contentOptions: WebviewContentOptions
2225
): WebviewElement {
23-
return this._instantiationService.createInstance(ElectronWebviewBasedWebview, options, contentOptions);
26+
const useExternalEndpoint = this._configService.getValue<string>('webview.experimental.useExternalEndpoint');
27+
if (useExternalEndpoint) {
28+
return this._instantiationService.createInstance(IFrameWebview, id, options, contentOptions);
29+
} else {
30+
return this._instantiationService.createInstance(ElectronWebviewBasedWebview, options, contentOptions);
31+
}
2432
}
2533

2634
createWebviewEditorOverlay(

0 commit comments

Comments
 (0)