Make the node environment constrained in browser_main_parts.
This commit is contained in:
parent
1d359cb8aa
commit
6a891be0e4
6 changed files with 24 additions and 21 deletions
|
@ -14,7 +14,6 @@
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "content/public/common/content_switches.h"
|
#include "content/public/common/content_switches.h"
|
||||||
#include "ui/base/resource/resource_bundle.h"
|
#include "ui/base/resource/resource_bundle.h"
|
||||||
#include "vendor/brightray/common/content_client.h"
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -49,13 +48,12 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
||||||
base::debug::EnableInProcessStackDumping();
|
base::debug::EnableInProcessStackDumping();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
content_client_.reset(new brightray::ContentClient);
|
|
||||||
SetContentClient(content_client_.get());
|
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
OverrideChildProcessPath();
|
OverrideChildProcessPath();
|
||||||
OverrideFrameworkBundlePath();
|
OverrideFrameworkBundlePath();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SetContentClient(&content_client_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ATOM_APP_ATOM_MAIN_DELEGATE_H_
|
#define ATOM_APP_ATOM_MAIN_DELEGATE_H_
|
||||||
|
|
||||||
#include "brightray/common/main_delegate.h"
|
#include "brightray/common/main_delegate.h"
|
||||||
|
#include "brightray/common/content_client.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ class AtomMainDelegate : public brightray::MainDelegate {
|
||||||
virtual content::ContentRendererClient*
|
virtual content::ContentRendererClient*
|
||||||
CreateContentRendererClient() OVERRIDE;
|
CreateContentRendererClient() OVERRIDE;
|
||||||
|
|
||||||
scoped_ptr<brightray::ContentClient> content_client_;
|
brightray::ContentClient content_client_;
|
||||||
scoped_ptr<content::ContentBrowserClient> browser_client_;
|
scoped_ptr<content::ContentBrowserClient> browser_client_;
|
||||||
scoped_ptr<content::ContentRendererClient> renderer_client_;
|
scoped_ptr<content::ContentRendererClient> renderer_client_;
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,7 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
|
|
||||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||||
const content::MainFunctionParams&) {
|
const content::MainFunctionParams&) {
|
||||||
|
v8::V8::Initialize(); // Init V8 before creating main parts.
|
||||||
return new AtomBrowserMainParts;
|
return new AtomBrowserMainParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,12 @@ AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL;
|
||||||
AtomBrowserMainParts::AtomBrowserMainParts()
|
AtomBrowserMainParts::AtomBrowserMainParts()
|
||||||
: atom_bindings_(new AtomBindings),
|
: atom_bindings_(new AtomBindings),
|
||||||
browser_(new Browser),
|
browser_(new Browser),
|
||||||
node_bindings_(NodeBindings::Create(true)) {
|
node_bindings_(NodeBindings::Create(true)),
|
||||||
|
isolate_(v8::Isolate::GetCurrent()),
|
||||||
|
locker_(isolate_),
|
||||||
|
handle_scope_(isolate_),
|
||||||
|
context_(isolate_, v8::Context::New(isolate_)),
|
||||||
|
context_scope_(v8::Local<v8::Context>::New(isolate_, context_)) {
|
||||||
DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
|
DCHECK(!self_) << "Cannot have two AtomBrowserMainParts";
|
||||||
self_ = this;
|
self_ = this;
|
||||||
}
|
}
|
||||||
|
@ -48,22 +53,12 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
||||||
|
|
||||||
node_bindings_->Initialize();
|
node_bindings_->Initialize();
|
||||||
|
|
||||||
v8::V8::Initialize();
|
|
||||||
|
|
||||||
// Create context.
|
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
|
||||||
v8::Locker locker(isolate);
|
|
||||||
v8::HandleScope handle_scope(isolate);
|
|
||||||
v8::Local<v8::Context> context = v8::Context::New(isolate);
|
|
||||||
|
|
||||||
// Create the global environment.
|
// Create the global environment.
|
||||||
global_env = node_bindings_->CreateEnvironment(context);
|
global_env = node_bindings_->CreateEnvironment(
|
||||||
|
v8::Local<v8::Context>::New(isolate_, context_));
|
||||||
// Wrap whole process in one global context.
|
|
||||||
context->Enter();
|
|
||||||
|
|
||||||
// Add atom-shell extended APIs.
|
// Add atom-shell extended APIs.
|
||||||
atom_bindings_->BindTo(isolate, global_env->process_object());
|
atom_bindings_->BindTo(isolate_, global_env->process_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
void AtomBrowserMainParts::PreMainMessageLoopRun() {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
#define ATOM_BROWSER_ATOM_BROWSER_MAIN_PARTS_H_
|
||||||
|
|
||||||
#include "brightray/browser/browser_main_parts.h"
|
#include "brightray/browser/browser_main_parts.h"
|
||||||
|
#include "v8/include/v8.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -40,6 +41,13 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||||
scoped_ptr<Browser> browser_;
|
scoped_ptr<Browser> browser_;
|
||||||
scoped_ptr<NodeBindings> node_bindings_;
|
scoped_ptr<NodeBindings> node_bindings_;
|
||||||
|
|
||||||
|
// The V8 environment of browser process.
|
||||||
|
v8::Isolate* isolate_;
|
||||||
|
v8::Locker locker_;
|
||||||
|
v8::HandleScope handle_scope_;
|
||||||
|
v8::UniquePersistent<v8::Context> context_;
|
||||||
|
v8::Context::Scope context_scope_;
|
||||||
|
|
||||||
static AtomBrowserMainParts* self_;
|
static AtomBrowserMainParts* self_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
|
DISALLOW_COPY_AND_ASSIGN(AtomBrowserMainParts);
|
||||||
|
|
Loading…
Reference in a new issue