mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 04:53:33 +01:00
Add remote-authority to webview uri
This commit is contained in:
@@ -10,21 +10,29 @@ 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):
|
||||
*
|
||||
* ```txt
|
||||
* /remote-authority?/scheme/resource-authority/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 + '/' + encodeURIComponent(resource.authority) + resource.path)
|
||||
.replace('{{uuid}}', uuid);
|
||||
return URI.parse(uri);
|
||||
}
|
||||
|
||||
function withoutScheme(resource: vscode.Uri): string {
|
||||
return resource.toString().replace(/^\S+?:/, '');
|
||||
return URI.parse(uri).with({
|
||||
fragment: resource.fragment,
|
||||
query: resource.query,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user