mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
@@ -12,7 +12,6 @@ import { IWebviewService, Webview } from 'vs/workbench/contrib/webview/common/we
|
||||
import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { IActiveCodeEditor, IViewZone } from 'vs/editor/browser/editorBrowser';
|
||||
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
// todo@joh move these things back into something like contrib/insets
|
||||
class EditorWebviewZone implements IViewZone {
|
||||
@@ -60,7 +59,6 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
|
||||
|
||||
constructor(
|
||||
context: IExtHostContext,
|
||||
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
|
||||
@ICodeEditorService private readonly _editorService: ICodeEditorService,
|
||||
@IWebviewService private readonly _webviewService: IWebviewService,
|
||||
) {
|
||||
@@ -147,8 +145,4 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
|
||||
}
|
||||
return inset;
|
||||
}
|
||||
|
||||
async $getResourceRoot(_handle: number): Promise<string> {
|
||||
return this._environmentService.webviewResourceRoot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ 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 { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadWebviews)
|
||||
export class MainThreadWebviews extends Disposable implements MainThreadWebviewsShape {
|
||||
@@ -51,11 +50,10 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
|
||||
@IExtensionService extensionService: IExtensionService,
|
||||
@IEditorGroupsService private readonly _editorGroupService: IEditorGroupsService,
|
||||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@IWebviewEditorService private readonly _webviewService: IWebviewEditorService,
|
||||
@IWebviewEditorService private readonly _webviewEditorService: IWebviewEditorService,
|
||||
@IOpenerService private readonly _openerService: IOpenerService,
|
||||
@ITelemetryService private readonly _telemetryService: ITelemetryService,
|
||||
@IProductService private readonly _productService: IProductService,
|
||||
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
|
||||
) {
|
||||
super();
|
||||
|
||||
@@ -65,7 +63,7 @@ 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(_webviewService.registerReviver({
|
||||
this._register(_webviewEditorService.registerReviver({
|
||||
canRevive: (webview) => {
|
||||
const viewType = webview.state.viewType;
|
||||
if (viewType) {
|
||||
@@ -97,7 +95,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
|
||||
mainThreadShowOptions.group = viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn);
|
||||
}
|
||||
|
||||
const webview = this._webviewService.createWebview(this.getInternalWebviewId(viewType), title, mainThreadShowOptions, reviveWebviewOptions(options), {
|
||||
const webview = this._webviewEditorService.createWebview(this.getInternalWebviewId(viewType), title, mainThreadShowOptions, reviveWebviewOptions(options), {
|
||||
location: URI.revive(extensionLocation),
|
||||
id: extensionId
|
||||
}, this.createWebviewEventDelegate(handle));
|
||||
@@ -141,10 +139,6 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
|
||||
webview.setOptions(reviveWebviewOptions(options as any /*todo@mat */));
|
||||
}
|
||||
|
||||
async $getResourceRoot(_handle: WebviewPanelHandle): Promise<string> {
|
||||
return this._environmentService.webviewResourceRoot;
|
||||
}
|
||||
|
||||
public $reveal(handle: WebviewPanelHandle, showOptions: WebviewPanelShowOptions): void {
|
||||
const webview = this.getWebview(handle);
|
||||
if (webview.isDisposed()) {
|
||||
@@ -153,7 +147,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
|
||||
|
||||
const targetGroup = this._editorGroupService.getGroup(viewColumnToEditorGroup(this._editorGroupService, showOptions.viewColumn)) || this._editorGroupService.getGroup(webview.group || 0);
|
||||
if (targetGroup) {
|
||||
this._webviewService.revealWebview(webview, targetGroup, !!showOptions.preserveFocus);
|
||||
this._webviewEditorService.revealWebview(webview, targetGroup, !!showOptions.preserveFocus);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +176,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
|
||||
throw new Error(`Reviver for ${viewType} already registered`);
|
||||
}
|
||||
|
||||
this._revivers.set(viewType, this._webviewService.registerReviver({
|
||||
this._revivers.set(viewType, this._webviewEditorService.registerReviver({
|
||||
canRevive: (webview) => {
|
||||
return webview.state && webview.state.viewType === viewType;
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
@@ -98,7 +98,7 @@ export function createApiFactory(
|
||||
// Addressable instances
|
||||
rpcProtocol.set(ExtHostContext.ExtHostLogService, extHostLogService);
|
||||
const extHostDecorations = rpcProtocol.set(ExtHostContext.ExtHostDecorations, new ExtHostDecorations(rpcProtocol));
|
||||
const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol));
|
||||
const extHostWebviews = rpcProtocol.set(ExtHostContext.ExtHostWebviews, new ExtHostWebviews(rpcProtocol, initData.environment));
|
||||
const extHostUrls = rpcProtocol.set(ExtHostContext.ExtHostUrls, new ExtHostUrls(rpcProtocol));
|
||||
const extHostDocumentsAndEditors = rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, new ExtHostDocumentsAndEditors(rpcProtocol));
|
||||
const extHostDocuments = rpcProtocol.set(ExtHostContext.ExtHostDocuments, new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors));
|
||||
@@ -109,7 +109,7 @@ export function createApiFactory(
|
||||
const extHostTreeViews = rpcProtocol.set(ExtHostContext.ExtHostTreeViews, new ExtHostTreeViews(rpcProtocol.getProxy(MainContext.MainThreadTreeViews), extHostCommands, extHostLogService));
|
||||
rpcProtocol.set(ExtHostContext.ExtHostWorkspace, extHostWorkspace);
|
||||
rpcProtocol.set(ExtHostContext.ExtHostConfiguration, extHostConfiguration);
|
||||
const extHostEditorInsets = rpcProtocol.set(ExtHostContext.ExtHostEditorInsets, new ExtHostEditorInsets(rpcProtocol.getProxy(MainContext.MainThreadEditorInsets), extHostEditors));
|
||||
const extHostEditorInsets = rpcProtocol.set(ExtHostContext.ExtHostEditorInsets, new ExtHostEditorInsets(rpcProtocol.getProxy(MainContext.MainThreadEditorInsets), extHostEditors, initData.environment));
|
||||
const extHostDiagnostics = rpcProtocol.set(ExtHostContext.ExtHostDiagnostics, new ExtHostDiagnostics(rpcProtocol));
|
||||
const extHostLanguageFeatures = rpcProtocol.set(ExtHostContext.ExtHostLanguageFeatures, new ExtHostLanguageFeatures(rpcProtocol, uriTransformer, extHostDocuments, extHostCommands, extHostDiagnostics, extHostLogService));
|
||||
const extHostFileSystem = rpcProtocol.set(ExtHostContext.ExtHostFileSystem, new ExtHostFileSystem(rpcProtocol, extHostLanguageFeatures));
|
||||
|
||||
Reference in New Issue
Block a user