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

Remove webview _onBeforeShutdown

This should no longer be required
上级 c9e83415
......@@ -10,7 +10,6 @@ import { URI, UriComponents } from 'vs/base/common/uri';
import * as modes from 'vs/editor/common/modes';
import { localize } from 'vs/nls';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle, WebviewPanelShowOptions } from 'vs/workbench/api/common/extHost.protocol';
......@@ -24,6 +23,11 @@ import { IExtensionService } from 'vs/workbench/services/extensions/common/exten
import { extHostNamedCustomer } from '../common/extHostCustomers';
import { IProductService } from 'vs/platform/product/common/product';
interface MainThreadWebviewState {
readonly viewType: string;
state: any;
}
@extHostNamedCustomer(MainContext.MainThreadWebviews)
export class MainThreadWebviews extends Disposable implements MainThreadWebviewsShape {
......@@ -39,14 +43,13 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
private readonly _proxy: ExtHostWebviewsShape;
private readonly _webviews = new Map<WebviewPanelHandle, WebviewEditorInput>();
private readonly _webviews = new Map<WebviewPanelHandle, WebviewEditorInput<MainThreadWebviewState>>();
private readonly _revivers = new Map<string, IDisposable>();
private _activeWebview: WebviewPanelHandle | undefined = undefined;
constructor(
context: IExtHostContext,
@ILifecycleService lifecycleService: ILifecycleService,
@IExtensionService extensionService: IExtensionService,
@IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService,
@IEditorService private readonly _editorService: IEditorService,
......@@ -64,20 +67,15 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
// This reviver's only job is to activate webview extensions
// This should trigger the real reviver to be registered from the extension host side.
this._register(_webviewEditorService.registerReviver({
canRevive: (webview) => {
const viewType = webview.state.viewType;
if (viewType) {
canRevive: (webview: WebviewEditorInput<any>) => {
const viewType = webview.state && webview.state.viewType;
if (typeof viewType === 'string') {
extensionService.activateByEvent(`onWebviewPanel:${viewType}`);
}
return false;
},
reviveWebview: () => { throw new Error('not implemented'); }
}));
this._register(lifecycleService.onBeforeShutdown(e => {
this._onBeforeShutdown();
e.veto(false); // Don't veto shutdown
}, this));
}
public $createWebviewPanel(
......@@ -98,7 +96,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
const webview = this._webviewEditorService.createWebview(this.getInternalWebviewId(viewType), title, mainThreadShowOptions, reviveWebviewOptions(options), {
location: URI.revive(extensionLocation),
id: extensionId
}, this.createWebviewEventDelegate(handle));
}, this.createWebviewEventDelegate(handle)) as WebviewEditorInput<MainThreadWebviewState>;
webview.state = {
viewType: viewType,
state: undefined
......@@ -218,14 +216,6 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
return `mainThreadWebview-${viewType}`;
}
private _onBeforeShutdown(): void {
this._webviews.forEach((webview) => {
if (!webview.isDisposed() && webview.state && this._revivers.has(webview.state.viewType)) {
webview.state.state = webview.webviewState;
}
});
}
private createWebviewEventDelegate(handle: WebviewPanelHandle) {
return {
onDidClickLink: (uri: URI) => this.onDidClickLink(handle, uri),
......@@ -234,6 +224,13 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
this._proxy.$onDidDisposeWebviewPanel(handle).finally(() => {
this._webviews.delete(handle);
});
},
onDidUpdateWebviewState: (newState: any) => {
const webview = this.tryGetWebview(handle);
if (!webview || webview.isDisposed()) {
return;
}
(webview as WebviewEditorInput<MainThreadWebviewState>).state.state = newState;
}
};
}
......@@ -326,13 +323,17 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
}
private getWebview(handle: WebviewPanelHandle): WebviewEditorInput {
const webview = this._webviews.get(handle);
const webview = this.tryGetWebview(handle);
if (!webview) {
throw new Error('Unknown webview handle:' + handle);
}
return webview;
}
private tryGetWebview(handle: WebviewPanelHandle): WebviewEditorInput | undefined {
return this._webviews.get(handle);
}
private static getDeserializationFailedContents(viewType: string) {
return `<!DOCTYPE html>
<html>
......
......@@ -256,7 +256,7 @@ export class WebviewEditor extends BaseEditor {
this._webview.initialScrollProgress = input.scrollYPercentage;
}
this._webview.state = input.webviewState;
this._webview.state = input.state ? input.state.state : undefined;
this._content!.setAttribute('aria-flowto', this._webviewContent.id);
......
......@@ -13,7 +13,7 @@ import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/bro
import { WebviewEvents, WebviewInputOptions } from './webviewEditorService';
import { Webview, WebviewOptions } from 'vs/workbench/contrib/webview/common/webview';
export class WebviewEditorInput extends EditorInput {
export class WebviewEditorInput<State = any> extends EditorInput {
private static handlePool = 0;
private static _styleElement?: HTMLStyleElement;
......@@ -62,7 +62,7 @@ export class WebviewEditorInput extends EditorInput {
private readonly _webviewDisposables = this._register(new DisposableStore());
private _group?: GroupIdentifier;
private _scrollYPercentage: number = 0;
private _state: any;
private _state: State;
public readonly extension?: {
readonly location: URI;
......@@ -74,7 +74,7 @@ export class WebviewEditorInput extends EditorInput {
public readonly viewType: string,
name: string,
options: WebviewInputOptions,
state: any,
state: State,
events: WebviewEvents,
extension: undefined | {
readonly location: URI;
......@@ -175,18 +175,14 @@ export class WebviewEditorInput extends EditorInput {
}
}
public get state(): any {
public get state(): State {
return this._state;
}
public set state(value: any) {
public set state(value: State) {
this._state = value;
}
public get webviewState() {
return this._state.state;
}
public get options(): WebviewInputOptions {
return this._options;
}
......@@ -253,7 +249,9 @@ export class WebviewEditorInput extends EditorInput {
}, null, this._webviewDisposables);
this._webview.onDidUpdateState(newState => {
this._state.state = newState;
if (this._events && this._events.onDidUpdateWebviewState) {
this._events.onDidUpdateWebviewState(newState);
}
}, null, this._webviewDisposables);
}
......@@ -262,7 +260,6 @@ export class WebviewEditorInput extends EditorInput {
}
public claimWebview(owner: any) {
this._webviewOwner = owner;
}
......
......@@ -79,6 +79,7 @@ export interface WebviewEvents {
onMessage?(message: any): void;
onDispose?(): void;
onDidClickLink?(link: URI, options: IWebviewOptions): void;
onDidUpdateWebviewState?(newState: any): void;
}
export interface WebviewInputOptions extends IWebviewOptions, IWebviewPanelOptions {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册