Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vscode-file:// instead of file:// #101837

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
86b7bbc
feat: add vscode-file scheme
deepak1556 May 27, 2020
09e273a
Merge remote-tracking branch 'origin/master' into robo/vscode-file
alexdima Jun 24, 2020
505b841
Experimental tweaks to load from vscode-file:
alexdima Jun 24, 2020
560df14
Merge remote-tracking branch 'origin/master' into robo/vscode-file
alexdima Jun 24, 2020
42aff25
Merge remote-tracking branch 'origin/master' into robo/vscode-file
alexdima Jun 25, 2020
71a03e1
support fetch api in vscode-file:
deepak1556 Jun 26, 2020
e88395e
Define node modules, to avoid attempting loading them as AMD modules
alexdima Jun 26, 2020
5224c7e
Massage dom uris
alexdima Jun 26, 2020
d56bd13
Merge remote-tracking branch 'origin/master' into robo/vscode-file
alexdima Jul 7, 2020
ca503e7
Merge remote-tracking branch 'origin/master' into robo/vscode-file
alexdima Jul 7, 2020
b47e26a
Adopt `preferScriptTags`
alexdima Jul 7, 2020
1fa495c
Fix a couple of tests
alexdima Jul 8, 2020
9fedad2
Fix test on Windows
alexdima Jul 8, 2020
a417d00
Merge branch 'master' into robo/vscode-file
bpasero Jul 20, 2020
2132f0f
Merge branch 'master' into robo/vscode-file
deepak1556 Jul 20, 2020
1de2e79
address review feedback
deepak1556 Jul 20, 2020
473cfd6
fix bad check
deepak1556 Jul 20, 2020
62c31e5
fix double encoding
deepak1556 Jul 21, 2020
8de656d
Merge branch 'origin/master' into robo/vscode-file
deepak1556 Jul 21, 2020
4539119
Merge branch 'origin/master' into robo/vscode-file
deepak1556 Jul 21, 2020
0e14a64
Merge branch 'master' into robo/vscode-file
bpasero Sep 15, 2020
c86abd4
Merge branch 'master' into robo/vscode-file
bpasero Sep 15, 2020
7180a48
adopt new path for native env service interface
bpasero Sep 15, 2020
24b5423
address review feedback
deepak1556 Sep 16, 2020
52c90cd
Merge remote-tracking branch 'origin' into robo/vscode-file
deepak1556 Sep 16, 2020
a3873d9
Merge remote-tracking branch 'origin' into robo/vscode-file
deepak1556 Sep 18, 2020
75e26bd
address review feedback
deepak1556 Sep 18, 2020
623990b
Merge branch 'master' into robo/vscode-file
bpasero Sep 18, 2020
88809ba
some :lipstick:
bpasero Sep 18, 2020
83c9a49
Merge branch 'master' into robo/vscode-file
bpasero Sep 21, 2020
e657360
Merge branch 'master' into robo/vscode-file
bpasero Sep 22, 2020
a1b667d
fix windows loading
bpasero Sep 22, 2020
a27854f
add v8CacheOptions (configurable via CLI arg)
bpasero Sep 22, 2020
0400631
Merge branch 'master' into robo/vscode-file
bpasero Sep 22, 2020
7347078
remove unused variables
bpasero Sep 22, 2020
e2316cf
clarify authority requirement
bpasero Sep 24, 2020
bcfc1a9
consolidate toCodeFileUri into LocalFileAccessImpl
bpasero Sep 24, 2020
7431395
some clarifications
bpasero Sep 24, 2020
81ec8ec
towards supporting authorities
bpasero Sep 24, 2020
4726868
Merge branch 'master' into robo/vscode-file
bpasero Sep 24, 2020
3fe9d3f
add some tests
bpasero Sep 24, 2020
ea4e572
fix tests
bpasero Sep 24, 2020
53c881a
clarify comment
bpasero Sep 24, 2020
ff6b6cd
use getUriFromAmdModule
bpasero Sep 24, 2020
c1cb360
Merge branch 'master' into robo/vscode-file
bpasero Sep 24, 2020
f5513f0
fix webview working
bpasero Sep 24, 2020
c32d682
valid roots: add extension dev location too
bpasero Sep 25, 2020
70b6ab0
:lipstick:
bpasero Sep 25, 2020
01d9bd1
Merge branch 'master' into robo/vscode-file
bpasero Sep 25, 2020
faf30a7
fix duplicate import
bpasero Sep 25, 2020
80e6e0c
touchbar - restore file protocol for icons
bpasero Sep 25, 2020
894f1a8
refactor network methods to make meaning clear
bpasero Sep 25, 2020
1529615
simplify moduleId usage
bpasero Sep 25, 2020
adb9b2c
further renames
bpasero Sep 25, 2020
76f8e44
adopt FileAccess in more places
bpasero Sep 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/bootstrap-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,9 @@

