Skip to content

Commit c5e2892

Browse files
author
Benjamin Pasero
committed
urls - add option to disable confirm dialog
1 parent 57aea60 commit c5e2892

10 files changed

Lines changed: 48 additions & 29 deletions

File tree

src/vs/code/electron-main/app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { ILogService } from 'vs/platform/log/common/log';
2424
import { IStateService } from 'vs/platform/state/node/state';
2525
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
2626
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
27-
import { IURLService } from 'vs/platform/url/common/url';
27+
import { IURLService, IOpenURLOptions } from 'vs/platform/url/common/url';
2828
import { URLHandlerChannelClient, URLHandlerRouter } from 'vs/platform/url/common/urlIpc';
2929
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
3030
import { NullTelemetryService, combinedAppender, LogAppender } from 'vs/platform/telemetry/common/telemetryUtils';
@@ -588,7 +588,7 @@ export class CodeApplication extends Disposable {
588588
// Create a URL handler to open file URIs in the active window
589589
const environmentService = accessor.get(IEnvironmentService);
590590
urlService.registerHandler({
591-
async handleURL(uri: URI): Promise<boolean> {
591+
async handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
592592

593593
// Catch file URLs
594594
if (uri.authority === Schemas.file && !!uri.path) {
@@ -615,7 +615,7 @@ export class CodeApplication extends Disposable {
615615
// if there is none
616616
if (isMacintosh) {
617617
urlService.registerHandler({
618-
async handleURL(uri: URI): Promise<boolean> {
618+
async handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
619619
if (windowsMainService.getWindowCount() === 0) {
620620
const cli = { ...environmentService.args };
621621
const [window] = windowsMainService.open({ context: OpenContext.API, cli, forceEmpty: true, gotoLineMode: true });

src/vs/platform/url/common/url.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@ import { IDisposable } from 'vs/base/common/lifecycle';
99

1010
export const IURLService = createDecorator<IURLService>('urlService');
1111

12+
export interface IOpenURLOptions {
13+
14+
/**
15+
* If not provided or `false`, signals that the
16+
* URL to open did not originate from the product
17+
* but outside. As such, a confirmation dialog
18+
* might be shown to the user.
19+
*/
20+
trusted?: boolean;
21+
}
22+
1223
export interface IURLHandler {
13-
handleURL(uri: URI): Promise<boolean>;
24+
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean>;
1425
}
1526

1627
export interface IURLService {
@@ -24,7 +35,7 @@ export interface IURLService {
2435
*/
2536
create(options?: Partial<UriComponents>): URI;
2637

27-
open(url: URI): Promise<boolean>;
38+
open(url: URI, options?: IOpenURLOptions): Promise<boolean>;
2839

2940
registerHandler(handler: IURLHandler): IDisposable;
3041
}

src/vs/platform/url/common/urlIpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { IChannel, IServerChannel, IClientRouter, IConnectionHub, Client } from 'vs/base/parts/ipc/common/ipc';
77
import { URI } from 'vs/base/common/uri';
88
import { Event } from 'vs/base/common/event';
9-
import { IURLHandler } from 'vs/platform/url/common/url';
9+
import { IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
1010
import { CancellationToken } from 'vs/base/common/cancellation';
1111
import { first } from 'vs/base/common/arrays';
1212

@@ -31,7 +31,7 @@ export class URLHandlerChannelClient implements IURLHandler {
3131

3232
constructor(private channel: IChannel) { }
3333

34-
handleURL(uri: URI): Promise<boolean> {
34+
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
3535
return this.channel.call('handleURL', uri.toJSON());
3636
}
3737
}

src/vs/platform/url/common/urlService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
6+
import { IURLService, IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
77
import { URI, UriComponents } from 'vs/base/common/uri';
88
import { values } from 'vs/base/common/map';
99
import { first } from 'vs/base/common/async';
@@ -17,9 +17,9 @@ export abstract class AbstractURLService extends Disposable implements IURLServi
1717

1818
abstract create(options?: Partial<UriComponents>): URI;
1919

20-
open(uri: URI): Promise<boolean> {
20+
open(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
2121
const handlers = values(this.handlers);
22-
return first(handlers.map(h => () => h.handleURL(uri)), undefined, false).then(val => val || false);
22+
return first(handlers.map(h => () => h.handleURL(uri, options)), undefined, false).then(val => val || false);
2323
}
2424

2525
registerHandler(handler: IURLHandler): IDisposable {

src/vs/workbench/api/browser/mainThreadUrls.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { ExtHostContext, IExtHostContext, MainContext, MainThreadUrlsShape, ExtHostUrlsShape } from 'vs/workbench/api/common/extHost.protocol';
77
import { extHostNamedCustomer } from '../common/extHostCustomers';
8-
import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
8+
import { IURLService, IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
99
import { URI, UriComponents } from 'vs/base/common/uri';
1010
import { IDisposable } from 'vs/base/common/lifecycle';
1111
import { IExtensionUrlHandler } from 'vs/workbench/services/extensions/browser/extensionUrlHandler';
@@ -19,7 +19,7 @@ class ExtensionUrlHandler implements IURLHandler {
1919
readonly extensionId: ExtensionIdentifier
2020
) { }
2121

22-
handleURL(uri: URI): Promise<boolean> {
22+
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
2323
if (!ExtensionIdentifier.equals(this.extensionId, uri.authority)) {
2424
return Promise.resolve(false);
2525
}

src/vs/workbench/contrib/extensions/browser/extensionsWorkbenchService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
2424
import { URI } from 'vs/base/common/uri';
2525
import { IExtension, ExtensionState, IExtensionsWorkbenchService, AutoUpdateConfigurationKey, AutoCheckUpdatesConfigurationKey } from 'vs/workbench/contrib/extensions/common/extensions';
2626
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
27-
import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
27+
import { IURLService, IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
2828
import { ExtensionsInput } from 'vs/workbench/contrib/extensions/common/extensionsInput';
2929
import { ILogService } from 'vs/platform/log/common/log';
3030
import { IProgressService, ProgressLocation } from 'vs/platform/progress/common/progress';
@@ -1048,7 +1048,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
10481048
this.notificationService.error(err);
10491049
}
10501050

1051-
handleURL(uri: URI): Promise<boolean> {
1051+
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
10521052
if (!/^extension/.test(uri.path)) {
10531053
return Promise.resolve(false);
10541054
}

src/vs/workbench/contrib/url/common/url.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class OpenUrlAction extends Action {
3535
run(): Promise<any> {
3636
return this.quickInputService.input({ prompt: 'URL to open' }).then(input => {
3737
const uri = URI.parse(input);
38-
this.urlService.open(uri);
38+
this.urlService.open(uri, { trusted: true });
3939
});
4040
}
4141
}

src/vs/workbench/services/extensions/browser/extensionUrlHandler.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { areSameExtensions } from 'vs/platform/extensionManagement/common/extens
1515
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1616
import { INotificationHandle, INotificationService, Severity } from 'vs/platform/notification/common/notification';
1717
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
18-
import { IURLHandler, IURLService } from 'vs/platform/url/common/url';
18+
import { IURLHandler, IURLService, IOpenURLOptions } from 'vs/platform/url/common/url';
1919
import { IHostService } from 'vs/workbench/services/host/browser/host';
2020
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
2121
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
@@ -74,7 +74,7 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
7474
const urlToHandleValue = this.storageService.get(URL_TO_HANDLE, StorageScope.WORKSPACE);
7575
if (urlToHandleValue) {
7676
this.storageService.remove(URL_TO_HANDLE, StorageScope.WORKSPACE);
77-
this.handleURL(URI.revive(JSON.parse(urlToHandleValue)), true);
77+
this.handleURL(URI.revive(JSON.parse(urlToHandleValue)), { trusted: true });
7878
}
7979

8080
this.disposable = combinedDisposable(
@@ -86,7 +86,7 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
8686
setTimeout(() => cache.forEach(uri => this.handleURL(uri)));
8787
}
8888

89-
async handleURL(uri: URI, confirmed?: boolean): Promise<boolean> {
89+
async handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
9090
if (!isExtensionId(uri.authority)) {
9191
return false;
9292
}
@@ -100,12 +100,15 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
100100
return true;
101101
}
102102

103-
if (!confirmed) {
103+
let showConfirm: boolean;
104+
if (options && options.trusted) {
105+
showConfirm = false;
106+
} else {
104107
const confirmedExtensionIds = this.getConfirmedExtensionIds();
105-
confirmed = confirmedExtensionIds.has(ExtensionIdentifier.toKey(extensionId));
108+
showConfirm = !confirmedExtensionIds.has(ExtensionIdentifier.toKey(extensionId));
106109
}
107110

108-
if (!confirmed) {
111+
if (showConfirm) {
109112
let uriString = uri.toString();
110113

111114
if (uriString.length > 40) {
@@ -136,7 +139,7 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
136139
if (handler) {
137140
if (!wasHandlerAvailable) {
138141
// forward it directly
139-
return await handler.handleURL(uri);
142+
return await handler.handleURL(uri, options);
140143
}
141144

142145
// let the ExtensionUrlHandler instance handle this
@@ -343,7 +346,7 @@ class ExtensionUrlBootstrapHandler implements IWorkbenchContribution, IURLHandle
343346
ExtensionUrlBootstrapHandler.disposable = urlService.registerHandler(this);
344347
}
345348

346-
handleURL(uri: URI): Promise<boolean> {
349+
handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
347350
ExtensionUrlBootstrapHandler._cache.push(uri);
348351
return Promise.resolve(true);
349352
}

src/vs/workbench/services/url/browser/urlService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class BrowserURLService extends AbstractURLService {
5454

5555
private registerListeners(): void {
5656
if (this.provider) {
57-
this._register(this.provider.onCallback(uri => this.open(uri)));
57+
this._register(this.provider.onCallback(uri => this.open(uri, { trusted: true })));
5858
}
5959
}
6060

src/vs/workbench/services/url/electron-browser/urlService.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
6+
import { IURLService, IURLHandler, IOpenURLOptions } from 'vs/platform/url/common/url';
77
import { URI, UriComponents } from 'vs/base/common/uri';
88
import { IMainProcessService } from 'vs/platform/ipc/electron-browser/mainProcessService';
99
import { URLHandlerChannel } from 'vs/platform/url/common/urlIpc';
@@ -15,6 +15,11 @@ import { IElectronEnvironmentService } from 'vs/workbench/services/electron/elec
1515
import { createChannelSender } from 'vs/base/parts/ipc/node/ipc';
1616
import { IElectronService } from 'vs/platform/electron/node/electron';
1717

18+
export interface IRelayOpenURLOptions extends IOpenURLOptions {
19+
openToSide?: boolean;
20+
openExternal?: boolean;
21+
}
22+
1823
export class RelayURLService extends URLService implements IURLHandler {
1924

2025
private urlService: IURLService;
@@ -46,16 +51,16 @@ export class RelayURLService extends URLService implements IURLHandler {
4651
return uri.with({ query });
4752
}
4853

49-
async open(resource: URI, options?: { openToSide?: boolean, openExternal?: boolean }): Promise<boolean> {
54+
async open(resource: URI, options?: IRelayOpenURLOptions): Promise<boolean> {
5055
if (resource.scheme !== product.urlProtocol) {
5156
return false;
5257
}
5358

54-
return await this.urlService.open(resource);
59+
return await this.urlService.open(resource, options);
5560
}
5661

57-
async handleURL(uri: URI): Promise<boolean> {
58-
const result = await super.open(uri);
62+
async handleURL(uri: URI, options?: IOpenURLOptions): Promise<boolean> {
63+
const result = await super.open(uri, options);
5964

6065
if (result) {
6166
await this.electronService.focusWindow();

0 commit comments

Comments
 (0)