mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
@@ -59,6 +59,8 @@ export interface IEnvironment {
|
||||
extensionTestsLocationURI?: URI;
|
||||
globalStorageHome: URI;
|
||||
userHome: URI;
|
||||
webviewResourceRoot: string;
|
||||
webviewCspRule: string;
|
||||
}
|
||||
|
||||
export interface IStaticWorkspaceData {
|
||||
@@ -533,7 +535,6 @@ export interface MainThreadEditorInsetsShape extends IDisposable {
|
||||
$setHtml(handle: number, value: string): void;
|
||||
$setOptions(handle: number, options: modes.IWebviewOptions): void;
|
||||
$postMessage(handle: number, value: any): Promise<boolean>;
|
||||
$getResourceRoot(handle: number): Promise<string>;
|
||||
}
|
||||
|
||||
export interface ExtHostEditorInsetsShape {
|
||||
@@ -558,7 +559,6 @@ export interface MainThreadWebviewsShape extends IDisposable {
|
||||
$setHtml(handle: WebviewPanelHandle, value: string): void;
|
||||
$setOptions(handle: WebviewPanelHandle, options: modes.IWebviewOptions): void;
|
||||
$postMessage(handle: WebviewPanelHandle, value: any): Promise<boolean>;
|
||||
$getResourceRoot(handle: WebviewPanelHandle): Promise<string>;
|
||||
|
||||
$registerSerializer(viewType: string): void;
|
||||
$unregisterSerializer(viewType: string): void;
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import * as vscode from 'vscode';
|
||||
import { MainThreadEditorInsetsShape, ExtHostEditorInsetsShape } from './extHost.protocol';
|
||||
import { ExtHostEditors } from 'vs/workbench/api/common/extHostTextEditors';
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { ExtHostTextEditor } from 'vs/workbench/api/common/extHostTextEditor';
|
||||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import { ExtHostTextEditor } from 'vs/workbench/api/common/extHostTextEditor';
|
||||
import { ExtHostEditors } from 'vs/workbench/api/common/extHostTextEditors';
|
||||
import * as vscode from 'vscode';
|
||||
import { ExtHostEditorInsetsShape, MainThreadEditorInsetsShape } from './extHost.protocol';
|
||||
import { toWebviewResource, WebviewInitData } from 'vs/workbench/api/common/shared/webview';
|
||||
|
||||
export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
|
||||
|
||||
@@ -19,7 +20,8 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
|
||||
|
||||
constructor(
|
||||
private readonly _proxy: MainThreadEditorInsetsShape,
|
||||
private readonly _editors: ExtHostEditors
|
||||
private readonly _editors: ExtHostEditors,
|
||||
private readonly _initData: WebviewInitData
|
||||
) {
|
||||
|
||||
// dispose editor inset whenever the hosting editor goes away
|
||||
@@ -61,8 +63,12 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
|
||||
private _html: string = '';
|
||||
private _options: vscode.WebviewOptions;
|
||||
|
||||
get resourceRoot(): Promise<string> {
|
||||
return that._proxy.$getResourceRoot(handle);
|
||||
toWebviewResource(resource: vscode.Uri): vscode.Uri {
|
||||
return toWebviewResource(that._initData, resource);
|
||||
}
|
||||
|
||||
get cspRule(): string {
|
||||
return that._initData.webviewCspRule;
|
||||
}
|
||||
|
||||
set options(value: vscode.WebviewOptions) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { ExtHostWebviewsShape, IMainContext, MainContext, MainThreadWebviewsShap
|
||||
import { Disposable } from './extHostTypes';
|
||||
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import { WebviewInitData, toWebviewResource } from 'vs/workbench/api/common/shared/webview';
|
||||
|
||||
type IconPath = URI | { light: URI, dark: URI };
|
||||
|
||||
@@ -28,7 +29,8 @@ export class ExtHostWebview implements vscode.Webview {
|
||||
constructor(
|
||||
handle: WebviewPanelHandle,
|
||||
proxy: MainThreadWebviewsShape,
|
||||
options: vscode.WebviewOptions
|
||||
options: vscode.WebviewOptions,
|
||||
private readonly initData: WebviewInitData
|
||||
) {
|
||||
this._handle = handle;
|
||||
this._proxy = proxy;
|
||||
@@ -39,8 +41,12 @@ export class ExtHostWebview implements vscode.Webview {
|
||||
this._onMessageEmitter.dispose();
|
||||
}
|
||||
|
||||
public get resourceRoot(): Promise<string> {
|
||||
return this._proxy.$getResourceRoot(this._handle);
|
||||
public toWebviewResource(resource: vscode.Uri): vscode.Uri {
|
||||
return toWebviewResource(this.initData, resource);
|
||||
}
|
||||
|
||||
public get cspRule(): string {
|
||||
return this.initData.webviewCspRule;
|
||||
}
|
||||
|
||||
public get html(): string {
|
||||
@@ -243,7 +249,8 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
private readonly _serializers = new Map<string, vscode.WebviewPanelSerializer>();
|
||||
|
||||
constructor(
|
||||
mainContext: IMainContext
|
||||
mainContext: IMainContext,
|
||||
private readonly initData: WebviewInitData
|
||||
) {
|
||||
this._proxy = mainContext.getProxy(MainContext.MainThreadWebviews);
|
||||
}
|
||||
@@ -264,7 +271,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
const handle = ExtHostWebviews.newHandle();
|
||||
this._proxy.$createWebviewPanel(handle, viewType, title, webviewShowOptions, convertWebviewOptions(options), extension.identifier, extension.extensionLocation);
|
||||
|
||||
const webview = new ExtHostWebview(handle, this._proxy, options);
|
||||
const webview = new ExtHostWebview(handle, this._proxy, options, this.initData);
|
||||
const panel = new ExtHostWebviewPanel(handle, this._proxy, viewType, title, viewColumn, options, webview);
|
||||
this._webviewPanels.set(handle, panel);
|
||||
return panel;
|
||||
@@ -337,7 +344,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
|
||||
return Promise.reject(new Error(`No serializer found for '${viewType}'`));
|
||||
}
|
||||
|
||||
const webview = new ExtHostWebview(webviewHandle, this._proxy, options);
|
||||
const webview = new ExtHostWebview(webviewHandle, this._proxy, options, this.initData);
|
||||
const revivedPanel = new ExtHostWebviewPanel(webviewHandle, this._proxy, viewType, title, typeof position === 'number' && position >= 0 ? typeConverters.ViewColumn.to(position) : undefined, options, webview);
|
||||
this._webviewPanels.set(webviewHandle, revivedPanel);
|
||||
return Promise.resolve(serializer.deserializeWebviewPanel(revivedPanel, state));
|
||||
|
||||
24
src/vs/workbench/api/common/shared/webview.ts
Normal file
24
src/vs/workbench/api/common/shared/webview.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export interface WebviewInitData {
|
||||
readonly webviewResourceRoot: string;
|
||||
readonly webviewCspRule: string;
|
||||
}
|
||||
|
||||
export function toWebviewResource(
|
||||
initData: WebviewInitData,
|
||||
resource: vscode.Uri
|
||||
): vscode.Uri {
|
||||
const rootUri = URI.parse(initData.webviewResourceRoot);
|
||||
return rootUri.with({
|
||||
path: rootUri.path + resource.path,
|
||||
query: resource.query,
|
||||
fragment: resource.fragment,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user