Skip to content

Commit

Permalink
consolidate toCodeFileUri into LocalFileAccessImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 24, 2020
1 parent e2316cf commit bcfc1a9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
21 changes: 16 additions & 5 deletions src/vs/base/common/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ class RemoteAuthoritiesImpl {
export const RemoteAuthorities = new RemoteAuthoritiesImpl();

class LocalFileAccessImpl {

/**
* Returns a `vscode-file` URI by from the provided URI.
*/
rewrite(uri: URI, query?: string): URI {
return uri.with({
scheme: Schemas.vscodeFileResource,
Expand All @@ -145,12 +149,19 @@ class LocalFileAccessImpl {
query
});
}
}

export const LocalFileAccess = new LocalFileAccessImpl();
/**
* Returns a `vscode-file` URI by resolving the `moduleId` to an absolute
* path on disk.
*/
fromModuleId(moduleId: string, query?: string): URI {

export function toCodeFileUri(path: string, query?: string): URI {
const url = require.toUrl(path);
// Use `require` to get the absolute URL for the module identifier
const url = require.toUrl(moduleId);

return LocalFileAccess.rewrite(URI.parse(url), query);
// Rewrite the URL to allow for local access
return this.rewrite(URI.parse(url), query);
}
}

export const LocalFileAccess = new LocalFileAccessImpl();
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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 { LocalFileAccess } from 'vs/base/common/network';
import { BrowserWindow, BrowserWindowConstructorOptions, app, AuthInfo, WebContents, Event as ElectronEvent } from 'electron';

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

const win = new BrowserWindow(opts);
const fileUrl = toCodeFileUri('vs/code/electron-sandbox/proxy/auth.html');
const fileUrl = LocalFileAccess.fromModuleId('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 Down
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/sharedProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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';
import { LocalFileAccess } from 'vs/base/common/network';

export class SharedProcess implements ISharedProcess {

Expand Down Expand Up @@ -62,7 +62,7 @@ export class SharedProcess implements ISharedProcess {
windowId: this.window.id
};

const fileUrl = toCodeFileUri(
const fileUrl = LocalFileAccess.fromModuleId(
'vs/code/electron-browser/sharedProcess/sharedProcess.html',
`config=${encodeURIComponent(JSON.stringify(config))}`);
this.window.loadURL(fileUrl.toString(true));
Expand Down
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +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 { LocalFileAccess } from 'vs/base/common/network';
import { ColorScheme } from 'vs/platform/theme/common/theme';

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

return toCodeFileUri(workbench, `config=${encodeURIComponent(JSON.stringify(config))}`).toString(true);
return LocalFileAccess.fromModuleId(workbench, `config=${encodeURIComponent(JSON.stringify(config))}`).toString(true);
}

private doGetPreloadUrl(): string {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/platform/issue/electron-main/issueMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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';
import { LocalFileAccess } from 'vs/base/common/network';

const DEFAULT_BACKGROUND_COLOR = '#1E1E1E';

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

return toCodeFileUri(pathToHtml, `config=${encodeURIComponent(JSON.stringify(config))}`).toString(true);
return LocalFileAccess.fromModuleId(pathToHtml, `config=${encodeURIComponent(JSON.stringify(config))}`).toString(true);
}

0 comments on commit bcfc1a9

Please sign in to comment.