Skip to content

Commit

Permalink
Revert "Use custom scheme for loading webview wrapper contents"
Browse files Browse the repository at this point in the history
This reverts commit 61f796e.

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

Fixes #100879
Fixes #100874
  • Loading branch information
mjbvz committed Jun 23, 2020
1 parent 876ea86 commit 5c11b81
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 46 deletions.
5 changes: 3 additions & 2 deletions src/main.js
Expand Up @@ -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',
Expand Down
8 changes: 0 additions & 8 deletions src/vs/base/common/network.ts
Expand Up @@ -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';

/**
Expand Down
7 changes: 3 additions & 4 deletions src/vs/code/electron-main/app.ts
Expand Up @@ -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);
Expand Down
21 changes: 1 addition & 20 deletions src/vs/platform/webview/electron-main/webviewProtocolProvider.ts
Expand Up @@ -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(
Expand Down Expand Up @@ -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)));
this._register(toDisposable(() => sess.protocol.unregisterProtocol(Schemas.vscodeWebviewResource)));
}

private streamToNodeReadable(stream: VSBufferReadableStream): Readable {
Expand Down
11 changes: 0 additions & 11 deletions src/vs/workbench/contrib/webview/electron-browser/pre/index.html

This file was deleted.

Expand Up @@ -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) {
Expand Down

0 comments on commit 5c11b81

Please sign in to comment.