Skip to content

Commit 21560e8

Browse files
committed
web api: IExternalURLOpener
1 parent bff0b78 commit 21560e8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/vs/workbench/browser/window.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ export class BrowserWindow extends Disposable {
141141
// will trigger the `beforeunload`.
142142
this.openerService.setDefaultExternalOpener({
143143
openExternal: async (href: string) => {
144+
if (this.environmentService.options?.externalURLOpener) {
145+
if (await this.environmentService.options?.externalURLOpener.openExternal(href)) {
146+
return true;
147+
}
148+
}
144149

145150
// HTTP(s): open in new window and deal with potential popup blockers
146151
if (matchesScheme(href, Schemas.http) || matchesScheme(href, Schemas.https)) {

src/vs/workbench/workbench.web.api.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ interface IExternalUriResolver {
3737
(uri: URI): Promise<URI>;
3838
}
3939

40+
/**
41+
* External URL opener
42+
*/
43+
interface IExternalURLOpener {
44+
45+
/**
46+
* Overrides the behavior when an external URL is about to be opened.
47+
* Returning false means that the URL wasn't handled, and the default
48+
* handling behavior should be used: `window.open(href, '_blank', 'noopener');`
49+
*
50+
* @returns true if URL was handled, false otherwise.
51+
*/
52+
openExternal(href: string): boolean | Promise<boolean>;
53+
}
54+
4055
interface ITunnelProvider {
4156

4257
/**
@@ -363,6 +378,11 @@ interface IWorkbenchConstructionOptions {
363378
*/
364379
readonly resolveExternalUri?: IExternalUriResolver;
365380

381+
/**
382+
* Support for URL callbacks.
383+
*/
384+
readonly externalURLOpener?: IExternalURLOpener;
385+
366386
/**
367387
* A provider for supplying tunneling functionality,
368388
* such as creating tunnels and showing candidate ports to forward.
@@ -742,6 +762,9 @@ export {
742762
// External Uris
743763
IExternalUriResolver,
744764

765+
// External URL Opener
766+
IExternalURLOpener,
767+
745768
// Tunnel
746769
ITunnelProvider,
747770
ITunnelFactory,

0 commit comments

Comments
 (0)