提交 c142b048 编写于 作者: M Matt Bierner

Prefer using the name `webviewInput` for variables that manage WebviewInput objects

上级 019bce14
...@@ -30,7 +30,7 @@ import { Schemas } from 'vs/base/common/network'; ...@@ -30,7 +30,7 @@ import { Schemas } from 'vs/base/common/network';
/** /**
* Bi-directional map between webview handles and inputs. * Bi-directional map between webview handles and inputs.
*/ */
class WebviewHandleStore { class WebviewInputStore {
private readonly _handlesToInputs = new Map<string, WebviewInput>(); private readonly _handlesToInputs = new Map<string, WebviewInput>();
private readonly _inputsToHandles = new Map<WebviewInput, string>(); private readonly _inputsToHandles = new Map<WebviewInput, string>();
...@@ -90,7 +90,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -90,7 +90,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
]); ]);
private readonly _proxy: ExtHostWebviewsShape; private readonly _proxy: ExtHostWebviewsShape;
private readonly _webviewEditorInputs = new WebviewHandleStore(); private readonly _webviewInputs = new WebviewInputStore();
private readonly _revivers = new Map<string, IDisposable>(); private readonly _revivers = new Map<string, IDisposable>();
private readonly _editorProviders = new Map<string, IDisposable>(); private readonly _editorProviders = new Map<string, IDisposable>();
...@@ -150,7 +150,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -150,7 +150,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
}); });
this.hookupWebviewEventDelegate(handle, webview); this.hookupWebviewEventDelegate(handle, webview);
this._webviewEditorInputs.add(handle, webview); this._webviewInputs.add(handle, webview);
/* __GDPR__ /* __GDPR__
"webviews:createWebviewPanel" : { "webviews:createWebviewPanel" : {
...@@ -161,39 +161,39 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -161,39 +161,39 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
} }
public $disposeWebview(handle: WebviewPanelHandle): void { public $disposeWebview(handle: WebviewPanelHandle): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
webview.dispose(); webview.dispose();
} }
public $setTitle(handle: WebviewPanelHandle, value: string): void { public $setTitle(handle: WebviewPanelHandle, value: string): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
webview.setName(value); webview.setName(value);
} }
public $setState(handle: WebviewPanelHandle, state: modes.WebviewContentState): void { public $setState(handle: WebviewPanelHandle, state: modes.WebviewContentState): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
if (webview instanceof CustomFileEditorInput) { if (webview instanceof CustomFileEditorInput) {
webview.setState(state); webview.setState(state);
} }
} }
public $setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents; } | undefined): void { public $setIconPath(handle: WebviewPanelHandle, value: { light: UriComponents, dark: UriComponents; } | undefined): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
webview.iconPath = reviveWebviewIcon(value); webview.iconPath = reviveWebviewIcon(value);
} }
public $setHtml(handle: WebviewPanelHandle, value: string): void { public $setHtml(handle: WebviewPanelHandle, value: string): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
webview.webview.html = value; webview.webview.html = value;
} }
public $setOptions(handle: WebviewPanelHandle, options: modes.IWebviewOptions): void { public $setOptions(handle: WebviewPanelHandle, options: modes.IWebviewOptions): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
webview.webview.contentOptions = reviveWebviewOptions(options as any /*todo@mat */); webview.webview.contentOptions = reviveWebviewOptions(options as any /*todo@mat */);
} }
public $reveal(handle: WebviewPanelHandle, showOptions: WebviewPanelShowOptions): void { public $reveal(handle: WebviewPanelHandle, showOptions: WebviewPanelShowOptions): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
if (webview.isDisposed()) { if (webview.isDisposed()) {
return; return;
} }
...@@ -205,7 +205,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -205,7 +205,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
} }
public async $postMessage(handle: WebviewPanelHandle, message: any): Promise<boolean> { public async $postMessage(handle: WebviewPanelHandle, message: any): Promise<boolean> {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
webview.webview.sendMessage(message); webview.webview.sendMessage(message);
return true; return true;
} }
...@@ -216,34 +216,34 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -216,34 +216,34 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
} }
this._revivers.set(viewType, this._webviewWorkbenchService.registerResolver({ this._revivers.set(viewType, this._webviewWorkbenchService.registerResolver({
canResolve: (webviewEditorInput) => { canResolve: (webviewInput) => {
return webviewEditorInput.viewType === webviewPanelViewType.fromExternal(viewType); return webviewInput.viewType === webviewPanelViewType.fromExternal(viewType);
}, },
resolveWebview: async (webviewEditorInput): Promise<void> => { resolveWebview: async (webviewInput): Promise<void> => {
const viewType = webviewPanelViewType.toExternal(webviewEditorInput.viewType); const viewType = webviewPanelViewType.toExternal(webviewInput.viewType);
if (!viewType) { if (!viewType) {
webviewEditorInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(webviewEditorInput.viewType); webviewInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(webviewInput.viewType);
return; return;
} }
const handle = webviewEditorInput.id; const handle = webviewInput.id;
this._webviewEditorInputs.add(handle, webviewEditorInput); this._webviewInputs.add(handle, webviewInput);
this.hookupWebviewEventDelegate(handle, webviewEditorInput); this.hookupWebviewEventDelegate(handle, webviewInput);
let state = undefined; let state = undefined;
if (webviewEditorInput.webview.state) { if (webviewInput.webview.state) {
try { try {
state = JSON.parse(webviewEditorInput.webview.state); state = JSON.parse(webviewInput.webview.state);
} catch { } catch {
// noop // noop
} }
} }
try { try {
await this._proxy.$deserializeWebviewPanel(handle, viewType, webviewEditorInput.getTitle(), state, editorGroupToViewColumn(this._editorGroupService, webviewEditorInput.group || 0), webviewEditorInput.webview.options); await this._proxy.$deserializeWebviewPanel(handle, viewType, webviewInput.getTitle(), state, editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0), webviewInput.webview.options);
} catch (error) { } catch (error) {
onUnexpectedError(error); onUnexpectedError(error);
webviewEditorInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType); webviewInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
} }
} }
})); }));
...@@ -267,34 +267,34 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -267,34 +267,34 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
const extension = { id: extensionId, location: URI.revive(extensionLocation) }; const extension = { id: extensionId, location: URI.revive(extensionLocation) };
this._editorProviders.set(viewType, this._webviewWorkbenchService.registerResolver({ this._editorProviders.set(viewType, this._webviewWorkbenchService.registerResolver({
canResolve: (webview) => { canResolve: (webviewInput) => {
return webview.getTypeId() !== WebviewInput.typeId && webview.viewType === viewType; return webviewInput.getTypeId() !== WebviewInput.typeId && webviewInput.viewType === viewType;
}, },
resolveWebview: async (webview) => { resolveWebview: async (webviewInput) => {
const handle = webview.id; const handle = webviewInput.id;
this._webviewEditorInputs.add(handle, webview); this._webviewInputs.add(handle, webviewInput);
this.hookupWebviewEventDelegate(handle, webview); this.hookupWebviewEventDelegate(handle, webviewInput);
webview.webview.extension = extension; webviewInput.webview.extension = extension;
if (webview instanceof CustomFileEditorInput) { if (webviewInput instanceof CustomFileEditorInput) {
webview.onWillSave(e => { webviewInput.onWillSave(e => {
e.waitUntil(this._proxy.$save(handle)); e.waitUntil(this._proxy.$save(handle));
}); });
} }
try { try {
await this._proxy.$resolveWebviewEditor( await this._proxy.$resolveWebviewEditor(
webview.getResource(), webviewInput.getResource(),
handle, handle,
viewType, viewType,
webview.getTitle(), webviewInput.getTitle(),
editorGroupToViewColumn(this._editorGroupService, webview.group || 0), editorGroupToViewColumn(this._editorGroupService, webviewInput.group || 0),
webview.webview.options webviewInput.webview.options
); );
} catch (error) { } catch (error) {
onUnexpectedError(error); onUnexpectedError(error);
webview.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType); webviewInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
} }
} }
})); }));
...@@ -315,14 +315,14 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -315,14 +315,14 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
input.webview.onMessage((message: any) => this._proxy.$onMessage(handle, message)); input.webview.onMessage((message: any) => this._proxy.$onMessage(handle, message));
input.onDispose(() => { input.onDispose(() => {
this._proxy.$onDidDisposeWebviewPanel(handle).finally(() => { this._proxy.$onDidDisposeWebviewPanel(handle).finally(() => {
this._webviewEditorInputs.delete(handle); this._webviewInputs.delete(handle);
}); });
}); });
input.webview.onMissingCsp((extension: ExtensionIdentifier) => this._proxy.$onMissingCsp(handle, extension.value)); input.webview.onMissingCsp((extension: ExtensionIdentifier) => this._proxy.$onMissingCsp(handle, extension.value));
} }
private updateWebviewViewStates() { private updateWebviewViewStates() {
if (!this._webviewEditorInputs.size) { if (!this._webviewInputs.size) {
return; return;
} }
...@@ -336,7 +336,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -336,7 +336,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
editorInput.updateGroup(group.id); editorInput.updateGroup(group.id);
const handle = this._webviewEditorInputs.getHandleForInput(editorInput); const handle = this._webviewInputs.getHandleForInput(editorInput);
if (handle) { if (handle) {
viewStates[handle] = { viewStates[handle] = {
visible: topLevelInput === group.activeEditor, visible: topLevelInput === group.activeEditor,
...@@ -363,7 +363,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -363,7 +363,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
} }
private onDidClickLink(handle: WebviewPanelHandle, link: URI): void { private onDidClickLink(handle: WebviewPanelHandle, link: URI): void {
const webview = this.getWebviewEditorInput(handle); const webview = this.getWebviewInput(handle);
if (this.isSupportedLink(webview, link)) { if (this.isSupportedLink(webview, link)) {
this._openerService.open(link); this._openerService.open(link);
} }
...@@ -379,16 +379,16 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews ...@@ -379,16 +379,16 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
return !!webview.webview.contentOptions.enableCommandUris && link.scheme === Schemas.command; return !!webview.webview.contentOptions.enableCommandUris && link.scheme === Schemas.command;
} }
private getWebviewEditorInput(handle: WebviewPanelHandle): WebviewInput { private getWebviewInput(handle: WebviewPanelHandle): WebviewInput {
const webview = this.tryGetWebviewEditorInput(handle); const webview = this.tryGetWebviewInput(handle);
if (!webview) { if (!webview) {
throw new Error('Unknown webview handle:' + handle); throw new Error('Unknown webview handle:' + handle);
} }
return webview; return webview;
} }
private tryGetWebviewEditorInput(handle: WebviewPanelHandle): WebviewInput | undefined { private tryGetWebviewInput(handle: WebviewPanelHandle): WebviewInput | undefined {
return this._webviewEditorInputs.getInputForHandle(handle); return this._webviewInputs.getInputForHandle(handle);
} }
private static getDeserializationFailedContents(viewType: string) { private static getDeserializationFailedContents(viewType: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册