From 271eba6590c0c00e79c25e47f3a8ca2aff1d6557 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 26 Apr 2018 10:35:51 +0200 Subject: [PATCH] prevent double protocol handler registration fixes #48476 --- src/vs/workbench/api/node/extHostUrls.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/vs/workbench/api/node/extHostUrls.ts b/src/vs/workbench/api/node/extHostUrls.ts index 6732afcad4d..534dfb4f02a 100644 --- a/src/vs/workbench/api/node/extHostUrls.ts +++ b/src/vs/workbench/api/node/extHostUrls.ts @@ -14,6 +14,7 @@ export class ExtHostUrls implements ExtHostUrlsShape { private static HandlePool = 0; private readonly _proxy: MainThreadUrlsShape; + private handles = new Set(); private handlers = new Map(); constructor( @@ -23,11 +24,17 @@ export class ExtHostUrls implements ExtHostUrlsShape { } registerProtocolHandler(extensionId: string, handler: vscode.ProtocolHandler): vscode.Disposable { + if (this.handles.has(extensionId)) { + throw new Error(`Protocol handler already registered for extension ${extensionId}`); + } + const handle = ExtHostUrls.HandlePool++; + this.handles.add(extensionId); this.handlers.set(handle, handler); this._proxy.$registerProtocolHandler(handle, extensionId); return toDisposable(() => { + this.handles.delete(extensionId); this.handlers.delete(handle); this._proxy.$unregisterProtocolHandler(handle); });