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

@@ -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;
}
}