diff --git a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts index 9f9af56b2d980..0e4be0e40a94a 100644 --- a/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts +++ b/src/vs/workbench/api/browser/mainThreadWebviewPanels.ts @@ -13,7 +13,7 @@ import { MainThreadWebviews, reviveWebviewContentOptions, reviveWebviewExtension import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; -import { WebviewOptions, WebviewOriginStore } from 'vs/workbench/contrib/webview/browser/webview'; +import { ExtensionKeyedWebviewOriginStore, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput'; import { WebviewIcons } from 'vs/workbench/contrib/webviewPanel/browser/webviewIconManager'; import { IWebViewShowOptions, IWebviewWorkbenchService } from 'vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService'; @@ -86,7 +86,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc private readonly _revivers = this._register(new DisposableMap()); - private readonly webviewOriginStore: WebviewOriginStore; + private readonly webviewOriginStore: ExtensionKeyedWebviewOriginStore; constructor( context: IExtHostContext, @@ -101,7 +101,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc ) { super(); - this.webviewOriginStore = new WebviewOriginStore('mainThreadWebviewPanel.origins', storageService); + this.webviewOriginStore = new ExtensionKeyedWebviewOriginStore('mainThreadWebviewPanel.origins', storageService); this._proxy = context.getProxy(extHostProtocol.ExtHostContext.ExtHostWebviewPanels); diff --git a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts index bbef3bc7abcc4..b144209bf15f9 100644 --- a/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts +++ b/src/vs/workbench/contrib/notebook/browser/view/renderers/backLayerWebView.ts @@ -5,14 +5,15 @@ import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent'; import { coalesce } from 'vs/base/common/arrays'; +import { DeferredPromise } from 'vs/base/common/async'; import { decodeBase64 } from 'vs/base/common/buffer'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import { getExtensionForMimeType } from 'vs/base/common/mime'; import { FileAccess, Schemas } from 'vs/base/common/network'; +import { equals } from 'vs/base/common/objects'; import { isMacintosh, isWeb } from 'vs/base/common/platform'; import { dirname, joinPath } from 'vs/base/common/resources'; -import { equals } from 'vs/base/common/objects'; import { URI } from 'vs/base/common/uri'; import * as UUID from 'vs/base/common/uuid'; import { TokenizationRegistry } from 'vs/editor/common/languages'; @@ -27,6 +28,7 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IFileService } from 'vs/platform/files/common/files'; import { IOpenerService, matchesScheme, matchesSomeScheme } from 'vs/platform/opener/common/opener'; +import { IStorageService } from 'vs/platform/storage/common/storage'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; import { asWebviewUri, webviewGenericCspSource } from 'vs/workbench/common/webview'; @@ -39,12 +41,11 @@ import { CellUri, INotebookRendererInfo, NotebookSetting, RendererMessagingSpec import { INotebookKernel } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; import { IScopedRendererMessaging } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService'; import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService'; -import { IWebviewElement, IWebviewService, WebviewContentPurpose } from 'vs/workbench/contrib/webview/browser/webview'; +import { IWebviewElement, IWebviewService, WebviewContentPurpose, WebviewOriginStore } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewWindowDragMonitor } from 'vs/workbench/contrib/webview/browser/webviewWindowDragMonitor'; import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { FromWebviewMessage, IAckOutputHeight, IClickedDataUrlMessage, ICodeBlockHighlightRequest, IContentWidgetTopRequest, IControllerPreload, ICreationContent, ICreationRequestMessage, IFindMatch, IMarkupCellInitialization, RendererMetadata, StaticPreloadMetadata, ToWebviewMessage } from './webviewMessages'; -import { DeferredPromise } from 'vs/base/common/async'; export interface ICachedInset { outputId: string; @@ -98,6 +99,14 @@ interface BacklayerWebviewOptions { } export class BackLayerWebView extends Disposable { + + private static _originStore?: WebviewOriginStore; + + private static getOriginStore(storageService: IStorageService): WebviewOriginStore { + this._originStore ??= new WebviewOriginStore('notebook.backlayerWebview.origins', storageService); + return this._originStore; + } + element: HTMLElement; webview: IWebviewElement | undefined = undefined; insetMapping: Map> = new Map(); @@ -139,6 +148,7 @@ export class BackLayerWebView extends Disposable { @ILanguageService private readonly languageService: ILanguageService, @IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService, @IEditorGroupsService private readonly editorGroupService: IEditorGroupsService, + @IStorageService private readonly storageService: IStorageService, ) { super(); @@ -912,6 +922,7 @@ var requirejs = (function() { this.localResourceRootsCache = this._getResourceRootsCache(); const webview = webviewService.createWebviewElement({ id: this.id, + origin: BackLayerWebView.getOriginStore(this.storageService).getOrigin(this.notebookViewType, undefined), options: { purpose: WebviewContentPurpose.NotebookRenderer, enableFindWidget: false, diff --git a/src/vs/workbench/contrib/webview/browser/webview.ts b/src/vs/workbench/contrib/webview/browser/webview.ts index 3b059b50717d9..89dd1c68c1295 100644 --- a/src/vs/workbench/contrib/webview/browser/webview.ts +++ b/src/vs/workbench/contrib/webview/browser/webview.ts @@ -300,7 +300,7 @@ export interface IOverlayWebview extends IWebview { /** * Stores the unique origins for a webview. * - * These are randomly generated, but keyed on extension and webview viewType. + * These are randomly generated */ export class WebviewOriginStore { @@ -315,8 +315,8 @@ export class WebviewOriginStore { this.state = this.memento.getMemento(StorageScope.APPLICATION, StorageTarget.MACHINE); } - public getOrigin(viewType: string, extId: ExtensionIdentifier): string { - const key = this.getKey(viewType, extId); + public getOrigin(viewType: string, additionalKey: string | undefined): string { + const key = this.getKey(viewType, additionalKey); const existing = this.state[key]; if (existing && typeof existing === 'string') { @@ -329,7 +329,28 @@ export class WebviewOriginStore { return newOrigin; } - private getKey(viewType: string, extId: ExtensionIdentifier): string { - return JSON.stringify({ viewType, extension: extId.value }); + private getKey(viewType: string, additionalKey: string | undefined): string { + return JSON.stringify({ viewType, key: additionalKey }); + } +} + +/** + * Stores the unique origins for a webview. + * + * These are randomly generated, but keyed on extension and webview viewType. + */ +export class ExtensionKeyedWebviewOriginStore { + + private readonly store: WebviewOriginStore; + + constructor( + rootStorageKey: string, + @IStorageService storageService: IStorageService, + ) { + this.store = new WebviewOriginStore(rootStorageKey, storageService); + } + + public getOrigin(viewType: string, extId: ExtensionIdentifier): string { + return this.store.getOrigin(viewType, extId.value); } } diff --git a/src/vs/workbench/contrib/webviewView/browser/webviewViewPane.ts b/src/vs/workbench/contrib/webviewView/browser/webviewViewPane.ts index b7e590d44f4c1..fee6a772e8c09 100644 --- a/src/vs/workbench/contrib/webviewView/browser/webviewViewPane.ts +++ b/src/vs/workbench/contrib/webviewView/browser/webviewViewPane.ts @@ -25,7 +25,7 @@ import { ViewPane } from 'vs/workbench/browser/parts/views/viewPane'; import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet'; import { Memento, MementoObject } from 'vs/workbench/common/memento'; import { IViewBadge, IViewDescriptorService, IViewsService } from 'vs/workbench/common/views'; -import { IOverlayWebview, IWebviewService, WebviewContentPurpose, WebviewOriginStore } from 'vs/workbench/contrib/webview/browser/webview'; +import { ExtensionKeyedWebviewOriginStore, IOverlayWebview, IWebviewService, WebviewContentPurpose } from 'vs/workbench/contrib/webview/browser/webview'; import { WebviewWindowDragMonitor } from 'vs/workbench/contrib/webview/browser/webviewWindowDragMonitor'; import { IWebviewViewService, WebviewView } from 'vs/workbench/contrib/webviewView/browser/webviewViewService'; import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity'; @@ -39,10 +39,10 @@ const storageKeys = { export class WebviewViewPane extends ViewPane { - private static _originStore?: WebviewOriginStore; + private static _originStore?: ExtensionKeyedWebviewOriginStore; - private static getOriginStore(storageService: IStorageService): WebviewOriginStore { - this._originStore ??= new WebviewOriginStore('webviewViews.origins', storageService); + private static getOriginStore(storageService: IStorageService): ExtensionKeyedWebviewOriginStore { + this._originStore ??= new ExtensionKeyedWebviewOriginStore('webviewViews.origins', storageService); return this._originStore; }