Initialize defaultSession after app is ready

This commit is contained in:
Cheng Zhao 2015-06-24 16:14:49 +08:00
parent 0ebd4d04ad
commit c2f14e6053

View file

@ -133,6 +133,14 @@ void App::OnWillFinishLaunching() {
} }
void App::OnFinishLaunching() { void App::OnFinishLaunching() {
// Create the defaultSession.
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto browser_context = static_cast<AtomBrowserContext*>(
AtomBrowserMainParts::Get()->browser_context());
auto handle = Session::CreateFrom(isolate(), browser_context);
default_session_.Reset(isolate(), handle.ToV8());
Emit("ready"); Emit("ready");
} }
@ -173,13 +181,10 @@ void App::SetAppUserModelId(const std::string& app_id) {
} }
v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) { v8::Local<v8::Value> App::DefaultSession(v8::Isolate* isolate) {
if (default_session_.IsEmpty()) { if (default_session_.IsEmpty())
auto browser_context = static_cast<AtomBrowserContext*>( return v8::Null(isolate);
AtomBrowserMainParts::Get()->browser_context()); else
auto handle = Session::CreateFrom(isolate, browser_context); return v8::Local<v8::Value>::New(isolate, default_session_);
default_session_.Reset(isolate, handle.ToV8());
}
return v8::Local<v8::Value>::New(isolate, default_session_);
} }
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(