window.document.documentElement.setAttribute('lang', locale);

// do not advertise AMD to avoid confusing UMD modules loaded with nodejs (TODO@sandbox non-sandboxed only)
if (!sandbox) {
window['define'] = undefined;
}

// replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only)
if (!sandbox) {
require.define('fs', ['original-fs'], function (originalFS) { return originalFS; });
require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); });
}

window['MonacoEnvironment'] = {};
Expand All @@ -105,6 +100,7 @@
baseUrl: `${uriFromPath(configuration.appRoot)}/out`,
'vs/nls': nlsConfig,
amdModulesPattern: /^vs\//,
preferScriptTags: true
};

// cached data config
Expand Down Expand Up @@ -247,7 +243,7 @@
if (safeProcess.platform === 'win32' && pathName.startsWith('//')) { // specially handle Windows UNC paths
uri = encodeURI(`file:${pathName}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this use of file protocol?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check how UNC path works with custom protocol, didn't want to update this before that.

} else {
uri = encodeURI(`file://${pathName}`);
uri = encodeURI(`vscode-file://app${pathName}`);
}

return uri.replace(/#/g, '%23');
Expand Down
9 changes: 9 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ protocol.registerSchemesAsPrivileged([
corsEnabled: true,
}
},
{
scheme: 'vscode-file',
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
privileges: {
bpasero marked this conversation as resolved.
Show resolved Hide resolved
secure: true,
standard: true,
supportFetchAPI: true,
corsEnabled: true
}
}
]);

// Global app listeners
Expand Down
3 changes: 3 additions & 0 deletions src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ export function asDomUri(uri: URI): URI {
if (Schemas.vscodeRemote === uri.scheme) {
return RemoteAuthorities.rewrite(uri);
}
if (platform.isNative && Schemas.file === uri.scheme) {
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
return uri.with({ authority: Schemas.vscodeFileAuthority, scheme: Schemas.vscodeFileResource });
}
return uri;
}

Expand Down
15 changes: 15 additions & 0 deletions src/vs/base/common/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export namespace Schemas {
* Scheme used for extension pages
*/
export const extension = 'extension';

/**
* Scheme used to load top level resources for the app
*/
export const vscodeFileResource = 'vscode-file';
export const vscodeFileAuthority = 'app';
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
}

