提交 e259543b 编写于 作者: M Matt Bierner

Split up static webview options and options that can be changed dynamically

上级 c460e31c
......@@ -525,9 +525,12 @@ export class ExtensionEditor extends BaseEditor {
.then(renderBody)
.then(removeEmbeddedSVGs)
.then(body => {
const allowedBadgeProviders = this.extensionsWorkbenchService.allowedBadgeProviders;
const webViewOptions = allowedBadgeProviders.length > 0 ? { allowScripts: false, allowSvgs: false, svgWhiteList: allowedBadgeProviders } : {};
const wbeviewElement = this.instantiationService.createInstance(WebviewElement, this.partService.getContainer(Parts.EDITOR_PART), webViewOptions);
const wbeviewElement = this.instantiationService.createInstance(WebviewElement,
this.partService.getContainer(Parts.EDITOR_PART),
{},
{
svgWhiteList: this.extensionsWorkbenchService.allowedBadgeProviders
});
wbeviewElement.mountTo(this.content);
const removeLayoutParticipant = arrays.insert(this.layoutParticipants, wbeviewElement);
this.contentDisposables.push(toDisposable(removeLayoutParticipant));
......
......@@ -17,7 +17,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { Dimension } from 'vs/base/browser/dom';
import { BaseWebviewEditor } from 'vs/workbench/contrib/webview/electron-browser/baseWebviewEditor';
import { WebviewElement, WebviewOptions } from 'vs/workbench/contrib/webview/electron-browser/webviewElement';
import { WebviewElement, WebviewContentOptions } from 'vs/workbench/contrib/webview/electron-browser/webviewElement';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { CancellationToken } from 'vs/base/common/cancellation';
......@@ -88,7 +88,7 @@ export class HtmlPreviewPart extends BaseWebviewEditor {
private get webview(): WebviewElement {
if (!this._webview) {
let webviewOptions: WebviewOptions = {};
let webviewOptions: WebviewContentOptions = {};
if (this.input && this.input instanceof HtmlInput) {
webviewOptions = this.input.options;
}
......@@ -96,9 +96,9 @@ export class HtmlPreviewPart extends BaseWebviewEditor {
this._webview = this._instantiationService.createInstance(WebviewElement,
this._partService.getContainer(Parts.EDITOR_PART),
{
...webviewOptions,
useSameOriginForRoot: true
});
},
webviewOptions);
this._webview.mountTo(this._content);
if (this.input && this.input instanceof HtmlInput) {
......
......@@ -183,10 +183,7 @@ export class WebviewEditor extends BaseWebviewEditor {
input.claimWebview(this);
webview.update(input.html, {
allowScripts: input.options.enableScripts,
allowSvgs: true,
useSameOriginForRoot: false,
localResourceRoots: input.options.localResourceRoots || this.getDefaultLocalResourceRoots(),
extensionLocation: input.extensionLocation
}, !!input.options.retainContextWhenHidden);
if (this._webviewContent) {
......@@ -224,9 +221,9 @@ export class WebviewEditor extends BaseWebviewEditor {
this._partService.getContainer(Parts.EDITOR_PART),
{
allowSvgs: true,
useSameOriginForRoot: false,
extensionLocation: input.extensionLocation
});
extensionLocation: input.extensionLocation,
},
{});
this._webview.mountTo(this._webviewContent);
input.webview = this._webview;
......
......@@ -207,8 +207,6 @@ export class WebviewEditorInput extends EditorInput {
if (this._webview) {
this._webview.options = {
allowScripts: this._options.enableScripts,
allowSvgs: true,
useSameOriginForRoot: false,
localResourceRoots: this._options.localResourceRoots
};
}
......
......@@ -21,14 +21,17 @@ import { endsWith } from 'vs/base/common/strings';
import { isMacintosh } from 'vs/base/common/platform';
export interface WebviewOptions {
readonly allowScripts?: boolean;
readonly allowSvgs?: boolean;
readonly svgWhiteList?: string[];
readonly useSameOriginForRoot?: boolean;
readonly localResourceRoots?: ReadonlyArray<URI>;
readonly extensionLocation?: URI;
}
export interface WebviewContentOptions {
readonly allowScripts?: boolean;
readonly svgWhiteList?: string[];
readonly localResourceRoots?: ReadonlyArray<URI>;
}
interface IKeydownEvent {
key: string;
keyCode: number;
......@@ -88,14 +91,10 @@ class SvgBlocker extends Disposable {
constructor(
webview: Electron.WebviewTag,
private readonly _options: WebviewOptions,
private readonly _options: WebviewContentOptions,
) {
super();
if (this._options.allowSvgs) {
return;
}
let loaded = false;
this._register(addDisposableListener(webview, 'did-start-loading', () => {
if (loaded) {
......@@ -134,9 +133,6 @@ class SvgBlocker extends Disposable {
}
private isAllowedSvg(uri: URI): boolean {
if (this._options.allowSvgs) {
return true;
}
if (this._options.svgWhiteList) {
return this._options.svgWhiteList.indexOf(uri.authority.toLowerCase()) >= 0;
}
......@@ -239,7 +235,8 @@ export class WebviewElement extends Disposable {
constructor(
private readonly _styleElement: Element,
private _options: WebviewOptions,
private readonly _options: WebviewOptions,
private _contentOptions: WebviewContentOptions,
@IInstantiationService instantiationService: IInstantiationService,
@IThemeService private readonly _themeService: IThemeService,
@IEnvironmentService environmentService: IEnvironmentService,
......@@ -276,12 +273,14 @@ export class WebviewElement extends Disposable {
new WebviewProtocolProvider(
this._webview,
this._options.extensionLocation,
() => (this._options.localResourceRoots || []),
() => (this._contentOptions.localResourceRoots || []),
environmentService,
fileService));
const svgBlocker = this._register(new SvgBlocker(this._webview, this._options));
svgBlocker.onDidBlockSvg(() => this.onDidBlockSvg());
if (!this._options.allowSvgs) {
const svgBlocker = this._register(new SvgBlocker(this._webview, this._contentOptions));
svgBlocker.onDidBlockSvg(() => this.onDidBlockSvg());
}
this._register(new WebviewKeyboardHandler(this._webview, this._keybindingService));
......@@ -397,15 +396,15 @@ export class WebviewElement extends Disposable {
this._state = value;
}
public set options(value: WebviewOptions) {
if (this._options && areWebviewInputOptionsEqual(value, this._options)) {
public set options(value: WebviewContentOptions) {
if (this._contentOptions && areWebviewInputOptionsEqual(value, this._contentOptions)) {
return;
}
this._options = value;
this._contentOptions = value;
this._send('content', {
contents: this._contents,
options: this._options,
options: this._contentOptions,
state: this._state
});
}
......@@ -414,20 +413,20 @@ export class WebviewElement extends Disposable {
this._contents = value;
this._send('content', {
contents: value,
options: this._options,
options: this._contentOptions,
state: this._state
});
}
public update(value: string, options: WebviewOptions, retainContextWhenHidden: boolean) {
if (retainContextWhenHidden && value === this._contents && this._options && areWebviewInputOptionsEqual(options, this._options)) {
public update(value: string, options: WebviewContentOptions, retainContextWhenHidden: boolean) {
if (retainContextWhenHidden && value === this._contents && this._contentOptions && areWebviewInputOptionsEqual(options, this._contentOptions)) {
return;
}
this._contents = value;
this._options = options;
this._contentOptions = options;
this._send('content', {
contents: this._contents,
options: this._options,
options: this._contentOptions,
state: this._state
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册