Skip to content

Commit

Permalink
keep links from web view untouch for as long as possible, #83645
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 29, 2019
1 parent c4f4c9c commit a716943
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/vs/workbench/api/browser/mainThreadWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down Expand Up @@ -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 });
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -94,7 +93,7 @@ export abstract class BaseWebview<T extends HTMLElement> 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) => {
Expand Down Expand Up @@ -145,7 +144,7 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
private readonly _onMissingCsp = this._register(new Emitter<ExtensionIdentifier>());
public readonly onMissingCsp = this._onMissingCsp.event;

private readonly _onDidClickLink = this._register(new Emitter<URI>());
private readonly _onDidClickLink = this._register(new Emitter<string>());
public readonly onDidClickLink = this._onDidClickLink.event;

private readonly _onMessage = this._register(new Emitter<any>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -160,8 +159,8 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
private readonly _onDidFocus = this._register(new Emitter<void>());
public readonly onDidFocus: Event<void> = this._onDidFocus.event;

private readonly _onDidClickLink = this._register(new Emitter<URI>());
public readonly onDidClickLink: Event<URI> = this._onDidClickLink.event;
private readonly _onDidClickLink = this._register(new Emitter<string>());
public readonly onDidClickLink: Event<string> = this._onDidClickLink.event;

private readonly _onDidScroll = this._register(new Emitter<{ scrollYPercentage: number; }>());
public readonly onDidScroll: Event<{ scrollYPercentage: number; }> = this._onDidScroll.event;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/webview/browser/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface Webview extends IDisposable {
state: string | undefined;

readonly onDidFocus: Event<void>;
readonly onDidClickLink: Event<URI>;
readonly onDidClickLink: Event<string>;
readonly onDidScroll: Event<{ scrollYPercentage: number }>;
readonly onDidUpdateState: Event<string | undefined>;
readonly onMessage: Event<any>;
Expand Down

0 comments on commit a716943

Please sign in to comment.