Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload webview on trust state change, no cache for output data. #179075

Merged
merged 4 commits into from Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -199,10 +199,9 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
}

this._register(workspaceTrustManagementService.onDidChangeTrust(e => {
this._sendMessageToWebview({
type: 'updateWorkspaceTrust',
isTrusted: e,
});
const baseUrl = this.asWebviewUri(this.getNotebookBaseUri(), undefined);
const htmlContent = this.generateContent(baseUrl.toString());
this.webview?.setHtml(htmlContent);
}));

this._register(TokenizationRegistry.onDidChange(() => {
Expand Down
Expand Up @@ -378,10 +378,6 @@ export interface INotebookOptionsMessage {
readonly renderOptions: RenderOptions;
}

export interface INotebookUpdateWorkspaceTrust {
readonly type: 'updateWorkspaceTrust';
readonly isTrusted: boolean;
}
export interface ITokenizedCodeBlockMessage {
readonly type: 'tokenizedCodeBlock';
readonly codeBlockId: string;
Expand Down Expand Up @@ -529,7 +525,6 @@ export type ToWebviewMessage = IClearMessage |
IInitializeMarkupCells |
INotebookStylesMessage |
INotebookOptionsMessage |
INotebookUpdateWorkspaceTrust |
ITokenizedCodeBlockMessage |
ITokenizedStylesChangedMessage |
IFindMessage |
Expand Down
Expand Up @@ -90,7 +90,7 @@ async function webviewPreloads(ctx: PreloadContext) {
const textDecoder = new TextDecoder();

let currentOptions = ctx.options;
let isWorkspaceTrusted = ctx.isWorkspaceTrusted;
const isWorkspaceTrusted = ctx.isWorkspaceTrusted;
let currentRenderOptions = ctx.renderOptions;
const settingChange: EmitterLike<RenderOptions> = createEmitter<RenderOptions>();

Expand Down Expand Up @@ -1397,11 +1397,6 @@ async function webviewPreloads(ctx: PreloadContext) {
currentRenderOptions = event.data.renderOptions;
settingChange.fire(currentRenderOptions);
break;
case 'updateWorkspaceTrust': {
isWorkspaceTrusted = event.data.isTrusted;
viewModel.rerender();
break;
}
case 'tokenizedCodeBlock': {
const { codeBlockId, html } = event.data;
MarkdownCodeBlock.highlightCodeBlock(codeBlockId, html);
Expand Down Expand Up @@ -1870,11 +1865,6 @@ async function webviewPreloads(ctx: PreloadContext) {
this._outputCells.clear();
}

public rerender() {
this.rerenderMarkupCells();
this.renderOutputCells();
}

private async createMarkupCell(init: webviewMessages.IMarkupCellInitialization, top: number, visible: boolean): Promise<MarkupCell> {
const existing = this._markupCells.get(init.cellId);
if (existing) {
Expand Down Expand Up @@ -1929,12 +1919,6 @@ async function webviewPreloads(ctx: PreloadContext) {
cell?.unhide();
}

private rerenderMarkupCells() {
for (const cell of this._markupCells.values()) {
cell.rerender();
}
}

private getExpectedMarkupCell(id: string): MarkupCell | undefined {
const cell = this._markupCells.get(id);
if (!cell) {
Expand Down Expand Up @@ -1966,12 +1950,6 @@ async function webviewPreloads(ctx: PreloadContext) {
}
}

private renderOutputCells() {
for (const outputCell of this._outputCells.values()) {
outputCell.rerender();
}
}

public async renderOutputCell(data: webviewMessages.ICreationRequestMessage, signal: AbortSignal): Promise<void> {
const preloadErrors = await Promise.all<undefined | Error>(
data.requiredPreloads.map(p => kernelPreloads.waitFor(p.uri).then(() => undefined, err => err))
Expand Down Expand Up @@ -2266,10 +2244,6 @@ async function webviewPreloads(ctx: PreloadContext) {
this.updateMarkupDimensions();
}

public rerender() {
this.updateContentAndRender(this._content.value, this._content.metadata);
}

public remove() {
this.element.remove();
}
Expand Down Expand Up @@ -2378,12 +2352,6 @@ async function webviewPreloads(ctx: PreloadContext) {
this.outputElements.get(outputId)?.updateContentAndRender(content);
}

public rerender() {
for (const outputElement of this.outputElements.values()) {
outputElement.rerender();
}
}

public updateOutputHeight(outputId: string, height: number) {
this.outputElements.get(outputId)?.updateHeight(height);
}
Expand Down Expand Up @@ -2458,10 +2426,6 @@ async function webviewPreloads(ctx: PreloadContext) {
return this._outputNode;
}

public rerender() {
this._outputNode?.rerender();
}

public updateContentAndRender(content: webviewMessages.ICreationContent) {
this._outputNode?.updateAndRerender(content);
}
Expand Down Expand Up @@ -2490,7 +2454,6 @@ async function webviewPreloads(ctx: PreloadContext) {
class OutputElement {
public readonly element: HTMLElement;
private _content?: {
readonly content: webviewMessages.ICreationContent;
readonly preferredRendererId: string | undefined;
readonly preloadErrors: ReadonlyArray<Error | undefined>;
};
Expand Down Expand Up @@ -2528,7 +2491,7 @@ async function webviewPreloads(ctx: PreloadContext) {
this.renderTaskAbort?.abort();
this.renderTaskAbort = undefined;

this._content = { content, preferredRendererId, preloadErrors };
this._content = { preferredRendererId, preloadErrors };
if (content.type === 0 /* RenderOutputType.Html */) {
const trustedHtml = ttPolicy?.createHTML(content.htmlContent) ?? content.htmlContent;
this.element.innerHTML = trustedHtml as string;
Expand Down Expand Up @@ -2586,16 +2549,9 @@ async function webviewPreloads(ctx: PreloadContext) {
}
}

public rerender() {
if (this._content) {
this.render(this._content.content, this._content.preferredRendererId, this._content.preloadErrors);
}
}

public updateAndRerender(content: webviewMessages.ICreationContent) {
if (this._content) {
this._content = { content, preferredRendererId: this._content.preferredRendererId, preloadErrors: this._content.preloadErrors };
this.rerender();
this.render(content, this._content.preferredRendererId, this._content.preloadErrors);
}
}
}
Expand Down