Introduce Trust Book in Book Viewlet (#9414)

This commit is contained in:
Jorge Berumen
2020-03-13 09:11:38 -07:00
committed by GitHub
parent 744e655dd3
commit d5fdec5699
21 changed files with 590 additions and 10 deletions

View File

@@ -362,6 +362,11 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
return Promise.resolve(this.doOpenEditor(resource, options));
}
$trySetTrusted(uriComponent: UriComponents, isTrusted: boolean): Promise<boolean> {
let uri = URI.revive(uriComponent);
return this._notebookService.setTrusted(uri, isTrusted);
}
$tryApplyEdits(id: string, modelVersionId: number, edits: ISingleNotebookEditOperation[], opts: IUndoStopOptions): Promise<boolean> {
let editor = this.getEditor(id);
if (!editor) {

View File

@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ok } from 'vs/base/common/assert';
@@ -50,6 +49,7 @@ export class ExtHostNotebookDocumentData implements IDisposable {
get cells() { return data._cells; },
get kernelSpec() { return data._kernelSpec; },
save() { return data._save(); },
setTrusted(isTrusted) { data._setTrusted(isTrusted); },
validateCellRange(range) { return data._validateRange(range); },
};
}
@@ -61,7 +61,13 @@ export class ExtHostNotebookDocumentData implements IDisposable {
return Promise.reject(new Error('Document has been closed'));
}
return this._proxy.$trySaveDocument(this._uri);
}
private _setTrusted(isTrusted: boolean): Thenable<boolean> {
if (this._isDisposed) {
return Promise.reject(new Error('Document has been closed'));
}
return this._proxy.$trySetTrusted(this._uri, isTrusted);
}
public onModelChanged(data: INotebookModelChangedData) {

View File

@@ -82,6 +82,10 @@ export class NotebookEditorEdit {
return range;
}
setTrusted(isTrusted: boolean) {
this._document.setTrusted(isTrusted);
}
insertCell(value: Partial<azdata.nb.ICellContents>, index?: number, collapsed?: boolean): void {
if (index === null || index === undefined) {
// If not specified, assume adding to end of list

View File

@@ -891,6 +891,7 @@ export interface ExtHostNotebookDocumentsAndEditorsShape {
}
export interface MainThreadNotebookDocumentsAndEditorsShape extends IDisposable {
$trySetTrusted(_uri: UriComponents, isTrusted: boolean): Thenable<boolean>;
$trySaveDocument(uri: UriComponents): Thenable<boolean>;
$tryShowNotebookDocument(resource: UriComponents, options: INotebookShowOptions): Promise<string>;
$tryApplyEdits(id: string, modelVersionId: number, edits: ISingleNotebookEditOperation[], opts: IUndoStopOptions): Promise<boolean>;

View File

@@ -58,7 +58,7 @@ export class LinkHandlerDirective {
// ignore
}
if (uri && this.openerService && this.isSupportedLink(uri)) {
if (uri.fragment && uri.fragment.length > 0 && uri.fsPath === this.workbenchFilePath.fsPath) {
if (uri.fragment && uri.fragment.length > 0 && uri.path === this.workbenchFilePath.path) {
this.notebookService.navigateTo(this.notebookUri, uri.fragment);
} else {
this.openerService.open(uri).catch(onUnexpectedError);

View File

@@ -205,6 +205,9 @@ export class NotebookServiceStub implements INotebookService {
get languageMagics(): ILanguageMagic[] {
throw new Error('Method not implemented.');
}
setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean> {
throw new Error('Method not implemented.');
}
registerProvider(providerId: string, provider: INotebookProvider): void {
throw new Error('Method not implemented.');
}

View File

@@ -233,6 +233,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
public set trustedMode(isTrusted: boolean) {
this._trustedMode = isTrusted;
if (this._cells) {
this._cells.forEach(c => {
c.trustedMode = this._trustedMode;
@@ -290,6 +291,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
public async loadContents(isTrusted: boolean = false): Promise<void> {
try {
this._trustedMode = isTrusted;
let contents = null;
if (this._notebookOptions && this._notebookOptions.contentManager) {

View File

@@ -112,6 +112,13 @@ export interface INotebookService {
* @param sectionId ID of the section to navigate to
*/
navigateTo(notebookUri: URI, sectionId: string): void;
/**
* Sets the trusted mode for the sepcified notebook.
* @param notebookUri URI of the notebook to navigate to
* @param isTrusted True if notebook is to be set to trusted, false otherwise.
*/
setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean>;
}
export interface INotebookProvider {

View File

@@ -606,4 +606,25 @@ export class NotebookService extends Disposable implements INotebookService {
editor.navigateToSection(sectionId);
}
}
/**
* Trusts a notebook with the specified URI.
* @param notebookUri The notebook URI to set the trusted mode for.
* @param isTrusted True if the notebook is to be trusted, false otherwise.
*/
async setTrusted(notebookUri: URI, isTrusted: boolean): Promise<boolean> {
let editor = this.findNotebookEditor(notebookUri);
if (editor && editor.model) {
if (isTrusted) {
this._trustedCacheQueue.push(notebookUri);
} else {
this._unTrustedCacheQueue.push(notebookUri);
}
await this.updateTrustedCache();
editor.model.trustedMode = isTrusted;
}
return isTrusted;
}
}