class RemoteAuthoritiesImpl {
Expand Down Expand Up @@ -129,3 +135,12 @@ class RemoteAuthoritiesImpl {
}

export const RemoteAuthorities = new RemoteAuthoritiesImpl();

export function toCodeFileUri(path: string, query?: string, skipEncoding?: boolean): string {
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
const url = require.toUrl(path);
return URI.parse(url).with({
scheme: Schemas.vscodeFileResource,
authority: Schemas.vscodeFileAuthority,
query: query
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
}).toString(skipEncoding);
}
4 changes: 4 additions & 0 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { resolveCommonProperties } from 'vs/platform/telemetry/node/commonProper
import { getDelayedChannel, StaticRouter, createChannelReceiver } from 'vs/base/parts/ipc/common/ipc';
import product from 'vs/platform/product/common/product';
import { ProxyAuthHandler } from 'vs/code/electron-main/auth';
import { FileProtocolHandler } from 'vs/code/electron-main/protocol';
import { Disposable } from 'vs/base/common/lifecycle';
import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { ActiveWindowManager } from 'vs/platform/windows/electron-main/windowTracker';
Expand Down Expand Up @@ -355,6 +356,9 @@ export class CodeApplication extends Disposable {
this.logService.error(error);
}

// Setup Protocol Handler
this._register(new FileProtocolHandler(this.environmentService));

// Create Electron IPC Server
const electronIpcServer = new ElectronIPCServer();

Expand Down
5 changes: 3 additions & 2 deletions src/vs/code/electron-main/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { localize } from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { toCodeFileUri } from 'vs/base/common/network';
import { BrowserWindow, BrowserWindowConstructorOptions, app, AuthInfo, WebContents, Event as ElectronEvent } from 'electron';

type LoginEvent = {
Expand Down Expand Up @@ -76,7 +77,7 @@ export class ProxyAuthHandler extends Disposable {
}

const win = new BrowserWindow(opts);
const url = require.toUrl('vs/code/electron-sandbox/proxy/auth.html');
const fileUrl = toCodeFileUri('vs/code/electron-sandbox/proxy/auth.html');
const proxyUrl = `${authInfo.host}:${authInfo.port}`;
const title = localize('authRequire', "Proxy Authentication Required");
const message = localize('proxyauth', "The proxy {0} requires authentication.", proxyUrl);
Expand All @@ -97,6 +98,6 @@ export class ProxyAuthHandler extends Disposable {
win.close();
}
});
win.loadURL(url);
win.loadURL(fileUrl);
}
}
44 changes: 44 additions & 0 deletions src/vs/code/electron-main/protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
import { session } from 'electron';

