Remove 'trusted' notebook document

See #118584 for more
This commit is contained in:
Rob Lourens 2021-05-03 16:08:08 -07:00
parent 9aac6ab8f6
commit 6c10fb4371
5 changed files with 23 additions and 65 deletions

View file

@ -1041,12 +1041,6 @@ declare module 'vscode' {
}
export class NotebookDocumentMetadata {
/**
* Whether the document is trusted, default to true
* When false, insecure outputs like HTML, JavaScript, SVG will not be rendered.
*/
readonly trusted: boolean;
/**
* Additional attributes of the document metadata.
*/
@ -1054,9 +1048,8 @@ declare module 'vscode' {
/**
* Create a new notebook document metadata
* @param trusted Whether the document metadata is trusted.
*/
constructor(trusted?: boolean);
constructor();
/**
* Derived a new document metadata from this metadata.
@ -1065,7 +1058,7 @@ declare module 'vscode' {
* @return A new NotebookDocumentMetadata that reflects the given change. Will return `this` NotebookDocumentMetadata if the change
* is not changing anything.
*/
with(change: { trusted?: boolean | null, [key: string]: any }): NotebookDocumentMetadata
with(change: { [key: string]: any }): NotebookDocumentMetadata
}
export interface NotebookDocumentContentOptions {

View file

@ -3008,45 +3008,16 @@ export class NotebookCellMetadata {
}
export class NotebookDocumentMetadata {
readonly trusted: boolean;
readonly [key: string]: any;
constructor(trusted?: boolean);
constructor(data: Record<string, any>);
constructor(trustedOrData: boolean | Record<string, any> = true) {
if (typeof trustedOrData === 'object') {
Object.assign(this, trustedOrData);
this.trusted = trustedOrData.trusted ?? true;
} else {
this.trusted = trustedOrData;
}
constructor(data: Record<string, any> = {}) {
Object.assign(this, data);
}
with(change: {
trusted?: boolean | null,
[key: string]: any
}): NotebookDocumentMetadata {
let { trusted, ...remaining } = change;
if (trusted === undefined) {
trusted = this.trusted;
} else if (trusted === null) {
trusted = undefined;
}
if (trusted === this.trusted &&
Object.keys(remaining).length === 0
) {
return this;
}
return new NotebookDocumentMetadata(
{
trusted,
...remaining
}
);
return new NotebookDocumentMetadata(change);
}
}

View file

@ -40,10 +40,6 @@ export class NotebookEditorKernelManager extends Disposable {
return;
}
if (!notebook.metadata.trusted) {
return;
}
let kernel = this.getSelectedOrSuggestedKernel(notebook);
if (!kernel) {
await this._commandService.executeCommand('notebook.selectKernel');

View file

@ -3,44 +3,44 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as glob from 'vs/base/common/glob';
import { localize } from 'vs/nls';
import { getPixelRatio, getZoomLevel } from 'vs/base/browser/browser';
import { Emitter, Event } from 'vs/base/common/event';
import * as glob from 'vs/base/common/glob';
import { Iterable } from 'vs/base/common/iterator';
import { Lazy } from 'vs/base/common/lazy';
import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ResourceMap } from 'vs/base/common/map';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { localize } from 'vs/nls';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { NotebookExtensionDescription } from 'vs/workbench/api/common/extHost.protocol';
import { EditorExtensions, IEditorInput } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { Memento } from 'vs/workbench/common/memento';
import { INotebookEditorContribution, notebookMarkupRendererExtensionPoint, notebookProviderExtensionPoint, notebookRendererExtensionPoint } from 'vs/workbench/contrib/notebook/browser/extensionPoint';
import { NotebookEditorOptions, updateEditorTopPadding } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookDiffEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookDiffEditorInput';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, BUILTIN_RENDERER_ID, CellUri, DisplayOrderKey, INotebookExclusiveDocumentFilter, INotebookMarkupRendererInfo, INotebookRendererInfo, INotebookTextModel, IOrderedMimeType, IOutputDto, mimeTypeIsAlwaysSecure, mimeTypeSupportedByCore, NotebookDataDto, NotebookEditorPriority, NotebookRendererMatch, NotebookTextDiffEditorPreview, RENDERER_NOT_AVAILABLE, sortMimeTypes, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, BUILTIN_RENDERER_ID, CellUri, DisplayOrderKey, INotebookExclusiveDocumentFilter, INotebookMarkupRendererInfo, INotebookRendererInfo, INotebookTextModel, IOrderedMimeType, IOutputDto, mimeTypeSupportedByCore, NotebookDataDto, NotebookEditorPriority, NotebookRendererMatch, NotebookTextDiffEditorPreview, RENDERER_NOT_AVAILABLE, sortMimeTypes, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { NotebookMarkupRendererInfo as NotebookMarkupRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookMarkdownRenderer';
import { NotebookOutputRendererInfo } from 'vs/workbench/contrib/notebook/common/notebookOutputRenderer';
import { NotebookEditorDescriptor, NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { ComplexNotebookProviderInfo, INotebookContentProvider, INotebookSerializer, INotebookService, SimpleNotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookService';
import { ContributedEditorPriority, DiffEditorInputFactoryFunction, EditorInputFactoryFunction, IEditorAssociationsRegistry, IEditorOverrideService, IEditorType, IEditorTypesHandler } from 'vs/workbench/services/editor/common/editorOverrideService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { Registry } from 'vs/platform/registry/common/platform';
import { Schemas } from 'vs/base/common/network';
import { Lazy } from 'vs/base/common/lazy';
import { IResourceEditorInput } from 'vs/platform/editor/common/editor';
import { NotebookDiffEditorInput } from 'vs/workbench/contrib/notebook/browser/notebookDiffEditorInput';
import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
import { ContributedEditorPriority, DiffEditorInputFactoryFunction, EditorInputFactoryFunction, IEditorAssociationsRegistry, IEditorOverrideService, IEditorType, IEditorTypesHandler } from 'vs/workbench/services/editor/common/editorOverrideService';
import { EditorExtensions, IEditorInput } from 'vs/workbench/common/editor';
import { IFileService } from 'vs/platform/files/common/files';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
export class NotebookProviderInfoStore extends Disposable {
@ -599,14 +599,14 @@ export class NotebookService extends Disposable implements INotebookService, IEd
orderMimeTypes.push({
mimeType: mimeType,
rendererId: handler.id,
isTrusted: textModel.metadata.trusted
isTrusted: true
});
for (let i = 1; i < handlers.length; i++) {
orderMimeTypes.push({
mimeType: mimeType,
rendererId: handlers[i].id,
isTrusted: textModel.metadata.trusted
isTrusted: true
});
}
@ -614,7 +614,7 @@ export class NotebookService extends Disposable implements INotebookService, IEd
orderMimeTypes.push({
mimeType: mimeType,
rendererId: BUILTIN_RENDERER_ID,
isTrusted: mimeTypeIsAlwaysSecure(mimeType) || textModel.metadata.trusted
isTrusted: true // TODO@roblourens mimeTypeIsAlwaysSecure(mimeType) || this.workspaceTrustManagementService.isWorkpaceTrusted()
});
}
} else {
@ -622,13 +622,13 @@ export class NotebookService extends Disposable implements INotebookService, IEd
orderMimeTypes.push({
mimeType: mimeType,
rendererId: BUILTIN_RENDERER_ID,
isTrusted: mimeTypeIsAlwaysSecure(mimeType) || textModel.metadata.trusted
isTrusted: true // TODO@roblourens mimeTypeIsAlwaysSecure(mimeType) || this.workspaceTrustManagementService.isWorkpaceTrusted()
});
} else {
orderMimeTypes.push({
mimeType: mimeType,
rendererId: RENDERER_NOT_AVAILABLE,
isTrusted: textModel.metadata.trusted
isTrusted: true
});
}
}

View file

@ -61,12 +61,10 @@ export enum NotebookRunState {
export const notebookDocumentMetadataDefaults: Required<NotebookDocumentMetadata> = {
custom: {},
trusted: true
};
export interface NotebookDocumentMetadata {
custom?: { [key: string]: unknown };
trusted: boolean;
[key: string]: unknown;
}