提交 61b6f24a 编写于 作者: M Matt Bierner

More control over webview

上级 e75ff7dc
......@@ -81,7 +81,7 @@ export class HtmlPreviewPart extends WebviewEditor {
private get webview(): Webview {
if (!this._webview) {
this._webview = new Webview(this._container, this.partService.getContainer(Parts.EDITOR_PART));
this._webview = new Webview(this._container, this.partService.getContainer(Parts.EDITOR_PART), { enableJavascript: true });
this._webview.baseUrl = this._baseUrl && this._baseUrl.toString(true);
if (this.input && this.input instanceof HtmlInput) {
const state = this.loadViewState(this.input.getResource());
......
......@@ -121,8 +121,9 @@
});
// update iframe-contents
ipcRenderer.on('content', function (_event, value) {
const text = value.join('\n');
ipcRenderer.on('content', function (_event, data) {
const options = data.options;
const text = data.contents.join('\n');
const newDocument = new DOMParser().parseFromString(text, 'text/html');
// know what happens here
......@@ -188,7 +189,7 @@
const newFrame = document.createElement('iframe');
newFrame.setAttribute('id', 'pending-frame');
newFrame.setAttribute('frameborder', '0');
newFrame.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin');
newFrame.setAttribute('sandbox', options.enableJavascript ? 'allow-scripts allow-forms allow-same-origin' : 'allow-same-origin');
newFrame.style.cssText = "margin: 0; overflow: hidden; position: absolute; width: 100%; height: 100%; display: none";
document.body.appendChild(newFrame);
......
......@@ -43,6 +43,10 @@ MenuRegistry.addCommand({
type ApiThemeClassName = 'vscode-light' | 'vscode-dark' | 'vscode-high-contrast';
export interface WebviewOptions {
enableJavascript?: boolean;
}
export default class Webview {
private _webview: WebviewElement;
......@@ -55,7 +59,8 @@ export default class Webview {
constructor(
private parent: HTMLElement,
private _styleElement: Element
private _styleElement: Element,
private options: WebviewOptions = {}
) {
this._webview = <any>document.createElement('webview');
......@@ -158,7 +163,10 @@ export default class Webview {
}
set contents(value: string[]) {
this._send('content', value);
this._send('content', {
contents: value,
options: this.options
});
}
set baseUrl(value: string) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册