Skip to content

Commit 3a75026

Browse files
authored
Remove webview.id public field (microsoft#166733)
The id is now separate from the origin. It should always be randomly generated instead of relying on callers to do so
1 parent 2f4c796 commit 3a75026

File tree

17 files changed

+26
-65
lines changed

17 files changed

+26
-65
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
9090
const disposables = new DisposableStore();
9191

9292
const webview = this._webviewService.createWebviewElement({
93-
id: 'mainThreadCodeInsets_' + handle,
9493
options: {
9594
enableFindWidget: false,
9695
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Schemas } from 'vs/base/common/network';
1414
import { basename } from 'vs/base/common/path';
1515
import { isEqual, isEqualOrParent, toLocalResource } from 'vs/base/common/resources';
1616
import { URI, UriComponents } from 'vs/base/common/uri';
17+
import { generateUuid } from 'vs/base/common/uuid';
1718
import { localize } from 'vs/nls';
1819
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1920
import { FileOperation, IFileService } from 'vs/platform/files/common/files';
@@ -137,7 +138,7 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
137138
return webviewInput instanceof CustomEditorInput && webviewInput.viewType === viewType;
138139
},
139140
resolveWebview: async (webviewInput: CustomEditorInput, cancellation: CancellationToken) => {
140-
const handle = webviewInput.id;
141+
const handle = generateUuid();
141142
const resource = webviewInput.resource;
142143

143144
webviewInput.webview.origin = this._webviewOriginStore.getOrigin(viewType, extension.id);
@@ -660,7 +661,6 @@ class MainThreadCustomEditorModel extends ResourceWorkingCopy implements ICustom
660661
location: primaryEditor.extension.location!,
661662
} : undefined,
662663
webview: {
663-
id: primaryEditor.id,
664664
origin: primaryEditor.webview.origin,
665665
options: primaryEditor.webview.options,
666666
state: primaryEditor.webview.state,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { onUnexpectedError } from 'vs/base/common/errors';
77
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle';
88
import { URI } from 'vs/base/common/uri';
9+
import { generateUuid } from 'vs/base/common/uuid';
910
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1011
import { IStorageService } from 'vs/platform/storage/common/storage';
1112
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
@@ -161,7 +162,6 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
161162
const origin = this.webviewOriginStore.getOrigin(viewType, extension.id);
162163

163164
const webview = this._webviewWorkbenchService.openWebview({
164-
id: handle,
165165
origin,
166166
providedViewType: viewType,
167167
options: reviveWebviewOptions(initData.panelOptions),
@@ -261,7 +261,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
261261
return;
262262
}
263263

264-
const handle = webviewInput.id;
264+
const handle = generateUuid();
265265

266266
this.addWebviewInput(handle, webviewInput, options);
267267

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { CancellationToken } from 'vs/base/common/cancellation';
77
import { onUnexpectedError } from 'vs/base/common/errors';
88
import { Disposable, DisposableMap } from 'vs/base/common/lifecycle';
9+
import { generateUuid } from 'vs/base/common/uuid';
910
import { MainThreadWebviews, reviveWebviewExtension } from 'vs/workbench/api/browser/mainThreadWebviews';
1011
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
1112
import { IViewBadge } from 'vs/workbench/common/views';
@@ -63,7 +64,7 @@ export class MainThreadWebviewsViews extends Disposable implements extHostProtoc
6364

6465
const registration = this._webviewViewService.register(viewType, {
6566
resolve: async (webviewView: WebviewView, cancellation: CancellationToken) => {
66-
const handle = webviewView.webview.id;
67+
const handle = generateUuid();
6768

6869
this._webviewViews.set(handle, webviewView);
6970
this.mainThreadWebviews.addWebview(handle, webviewView.webview, { serializeBuffersForPostMessage: options.serializeBuffersForPostMessage });

src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { basename } from 'vs/base/common/path';
1010
import { dirname, isEqual } from 'vs/base/common/resources';
1111
import { assertIsDefined } from 'vs/base/common/types';
1212
import { URI } from 'vs/base/common/uri';
13-
import { generateUuid } from 'vs/base/common/uuid';
1413
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1514
import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
1615
import { FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files';
@@ -20,14 +19,13 @@ import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
2019
import { EditorInputCapabilities, GroupIdentifier, IMoveResult, IRevertOptions, ISaveOptions, IUntypedEditorInput, Verbosity } from 'vs/workbench/common/editor';
2120
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
2221
import { ICustomEditorModel, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
23-
import { IWebviewService, IOverlayWebview } from 'vs/workbench/contrib/webview/browser/webview';
22+
import { IOverlayWebview, IWebviewService } from 'vs/workbench/contrib/webview/browser/webview';
2423
import { IWebviewWorkbenchService, LazilyResolvedWebviewEditorInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewWorkbenchService';
2524
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
2625

2726
interface CustomEditorInputInitInfo {
2827
readonly resource: URI;
2928
readonly viewType: string;
30-
readonly id: string;
3129
}
3230

3331
export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
@@ -43,15 +41,13 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
4341
// If it's an untitled file we must populate the untitledDocumentData
4442
const untitledString = accessor.get(IUntitledTextEditorService).getValue(resource);
4543
const untitledDocumentData = untitledString ? VSBuffer.fromString(untitledString) : undefined;
46-
const id = generateUuid();
4744
const webview = accessor.get(IWebviewService).createWebviewOverlay({
48-
id,
4945
providedViewType: viewType,
5046
options: { customClasses: options?.customClasses },
5147
contentOptions: {},
5248
extension: undefined,
5349
});
54-
const input = instantiationService.createInstance(CustomEditorInput, { resource, viewType, id }, webview, { untitledDocumentData: untitledDocumentData, oldResource: options?.oldResource });
50+
const input = instantiationService.createInstance(CustomEditorInput, { resource, viewType }, webview, { untitledDocumentData: untitledDocumentData, oldResource: options?.oldResource });
5551
if (typeof group !== 'undefined') {
5652
input.updateGroup(group);
5753
}
@@ -85,7 +81,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
8581
@IUndoRedoService private readonly undoRedoService: IUndoRedoService,
8682
@IFileService private readonly fileService: IFileService
8783
) {
88-
super({ id: init.id, providedId: init.viewType, viewType: init.viewType, name: '' }, webview, webviewWorkbenchService);
84+
super({ providedId: init.viewType, viewType: init.viewType, name: '' }, webview, webviewWorkbenchService);
8985
this._editorResource = init.resource;
9086
this.oldResource = options.oldResource;
9187
this._defaultDirtyState = options.startsDirty;

src/vs/workbench/contrib/customEditor/browser/customEditorInputFactory.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface CustomDocumentBackupData extends IWorkingCopyBackupMeta {
3030
};
3131

3232
readonly webview: {
33-
readonly id: string;
3433
readonly origin: string | undefined;
3534
readonly options: SerializedWebviewOptions;
3635
readonly state: any;
@@ -92,17 +91,16 @@ export class CustomEditorInputSerializer extends WebviewEditorInputSerializer {
9291
const data = this.fromJson(JSON.parse(serializedEditorInput));
9392

9493
const webview = reviveWebview(this._webviewService, data);
95-
const customInput = this._instantiationService.createInstance(CustomEditorInput, { resource: data.editorResource, viewType: data.viewType, id: data.id }, webview, { startsDirty: data.dirty, backupId: data.backupId });
94+
const customInput = this._instantiationService.createInstance(CustomEditorInput, { resource: data.editorResource, viewType: data.viewType }, webview, { startsDirty: data.dirty, backupId: data.backupId });
9695
if (typeof data.group === 'number') {
9796
customInput.updateGroup(data.group);
9897
}
9998
return customInput;
10099
}
101100
}
102101

103-
function reviveWebview(webviewService: IWebviewService, data: { id: string; origin: string | undefined; viewType: string; state: any; webviewOptions: WebviewOptions; contentOptions: WebviewContentOptions; extension?: WebviewExtensionDescription }) {
102+
function reviveWebview(webviewService: IWebviewService, data: { origin: string | undefined; viewType: string; state: any; webviewOptions: WebviewOptions; contentOptions: WebviewContentOptions; extension?: WebviewExtensionDescription }) {
104103
const webview = webviewService.createWebviewOverlay({
105-
id: data.id,
106104
providedViewType: data.viewType,
107105
origin: data.origin,
108106
options: {
@@ -168,10 +166,8 @@ export class ComplexCustomWorkingCopyEditorHandler extends Disposable implements
168166
}
169167

170168
const backupData = backup.meta;
171-
const id = backupData.webview.id;
172169
const extension = reviveWebviewExtensionDescription(backupData.extension?.id, backupData.extension?.location);
173170
const webview = reviveWebview(this._webviewService, {
174-
id,
175171
viewType: backupData.viewType,
176172
origin: backupData.webview.origin,
177173
webviewOptions: restoreWebviewOptions(backupData.webview.options),
@@ -180,7 +176,7 @@ export class ComplexCustomWorkingCopyEditorHandler extends Disposable implements
180176
extension,
181177
});
182178

183-
const editor = this._instantiationService.createInstance(CustomEditorInput, { resource: URI.revive(backupData.editorResource), viewType: backupData.viewType, id }, webview, { backupId: backupData.backupId });
179+
const editor = this._instantiationService.createInstance(CustomEditorInput, { resource: URI.revive(backupData.editorResource), viewType: backupData.viewType }, webview, { backupId: backupData.backupId });
184180
editor.updateGroup(0);
185181
return editor;
186182
}

src/vs/workbench/contrib/extensions/browser/extensionEditor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ export class ExtensionEditor extends EditorPane {
681681
}
682682

683683
const webview = this.contentDisposables.add(this.webviewService.createWebviewOverlay({
684-
id: generateUuid(),
685684
options: {
686685
enableFindWidget: true,
687686
tryRestoreScrollPosition: true,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
138138

139139
constructor(
140140
public notebookEditor: INotebookDelegateForWebview,
141-
public readonly id: string,
141+
private readonly id: string,
142142
public readonly notebookViewType: string,
143143
public readonly documentUri: URI,
144144
private options: BacklayerWebviewOptions,
@@ -952,7 +952,6 @@ var requirejs = (function() {
952952
private _createInset(webviewService: IWebviewService, content: string) {
953953
this.localResourceRootsCache = this._getResourceRootsCache();
954954
const webview = webviewService.createWebviewElement({
955-
id: this.id,
956955
origin: BackLayerWebView.getOriginStore(this.storageService).getOrigin(this.notebookViewType, undefined),
957956
options: {
958957
purpose: WebviewContentPurpose.NotebookRenderer,

src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export class ReleaseNotesManager {
7676
} else {
7777
this._currentReleaseNotes = this._webviewWorkbenchService.openWebview(
7878
{
79-
id: generateUuid(),
8079
options: {
8180
tryRestoreScrollPosition: true,
8281
enableFindWidget: true,

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
4040
private _findWidgetEnabled: IContextKey<boolean> | undefined;
4141
private _shouldShowFindWidgetOnRestore = false;
4242

43-
public readonly id: string;
4443
public readonly providedViewType?: string;
4544

4645
public origin: string;
@@ -55,7 +54,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
5554
) {
5655
super();
5756

58-
this.id = initInfo.id;
5957
this.providedViewType = initInfo.providedViewType;
6058
this.origin = initInfo.origin ?? generateUuid();
6159

@@ -96,7 +94,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
9694

9795
if (!this._container) {
9896
const node = document.createElement('div');
99-
node.id = `webview-${this.id}`;
10097
node.style.position = 'absolute';
10198
node.style.overflow = 'hidden';
10299
this._container = new FastDomNode(node);
@@ -188,7 +185,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
188185

189186
if (!this._webview.value) {
190187
const webview = this._webviewService.createWebviewElement({
191-
id: this.id,
192188
providedViewType: this.providedViewType,
193189
origin: this.origin,
194190
options: this._options,

0 commit comments

Comments
 (0)