diff --git a/src/main.js b/src/main.js index 1eef87ad080ec..04e39a6f38ccd 100644 --- a/src/main.js +++ b/src/main.js @@ -88,6 +88,14 @@ protocol.registerSchemesAsPrivileged([ corsEnabled: true, } }, + { + scheme: 'vscode-file', + privileges: { + secure: true, + standard: true, + corsEnabled: true + } + } ]); // Global app listeners @@ -161,6 +169,24 @@ async function onReady() { try { const [cachedDataDir, nlsConfig] = await Promise.all([nodeCachedDataDir.ensureExists(), resolveNlsConfiguration()]); + protocol.registerFileProtocol('vscode-file', async (request, callback) => { + const uri = new URL(request.url); + + if (uri.pathname.startsWith(app.getAppPath())) { + return callback({ + path: uri.pathname + }); + } else { + console.error('vscode-file: Cannot load resource outside of app root'); + return callback({ error: -3 /* ABORTED */ }); + } + }); + + protocol.interceptFileProtocol('file', async (request, callback) => { + console.error('file: protocol is not allowed in this app'); + return callback({ error: -3 /* ABORTED */ }); + }); + startup(cachedDataDir, nlsConfig); } catch (error) { console.error(error); diff --git a/src/vs/code/electron-main/sharedProcess.ts b/src/vs/code/electron-main/sharedProcess.ts index 782cb228ea479..1ef9d08a43837 100644 --- a/src/vs/code/electron-main/sharedProcess.ts +++ b/src/vs/code/electron-main/sharedProcess.ts @@ -56,7 +56,7 @@ export class SharedProcess implements ISharedProcess { }; const url = `${require.toUrl('vs/code/electron-browser/sharedProcess/sharedProcess.html')}?config=${encodeURIComponent(JSON.stringify(config))}`; - this.window.loadURL(url); + this.window.loadURL('vscode-file://localhost' + url.slice(7)); // Prevent the window from dying const onClose = (e: ElectronEvent) => { diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 2cdb6b90d6df3..9973a15ebfdfd 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -665,7 +665,7 @@ export class CodeWindow extends Disposable implements ICodeWindow { // Load URL perf.mark('main:loadWindow'); - this._win.loadURL(this.getUrl(configuration)); + this._win.loadURL('vscode-file://localhost' + this.getUrl(configuration).slice(7)); // Make window visible if it did not open in N seconds because this indicates an error // Only do this when running out of sources and not when running tests