@@ -16,7 +16,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati
16
16
import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
17
17
import { IURLHandler , IURLService , IOpenURLOptions } from 'vs/platform/url/common/url' ;
18
18
import { IHostService } from 'vs/workbench/services/host/browser/host' ;
19
- import { IExtensionService , toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions' ;
19
+ import { ActivationKind , IExtensionService , toExtensionDescription } from 'vs/workbench/services/extensions/common/extensions' ;
20
20
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
21
21
import { InstantiationType , registerSingleton } from 'vs/platform/instantiation/common/extensions' ;
22
22
import { Registry } from 'vs/platform/registry/common/platform' ;
@@ -70,9 +70,13 @@ class UserTrustedExtensionIdStorage {
70
70
71
71
export const IExtensionUrlHandler = createDecorator < IExtensionUrlHandler > ( 'extensionUrlHandler' ) ;
72
72
73
+ export interface IExtensionContributedURLHandler extends IURLHandler {
74
+ extensionDisplayName : string ;
75
+ }
76
+
73
77
export interface IExtensionUrlHandler {
74
78
readonly _serviceBrand : undefined ;
75
- registerExtensionHandler ( extensionId : ExtensionIdentifier , handler : IURLHandler ) : void ;
79
+ registerExtensionHandler ( extensionId : ExtensionIdentifier , handler : IExtensionContributedURLHandler ) : void ;
76
80
unregisterExtensionHandler ( extensionId : ExtensionIdentifier ) : void ;
77
81
}
78
82
@@ -99,7 +103,7 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
99
103
100
104
readonly _serviceBrand : undefined ;
101
105
102
- private extensionHandlers = new Map < string , IURLHandler > ( ) ;
106
+ private extensionHandlers = new Map < string , IExtensionContributedURLHandler > ( ) ;
103
107
private uriBuffer = new Map < string , { timestamp : number ; uri : URI } [ ] > ( ) ;
104
108
private userTrustedExtensionsStorage : UserTrustedExtensionIdStorage ;
105
109
private disposable : IDisposable ;
@@ -145,12 +149,20 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
145
149
const extensionId = uri . authority ;
146
150
this . telemetryService . publicLog2 < ExtensionUrlHandlerEvent , ExtensionUrlHandlerClassification > ( 'uri_invoked/start' , { extensionId } ) ;
147
151
148
- const wasHandlerAvailable = this . extensionHandlers . has ( ExtensionIdentifier . toKey ( extensionId ) ) ;
149
- const extension = await this . extensionService . getExtension ( extensionId ) ;
152
+ const initialHandler = this . extensionHandlers . get ( ExtensionIdentifier . toKey ( extensionId ) ) ;
153
+ let extensionDisplayName : string ;
150
154
151
- if ( ! extension ) {
152
- await this . handleUnhandledURL ( uri , { id : extensionId } , options ) ;
153
- return true ;
155
+ if ( ! initialHandler ) {
156
+ // The extension is not yet activated, so let's check if it is installed and enabled
157
+ const extension = await this . extensionService . getExtension ( extensionId ) ;
158
+ if ( ! extension ) {
159
+ await this . handleUnhandledURL ( uri , { id : extensionId } , options ) ;
160
+ return true ;
161
+ } else {
162
+ extensionDisplayName = extension . displayName || extension . name ;
163
+ }
164
+ } else {
165
+ extensionDisplayName = initialHandler . extensionDisplayName ;
154
166
}
155
167
156
168
const trusted = options ?. trusted
@@ -169,7 +181,7 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
169
181
checkbox : {
170
182
label : localize ( 'rememberConfirmUrl' , "Don't ask again for this extension." ) ,
171
183
} ,
172
- detail : `${ extension . displayName || extension . name } (${ extensionId } ) wants to open a URI:\n\n${ uriString } ` ,
184
+ detail : `${ extensionDisplayName } (${ extensionId } ) wants to open a URI:\n\n${ uriString } ` ,
173
185
primaryButton : localize ( { key : 'open' , comment : [ '&& denotes a mnemonic' ] } , "&&Open" )
174
186
} ) ;
175
187
@@ -186,7 +198,7 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
186
198
const handler = this . extensionHandlers . get ( ExtensionIdentifier . toKey ( extensionId ) ) ;
187
199
188
200
if ( handler ) {
189
- if ( ! wasHandlerAvailable ) {
201
+ if ( ! initialHandler ) {
190
202
// forward it directly
191
203
return await this . handleURLByExtension ( extensionId , handler , uri , options ) ;
192
204
}
@@ -206,12 +218,13 @@ class ExtensionUrlHandler implements IExtensionUrlHandler, IURLHandler {
206
218
207
219
uris . push ( { timestamp, uri } ) ;
208
220
209
- // activate the extension
210
- await this . extensionService . activateByEvent ( `onUri:${ ExtensionIdentifier . toKey ( extensionId ) } ` ) ;
221
+ // activate the extension using ActivationKind.Immediate because URI handling might be part
222
+ // of resolving authorities (via authentication extensions)
223
+ await this . extensionService . activateByEvent ( `onUri:${ ExtensionIdentifier . toKey ( extensionId ) } ` , ActivationKind . Immediate ) ;
211
224
return true ;
212
225
}
213
226
214
- registerExtensionHandler ( extensionId : ExtensionIdentifier , handler : IURLHandler ) : void {
227
+ registerExtensionHandler ( extensionId : ExtensionIdentifier , handler : IExtensionContributedURLHandler ) : void {
215
228
this . extensionHandlers . set ( ExtensionIdentifier . toKey ( extensionId ) , handler ) ;
216
229
217
230
const uris = this . uriBuffer . get ( ExtensionIdentifier . toKey ( extensionId ) ) || [ ] ;
0 commit comments