diff --git a/extensions/markdown-language-features/src/features/preview.ts b/extensions/markdown-language-features/src/features/preview.ts
index 694a4fbb13c..775734d1140 100644
--- a/extensions/markdown-language-features/src/features/preview.ts
+++ b/extensions/markdown-language-features/src/features/preview.ts
@@ -439,8 +439,8 @@ export class MarkdownPreview extends Disposable {
if (this._resource === markdownResource) {
const self = this;
const resourceProvider: WebviewResourceProvider = {
- toWebviewResource: (resource) => {
- return this.editor.webview.toWebviewResource(normalizeResource(markdownResource, resource));
+ asWebviewUri: (resource) => {
+ return this.editor.webview.asWebviewUri(normalizeResource(markdownResource, resource));
},
get cspSource() { return self.editor.webview.cspSource; }
};
diff --git a/extensions/markdown-language-features/src/features/previewContentProvider.ts b/extensions/markdown-language-features/src/features/previewContentProvider.ts
index 9b70fe3beb3..0be66d1d630 100644
--- a/extensions/markdown-language-features/src/features/previewContentProvider.ts
+++ b/extensions/markdown-language-features/src/features/previewContentProvider.ts
@@ -65,7 +65,7 @@ export class MarkdownContentProvider {
scrollEditorWithPreview: config.scrollEditorWithPreview,
doubleClickToSwitchToEditor: config.doubleClickToSwitchToEditor,
disableSecurityWarnings: this.cspArbiter.shouldDisableSecurityWarnings(),
- webviewResourceRoot: resourceProvider.toWebviewResource(markdownDocument.uri).toString(),
+ webviewResourceRoot: resourceProvider.asWebviewUri(markdownDocument.uri).toString(),
};
this.logger.log('provideTextDocumentContent', initialData);
@@ -86,7 +86,7 @@ export class MarkdownContentProvider {
data-state="${escapeAttribute(JSON.stringify(state || {}))}">
${this.getStyles(resourceProvider, sourceUri, config, state)}
-
`
+ * ```
+ */
+ asWebviewUri(localResource: Uri): Uri;
+
+ /**
+ * Content security policy source for webview resources.
+ *
+ * This is the origin that should be used in a content security policy rule:
+ *
+ * ```
+ * img-src https: ${webview.cspSource} ...;
+ * ```
+ */
+ readonly cspSource: string;
}
/**
diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts
index 5284711d6e1..9dcf41062f4 100644
--- a/src/vs/vscode.proposed.d.ts
+++ b/src/vs/vscode.proposed.d.ts
@@ -1141,35 +1141,4 @@ declare module 'vscode' {
}
//#endregion
-
- //#region Webview Resource Roots
-
- export interface Webview {
- /**
- * Convert a uri for the local file system to one that can be used inside webviews.
- *
- * Webviews cannot directly load resoruces from the workspace or local file system using `file:` uris. The
- * `toWebviewResource` function takes a local `file:` uri and converts it into a uri that can be used inside of
- * a webview to load the same resource:
- *
- * ```ts
- * webview.html = `
`
- * ```
- */
- toWebviewResource(localResource: Uri): Uri;
-
- /**
- * Content security policy source for webview resources.
- *
- * This is the origin that should be used in a content security policy rule:
- *
- * ```
- * img-src https: ${webview.cspSource} ...;
- * ```
- */
- readonly cspSource: string;
- }
-
- //#endregion
-
}
diff --git a/src/vs/workbench/api/common/extHostCodeInsets.ts b/src/vs/workbench/api/common/extHostCodeInsets.ts
index 066b25f2b02..769e4de2a7a 100644
--- a/src/vs/workbench/api/common/extHostCodeInsets.ts
+++ b/src/vs/workbench/api/common/extHostCodeInsets.ts
@@ -10,7 +10,7 @@ import { ExtHostTextEditor } from 'vs/workbench/api/common/extHostTextEditor';
import { ExtHostEditors } from 'vs/workbench/api/common/extHostTextEditors';
import * as vscode from 'vscode';
import { ExtHostEditorInsetsShape, MainThreadEditorInsetsShape } from './extHost.protocol';
-import { toWebviewResource, WebviewInitData } from 'vs/workbench/api/common/shared/webview';
+import { asWebviewUri, WebviewInitData } from 'vs/workbench/api/common/shared/webview';
import { generateUuid } from 'vs/base/common/uuid';
export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
@@ -65,8 +65,8 @@ export class ExtHostEditorInsets implements ExtHostEditorInsetsShape {
private _html: string = '';
private _options: vscode.WebviewOptions = Object.create(null);
- toWebviewResource(resource: vscode.Uri): vscode.Uri {
- return toWebviewResource(that._initData, this._uuid, resource);
+ asWebviewUri(resource: vscode.Uri): vscode.Uri {
+ return asWebviewUri(that._initData, this._uuid, resource);
}
get cspSource(): string {
diff --git a/src/vs/workbench/api/common/extHostWebview.ts b/src/vs/workbench/api/common/extHostWebview.ts
index aaa6a49734c..44b99bcbd4c 100644
--- a/src/vs/workbench/api/common/extHostWebview.ts
+++ b/src/vs/workbench/api/common/extHostWebview.ts
@@ -12,7 +12,7 @@ import { ExtHostWebviewsShape, IMainContext, MainContext, MainThreadWebviewsShap
import { Disposable } from './extHostTypes';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import * as modes from 'vs/editor/common/modes';
-import { WebviewInitData, toWebviewResource } from 'vs/workbench/api/common/shared/webview';
+import { WebviewInitData, asWebviewUri } from 'vs/workbench/api/common/shared/webview';
import { generateUuid } from 'vs/base/common/uuid';
type IconPath = URI | { light: URI, dark: URI };
@@ -35,8 +35,8 @@ export class ExtHostWebview implements vscode.Webview {
this._onMessageEmitter.dispose();
}
- public toWebviewResource(resource: vscode.Uri): vscode.Uri {
- return toWebviewResource(this._initData, this._handle, resource);
+ public asWebviewUri(resource: vscode.Uri): vscode.Uri {
+ return asWebviewUri(this._initData, this._handle, resource);
}
public get cspSource(): string {
diff --git a/src/vs/workbench/api/common/shared/webview.ts b/src/vs/workbench/api/common/shared/webview.ts
index 3969d74dbe1..9740cd21a6f 100644
--- a/src/vs/workbench/api/common/shared/webview.ts
+++ b/src/vs/workbench/api/common/shared/webview.ts
@@ -11,7 +11,7 @@ export interface WebviewInitData {
readonly webviewCspSource: string;
}
-export function toWebviewResource(
+export function asWebviewUri(
initData: WebviewInitData,
uuid: string,
resource: vscode.Uri
diff --git a/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts b/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts
index 8a121279041..fb75ee14a20 100644
--- a/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts
+++ b/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts
@@ -48,7 +48,7 @@ suite('ExtHostWebview', () => {
assert.strictEqual(lastInvokedDeserializer, serializerB);
});
- test('toWebviewResource for desktop vscode-resource scheme', () => {
+ test('asWebviewUri for desktop vscode-resource scheme', () => {
const shape = createNoopMainThreadWebviews();
const extHostWebviews = new ExtHostWebviews(SingleProxyRPCProtocol(shape), {
webviewCspSource: '',
@@ -57,37 +57,37 @@ suite('ExtHostWebview', () => {
const webview = extHostWebviews.createWebviewPanel({} as any, 'type', 'title', 1, {});
assert.strictEqual(
- webview.webview.toWebviewResource(URI.parse('file:///Users/codey/file.html')).toString(),
+ webview.webview.asWebviewUri(URI.parse('file:///Users/codey/file.html')).toString(),
'vscode-resource:/Users/codey/file.html',
'Unix basic'
);
assert.strictEqual(
- webview.webview.toWebviewResource(URI.parse('file:///Users/codey/file.html#frag')).toString(),
+ webview.webview.asWebviewUri(URI.parse('file:///Users/codey/file.html#frag')).toString(),
'vscode-resource:/Users/codey/file.html#frag',
'Unix should preserve fragment'
);
assert.strictEqual(
- webview.webview.toWebviewResource(URI.parse('file:///Users/codey/f%20ile.html')).toString(),
+ webview.webview.asWebviewUri(URI.parse('file:///Users/codey/f%20ile.html')).toString(),
'vscode-resource:/Users/codey/f%20ile.html',
'Unix with encoding'
);
assert.strictEqual(
- webview.webview.toWebviewResource(URI.parse('file://localhost/Users/codey/file.html')).toString(),
+ webview.webview.asWebviewUri(URI.parse('file://localhost/Users/codey/file.html')).toString(),
'vscode-resource://localhost/Users/codey/file.html',
'Unix should preserve authority'
);
assert.strictEqual(
- webview.webview.toWebviewResource(URI.parse('file:///c:/codey/file.txt')).toString(),
+ webview.webview.asWebviewUri(URI.parse('file:///c:/codey/file.txt')).toString(),
'vscode-resource:/c%3A/codey/file.txt',
'Windows C drive'
);
});
- test('toWebviewResource for web endpoint', () => {
+ test('asWebviewUri for web endpoint', () => {
const shape = createNoopMainThreadWebviews();
const extHostWebviews = new ExtHostWebviews(SingleProxyRPCProtocol(shape), {
@@ -101,31 +101,31 @@ suite('ExtHostWebview', () => {
}
assert.strictEqual(
- stripEndpointUuid(webview.webview.toWebviewResource(URI.parse('file:///Users/codey/file.html')).toString()),
+ stripEndpointUuid(webview.webview.asWebviewUri(URI.parse('file:///Users/codey/file.html')).toString()),
'webview.contoso.com/commit///Users/codey/file.html',
'Unix basic'
);
assert.strictEqual(
- stripEndpointUuid(webview.webview.toWebviewResource(URI.parse('file:///Users/codey/file.html#frag')).toString()),
+ stripEndpointUuid(webview.webview.asWebviewUri(URI.parse('file:///Users/codey/file.html#frag')).toString()),
'webview.contoso.com/commit///Users/codey/file.html#frag',
'Unix should preserve fragment'
);
assert.strictEqual(
- stripEndpointUuid(webview.webview.toWebviewResource(URI.parse('file:///Users/codey/f%20ile.html')).toString()),
+ stripEndpointUuid(webview.webview.asWebviewUri(URI.parse('file:///Users/codey/f%20ile.html')).toString()),
'webview.contoso.com/commit///Users/codey/f%20ile.html',
'Unix with encoding'
);
assert.strictEqual(
- stripEndpointUuid(webview.webview.toWebviewResource(URI.parse('file://localhost/Users/codey/file.html')).toString()),
+ stripEndpointUuid(webview.webview.asWebviewUri(URI.parse('file://localhost/Users/codey/file.html')).toString()),
'webview.contoso.com/commit//localhost/Users/codey/file.html',
'Unix should preserve authority'
);
assert.strictEqual(
- stripEndpointUuid(webview.webview.toWebviewResource(URI.parse('file:///c:/codey/file.txt')).toString()),
+ stripEndpointUuid(webview.webview.asWebviewUri(URI.parse('file:///c:/codey/file.txt')).toString()),
'webview.contoso.com/commit///c%3A/codey/file.txt',
'Windows C drive'
);