From 5fb5f93482ba973e7a04c2ef82d8ec530dac2b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=A4der?= Date: Thu, 19 Jan 2023 16:50:32 +0100 Subject: [PATCH] Fix some API inconsistencies related to web views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #12087 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder --- CHANGELOG.md | 2 +- .../plugin-ext/src/main/browser/webview/webview.ts | 10 +++++++--- packages/plugin/src/theia.d.ts | 8 +++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f10331a02eba..ce9c48f47a897 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/) ## v1.34.0 - 01/26/2023 - +- [plugin] Fixed some API inconsistencies related to web views [#12087](https://github.com/eclipse-theia/theia/issues/12087) - Contributed on behalf of STMicroelectronics - [plugin] added support for `isTransient` of `TerminalOptions` and `ExternalTerminalOptions` VS Code API [#12055](https://github.com/eclipse-theia/theia/pull/12055) - Contributed on behalf of STMicroelectronics - [terminal] added support for preference `terminal.integrated.enablePersistentSessions` to allow disabling restoring terminals on reload [#12055](https://github.com/eclipse-theia/theia/pull/12055) - Contributed on behalf of STMicroelectronics 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; /**