Skip to content

Commit

Permalink
Fix some API inconsistencies related to web views
Browse files Browse the repository at this point in the history
Fixes eclipse-theia#12087

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <[email protected]>
  • Loading branch information
tsmaeder committed Jan 19, 2023
1 parent d383fe2 commit b018290
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/plugin-ext/src/main/browser/webview/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface WebviewContentOptions {
readonly allowForms?: boolean;
readonly localResourceRoots?: ReadonlyArray<string>;
readonly portMapping?: ReadonlyArray<WebviewPortMapping>;
readonly enableCommandUris?: boolean;
readonly enableCommandUris?: boolean | readonly string[];
}

@injectable()
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

/**
Expand Down

0 comments on commit b018290

Please sign in to comment.