提交 776f9f74 编写于 作者: B Benjamin Pasero

debt - drop support for URL preview

上级 b98f99c5
......@@ -22,12 +22,11 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
/**
* An implementation of editor for embedding a URL into an IFrame by leveraging the IFrameEditorInput.
* An implementation of editor for showing HTML content in an IFrame by leveraging the IFrameEditorInput.
*/
export class IFrameEditor extends BaseEditor {
public static ID = 'workbench.editors.iFrameEditor';
public static allowScriptExecutionSettingsKey = 'workbench.editor.allowIframeScriptExecution';
private static RESOURCE_PROPERTY = 'resource';
......@@ -96,44 +95,19 @@ export class IFrameEditor extends BaseEditor {
return null;
}
let allowScriptExecution = this.storageService.getBoolean(IFrameEditor.allowScriptExecutionSettingsKey, StorageScope.WORKSPACE, false);
// Set IFrame contents directly
// Set IFrame contents
let iframeModel = <IFrameEditorModel>resolvedModel;
if (iframeModel.hasContents()) {
let isUpdate = !isNewInput && !!this.iframeBuilder.getProperty(IFrameEditor.RESOURCE_PROPERTY);
let contents = iframeModel.getContents();
// Sanitize Script from content if script execution is not allowed
if (!allowScriptExecution) {
contents.body = DOM.removeScriptTags(contents.body);
}
// Crazy hack to get keybindings to bubble out of the iframe to us
contents.body = contents.body + this.enableKeybindings();
// Set Contents
try {
this.setFrameContents(iframeModel.resource, isUpdate ? contents.body : [contents.head, contents.body, contents.tail].join('\n'), isUpdate /* body only */);
} catch (error) {
setTimeout(() => this.reload(true /* clear */), 1000); // retry in case of an error which indicates the iframe (only) might be on a different URL
}
}
// Set IFrame source location
else {
let isUpdate = !isNewInput && !!this.iframeBuilder.getProperty(IFrameEditor.RESOURCE_PROPERTY);
let contents = iframeModel.getContents();
// Sandboxing (can only be applied when using a real source location)
if (allowScriptExecution) {
this.iframeBuilder.removeAttribute('sandbox');
} else {
this.iframeBuilder.attr({
'sandbox': 'allow-same-origin' // protect us from attacks (see http://www.w3schools.com/tags/att_iframe_sandbox.asp)
});
}
// Crazy hack to get keybindings to bubble out of the iframe to us
contents.body = contents.body + this.enableKeybindings();
// Set URL
this.iframeBuilder.src(iframeModel.getUrl() + '?etag=' + new Date().getTime()); // make sure to bypass browser caches by appending current time
// Set Contents
try {
this.setFrameContents(iframeModel.resource, isUpdate ? contents.body : [contents.head, contents.body, contents.tail].join('\n'), isUpdate /* body only */);
} catch (error) {
setTimeout(() => this.reload(true /* clear */), 1000); // retry in case of an error which indicates the iframe (only) might be on a different URL
}
});
}
......@@ -278,35 +252,4 @@ export class IFrameEditor extends BaseEditor {
super.dispose();
}
}
export class ToggleJavaScriptInIFrameEditorInputAction extends EditorInputAction {
constructor(
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IStorageService private storageService: IStorageService
) {
super('workbench.files.action.toggleJSInIFrameEditor', nls.localize('enableJavaScript', "Enable JavaScript"));
}
public get label(): string {
let allowScriptExecution = this.storageService.getBoolean(IFrameEditor.allowScriptExecutionSettingsKey, StorageScope.WORKSPACE, false);
if (allowScriptExecution) {
return nls.localize('disableJavaScript', "Disable JavaScript");
}
return nls.localize('enableJavaScript', "Enable JavaScript");
}
public run(event?: any): Promise {
// Apply globally
this.storageService.swap(IFrameEditor.allowScriptExecutionSettingsKey, true, false, StorageScope.WORKSPACE, false);
let options = new EditorOptions();
options.forceOpen = true; // force open since we open the same input again
return this.editorService.openEditor(this.input, options, this.position);
}
}
\ No newline at end of file
......@@ -15,9 +15,9 @@ export interface IFrameContents {
/**
* An editor model that represents the resolved state for an iframe editor input. After the model has been
* resolved it knows which URL or content to pass to the iframe editor. If a URL is being used, this will
* be set as the iframe's URL. Otherwise the contents will be set directly into the iframe. In that case
* the contents have to ensure that e.g. a base URL is set so that relative links or images can be resolved.
* resolved it knows which content to pass to the iframe editor. The contents will be set directly into the
* iframe. The contents have to ensure that e.g. a base URL is set so that relative links or images can be
* resolved.
*/
export class IFrameEditorModel extends EditorModel {
private _resource: URI;
......@@ -37,18 +37,6 @@ export class IFrameEditorModel extends EditorModel {
return this._resource;
}
public setUrl(url: string): void {
this.url = url;
}
public getUrl(): string {
return this.url;
}
public hasUrl(): boolean {
return !!this.url;
}
public setContents(head: string, body: string, tail: string): void {
this.head = head;
this.body = body;
......@@ -62,8 +50,4 @@ export class IFrameEditorModel extends EditorModel {
tail: this.tail
};
}
public hasContents(): boolean {
return !!this.head || !!this.body || !!this.tail;
}
}
\ No newline at end of file
......@@ -30,7 +30,8 @@ interface IMarkdownWorkerOutput extends IEmitOutput {
*/
export class MarkdownEditorModel extends IFrameEditorModel {
constructor(resource: URI,
constructor(
resource: URI,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IStorageService private storageService: IStorageService
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册