Merge from vscode aba87f135229c17c4624341b7a2499dcedafcb87 (#6430)

* Merge from vscode aba87f135229c17c4624341b7a2499dcedafcb87

* fix compile errors
This commit is contained in:
Anthony Dresser
2019-07-18 18:32:57 -07:00
committed by GitHub
parent bf4815d364
commit ee3663c1cd
158 changed files with 3101 additions and 2361 deletions

View File

@@ -14,7 +14,6 @@ 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';
import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/common/shared/editor';
import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
import { ICreateWebViewShowOptions, IWebviewEditorService, WebviewInputOptions } from 'vs/workbench/contrib/webview/browser/webviewEditorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
@@ -22,8 +21,9 @@ import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/commo
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { extHostNamedCustomer } from '../common/extHostCustomers';
import { IProductService } from 'vs/platform/product/common/product';
import { startsWith } from 'vs/base/common/strings';
interface MainThreadWebviewState {
interface OldMainThreadWebviewState {
readonly viewType: string;
state: any;
}
@@ -43,7 +43,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
private readonly _proxy: ExtHostWebviewsShape;
private readonly _webviews = new Map<WebviewPanelHandle, WebviewEditorInput<MainThreadWebviewState>>();
private readonly _webviews = new Map<WebviewPanelHandle, WebviewEditorInput>();
private readonly _revivers = new Map<string, IDisposable>();
private _activeWebview: WebviewPanelHandle | undefined = undefined;
@@ -67,8 +67,12 @@ 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: WebviewEditorInput<any>) => {
const viewType = webview.state && webview.state.viewType;
canRevive: (webview: WebviewEditorInput) => {
if (!webview.webview.state) {
return false;
}
const viewType = this.fromInternalWebviewViewType(webview.viewType);
if (typeof viewType === 'string') {
extensionService.activateByEvent(`onWebviewPanel:${viewType}`);
}
@@ -96,11 +100,8 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
const webview = this._webviewEditorService.createWebview(handle, this.getInternalWebviewViewType(viewType), title, mainThreadShowOptions, reviveWebviewOptions(options), {
location: URI.revive(extensionLocation),
id: extensionId
}, this.createWebviewEventDelegate(handle)) as WebviewEditorInput<MainThreadWebviewState>;
webview.state = {
viewType: viewType,
state: undefined
};
});
this.hookupWebviewEventDelegate(handle, webview);
this._webviews.set(handle, webview);
@@ -129,12 +130,12 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
public $setHtml(handle: WebviewPanelHandle, value: string): void {
const webview = this.getWebview(handle);
webview.html = value;
webview.webview.html = value;
}
public $setOptions(handle: WebviewPanelHandle, options: modes.IWebviewOptions): void {
const webview = this.getWebview(handle);
webview.setOptions(reviveWebviewOptions(options as any /*todo@mat */));
webview.webview.contentOptions = reviveWebviewOptions(options as any /*todo@mat */);
}
public $reveal(handle: WebviewPanelHandle, showOptions: WebviewPanelShowOptions): void {
@@ -151,22 +152,8 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
public async $postMessage(handle: WebviewPanelHandle, message: any): Promise<boolean> {
const webview = this.getWebview(handle);
const editors = this._editorService.visibleControls
.filter(e => e instanceof WebviewEditor)
.map(e => e as WebviewEditor)
.filter(e => e.input!.matches(webview));
if (editors.length > 0) {
editors[0].sendMessage(message);
return true;
}
if (webview.webview) {
webview.webview.sendMessage(message);
return true;
}
return false;
webview.webview.sendMessage(message);
return true;
}
public $registerSerializer(viewType: string): void {
@@ -175,28 +162,42 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
}
this._revivers.set(viewType, this._webviewEditorService.registerReviver({
canRevive: (webview) => {
return webview.state && webview.state.viewType === viewType;
canRevive: (webviewEditorInput) => {
return !!webviewEditorInput.webview.state && webviewEditorInput.viewType === this.getInternalWebviewViewType(viewType);
},
reviveWebview: async (webview): Promise<void> => {
const viewType = webview.state.viewType;
const handle = 'revival-' + MainThreadWebviews.revivalPool++;
this._webviews.set(handle, webview);
webview._events = this.createWebviewEventDelegate(handle);
reviveWebview: async (webviewEditorInput): Promise<void> => {
const viewType = this.fromInternalWebviewViewType(webviewEditorInput.viewType);
if (!viewType) {
webviewEditorInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(webviewEditorInput.viewType);
return;
}
const handle = `revival-${MainThreadWebviews.revivalPool++}`;
this._webviews.set(handle, webviewEditorInput);
this.hookupWebviewEventDelegate(handle, webviewEditorInput);
let state = undefined;
if (webview.state.state) {
if (webviewEditorInput.webview.state) {
try {
state = JSON.parse(webview.state.state);
// Check for old-style webview state first which stored state inside another state object
// TODO: remove this after 1.37 ships.
if (
typeof (webviewEditorInput.webview.state as unknown as OldMainThreadWebviewState).viewType === 'string' &&
'state' in (webviewEditorInput.webview.state as unknown as OldMainThreadWebviewState)
) {
state = JSON.parse((webviewEditorInput.webview.state as any).state);
} else {
state = JSON.parse(webviewEditorInput.webview.state);
}
} catch {
// noop
}
}
try {
await this._proxy.$deserializeWebviewPanel(handle, viewType, webview.getTitle(), state, editorGroupToViewColumn(this._editorGroupService, webview.group || 0), webview.options);
await this._proxy.$deserializeWebviewPanel(handle, viewType, webviewEditorInput.getTitle(), state, editorGroupToViewColumn(this._editorGroupService, webviewEditorInput.group || 0), webviewEditorInput.webview.options);
} catch (error) {
onUnexpectedError(error);
webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
webviewEditorInput.webview.html = MainThreadWebviews.getDeserializationFailedContents(viewType);
}
}
}));
@@ -216,23 +217,28 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
return `mainThreadWebview-${viewType}`;
}
private createWebviewEventDelegate(handle: WebviewPanelHandle) {
return {
onDidClickLink: (uri: URI) => this.onDidClickLink(handle, uri),
onMessage: (message: any) => this._proxy.$onMessage(handle, message),
onDispose: () => {
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;
private fromInternalWebviewViewType(viewType: string): string | undefined {
if (!startsWith(viewType, 'mainThreadWebview-')) {
return undefined;
}
return viewType.replace(/^mainThreadWebview-/, '');
}
private hookupWebviewEventDelegate(handle: WebviewPanelHandle, input: WebviewEditorInput) {
input.webview.onDidClickLink((uri: URI) => this.onDidClickLink(handle, uri));
input.webview.onMessage((message: any) => this._proxy.$onMessage(handle, message));
input.onDispose(() => {
this._proxy.$onDidDisposeWebviewPanel(handle).finally(() => {
this._webviews.delete(handle);
});
});
input.webview.onDidUpdateState((newState: any) => {
const webview = this.tryGetWebview(handle);
if (!webview || webview.isDisposed()) {
return;
}
};
webview.webview.state = newState;
});
}
private onActiveEditorChanged() {
@@ -319,7 +325,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
if (this._productService.urlProtocol === link.scheme) {
return true;
}
return !!webview.options.enableCommandUris && link.scheme === 'command';
return !!webview.webview.contentOptions.enableCommandUris && link.scheme === 'command';
}
private getWebview(handle: WebviewPanelHandle): WebviewEditorInput {
@@ -347,13 +353,15 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
}
}
function reviveWebviewOptions(options: WebviewInputOptions): WebviewInputOptions {
function reviveWebviewOptions(options: modes.IWebviewOptions): WebviewInputOptions {
return {
...options,
allowScripts: options.enableScripts,
localResourceRoots: Array.isArray(options.localResourceRoots) ? options.localResourceRoots.map(r => URI.revive(r)) : undefined,
};
}
function reviveWebviewIcon(
value: { light: UriComponents, dark: UriComponents } | undefined
): { light: URI, dark: URI } | undefined {