Skip to content

Commit

Permalink
feat: add vscode-file scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed May 27, 2020
1 parent 876f2e7 commit 86b7bbc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ protocol.registerSchemesAsPrivileged([
corsEnabled: true,
}
},
{
scheme: 'vscode-file',
privileges: {
secure: true,
standard: true,
corsEnabled: true
}
}
]);

// Global app listeners
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/sharedProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 86b7bbc

Please sign in to comment.