提交 3b1dad55 编写于 作者: M Matt Bierner

Use absolute paths for webview core resources

Fixes #41887
上级 d3e2fe7c
......@@ -53,7 +53,6 @@ import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRe
import { Color } from 'vs/base/common/color';
import { WorkbenchTree } from 'vs/platform/list/browser/listService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import URI from 'vs/base/common/uri';
/** A context key that is set when an extension editor webview has focus. */
export const KEYBINDING_CONTEXT_EXTENSIONEDITOR_WEBVIEW_FOCUS = new RawContextKey<boolean>('extensionEditorWebviewFocus', undefined);
......@@ -64,11 +63,8 @@ export const KEYBINDING_CONTEXT_EXTENSIONEDITOR_FIND_WIDGET_INPUT_FOCUSED = new
/** A context key that is set when the find widget find input in extension editor webview is not focused. */
export const KEYBINDING_CONTEXT_EXTENSIONEDITOR_FIND_WIDGET_INPUT_NOT_FOCUSED: ContextKeyExpr = KEYBINDING_CONTEXT_EXTENSIONEDITOR_FIND_WIDGET_INPUT_FOCUSED.toNegated();
function renderBody(
body: string,
environmentService: IEnvironmentService
): string {
const styleSheetPath = require.toUrl('./media/markdown.css').replace(URI.file(environmentService.appRoot).toString(true), 'vscode-core-resource://');
function renderBody(body: string): string {
const styleSheetPath = require.toUrl('./media/markdown.css').replace('file://', 'vscode-core-resource://');
return `<!DOCTYPE html>
<html>
<head>
......@@ -415,7 +411,7 @@ export class ExtensionEditor extends BaseEditor {
private openMarkdown(content: TPromise<string>, noContentCopy: string) {
return this.loadContents(() => content
.then(marked.parse)
.then(content => renderBody(content, this.environmentService))
.then(renderBody)
.then(removeEmbeddedSVGs)
.then<void>(body => {
const allowedBadgeProviders = this.extensionsWorkbenchService.allowedBadgeProviders;
......
......@@ -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, join, nativeSep } from 'vs/base/common/paths';
import { normalize, nativeSep } from 'vs/base/common/paths';
import { startsWith } from 'vs/base/common/strings';
export interface WebviewElementFindInPageOptions {
......@@ -102,7 +102,7 @@ export default class Webview {
const contents = this._webview.getWebContents();
if (contents && !contents.isDestroyed()) {
registerFileProtocol(contents, 'vscode-core-resource', this._environmentService.appRoot + nativeSep);
registerFileProtocol(contents, 'vscode-core-resource', [this._environmentService.appRoot]);
}
}));
}
......@@ -417,20 +417,21 @@ export default class Webview {
function registerFileProtocol(
contents: Electron.WebContents,
protocol: string,
root: string
roots: string[]
) {
contents.session.protocol.registerFileProtocol(protocol, (request, callback: any) => {
const requestPath = URI.parse(request.url).path;
const normalizedPath = normalize(join(root, requestPath), true);
if (startsWith(normalizedPath, root)) {
callback({ path: normalizedPath });
} else {
callback({ error: 'Cannot load resource outside of protocol root' });
for (const root of roots) {
const normalizedPath = normalize(requestPath, true);
if (startsWith(normalizedPath, root + nativeSep)) {
callback({ path: normalizedPath });
return;
}
}
callback({ error: 'Cannot load resource outside of protocol root' });
}, (error) => {
if (error) {
console.error('Failed to register protocol ' + protocol);
}
});
}
}
\ No newline at end of file
......@@ -28,14 +28,12 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { onUnexpectedError } from 'vs/base/common/errors';
import { addGAParameters } from 'vs/platform/telemetry/node/telemetryNodeUtils';
import { generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
import URI from 'vs/base/common/uri';
function renderBody(
body: string,
css: string,
environmentService: IEnvironmentService
css: string
): string {
const styleSheetPath = require.toUrl('./media/markdown.css').replace(URI.file(environmentService.appRoot).toString(true), 'vscode-core-resource://');
const styleSheetPath = require.toUrl('./media/markdown.css').replace('file://', 'vscode-core-resource://');
return `<!DOCTYPE html>
<html>
<head>
......@@ -105,7 +103,7 @@ export class ReleaseNotesEditor extends WebviewEditor {
const colorMap = TokenizationRegistry.getColorMap();
const css = generateTokensCSSForColorMap(colorMap);
const body = renderBody(marked(text, { renderer }), css, this.environmentService);
const body = renderBody(marked(text, { renderer }), css);
this._webview = new WebView(this.content, this.partService.getContainer(Parts.EDITOR_PART), this.environmentService, this._contextViewService, this.contextKey, this.findInputFocusContextKey, {}, false);
if (this.input && this.input instanceof ReleaseNotesInput) {
const state = this.loadViewState(this.input.version);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册