Skip to content

Commit b6f4df8

Browse files
authored
Run notebook webviews in consistent origins (microsoft#163956)
1 parent b09701a commit b6f4df8

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { MainThreadWebviews, reviveWebviewContentOptions, reviveWebviewExtension
1313
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
1414
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
1515
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
16-
import { WebviewOptions, WebviewOriginStore } from 'vs/workbench/contrib/webview/browser/webview';
16+
import { ExtensionKeyedWebviewOriginStore, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview';
1717
import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput';
1818
import { WebviewIcons } from 'vs/workbench/contrib/webviewPanel/browser/webviewIconManager';
1919
import { IWebViewShowOptions, IWebviewWorkbenchService } from 'vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService';
@@ -86,7 +86,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
8686

8787
private readonly _revivers = this._register(new DisposableMap<string>());
8888

89-
private readonly webviewOriginStore: WebviewOriginStore;
89+
private readonly webviewOriginStore: ExtensionKeyedWebviewOriginStore;
9090

9191
constructor(
9292
context: IExtHostContext,
@@ -101,7 +101,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
101101
) {
102102
super();
103103

104-
this.webviewOriginStore = new WebviewOriginStore('mainThreadWebviewPanel.origins', storageService);
104+
this.webviewOriginStore = new ExtensionKeyedWebviewOriginStore('mainThreadWebviewPanel.origins', storageService);
105105

106106
this._proxy = context.getProxy(extHostProtocol.ExtHostContext.ExtHostWebviewPanels);
107107

src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
77
import { coalesce } from 'vs/base/common/arrays';
8+
import { DeferredPromise } from 'vs/base/common/async';
89
import { decodeBase64 } from 'vs/base/common/buffer';
910
import { Emitter, Event } from 'vs/base/common/event';
1011
import { Disposable } from 'vs/base/common/lifecycle';
1112
import { getExtensionForMimeType } from 'vs/base/common/mime';
1213
import { FileAccess, Schemas } from 'vs/base/common/network';
14+
import { equals } from 'vs/base/common/objects';
1315
import { isMacintosh, isWeb } from 'vs/base/common/platform';
1416
import { dirname, joinPath } from 'vs/base/common/resources';
15-
import { equals } from 'vs/base/common/objects';
1617
import { URI } from 'vs/base/common/uri';
1718
import * as UUID from 'vs/base/common/uuid';
1819
import { TokenizationRegistry } from 'vs/editor/common/languages';
@@ -27,6 +28,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
2728
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
2829
import { IFileService } from 'vs/platform/files/common/files';
2930
import { IOpenerService, matchesScheme, matchesSomeScheme } from 'vs/platform/opener/common/opener';
31+
import { IStorageService } from 'vs/platform/storage/common/storage';
3032
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
3133
import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust';
3234
import { asWebviewUri, webviewGenericCspSource } from 'vs/workbench/common/webview';
@@ -39,12 +41,11 @@ import { CellUri, INotebookRendererInfo, NotebookSetting, RendererMessagingSpec
3941
import { INotebookKernel } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
4042
import { IScopedRendererMessaging } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService';
4143
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
42-
import { IWebviewElement, IWebviewService, WebviewContentPurpose } from 'vs/workbench/contrib/webview/browser/webview';
44+
import { IWebviewElement, IWebviewService, WebviewContentPurpose, WebviewOriginStore } from 'vs/workbench/contrib/webview/browser/webview';
4345
import { WebviewWindowDragMonitor } from 'vs/workbench/contrib/webview/browser/webviewWindowDragMonitor';
4446
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
4547
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
4648
import { FromWebviewMessage, IAckOutputHeight, IClickedDataUrlMessage, ICodeBlockHighlightRequest, IContentWidgetTopRequest, IControllerPreload, ICreationContent, ICreationRequestMessage, IFindMatch, IMarkupCellInitialization, RendererMetadata, StaticPreloadMetadata, ToWebviewMessage } from './webviewMessages';
47-
import { DeferredPromise } from 'vs/base/common/async';
4849

4950
export interface ICachedInset<K extends ICommonCellInfo> {
5051
outputId: string;
@@ -98,6 +99,14 @@ interface BacklayerWebviewOptions {
9899
}
99100

100101
export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
102+
103+
private static _originStore?: WebviewOriginStore;
104+
105+
private static getOriginStore(storageService: IStorageService): WebviewOriginStore {
106+
this._originStore ??= new WebviewOriginStore('notebook.backlayerWebview.origins', storageService);
107+
return this._originStore;
108+
}
109+
101110
element: HTMLElement;
102111
webview: IWebviewElement | undefined = undefined;
103112
insetMapping: Map<IDisplayOutputViewModel, ICachedInset<T>> = new Map();
@@ -139,6 +148,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
139148
@ILanguageService private readonly languageService: ILanguageService,
140149
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
141150
@IEditorGroupsService private readonly editorGroupService: IEditorGroupsService,
151+
@IStorageService private readonly storageService: IStorageService,
142152
) {
143153
super();
144154

@@ -912,6 +922,7 @@ var requirejs = (function() {
912922
this.localResourceRootsCache = this._getResourceRootsCache();
913923
const webview = webviewService.createWebviewElement({
914924
id: this.id,
925+
origin: BackLayerWebView.getOriginStore(this.storageService).getOrigin(this.notebookViewType, undefined),
915926
options: {
916927
purpose: WebviewContentPurpose.NotebookRenderer,
917928
enableFindWidget: false,

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export interface IOverlayWebview extends IWebview {
300300
/**
301301
* Stores the unique origins for a webview.
302302
*
303-
* These are randomly generated, but keyed on extension and webview viewType.
303+
* These are randomly generated
304304
*/
305305
export class WebviewOriginStore {
306306

@@ -315,8 +315,8 @@ export class WebviewOriginStore {
315315
this.state = this.memento.getMemento(StorageScope.APPLICATION, StorageTarget.MACHINE);
316316
}
317317

318-
public getOrigin(viewType: string, extId: ExtensionIdentifier): string {
319-
const key = this.getKey(viewType, extId);
318+
public getOrigin(viewType: string, additionalKey: string | undefined): string {
319+
const key = this.getKey(viewType, additionalKey);
320320

321321
const existing = this.state[key];
322322
if (existing && typeof existing === 'string') {
@@ -329,7 +329,28 @@ export class WebviewOriginStore {
329329
return newOrigin;
330330
}
331331

332-
private getKey(viewType: string, extId: ExtensionIdentifier): string {
333-
return JSON.stringify({ viewType, extension: extId.value });
332+
private getKey(viewType: string, additionalKey: string | undefined): string {
333+
return JSON.stringify({ viewType, key: additionalKey });
334+
}
335+
}
336+
337+
/**
338+
* Stores the unique origins for a webview.
339+
*
340+
* These are randomly generated, but keyed on extension and webview viewType.
341+
*/
342+
export class ExtensionKeyedWebviewOriginStore {
343+
344+
private readonly store: WebviewOriginStore;
345+
346+
constructor(
347+
rootStorageKey: string,
348+
@IStorageService storageService: IStorageService,
349+
) {
350+
this.store = new WebviewOriginStore(rootStorageKey, storageService);
351+
}
352+
353+
public getOrigin(viewType: string, extId: ExtensionIdentifier): string {
354+
return this.store.getOrigin(viewType, extId.value);
334355
}
335356
}

src/vs/workbench/contrib/webviewView/browser/webviewViewPane.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ViewPane } from 'vs/workbench/browser/parts/views/viewPane';
2525
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';
2626
import { Memento, MementoObject } from 'vs/workbench/common/memento';
2727
import { IViewBadge, IViewDescriptorService, IViewsService } from 'vs/workbench/common/views';
28-
import { IOverlayWebview, IWebviewService, WebviewContentPurpose, WebviewOriginStore } from 'vs/workbench/contrib/webview/browser/webview';
28+
import { ExtensionKeyedWebviewOriginStore, IOverlayWebview, IWebviewService, WebviewContentPurpose } from 'vs/workbench/contrib/webview/browser/webview';
2929
import { WebviewWindowDragMonitor } from 'vs/workbench/contrib/webview/browser/webviewWindowDragMonitor';
3030
import { IWebviewViewService, WebviewView } from 'vs/workbench/contrib/webviewView/browser/webviewViewService';
3131
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
@@ -39,10 +39,10 @@ const storageKeys = {
3939

4040
export class WebviewViewPane extends ViewPane {
4141

42-
private static _originStore?: WebviewOriginStore;
42+
private static _originStore?: ExtensionKeyedWebviewOriginStore;
4343

44-
private static getOriginStore(storageService: IStorageService): WebviewOriginStore {
45-
this._originStore ??= new WebviewOriginStore('webviewViews.origins', storageService);
44+
private static getOriginStore(storageService: IStorageService): ExtensionKeyedWebviewOriginStore {
45+
this._originStore ??= new ExtensionKeyedWebviewOriginStore('webviewViews.origins', storageService);
4646
return this._originStore;
4747
}
4848

0 commit comments

Comments
 (0)