diff --git a/packages/plugin-ext/src/main/browser/webview/webview.ts b/packages/plugin-ext/src/main/browser/webview/webview.ts index b40dde18dc422..1cd19c66177a5 100644 --- a/packages/plugin-ext/src/main/browser/webview/webview.ts +++ b/packages/plugin-ext/src/main/browser/webview/webview.ts @@ -76,7 +76,7 @@ export interface WebviewContentOptions { readonly allowForms?: boolean; readonly localResourceRoots?: ReadonlyArray; readonly portMapping?: ReadonlyArray; - readonly enableCommandUris?: boolean; + readonly enableCommandUris?: boolean | readonly string[]; } @injectable() @@ -450,8 +450,12 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract } return link; } - if (!!this.contentOptions.enableCommandUris && link.scheme === Schemes.command) { - return link; + if (link.scheme === Schemes.command) { + if (Array.isArray(this.contentOptions.enableCommandUris) && this.contentOptions.enableCommandUris.some(value => value === link.path.toString())) { + return link; + } else if (this.contentOptions.enableCommandUris === true) { + return link; + } } return undefined; } diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index 65b48c129cbe8..49a7f5acedd1a 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -3871,9 +3871,11 @@ export module '@theia/plugin' { /** * Controls whether command uris are enabled in webview content or not. * - * Defaults to false. + * Defaults to `false` (command uris are disabled). + * + * If you pass in an array, only the commands in the array are allowed. */ - readonly enableCommandUris?: boolean; + readonly enableCommandUris?: boolean | readonly string[]; /** * Root paths from which the webview can load local (filesystem) resources using the `theia-resource:` scheme. @@ -5026,7 +5028,7 @@ export module '@theia/plugin' { * * @return New webview panel. */ - export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | WebviewPanelShowOptions, + export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | { readonly viewColumn: ViewColumn; readonly preserveFocus?: boolean }, options?: WebviewPanelOptions & WebviewOptions): WebviewPanel; /**