Move the webviewResourceRoot property to be set on each webview instead of as a global property

For #72155

This allows  us to potentially change the resource root per webview
This commit is contained in:
Matt Bierner
2019-06-24 15:42:14 -07:00
parent 1083123758
commit 8119b4aee7
14 changed files with 57 additions and 38 deletions

View File

@@ -12,6 +12,7 @@ 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 {
@@ -59,6 +60,7 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
constructor(
context: IExtHostContext,
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
@ICodeEditorService private readonly _editorService: ICodeEditorService,
@IWebviewService private readonly _webviewService: IWebviewService,
) {
@@ -144,4 +146,8 @@ export class MainThreadEditorInsets implements MainThreadEditorInsetsShape {
}
return Promise.resolve(false);
}
async $getResourceRoot(_handle: number): Promise<string> {
return this._environmentService.webviewResourceRoot;
}
}

View File

@@ -23,6 +23,7 @@ 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 {
@@ -54,6 +55,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
@IOpenerService private readonly _openerService: IOpenerService,
@ITelemetryService private readonly _telemetryService: ITelemetryService,
@IProductService private readonly _productService: IProductService,
@IEnvironmentService private readonly _environmentService: IEnvironmentService,
) {
super();
@@ -139,6 +141,10 @@ 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()) {

View File

@@ -59,7 +59,6 @@ export interface IEnvironment {
extensionTestsLocationURI?: URI;
globalStorageHome: URI;
userHome: URI;
webviewResourceRoot: string;
}
export interface IStaticWorkspaceData {
@@ -519,6 +518,7 @@ 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 {
@@ -543,6 +543,7 @@ 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;

View File

@@ -61,6 +61,10 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
private _html: string = '';
private _options: vscode.WebviewOptions;
get resourceRoot(): Promise<string> {
return that._proxy.$getResourceRoot(handle);
}
set options(value: vscode.WebviewOptions) {
this._options = value;
that._proxy.$setOptions(handle, value);

View File

@@ -39,6 +39,10 @@ export class ExtHostWebview implements vscode.Webview {
this._onMessageEmitter.dispose();
}
public get resourceRoot(): Promise<string> {
return this._proxy.$getResourceRoot(this._handle);
}
public get html(): string {
this.assertNotDisposed();
return this._html;

View File

@@ -262,10 +262,6 @@ export function createApiFactory(
openExternal(uri: URI) {
return extHostWindow.openUri(uri, { allowTunneling: !!initData.remote.isRemote });
},
get webviewResourceRoot() {
checkProposedApiEnabled(extension);
return initData.environment.webviewResourceRoot;
},
get remoteName() {
if (!initData.remote.authority) {
return undefined;