Skip to content

Commit

Permalink
prevent double protocol handler registration
Browse files Browse the repository at this point in the history
fixes #48476
  • Loading branch information
joaomoreno committed Apr 26, 2018
1 parent 9d2bc79 commit 271eba6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/vs/workbench/api/node/extHostUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class ExtHostUrls implements ExtHostUrlsShape {
private static HandlePool = 0;
private readonly _proxy: MainThreadUrlsShape;

private handles = new Set<string>();
private handlers = new Map<number, vscode.ProtocolHandler>();

constructor(
Expand All @@ -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);
});
Expand Down

0 comments on commit 271eba6

Please sign in to comment.