From c4aa0108356fb01af46d3d09b7bd7213169af632 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 18 Sep 2020 17:23:50 +0200 Subject: [PATCH] sandbox - expose `vscode-windows-registry` from native host service --- src/vs/platform/native/common/native.ts | 3 +++ .../native/electron-main/nativeHostMainService.ts | 15 +++++++++++++++ .../tags/electron-browser/workspaceTags.ts | 12 ++++-------- .../electron-sandbox/accessibilityService.ts | 14 ++++---------- .../electron-browser/workbenchTestServices.ts | 1 + 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/vs/platform/native/common/native.ts b/src/vs/platform/native/common/native.ts index f9e86140edc62..e1acb200a6e23 100644 --- a/src/vs/platform/native/common/native.ts +++ b/src/vs/platform/native/common/native.ts @@ -135,4 +135,7 @@ export interface ICommonNativeHostService { // Connectivity resolveProxy(url: string): Promise; + + // Registry (windows only) + windowsGetStringRegKey(hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise; } diff --git a/src/vs/platform/native/electron-main/nativeHostMainService.ts b/src/vs/platform/native/electron-main/nativeHostMainService.ts index fbe0e31ada4fd..924f823e7f8f2 100644 --- a/src/vs/platform/native/electron-main/nativeHostMainService.ts +++ b/src/vs/platform/native/electron-main/nativeHostMainService.ts @@ -527,6 +527,21 @@ export class NativeHostMainService implements INativeHostMainService { //#endregion + //#region Registry (windows) + + async windowsGetStringRegKey(windowId: number | undefined, hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise { + if (!isWindows) { + return undefined; + } + + const Registry = await import('vscode-windows-registry'); + try { + return Registry.GetStringRegKey(hive, path, name); + } catch { + return undefined; + } + } + private windowById(windowId: number | undefined): ICodeWindow | undefined { if (typeof windowId !== 'number') { return undefined; diff --git a/src/vs/workbench/contrib/tags/electron-browser/workspaceTags.ts b/src/vs/workbench/contrib/tags/electron-browser/workspaceTags.ts index 43cc4d58f3adf..1d722fdf6ecfd 100644 --- a/src/vs/workbench/contrib/tags/electron-browser/workspaceTags.ts +++ b/src/vs/workbench/contrib/tags/electron-browser/workspaceTags.ts @@ -17,6 +17,7 @@ import { IRequestService } from 'vs/platform/request/common/request'; import { isWindows } from 'vs/base/common/platform'; import { getRemotes, AllowedSecondLevelDomains, getDomainsOfRemotes } from 'vs/platform/extensionManagement/common/configRemotes'; import { IDiagnosticsService } from 'vs/platform/diagnostics/node/diagnosticsService'; +import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; export function getHashedRemotesFromConfig(text: string, stripEndingDotGit: boolean = false): string[] { return getRemotes(text, stripEndingDotGit).map(r => { @@ -33,7 +34,8 @@ export class WorkspaceTags implements IWorkbenchContribution { @IRequestService private readonly requestService: IRequestService, @ITextFileService private readonly textFileService: ITextFileService, @IWorkspaceTagsService private readonly workspaceTagsService: IWorkspaceTagsService, - @IDiagnosticsService private readonly diagnosticsService: IDiagnosticsService + @IDiagnosticsService private readonly diagnosticsService: IDiagnosticsService, + @INativeHostService private readonly nativeHostService: INativeHostService ) { if (this.telemetryService.isOptedIn) { this.report(); @@ -61,13 +63,7 @@ export class WorkspaceTags implements IWorkbenchContribution { return; } - const Registry = await import('vscode-windows-registry'); - - let value; - try { - value = Registry.GetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', 'EditionID'); - } catch { } - + let value = await this.nativeHostService.windowsGetStringRegKey('HKEY_LOCAL_MACHINE', 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion', 'EditionID'); if (value === undefined) { value = 'Unknown'; } diff --git a/src/vs/workbench/services/accessibility/electron-sandbox/accessibilityService.ts b/src/vs/workbench/services/accessibility/electron-sandbox/accessibilityService.ts index 3bdc5475c05b6..2532a63106182 100644 --- a/src/vs/workbench/services/accessibility/electron-sandbox/accessibilityService.ts +++ b/src/vs/workbench/services/accessibility/electron-sandbox/accessibilityService.ts @@ -15,6 +15,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing'; import { IWorkbenchContribution, IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions'; import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle'; +import { INativeHostService } from 'vs/platform/native/electron-sandbox/native'; interface AccessibilityMetrics { enabled: boolean; @@ -33,7 +34,8 @@ export class NativeAccessibilityService extends AccessibilityService implements @INativeWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService, @IContextKeyService contextKeyService: IContextKeyService, @IConfigurationService configurationService: IConfigurationService, - @ITelemetryService private readonly _telemetryService: ITelemetryService + @ITelemetryService private readonly _telemetryService: ITelemetryService, + @INativeHostService private readonly nativeHostService: INativeHostService ) { super(contextKeyService, configurationService); this.setAccessibilitySupport(environmentService.configuration.accessibilitySupport ? AccessibilitySupport.Enabled : AccessibilitySupport.Disabled); @@ -44,15 +46,7 @@ export class NativeAccessibilityService extends AccessibilityService implements return false; } - const Registry = await import('vscode-windows-registry'); - - let value: string | undefined = undefined; - try { - value = Registry.GetStringRegKey('HKEY_CURRENT_USER', 'Control Panel\\Accessibility\\Keyboard Preference', 'On'); - } catch { - return false; - } - + const value = await this.nativeHostService.windowsGetStringRegKey('HKEY_CURRENT_USER', 'Control Panel\\Accessibility\\Keyboard Preference', 'On'); return value === '1'; } diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index 27879201c6578..397a07aa50d96 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -230,6 +230,7 @@ export class TestNativeHostService implements INativeHostService { async readClipboardBuffer(format: string): Promise { return Uint8Array.from([]); } async hasClipboard(format: string, type?: 'selection' | 'clipboard' | undefined): Promise { return false; } async sendInputEvent(event: MouseInputEvent): Promise { } + async windowsGetStringRegKey(hive: 'HKEY_CURRENT_USER' | 'HKEY_LOCAL_MACHINE' | 'HKEY_CLASSES_ROOT' | 'HKEY_USERS' | 'HKEY_CURRENT_CONFIG', path: string, name: string): Promise { return undefined; } } export function workbenchInstantiationService(): ITestInstantiationService {