mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
Put authority into webview resource uri
This lets us handle the case where a webview needs to load both local and remote resources
This commit is contained in:
@@ -10,17 +10,24 @@ export interface WebviewInitData {
|
||||
readonly isExtensionDevelopmentDebug: boolean;
|
||||
readonly webviewResourceRoot: string;
|
||||
readonly webviewCspSource: string;
|
||||
readonly remote: { readonly authority: string | undefined };
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a uri that can load resources inside a webview
|
||||
*
|
||||
* We encode the resource component of the uri so that on the main thread
|
||||
* we know where to load the resource from (remote or truly local):
|
||||
*
|
||||
* /authority?/scheme/path...
|
||||
*/
|
||||
export function asWebviewUri(
|
||||
initData: WebviewInitData,
|
||||
uuid: string,
|
||||
resource: vscode.Uri,
|
||||
): vscode.Uri {
|
||||
const uri = initData.webviewResourceRoot
|
||||
// Make sure we preserve the scheme of the resource but convert it into a normal path segment
|
||||
// The scheme is important as we need to know if we are requesting a local or a remote resource.
|
||||
.replace('{{resource}}', resource.scheme + withoutScheme(resource))
|
||||
.replace('{{resource}}', (initData.remote.authority ?? '') + '/' + resource.scheme + withoutScheme(resource))
|
||||
.replace('{{uuid}}', uuid);
|
||||
return URI.parse(uri);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user