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_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/apps/js/mojo_module.h" | |
13 #include "mojo/bindings/js/handle.h" | |
14 #include "mojo/common/data_pipe_utils.h" | |
15 | |
16 namespace mojo { | |
17 namespace apps { | |
18 | |
19 namespace { | |
20 | |
21 //TODO(hansmuller): define a new gin nullable string type for the return value. | |
22 std::string CopyToString(const gin::Arguments& args, Handle source) { | |
Aaron Boodman
2014/09/10 02:22:10
You don't seem to be using |args|. Remove?
hansmuller
2014/09/11 00:26:18
Done.
| |
23 //TODO(hansmuller); if !pipe.is_valid() return null | |
24 DataPipeConsumerHandle handle(source.value()); | |
25 ScopedDataPipeConsumerHandle scoped_handle(handle); | |
26 std::string result; | |
27 return mojo::common::BlockingCopyToString(scoped_handle.Pass(), &result) | |
28 ? result : "Fail"; | |
Aaron Boodman
2014/09/10 02:22:10
You could also throw a JS exception. Throwing an e
hansmuller
2014/09/11 16:44:43
Done.
| |
29 } | |
30 | |
31 Handle ConnectToService(const gin::Arguments& args, | |
32 std::string application_url, | |
33 std::string interface_name) { | |
34 JSApp* app = JSApp::From(args.isolate()); | |
35 CHECK(app); | |
36 return app->ConnectToService(application_url, interface_name).release(); | |
37 } | |
38 | |
39 void Quit(const gin::Arguments& args) { | |
40 JSApp* app = JSApp::From(args.isolate()); | |
41 CHECK(app); | |
42 app->Quit(); | |
43 } | |
44 | |
45 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | |
Aaron Boodman
2014/09/10 02:22:10
Should this be gin::kEmbedderMojo?
Aaron Boodman
2014/09/10 17:39:17
Whoops I meant to delete this comment... it of cou
hansmuller
2014/09/11 00:26:17
Correct.
| |
46 | |
47 } // namespace | |
48 | |
49 const char Mojo::kModuleName[] = "mojo"; | |
50 | |
51 v8::Local<v8::Value> Mojo::GetModule(v8::Isolate* isolate) { | |
52 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | |
53 v8::Local<v8::ObjectTemplate> templ = | |
54 data->GetObjectTemplate(&g_wrapper_info); | |
55 | |
56 if (templ.IsEmpty()) { | |
57 templ = gin::ObjectTemplateBuilder(isolate) | |
58 .SetMethod("connectToService", ConnectToService) | |
59 .SetMethod("copyToString", CopyToString) | |
Aaron Boodman
2014/09/10 02:22:10
Isn't readData() sufficient?
https://code.google.
hansmuller
2014/09/11 00:26:18
The core readData() function just hang in my case.
Aaron Boodman
2014/09/11 05:24:53
I'm sorry... I don't follow. It seems like we shou
hansmuller
2014/09/11 16:44:43
I was mistaken about the hang. The core readData()
| |
60 .SetMethod("quit", Quit) | |
Aaron Boodman
2014/09/10 02:22:10
It seems like https://code.google.com/p/chromium/c
| |
61 .Build(); | |
62 data->SetObjectTemplate(&g_wrapper_info, templ); | |
63 } | |
64 | |
65 return templ->NewInstance(); | |
66 } | |
67 | |
68 } // namespace apps | |
69 } // namespace mojo | |
OLD | NEW |