| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/apps/js/bootstrap.h" | 5 #include "mojo/apps/js/threading.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "gin/function_template.h" | 9 #include "gin/function_template.h" |
| 10 #include "gin/per_isolate_data.h" | 10 #include "gin/per_isolate_data.h" |
| 11 #include "mojo/public/bindings/js/handle.h" | 11 #include "mojo/public/bindings/js/handle.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace apps { | 14 namespace apps { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 void Quit() { | 18 void Quit() { |
| 19 base::MessageLoop::current()->QuitNow(); | 19 base::MessageLoop::current()->QuitNow(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 MojoHandle g_initial_handle = MOJO_HANDLE_INVALID; | |
| 23 | |
| 24 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | 22 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |
| 25 | 23 |
| 26 } // namespace | 24 } // namespace |
| 27 | 25 |
| 28 const char Bootstrap::kModuleName[] = "mojo/apps/js/bootstrap"; | 26 const char Threading::kModuleName[] = "mojo/apps/js/threading"; |
| 29 | 27 |
| 30 v8::Local<v8::ObjectTemplate> Bootstrap::GetTemplate(v8::Isolate* isolate) { | 28 v8::Local<v8::ObjectTemplate> Threading::GetTemplate(v8::Isolate* isolate) { |
| 31 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 29 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 32 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 30 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
| 33 &g_wrapper_info); | 31 &g_wrapper_info); |
| 34 | 32 |
| 35 if (templ.IsEmpty()) { | 33 if (templ.IsEmpty()) { |
| 36 templ = v8::ObjectTemplate::New(); | 34 templ = v8::ObjectTemplate::New(); |
| 37 templ->Set(gin::StringToSymbol(isolate, "quit"), | 35 templ->Set(gin::StringToSymbol(isolate, "quit"), |
| 38 gin::CreateFunctionTemplate(isolate, base::Bind(Quit))); | 36 gin::CreateFunctionTemplate(isolate, base::Bind(Quit))); |
| 39 | |
| 40 // Don't forget to call SetInitialHandle before getting the template. | |
| 41 DCHECK(g_initial_handle != MOJO_HANDLE_INVALID); | |
| 42 templ->Set(gin::StringToSymbol(isolate, "initialHandle"), | |
| 43 gin::ConvertToV8(isolate, g_initial_handle)); | |
| 44 | |
| 45 data->SetObjectTemplate(&g_wrapper_info, templ); | 37 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 46 } | 38 } |
| 47 | 39 |
| 48 return templ; | 40 return templ; |
| 49 } | 41 } |
| 50 | 42 |
| 51 void Bootstrap::SetInitialHandle(MojoHandle pipe) { | |
| 52 g_initial_handle = pipe; | |
| 53 } | |
| 54 | |
| 55 } // namespace apps | 43 } // namespace apps |
| 56 } // namespace mojo | 44 } // namespace mojo |
| OLD | NEW |