diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index 44107c197012..401fedb906c0 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -20,6 +20,7 @@ #include "base/process/process_metrics_iocounters.h" #include "base/sys_info.h" #include "base/threading/thread_restrictions.h" +#include "brightray/common/application_info.h" #include "native_mate/dictionary.h" namespace atom { @@ -74,6 +75,11 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local process) { dict.Set("mas", true); #endif +#if defined(OS_WIN) + if (brightray::IsRunningInDesktopBridge()) + dict.Set("windowsStore", true); +#endif + mate::Dictionary versions; if (dict.Get("versions", &versions)) { // TODO(kevinsawicki): Make read-only in 2.0 to match node diff --git a/atom/renderer/atom_sandboxed_renderer_client.cc b/atom/renderer/atom_sandboxed_renderer_client.cc index 8bbfe4abb400..4e81750a14c4 100644 --- a/atom/renderer/atom_sandboxed_renderer_client.cc +++ b/atom/renderer/atom_sandboxed_renderer_client.cc @@ -17,6 +17,7 @@ #include "base/files/file_path.h" #include "base/path_service.h" #include "base/process/process_handle.h" +#include "brightray/common/application_info.h" #include "chrome/renderer/printing/print_web_view_helper.h" #include "content/public/renderer/render_frame.h" #include "native_mate/dictionary.h" @@ -80,10 +81,6 @@ v8::Local GetBinding(v8::Isolate* isolate, return exports; } -base::CommandLine::StringVector GetArgv() { - return base::CommandLine::ForCurrentProcess()->argv(); -} - base::FilePath::StringType GetExecPath() { base::FilePath path; PathService::Get(base::FILE_EXE, &path); @@ -146,17 +143,34 @@ void AtomSandboxedRendererClient::InitializeBindings( mate::Dictionary b(isolate, binding); b.SetMethod("get", GetBinding); b.SetMethod("createPreloadScript", CreatePreloadScript); - b.SetMethod("crash", AtomBindings::Crash); - b.SetMethod("hang", AtomBindings::Hang); - b.SetMethod("getArgv", GetArgv); - b.SetMethod("getExecPath", GetExecPath); - b.SetMethod("getPid", &base::GetCurrentProcId); - b.SetMethod("getResourcesPath", &NodeBindings::GetHelperResourcesPath); - b.SetMethod("getHeapStatistics", &AtomBindings::GetHeapStatistics); - b.SetMethod("getSystemMemoryInfo", &AtomBindings::GetSystemMemoryInfo); - b.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage, - base::Unretained(metrics_.get()))); - b.SetMethod("getIOCounters", &AtomBindings::GetIOCounters); + + mate::Dictionary process = mate::Dictionary::CreateEmpty(isolate); + b.Set("process", process); + + process.SetMethod("crash", AtomBindings::Crash); + process.SetMethod("hang", AtomBindings::Hang); + process.SetMethod("getHeapStatistics", &AtomBindings::GetHeapStatistics); + process.SetMethod("getSystemMemoryInfo", &AtomBindings::GetSystemMemoryInfo); + process.SetMethod( + "getCPUUsage", + base::Bind(&AtomBindings::GetCPUUsage, base::Unretained(metrics_.get()))); + process.SetMethod("getIOCounters", &AtomBindings::GetIOCounters); + + process.Set("argv", base::CommandLine::ForCurrentProcess()->argv()); + process.Set("execPath", GetExecPath()); + process.Set("pid", base::GetCurrentProcId()); + process.Set("resourcesPath", NodeBindings::GetHelperResourcesPath()); + process.Set("sandboxed", true); + process.Set("type", "renderer"); + +#if defined(MAS_BUILD) + process.Set("mas", true); +#endif + +#if defined(OS_WIN) + if (brightray::IsRunningInDesktopBridge()) + process.Set("windowsStore", true); +#endif // Pass in CLI flags needed to setup the renderer base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); diff --git a/docs/api/process.md b/docs/api/process.md index 1f2a9fdc56d9..12c06b69b3d7 100644 --- a/docs/api/process.md +++ b/docs/api/process.md @@ -28,6 +28,8 @@ In sandboxed renderers the `process` object contains only a subset of the APIs: - `type` - `version` - `versions` +- `mas` +- `windowsStore` ## Events diff --git a/lib/common/init.js b/lib/common/init.js index ccc39ced5dea..a69d9627e0ea 100644 --- a/lib/common/init.js +++ b/lib/common/init.js @@ -50,13 +50,4 @@ if (process.platform === 'win32') { process.__defineGetter__('stdin', function () { return stdin }) - - // If we're running as a Windows Store app, __dirname will be set - // to C:/Program Files/WindowsApps. - // - // Nobody else get's to install there, changing the path is forbidden - // We can therefore say that we're running as appx - if (__dirname.includes('\\WindowsApps\\')) { - process.windowsStore = true - } } diff --git a/lib/sandboxed_renderer/init.js b/lib/sandboxed_renderer/init.js index 33284381d1a1..c8db59362610 100644 --- a/lib/sandboxed_renderer/init.js +++ b/lib/sandboxed_renderer/init.js @@ -3,6 +3,7 @@ /* eslint no-eval: "off" */ /* global binding, Buffer */ const events = require('events') +const { EventEmitter } = events process.atomBinding = require('@electron/internal/common/atom-binding-setup')(binding.get, 'renderer') @@ -15,15 +16,15 @@ const v8Util = process.atomBinding('v8_util') v8Util.setHiddenValue(global, 'Buffer', Buffer) // The `lib/renderer/api/ipc-renderer.js` module looks for the ipc object in the // "ipc" hidden value -v8Util.setHiddenValue(global, 'ipc', new events.EventEmitter()) +v8Util.setHiddenValue(global, 'ipc', new EventEmitter()) // The process object created by browserify is not an event emitter, fix it so // the API is more compatible with non-sandboxed renderers. -for (let prop of Object.keys(events.EventEmitter.prototype)) { +for (let prop of Object.keys(EventEmitter.prototype)) { if (process.hasOwnProperty(prop)) { delete process[prop] } } -Object.setPrototypeOf(process, events.EventEmitter.prototype) +Object.setPrototypeOf(process, EventEmitter.prototype) const remoteModules = new Set([ 'child_process', @@ -47,24 +48,12 @@ require('@electron/internal/renderer/web-frame-init')() // Pass different process object to the preload script(which should not have // access to things like `process.atomBinding`). -const preloadProcess = new events.EventEmitter() -preloadProcess.crash = () => binding.crash() -preloadProcess.hang = () => binding.hang() -preloadProcess.getHeapStatistics = () => binding.getHeapStatistics() -preloadProcess.getSystemMemoryInfo = () => binding.getSystemMemoryInfo() -preloadProcess.getCPUUsage = () => binding.getCPUUsage() -preloadProcess.getIOCounters = () => binding.getIOCounters() - -Object.assign(processProps, { - argv: binding.getArgv(), - execPath: binding.getExecPath(), - pid: binding.getPid(), - resourcesPath: binding.getResourcesPath(), - sandboxed: true, - type: 'renderer' -}) +const preloadProcess = new EventEmitter() +Object.assign(preloadProcess, binding.process) Object.assign(preloadProcess, processProps) + +Object.assign(process, binding.process) Object.assign(process, processProps) process.on('exit', () => preloadProcess.emit('exit'))