Skip to content

Commit 79c26b4

Browse files
authored
Try using consistent origin for main thread custom editors (microsoft#166520)
For microsoft#132464
1 parent 355c006 commit 79c26b4

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/vs/workbench/api/browser/mainThreadCustomEditors.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1919
import { FileOperation, IFileService } from 'vs/platform/files/common/files';
2020
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2121
import { ILabelService } from 'vs/platform/label/common/label';
22+
import { IStorageService } from 'vs/platform/storage/common/storage';
2223
import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo';
2324
import { MainThreadWebviewPanels } from 'vs/workbench/api/browser/mainThreadWebviewPanels';
2425
import { MainThreadWebviews, reviveWebviewExtension } from 'vs/workbench/api/browser/mainThreadWebviews';
@@ -28,7 +29,7 @@ import { CustomEditorInput } from 'vs/workbench/contrib/customEditor/browser/cus
2829
import { CustomDocumentBackupData } from 'vs/workbench/contrib/customEditor/browser/customEditorInputFactory';
2930
import { ICustomEditorModel, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
3031
import { CustomTextEditorModel } from 'vs/workbench/contrib/customEditor/common/customTextEditorModel';
31-
import { WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview';
32+
import { ExtensionKeyedWebviewOriginStore, WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview';
3233
import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput';
3334
import { IWebviewWorkbenchService } from 'vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService';
3435
import { editorGroupToColumn } from 'vs/workbench/services/editor/common/editorGroupColumn';
@@ -55,11 +56,14 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
5556

5657
private readonly _editorRenameBackups = new Map<string, CustomDocumentBackupData>();
5758

59+
private readonly _webviewOriginStore: ExtensionKeyedWebviewOriginStore;
60+
5861
constructor(
5962
context: IExtHostContext,
6063
private readonly mainThreadWebview: MainThreadWebviews,
6164
private readonly mainThreadWebviewPanels: MainThreadWebviewPanels,
6265
@IExtensionService extensionService: IExtensionService,
66+
@IStorageService storageService: IStorageService,
6367
@IWorkingCopyService workingCopyService: IWorkingCopyService,
6468
@IWorkingCopyFileService workingCopyFileService: IWorkingCopyFileService,
6569
@ICustomEditorService private readonly _customEditorService: ICustomEditorService,
@@ -69,6 +73,8 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
6973
) {
7074
super();
7175

76+
this._webviewOriginStore = new ExtensionKeyedWebviewOriginStore('mainThreadCustomEditors.origins', storageService);
77+
7278
this._proxyCustomEditors = context.getProxy(extHostProtocol.ExtHostContext.ExtHostCustomEditors);
7379

7480
this._register(workingCopyFileService.registerWorkingCopyProvider((editorResource) => {
@@ -134,6 +140,8 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
134140
const handle = webviewInput.id;
135141
const resource = webviewInput.resource;
136142

143+
webviewInput.webview.origin = this._webviewOriginStore.getOrigin(viewType, extension.id);
144+
137145
this.mainThreadWebviewPanels.addWebviewInput(handle, webviewInput, { serializeBuffersForPostMessage });
138146
webviewInput.webview.options = options;
139147
webviewInput.webview.extension = extension;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
4242

4343
public readonly id: string;
4444
public readonly providedViewType?: string;
45-
public readonly origin: string;
45+
46+
public origin: string;
4647

4748
private _container: FastDomNode<HTMLDivElement> | undefined;
4849

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,37 @@ export interface IWebview extends IDisposable {
176176
readonly id: string;
177177

178178
/**
179-
* The origin this webview itself is loaded from. May not be unique
179+
* The original view type of the webview.
180180
*/
181-
readonly origin: string;
181+
readonly providedViewType?: string;
182182

183183
/**
184-
* The original view type of the webview.
184+
* The origin this webview itself is loaded from. May not be unique.
185185
*/
186-
readonly providedViewType?: string;
186+
readonly origin: string;
187187

188+
/**
189+
* The html content of the webview.
190+
*/
188191
html: string;
192+
193+
/**
194+
* Control what content is allowed/blocked inside the webview.
195+
*/
189196
contentOptions: WebviewContentOptions;
197+
198+
/**
199+
* List of roots from which local resources can be loaded.
200+
*
201+
* Requests for local resources not in this list are blocked.
202+
*/
190203
localResourcesRoot: readonly URI[];
204+
205+
/**
206+
* The extension that created/owns this webview.
207+
*/
191208
extension: WebviewExtensionDescription | undefined;
209+
192210
initialScrollProgress: number;
193211
state: string | undefined;
194212

@@ -258,6 +276,8 @@ export interface IOverlayWebview extends IWebview {
258276
*/
259277
readonly container: HTMLElement;
260278

279+
origin: string;
280+
261281
options: WebviewOptions;
262282

263283
/**

0 commit comments

Comments
 (0)