From 9e8719ba794abec9fda0f2c173e58286959da764 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 7 Nov 2018 13:31:38 -0800 Subject: [PATCH] Add alert when trying to use the previewHtml command while developing an extension Fixes #62685 --- src/vs/workbench/api/node/extHost.api.impl.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 3b49a1a9524..acf69746b51 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -146,7 +146,7 @@ export function createApiFactory( // extension should specify then the `file`-scheme, e.g `{ scheme: 'fooLang', language: 'fooLang' }` // We only inform once, it is not a warning because we just want to raise awareness and because // we cannot say if the extension is doing it right or wrong... - let checkSelector = (function () { + const checkSelector = (function () { let done = (!extension.isUnderDevelopment); function informOnce(selector: vscode.DocumentSelector) { if (!done) { @@ -171,6 +171,24 @@ export function createApiFactory( }; })(); + // Warn when trying to use the vscode.previewHtml command as it does not work properly in all scenarios and + // has security concerns. + const checkCommand = (() => { + let done = !extension.isUnderDevelopment; + const informOnce = () => { + if (!done) { + done = true; + console.warn(`Extension '${extension.id}' uses the 'vscode.previewHtml' command which is deprecated and will be removed. Please update your extension to use the Webview API: https://go.microsoft.com/fwlink/?linkid=2039309`); + } + }; + return (commandId: string) => { + if (commandId === 'vscode.previewHtml') { + informOnce(); + } + return commandId; + }; + })(); + // namespace: commands const commands: typeof vscode.commands = { registerCommand(id: string, command: (...args: any[]) => T | Thenable, thisArgs?: any): vscode.Disposable { @@ -210,7 +228,7 @@ export function createApiFactory( }); }), executeCommand(id: string, ...args: any[]): Thenable { - return extHostCommands.executeCommand(id, ...args); + return extHostCommands.executeCommand(checkCommand(id), ...args); }, getCommands(filterInternal: boolean = false): Thenable { return extHostCommands.getCommands(filterInternal); -- GitLab