Revert "Use custom scheme for loading webview wrapper contents"

This reverts commit 61f796ee89.

Not sure how this change causes problems but revert seems to fix it.

Fixes #100879
Fixes #100874
This commit is contained in:
Matt Bierner 2020-06-23 14:17:58 -07:00
parent 876ea86423
commit 5c11b81875
6 changed files with 8 additions and 46 deletions

View file

@ -86,10 +86,11 @@ setCurrentWorkingDirectory();
// Register custom schemes with privileges
protocol.registerSchemesAsPrivileged([
{
scheme: 'vscode-webview',
scheme: 'vscode-resource',
privileges: {
standard: true,
secure: true,
supportFetchAPI: true,
corsEnabled: true,
}
}, {
scheme: 'vscode-webview-resource',

View file

@ -62,14 +62,6 @@ export namespace Schemas {
export const webviewPanel = 'webview-panel';
/**
* Scheme used for loading the wrapper html and script in webviews.
*/
export const vscodeWebview = 'vscode-webview';
/**
* Scheme used for loading resources inside of webviews.
*/
export const vscodeWebviewResource = 'vscode-webview-resource';
/**

View file

@ -172,12 +172,11 @@ export class CodeApplication extends Disposable {
return false;
}
const uri = URI.parse(source);
if (uri.scheme === Schemas.vscodeWebview) {
return uri.path === '/index.html';
if (source === 'data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%0D%0A%3Chtml%20lang%3D%22en%22%20style%3D%22width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3Chead%3E%0D%0A%3Ctitle%3EVirtual%20Document%3C%2Ftitle%3E%0D%0A%3C%2Fhead%3E%0D%0A%3Cbody%20style%3D%22margin%3A%200%3B%20overflow%3A%20hidden%3B%20width%3A%20100%25%3B%20height%3A%20100%25%22%20role%3D%22document%22%3E%0D%0A%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E') {
return true;
}
const srcUri = uri.fsPath.toLowerCase();
const srcUri = URI.parse(source).fsPath.toLowerCase();
const rootUri = URI.file(this.environmentService.appRoot).fsPath.toLowerCase();
return srcUri.startsWith(rootUri + sep);

View file

@ -23,10 +23,6 @@ interface WebviewMetadata {
export class WebviewProtocolProvider extends Disposable {
private static validWebviewFilePaths = new Map([
['/index.html', 'index.html'],
]);
private readonly webviewMetadata = new Map<string, WebviewMetadata>();
constructor(
@ -91,23 +87,8 @@ export class WebviewProtocolProvider extends Disposable {
return callback({ data: null, statusCode: 404 });
});
this._register(toDisposable(() => sess.protocol.unregisterProtocol(Schemas.vscodeWebviewResource)));
sess.protocol.registerFileProtocol(Schemas.vscodeWebview, (request, callback: any) => {
try {
const uri = URI.parse(request.url);
const entry = WebviewProtocolProvider.validWebviewFilePaths.get(uri.path);
if (typeof entry === 'string') {
const url = require.toUrl(`vs/workbench/contrib/webview/electron-browser/pre/${entry}`);
return callback(url.replace('file://', ''));
}
} catch {
// noop
}
callback({ error: -10 /* ACCESS_DENIED - https://cs.chromium.org/chromium/src/net/base/net_error_list.h?l=32 */ });
});
this._register(toDisposable(() => sess.protocol.unregisterProtocol(Schemas.vscodeWebview)));
}
private streamToNodeReadable(stream: VSBufferReadableStream): Readable {

View file

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en" style="width: 100%; height: 100%">
<head>
<title>Virtual Document</title>
</head>
<body style="margin: 0; overflow: hidden; width: 100%; height: 100%" role="document">
</body>
</html>

View file

@ -289,7 +289,7 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
}
this.element!.preload = require.toUrl('./pre/electron-index.js');
this.element!.src = `${Schemas.vscodeWebview}://${id}/index.html`;
this.element!.src = 'data:text/html;charset=utf-8,%3C%21DOCTYPE%20html%3E%0D%0A%3Chtml%20lang%3D%22en%22%20style%3D%22width%3A%20100%25%3B%20height%3A%20100%25%22%3E%0D%0A%3Chead%3E%0D%0A%3Ctitle%3EVirtual%20Document%3C%2Ftitle%3E%0D%0A%3C%2Fhead%3E%0D%0A%3Cbody%20style%3D%22margin%3A%200%3B%20overflow%3A%20hidden%3B%20width%3A%20100%25%3B%20height%3A%20100%25%22%20role%3D%22document%22%3E%0D%0A%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E';
}
protected createElement(options: WebviewOptions) {