Skip to content

Commit 4e436d1

Browse files
committed
Investigate using Electron's resolveProxy API (microsoft#60773)
1 parent 53d48f4 commit 4e436d1

15 files changed

Lines changed: 298 additions & 24 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
},
2929
"dependencies": {
3030
"applicationinsights": "1.0.6",
31+
"electron-proxy-agent": "^1.0.2",
3132
"fast-plist": "0.1.2",
3233
"gc-signals": "^0.0.1",
3334
"getmac": "1.4.1",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'electron-proxy-agent';

src/vs/platform/request/node/request.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ Registry.as<IConfigurationRegistry>(Extensions.Configuration)
4747
type: ['null', 'string'],
4848
default: null,
4949
description: localize('proxyAuthorization', "The value to send as the 'Proxy-Authorization' header for every network request.")
50+
},
51+
'http.systemProxy': {
52+
type: 'string',
53+
enum: ['off', 'on', 'force'],
54+
enumDescriptions: [
55+
localize('systemProxyOff', "Do not use system proxy configuration."),
56+
localize('systemProxyOn', "Use system proxy configuration if not specified in the request options."),
57+
localize('systemProxyForce', "Always use system proxy configuration."),
58+
],
59+
default: 'off',
60+
description: localize('systemProxy', "Experimental setting: Use the system proxy configuration.")
5061
}
5162
}
5263
});

src/vs/platform/windows/common/windows.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export interface IWindowsService {
167167
startCrashReporter(config: CrashReporterStartOptions): TPromise<void>;
168168

169169
openAboutDialog(): TPromise<void>;
170+
resolveProxy(windowId: number, url: string): Promise<string | undefined>;
170171
}
171172

172173
export const IWindowService = createDecorator<IWindowService>('windowService');
@@ -214,6 +215,7 @@ export interface IWindowService {
214215
showMessageBox(options: MessageBoxOptions): TPromise<IMessageBoxResult>;
215216
showSaveDialog(options: SaveDialogOptions): TPromise<string>;
216217
showOpenDialog(options: OpenDialogOptions): TPromise<string[]>;
218+
resolveProxy(url: string): Promise<string | undefined>;
217219
}
218220

219221
export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden';

src/vs/platform/windows/electron-browser/windowService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,8 @@ export class WindowService implements IWindowService {
163163
updateTouchBar(items: ISerializableCommandAction[][]): TPromise<void> {
164164
return this.windowsService.updateTouchBar(this.windowId, items);
165165
}
166+
167+
resolveProxy(url: string): Promise<string | undefined> {
168+
return this.windowsService.resolveProxy(this.windowId, url);
169+
}
166170
}

src/vs/platform/windows/electron-main/windowsService.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,19 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable
564564
return TPromise.wrap(true);
565565
}
566566

567+
resolveProxy(windowId: number, url: string): Promise<string | undefined> {
568+
return new Promise(resolve => {
569+
const codeWindow = this.windowsMainService.getWindowById(windowId);
570+
if (codeWindow) {
571+
codeWindow.win.webContents.session.resolveProxy(url, proxy => {
572+
resolve(proxy);
573+
});
574+
} else {
575+
resolve();
576+
}
577+
});
578+
}
579+
567580
dispose(): void {
568581
this.disposables = dispose(this.disposables);
569582
}

src/vs/platform/windows/node/windowsIpc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface IWindowsChannel extends IChannel {
7373
call(command: 'openExternal', arg: string): Thenable<boolean>;
7474
call(command: 'startCrashReporter', arg: CrashReporterStartOptions): Thenable<void>;
7575
call(command: 'openAboutDialog'): Thenable<void>;
76+
call(command: 'resolveProxy', arg: [number, string]): Thenable<string | undefined>;
7677
}
7778

7879
export class WindowsChannel implements IWindowsChannel {
@@ -178,6 +179,7 @@ export class WindowsChannel implements IWindowsChannel {
178179
case 'openExternal': return this.service.openExternal(arg);
179180
case 'startCrashReporter': return this.service.startCrashReporter(arg);
180181
case 'openAboutDialog': return this.service.openAboutDialog();
182+
case 'resolveProxy': return this.service.resolveProxy(arg[0], arg[1]);
181183
}
182184
return undefined;
183185
}
@@ -404,4 +406,8 @@ export class WindowsChannelClient implements IWindowsService {
404406
openAboutDialog(): TPromise<void> {
405407
return TPromise.wrap(this.channel.call('openAboutDialog'));
406408
}
409+
410+
resolveProxy(windowId: number, url: string): Promise<string | undefined> {
411+
return Promise.resolve(this.channel.call('resolveProxy', [windowId, url]));
412+
}
407413
}

src/vs/workbench/api/electron-browser/mainThreadWorkspace.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
4040
@IConfigurationService private readonly _configurationService: IConfigurationService,
4141
@IWorkspaceEditingService private readonly _workspaceEditingService: IWorkspaceEditingService,
4242
@IStatusbarService private readonly _statusbarService: IStatusbarService,
43+
@IWindowService private readonly _windowService: IWindowService,
4344
@IInstantiationService private readonly _instantiationService: IInstantiationService,
4445
@ILabelService private readonly _labelService: ILabelService
4546
) {
@@ -231,6 +232,10 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
231232
return result.results.every(each => each.success === true);
232233
});
233234
}
235+
236+
$resolveProxy(url: string): Thenable<string> {
237+
return this._windowService.resolveProxy(url);
238+
}
234239
}
235240

236241
CommandsRegistry.registerCommand('_workbench.enterWorkspace', async function (accessor: ServicesAccessor, workspace: URI, disableExtensions: string[]) {

src/vs/workbench/api/node/extHost.protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ export interface MainThreadWorkspaceShape extends IDisposable {
487487
$checkExists(includes: string[], token: CancellationToken): Thenable<boolean>;
488488
$saveAll(includeUntitled?: boolean): Thenable<boolean>;
489489
$updateWorkspaceFolders(extensionName: string, index: number, deleteCount: number, workspaceFoldersToAdd: { uri: UriComponents, name?: string }[]): Thenable<void>;
490+
$resolveProxy(url: string): Thenable<string>;
490491
}
491492

492493
export interface IFileChangeDto {

src/vs/workbench/api/node/extHostExtensionService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ export class ExtHostExtensionService implements ExtHostExtensionServiceShape {
147147
extHostContext: IMainContext,
148148
extHostWorkspace: ExtHostWorkspace,
149149
extHostConfiguration: ExtHostConfiguration,
150-
extHostLogService: ExtHostLogService
150+
extHostLogService: ExtHostLogService,
151+
mainThreadTelemetry: MainThreadTelemetryShape
151152
) {
152153
this._barrier = new Barrier();
153154
this._registry = new ExtensionDescriptionRegistry(initData.extensions);
154155
this._extHostLogService = extHostLogService;
155-
this._mainThreadTelemetry = extHostContext.getProxy(MainContext.MainThreadTelemetry);
156+
this._mainThreadTelemetry = mainThreadTelemetry;
156157
this._storage = new ExtHostStorage(extHostContext);
157158
this._storagePath = new ExtensionStoragePath(initData.workspace, initData.environment);
158159
this._proxy = extHostContext.getProxy(MainContext.MainThreadExtensionService);

0 commit comments

Comments
 (0)