feat: expose missing process APIs in sandboxed renderers (#13505)

This commit is contained in:
Milan Burda 2018-08-21 20:05:45 +02:00 committed by Samuel Attard
parent f82f89b2a3
commit fc85d02786
11 changed files with 95 additions and 35 deletions

View file

@ -59,7 +59,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process) {
dict.SetMethod("getCreationTime", &GetCreationTime);
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
dict.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage,
base::Unretained(this)));
base::Unretained(metrics_.get())));
dict.SetMethod("getIOCounters", &GetIOCounters);
#if defined(OS_POSIX)
dict.SetMethod("setFdLimit", &base::SetFdLimit);
@ -220,17 +220,19 @@ v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
return dict.GetHandle();
}
v8::Local<v8::Value> AtomBindings::GetCPUUsage(v8::Isolate* isolate) {
// static
v8::Local<v8::Value> AtomBindings::GetCPUUsage(base::ProcessMetrics* metrics,
v8::Isolate* isolate) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.SetHidden("simple", true);
int processor_count = base::SysInfo::NumberOfProcessors();
dict.Set("percentCPUUsage",
metrics_->GetPlatformIndependentCPUUsage() / processor_count);
metrics->GetPlatformIndependentCPUUsage() / processor_count);
// NB: This will throw NOTIMPLEMENTED() on Windows
// For backwards compatibility, we'll return 0
#if !defined(OS_WIN)
dict.Set("idleWakeupsPerSecond", metrics_->GetIdleWakeupsPerSecond());
dict.Set("idleWakeupsPerSecond", metrics->GetIdleWakeupsPerSecond());
#else
dict.Set("idleWakeupsPerSecond", 0);
#endif

View file

@ -40,7 +40,8 @@ class AtomBindings {
static v8::Local<v8::Value> GetCreationTime(v8::Isolate* isolate);
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
mate::Arguments* args);
v8::Local<v8::Value> GetCPUUsage(v8::Isolate* isolate);
static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
v8::Isolate* isolate);
static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
private:

View file

@ -15,7 +15,6 @@
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
@ -195,6 +194,10 @@ bool NodeBindings::IsInitialized() {
return g_is_initialized;
}
base::FilePath::StringType NodeBindings::GetHelperResourcesPath() {
return GetResourcesPath(false).value();
}
void NodeBindings::Initialize() {
// Open node's error reporting system for browser process.
node::g_standalone_mode = browser_env_ == BROWSER;

View file

@ -5,6 +5,7 @@
#ifndef ATOM_COMMON_NODE_BINDINGS_H_
#define ATOM_COMMON_NODE_BINDINGS_H_
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
@ -33,6 +34,7 @@ class NodeBindings {
static NodeBindings* Create(BrowserEnvironment browser_env);
static void RegisterBuiltinModules();
static bool IsInitialized();
static base::FilePath::StringType GetHelperResourcesPath();
virtual ~NodeBindings();