From c2f14e6053515d51ff925e589b6531981178eace Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 24 Jun 2015 16:14:49 +0800 Subject: [PATCH] Initialize defaultSession after app is ready --- atom/browser/api/atom_api_app.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index ec9e86dd8440..473111dbc7e1 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -133,6 +133,14 @@ void App::OnWillFinishLaunching() { } void App::OnFinishLaunching() { + // Create the defaultSession. + v8::Locker locker(isolate()); + v8::HandleScope handle_scope(isolate()); + auto browser_context = static_cast( + AtomBrowserMainParts::Get()->browser_context()); + auto handle = Session::CreateFrom(isolate(), browser_context); + default_session_.Reset(isolate(), handle.ToV8()); + Emit("ready"); } @@ -173,13 +181,10 @@ void App::SetAppUserModelId(const std::string& app_id) { } v8::Local App::DefaultSession(v8::Isolate* isolate) { - if (default_session_.IsEmpty()) { - auto browser_context = static_cast( - AtomBrowserMainParts::Get()->browser_context()); - auto handle = Session::CreateFrom(isolate, browser_context); - default_session_.Reset(isolate, handle.ToV8()); - } - return v8::Local::New(isolate, default_session_); + if (default_session_.IsEmpty()) + return v8::Null(isolate); + else + return v8::Local::New(isolate, default_session_); } mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(