export class FileProtocolHandler extends Disposable {

constructor(
@IEnvironmentService private readonly environmentService: INativeEnvironmentService
) {
super();

const { defaultSession } = session;

const resourceHandler = this.handleResourceRequest.bind(this);
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved
defaultSession.protocol.registerFileProtocol(Schemas.vscodeFileResource, resourceHandler);
deepak1556 marked this conversation as resolved.
Show resolved Hide resolved

this._register(toDisposable(() => {
defaultSession.protocol.unregisterProtocol(Schemas.vscodeFileResource);
}));
}

private async handleResourceRequest(
request: Electron.Request,
callback: any) {
const uri = URI.parse(request.url);
const appRoot = this.environmentService.appRoot;
const extensionsPath = this.environmentService.extensionsPath;
if (uri.path.startsWith(appRoot) ||
(extensionsPath && uri.path.startsWith(extensionsPath))) {
return callback({
path: decodeURIComponent(uri.path)
});
}
console.error(`vscode-file: Refused to load resource ${uri.path}`);
callback({ error: -3 /* ABORTED */ });
}
}
7 changes: 5 additions & 2 deletions src/vs/code/electron-main/sharedProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifec
import { IThemeMainService } from 'vs/platform/theme/electron-main/themeMainService';
import { toDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { toCodeFileUri } from 'vs/base/common/network';

export class SharedProcess implements ISharedProcess {

Expand Down Expand Up @@ -60,8 +61,10 @@ export class SharedProcess implements ISharedProcess {
windowId: this.window.id
};

const url = `${require.toUrl('vs/code/electron-browser/sharedProcess/sharedProcess.html')}?config=${encodeURIComponent(JSON.stringify(config))}`;
this.window.loadURL(url);
const fileUrl = toCodeFileUri(
'vs/code/electron-browser/sharedProcess/sharedProcess.html',
`config=${encodeURIComponent(JSON.stringify(config))}`, true);
this.window.loadURL(fileUrl);

// Prevent the window from dying
const onClose = (e: ElectronEvent) => {
Expand Down
7 changes: 6 additions & 1 deletion src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { IStorageMainService } from 'vs/platform/storage/node/storageMainService';
import { IFileService } from 'vs/platform/files/common/files';
import { toCodeFileUri } from 'vs/base/common/network';
import { ColorScheme } from 'vs/platform/theme/common/theme';

export interface IWindowCreationOptions {
Expand Down Expand Up @@ -835,7 +836,11 @@ export class CodeWindow extends Disposable implements ICodeWindow {
workbench = 'vs/code/electron-browser/workbench/workbench.html';
}

return `${require.toUrl(workbench)}?config=${encodeURIComponent(JSON.stringify(config))}`;
const fileUrl = toCodeFileUri(
workbench,
`config=${encodeURIComponent(JSON.stringify(config))}`, true);

return fileUrl;
}

private doGetPreloadUrl(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,33 @@ suite('Decoration Render Options', () => {
assert(readStyleSheet(styleSheet).indexOf(`{background:url('data:image/svg+xml;base64,PHN2ZyB4b+') center center no-repeat;}`) > 0);
s.removeDecorationType('example');

function assertBackground(url1: string, url2: string) {
const actual = readStyleSheet(styleSheet);
assert(
actual.indexOf(`{background:url('${url1}') center center no-repeat;}`) > 0
|| actual.indexOf(`{background:url('${url2}') center center no-repeat;}`) > 0
);
}

if (platform.isWindows) {
// windows file path (used as string)
s.registerDecorationType('example', { gutterIconPath: URI.file('c:\\files\\miles\\more.png') });
assert(readStyleSheet(styleSheet).indexOf(`{background:url('file:///c:/files/miles/more.png') center center no-repeat;}`) > 0);
assertBackground('file:///c:/files/miles/more.png', 'vscode-file://app/c:/files/miles/more.png');
s.removeDecorationType('example');

// single quote must always be escaped/encoded
s.registerDecorationType('example', { gutterIconPath: URI.file('c:\\files\\foo\\b\'ar.png') });
assert(readStyleSheet(styleSheet).indexOf(`{background:url('file:///c:/files/foo/b%27ar.png') center center no-repeat;}`) > 0);
assertBackground('file:///c:/files/foo/b%27ar.png', 'vscode-file://app/c:/files/foo/b%27ar.png');
s.removeDecorationType('example');
} else {
// unix file path (used as string)
s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/bar.png') });
assert(readStyleSheet(styleSheet).indexOf(`{background:url('file:///Users/foo/bar.png') center center no-repeat;}`) > 0);
assertBackground('file:///Users/foo/bar.png', 'vscode-file://app/Users/foo/bar.png');
s.removeDecorationType('example');

// single quote must always be escaped/encoded
s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/b\'ar.png') });
assert(readStyleSheet(styleSheet).indexOf(`{background:url('file:///Users/foo/b%27ar.png') center center no-repeat;}`) > 0);
assertBackground('file:///Users/foo/b%27ar.png', 'vscode-file://app/Users/foo/b%27ar.png');
s.removeDecorationType('example');
}

Expand Down
6 changes: 5 additions & 1 deletion src/vs/platform/issue/electron-main/issueMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogs';
import { URI } from 'vs/base/common/uri';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { zoomLevelToZoomFactor } from 'vs/platform/windows/common/windows';
import { toCodeFileUri } from 'vs/base/common/network';

const DEFAULT_BACKGROUND_COLOR = '#1E1E1E';

Expand Down Expand Up @@ -449,5 +450,8 @@ function toLauchUrl<T>(pathToHtml: string, windowConfiguration: T): string {
}
}

return `${require.toUrl(pathToHtml)}?config=${encodeURIComponent(JSON.stringify(config))}`;
const fileUrl = toCodeFileUri(
pathToHtml,
`config=${encodeURIComponent(JSON.stringify(config))}`, true);
return fileUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ suite('ExtensionsWorkbenchServiceTest', () => {
assert.equal('1.1.0', actual.version);
assert.equal('1.1.0', actual.latestVersion);
assert.equal('localDescription1', actual.description);
assert.equal('file:///localPath1/localIcon1', actual.iconUrl);
assert.equal('file:///localPath1/localIcon1', actual.iconUrlFallback);
assert.ok(actual.iconUrl === 'file:///localPath1/localIcon1' || actual.iconUrl === 'vscode-file://app/localPath1/localIcon1');
assert.ok(actual.iconUrlFallback === 'file:///localPath1/localIcon1' || actual.iconUrlFallback === 'vscode-file://app/localPath1/localIcon1');
assert.equal(null, actual.licenseUrl);
assert.equal(ExtensionState.Installed, actual.state);
assert.equal(null, actual.installCount);
Expand Down