From a71694386db4d321ccb6cafcc9e796e320319183 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Fri, 29 Nov 2019 15:51:37 +0100 Subject: [PATCH] keep links from web view untouch for as long as possible, #83645 --- src/vs/workbench/api/browser/mainThreadWebview.ts | 6 +++--- .../contrib/extensions/browser/extensionEditor.ts | 7 ++++--- .../workbench/contrib/update/browser/releaseNotesEditor.ts | 2 +- .../contrib/webview/browser/baseWebviewElement.ts | 5 ++--- .../contrib/webview/browser/dynamicWebviewEditorOverlay.ts | 5 ++--- src/vs/workbench/contrib/webview/browser/webview.ts | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadWebview.ts b/src/vs/workbench/api/browser/mainThreadWebview.ts index ca38f063be623..1bd635659f9e3 100644 --- a/src/vs/workbench/api/browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/browser/mainThreadWebview.ts @@ -332,7 +332,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma private hookupWebviewEventDelegate(handle: extHostProtocol.WebviewPanelHandle, input: WebviewInput) { const disposables = new DisposableStore(); - disposables.add(input.webview.onDidClickLink((uri: URI) => this.onDidClickLink(handle, uri))); + disposables.add(input.webview.onDidClickLink((uri) => this.onDidClickLink(handle, uri))); disposables.add(input.webview.onMessage((message: any) => { this._proxy.$onMessage(handle, message); })); disposables.add(input.webview.onMissingCsp((extension: ExtensionIdentifier) => this._proxy.$onMissingCsp(handle, extension.value))); @@ -387,9 +387,9 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma } } - private onDidClickLink(handle: extHostProtocol.WebviewPanelHandle, link: URI): void { + private onDidClickLink(handle: extHostProtocol.WebviewPanelHandle, link: string): void { const webview = this.getWebviewInput(handle); - if (this.isSupportedLink(webview, link)) { + if (this.isSupportedLink(webview, URI.parse(link))) { this._openerService.open(link, { fromUserGesture: true }); } } diff --git a/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts b/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts index 7a6a573198ec3..f302a97cfc70a 100644 --- a/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts +++ b/src/vs/workbench/contrib/extensions/browser/extensionEditor.ts @@ -30,7 +30,7 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { CombinedInstallAction, UpdateAction, ExtensionEditorDropDownAction, ReloadAction, MaliciousStatusLabelAction, IgnoreExtensionRecommendationAction, UndoIgnoreExtensionRecommendationAction, EnableDropDownAction, DisableDropDownAction, StatusLabelAction, SetFileIconThemeAction, SetColorThemeAction, RemoteInstallAction, ExtensionToolTipAction, SystemDisabledWarningAction, LocalInstallAction } from 'vs/workbench/contrib/extensions/browser/extensionsActions'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; -import { IOpenerService } from 'vs/platform/opener/common/opener'; +import { IOpenerService, matchesScheme } from 'vs/platform/opener/common/opener'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { KeybindingLabel } from 'vs/base/browser/ui/keybindingLabel/keybindingLabel'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; @@ -608,9 +608,10 @@ export class ExtensionEditor extends BaseEditor { if (!link) { return; } - // Whitelist supported schemes for links - if ([Schemas.http, Schemas.https, Schemas.mailto].indexOf(link.scheme) >= 0 || (link.scheme === 'command' && link.path === ShowCurrentReleaseNotesActionId)) { + if (matchesScheme(link, Schemas.http) || matchesScheme(link, Schemas.https) || matchesScheme(link, Schemas.mailto) + || (matchesScheme(link, Schemas.command) && URI.parse(link).path === ShowCurrentReleaseNotesActionId) + ) { this.openerService.open(link); } }, null, this.contentDisposables)); diff --git a/src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts b/src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts index ce64aefccc1dd..f0150abdd1611 100644 --- a/src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts +++ b/src/vs/workbench/contrib/update/browser/releaseNotesEditor.ts @@ -85,7 +85,7 @@ export class ReleaseNotesManager { }, undefined); - this._currentReleaseNotes.webview.onDidClickLink(uri => this.onDidClickLink(uri)); + this._currentReleaseNotes.webview.onDidClickLink(uri => this.onDidClickLink(URI.parse(uri))); this._currentReleaseNotes.onDispose(() => { this._currentReleaseNotes = undefined; }); const iconPath = URI.parse(require.toUrl('./media/code-icon.svg')); diff --git a/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts b/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts index 466e046411abe..5cf9df18ef8af 100644 --- a/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts +++ b/src/vs/workbench/contrib/webview/browser/baseWebviewElement.ts @@ -10,7 +10,6 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { WebviewExtensionDescription, WebviewOptions, WebviewContentOptions } from 'vs/workbench/contrib/webview/browser/webview'; -import { URI } from 'vs/base/common/uri'; import { areWebviewInputOptionsEqual } from 'vs/workbench/contrib/webview/browser/webviewWorkbenchService'; import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/common/themeing'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; @@ -94,7 +93,7 @@ export abstract class BaseWebview extends Disposable { })); this._register(this.on(WebviewMessageChannels.didClickLink, (uri: string) => { - this._onDidClickLink.fire(URI.parse(uri)); + this._onDidClickLink.fire(uri); })); this._register(this.on(WebviewMessageChannels.onmessage, (data: any) => { @@ -145,7 +144,7 @@ export abstract class BaseWebview extends Disposable { private readonly _onMissingCsp = this._register(new Emitter()); public readonly onMissingCsp = this._onMissingCsp.event; - private readonly _onDidClickLink = this._register(new Emitter()); + private readonly _onDidClickLink = this._register(new Emitter()); public readonly onDidClickLink = this._onDidClickLink.event; private readonly _onMessage = this._register(new Emitter()); diff --git a/src/vs/workbench/contrib/webview/browser/dynamicWebviewEditorOverlay.ts b/src/vs/workbench/contrib/webview/browser/dynamicWebviewEditorOverlay.ts index 16b5b7e7d1d1a..9848ce0cb7065 100644 --- a/src/vs/workbench/contrib/webview/browser/dynamicWebviewEditorOverlay.ts +++ b/src/vs/workbench/contrib/webview/browser/dynamicWebviewEditorOverlay.ts @@ -6,7 +6,6 @@ import { memoize } from 'vs/base/common/decorators'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; -import { URI } from 'vs/base/common/uri'; import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions'; import { IWebviewService, Webview, WebviewContentOptions, WebviewEditorOverlay, WebviewElement, WebviewOptions, WebviewExtensionDescription } from 'vs/workbench/contrib/webview/browser/webview'; import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService'; @@ -160,8 +159,8 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd private readonly _onDidFocus = this._register(new Emitter()); public readonly onDidFocus: Event = this._onDidFocus.event; - private readonly _onDidClickLink = this._register(new Emitter()); - public readonly onDidClickLink: Event = this._onDidClickLink.event; + private readonly _onDidClickLink = this._register(new Emitter()); + public readonly onDidClickLink: Event = this._onDidClickLink.event; private readonly _onDidScroll = this._register(new Emitter<{ scrollYPercentage: number; }>()); public readonly onDidScroll: Event<{ scrollYPercentage: number; }> = this._onDidScroll.event; diff --git a/src/vs/workbench/contrib/webview/browser/webview.ts b/src/vs/workbench/contrib/webview/browser/webview.ts index c9c0c88a08c4c..3d825f8f8f2c7 100644 --- a/src/vs/workbench/contrib/webview/browser/webview.ts +++ b/src/vs/workbench/contrib/webview/browser/webview.ts @@ -71,7 +71,7 @@ export interface Webview extends IDisposable { state: string | undefined; readonly onDidFocus: Event; - readonly onDidClickLink: Event; + readonly onDidClickLink: Event; readonly onDidScroll: Event<{ scrollYPercentage: number }>; readonly onDidUpdateState: Event; readonly onMessage: Event;