diff --git a/extensions/markdown/src/markdownExtensions.ts b/extensions/markdown/src/markdownExtensions.ts index 6bba131e107631920fd0b91389e7e2c6ba27ae45..124fabd46ee387f8b779670bcc7b85085056dc9f 100644 --- a/extensions/markdown/src/markdownExtensions.ts +++ b/extensions/markdown/src/markdownExtensions.ts @@ -10,7 +10,7 @@ import { MarkdownContentProvider } from './features/previewContentProvider'; import { MarkdownEngine } from './markdownEngine'; const resolveExtensionResources = (extension: vscode.Extension, resourcePath: string): vscode.Uri => { - return vscode.Uri.parse(path.join(extension.extensionPath, resourcePath)) + return vscode.Uri.file(path.join(extension.extensionPath, resourcePath)) .with({ scheme: 'vscode-extension-resource' }); }; diff --git a/src/vs/workbench/parts/html/electron-browser/webview.ts b/src/vs/workbench/parts/html/electron-browser/webview.ts index ebeb734569b2a4534afc1534f046ceede78b3dd5..12d90e9e39e8e95c867c685e26e8e00849ccfe17 100644 --- a/src/vs/workbench/parts/html/electron-browser/webview.ts +++ b/src/vs/workbench/parts/html/electron-browser/webview.ts @@ -15,7 +15,7 @@ import { WebviewFindWidget } from './webviewFindWidget'; import { IContextViewService } from 'vs/platform/contextview/browser/contextView'; import { IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { normalize, nativeSep } from 'vs/base/common/paths'; +import { nativeSep } from 'vs/base/common/paths'; import { startsWith } from 'vs/base/common/strings'; export interface WebviewOptions { @@ -322,16 +322,24 @@ export class Webview { return; } + const appRootUri = URI.file(this._environmentService.appRoot); + registerFileProtocol(contents, 'vscode-core-resource', () => [ - this._environmentService.appRoot - ]); - registerFileProtocol(contents, 'vscode-extension-resource', () => [ - this._environmentService.extensionsPath, - this._environmentService.appRoot, - this._environmentService.extensionDevelopmentPath + appRootUri ]); + + const extensionPaths = [ + URI.file(this._environmentService.extensionsPath), + appRootUri, + ]; + + if (this._environmentService.extensionDevelopmentPath) { + extensionPaths.push(URI.file(this._environmentService.extensionDevelopmentPath)); + } + registerFileProtocol(contents, 'vscode-extension-resource', () => extensionPaths); + registerFileProtocol(contents, 'vscode-workspace-resource', () => - (this._options.localResourceRoots || []).map(uri => uri.fsPath) + (this._options.localResourceRoots || []) ); } @@ -425,13 +433,13 @@ namespace ApiThemeClassName { function registerFileProtocol( contents: Electron.WebContents, protocol: string, - getRoots: () => string[] + getRoots: () => URI[] ) { contents.session.protocol.registerFileProtocol(protocol, (request, callback: any) => { - const requestPath = URI.parse(request.url).fsPath; + const requestPath = URI.parse(request.url).path; + const normalizedPath = URI.file(requestPath).fsPath; for (const root of getRoots()) { - const normalizedPath = normalize(requestPath, true); - if (startsWith(normalizedPath, root + nativeSep)) { + if (startsWith(normalizedPath, root.fsPath + nativeSep)) { callback({ path: normalizedPath }); return; }