Skip to content

Commit b018290

Browse files
committed
Fix some API inconsistencies related to web views
Fixes eclipse-theia#12087 Contributed on behalf of STMicroelectronics Signed-off-by: Thomas Mäder <[email protected]>
1 parent d383fe2 commit b018290

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/plugin-ext/src/main/browser/webview/webview.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface WebviewContentOptions {
7676
readonly allowForms?: boolean;
7777
readonly localResourceRoots?: ReadonlyArray<string>;
7878
readonly portMapping?: ReadonlyArray<WebviewPortMapping>;
79-
readonly enableCommandUris?: boolean;
79+
readonly enableCommandUris?: boolean | readonly string[];
8080
}
8181

8282
@injectable()
@@ -450,8 +450,12 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget, Extract
450450
}
451451
return link;
452452
}
453-
if (!!this.contentOptions.enableCommandUris && link.scheme === Schemes.command) {
454-
return link;
453+
if (link.scheme === Schemes.command) {
454+
if (Array.isArray(this.contentOptions.enableCommandUris) && this.contentOptions.enableCommandUris.some(value => value === link.path.toString())) {
455+
return link;
456+
} else if (this.contentOptions.enableCommandUris === true) {
457+
return link;
458+
}
455459
}
456460
return undefined;
457461
}

packages/plugin/src/theia.d.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -3871,9 +3871,11 @@ export module '@theia/plugin' {
38713871
/**
38723872
* Controls whether command uris are enabled in webview content or not.
38733873
*
3874-
* Defaults to false.
3874+
* Defaults to `false` (command uris are disabled).
3875+
*
3876+
* If you pass in an array, only the commands in the array are allowed.
38753877
*/
3876-
readonly enableCommandUris?: boolean;
3878+
readonly enableCommandUris?: boolean | readonly string[];
38773879

38783880
/**
38793881
* Root paths from which the webview can load local (filesystem) resources using the `theia-resource:` scheme.
@@ -5026,7 +5028,7 @@ export module '@theia/plugin' {
50265028
*
50275029
* @return New webview panel.
50285030
*/
5029-
export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | WebviewPanelShowOptions,
5031+
export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | { readonly viewColumn: ViewColumn; readonly preserveFocus?: boolean },
50305032
options?: WebviewPanelOptions & WebviewOptions): WebviewPanel;
50315033

50325034
/**

0 commit comments

Comments
 (0)