Show error when webview restore fails

This commit is contained in:
Matt Bierner 2018-04-05 19:18:55 -07:00
parent 753b18ddc1
commit c14e30aeb4
5 changed files with 23 additions and 10 deletions

View file

@ -91,7 +91,7 @@ export class MarkdownPreviewManager implements vscode.WebviewSerializer {
public async deserializeWebview(
webview: vscode.Webview,
state: any
): Promise<boolean> {
): Promise<void> {
const preview = await MarkdownPreview.revive(
webview,
state,
@ -101,7 +101,6 @@ export class MarkdownPreviewManager implements vscode.WebviewSerializer {
this.topmostLineMonitor);
this.registerPreview(preview);
return true;
}
public async serializeWebview(

View file

@ -658,10 +658,8 @@ declare module 'vscode' {
*
* @param webview Webview to restore. The serializer should take ownership of this webview.
* @param state Persisted state.
*
* @return Was deserialization successful?
*/
deserializeWebview(webview: Webview, state: any): Thenable<boolean>;
deserializeWebview(webview: Webview, state: any): Thenable<void>;
}
namespace window {

View file

@ -2,6 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import * as map from 'vs/base/common/map';
import URI from 'vs/base/common/uri';
@ -132,7 +133,8 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
}
reviveWebview(webview: WebviewEditorInput): TPromise<void> {
return this._extensionService.activateByEvent(`onView:${webview.state.viewType}`).then(() => {
const viewType = webview.state.viewType;
return this._extensionService.activateByEvent(`onView:${viewType}`).then(() => {
const handle = 'revival-' + MainThreadWebviews.revivalPool++;
this._webviews.set(handle, webview);
@ -148,7 +150,9 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
};
return this._proxy.$deserializeWebview(handle, webview.state.viewType, webview.state.state, webview.position, webview.options)
.then(() => { });
.then(undefined, () => {
webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
});
});
}
@ -231,4 +235,16 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
this._openerService.open(link);
}
}
private static getDeserializationFailedContents(viewType: string) {
return `<!DOCTYPE html>
<html>
<head>
<base href="https://code.visualstudio.com/raw/">
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src https: data:; media-src https:; script-src 'none'; style-src vscode-core-resource: https: 'unsafe-inline'; child-src 'none'; frame-src 'none';">
</head>
<body>${localize('errorMessage', "An error occurred while restoring view:{0}", viewType)}</body>
</html>`;
}
}

View file

@ -366,7 +366,7 @@ export interface ExtHostWebviewsShape {
$onDidChangeActiveWeview(handle: WebviewHandle | undefined): void;
$onDidDisposeWeview(handle: WebviewHandle): Thenable<void>;
$onDidChangePosition(handle: WebviewHandle, newPosition: EditorPosition): void;
$deserializeWebview(newWebviewHandle: WebviewHandle, viewType: string, state: any, position: EditorPosition, options: vscode.WebviewOptions): Thenable<boolean>;
$deserializeWebview(newWebviewHandle: WebviewHandle, viewType: string, state: any, position: EditorPosition, options: vscode.WebviewOptions): Thenable<void>;
$serializeWebview(webviewHandle: WebviewHandle): Thenable<any>;
}

View file

@ -237,10 +237,10 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
state: any,
position: Position,
options: vscode.WebviewOptions
): Thenable<boolean> {
): Thenable<void> {
const serializer = this._serializers.get(viewType);
if (!serializer) {
return TPromise.as(false);
return TPromise.wrapError(new Error(`No serializer found for '${viewType}'`));
}
const revivedWebview = new ExtHostWebview(webviewHandle, this._proxy, viewType, typeConverters.toViewColumn(position), options);