OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/apps/js/mojo_bridge_module.h" | |
6 | |
7 #include "gin/arguments.h" | |
8 #include "gin/converter.h" | |
9 #include "gin/object_template_builder.h" | |
10 #include "gin/per_isolate_data.h" | |
11 #include "mojo/apps/js/js_app.h" | |
12 #include "mojo/bindings/js/handle.h" | |
13 | |
14 namespace mojo { | |
15 namespace apps { | |
16 | |
17 namespace { | |
18 | |
19 gin::WrapperInfo g_wrapper_info = {gin::kEmbedderNativeGin}; | |
20 | |
21 } // namespace | |
22 | |
23 const char MojoInternals::kModuleName[] = "mojo/apps/js/bridge"; | |
24 | |
25 v8::Local<v8::Value> MojoInternals::GetModule(JSApp* js_app, | |
26 v8::Isolate* isolate) { | |
27 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | |
28 v8::Local<v8::ObjectTemplate> templ = | |
29 data->GetObjectTemplate(&g_wrapper_info); | |
30 | |
31 if (templ.IsEmpty()) { | |
32 templ = gin::ObjectTemplateBuilder(isolate) | |
33 .SetMethod("connectToService", | |
34 base::Bind(&JSApp::ConnectToService, | |
35 base::Unretained(js_app))) | |
36 .SetMethod("quit", | |
37 base::Bind(&JSApp::Quit, base::Unretained(js_app))) | |
38 .Build(); | |
39 data->SetObjectTemplate(&g_wrapper_info, templ); | |
40 } | |
41 | |
42 return templ->NewInstance(); | |
43 } | |
44 | |
45 } // namespace apps | |
46 } // namespace mojo | |
OLD | NEW |