Chromium Code Reviews| Index: mojo/apps/js/mojo_module.cc |
| diff --git a/mojo/apps/js/mojo_module.cc b/mojo/apps/js/mojo_module.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..98ace6bf3a5ce7959952291002b2e7df880492a7 |
| --- /dev/null |
| +++ b/mojo/apps/js/mojo_module.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "mojo/apps/js/mojo_module.h" |
| + |
| +#include "gin/arguments.h" |
| +#include "gin/converter.h" |
| +#include "gin/object_template_builder.h" |
| +#include "gin/per_isolate_data.h" |
| +#include "mojo/apps/js/js_app.h" |
| +#include "mojo/apps/js/mojo_module.h" |
| +#include "mojo/bindings/js/handle.h" |
| +#include "mojo/common/data_pipe_utils.h" |
| + |
| +namespace mojo { |
| +namespace apps { |
| + |
| +namespace { |
| + |
| +//TODO(hansmuller): define a new gin nullable string type for the return value. |
| +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.
|
| + //TODO(hansmuller); if !pipe.is_valid() return null |
| + DataPipeConsumerHandle handle(source.value()); |
| + ScopedDataPipeConsumerHandle scoped_handle(handle); |
| + std::string result; |
| + return mojo::common::BlockingCopyToString(scoped_handle.Pass(), &result) |
| + ? 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.
|
| +} |
| + |
| +Handle ConnectToService(const gin::Arguments& args, |
| + std::string application_url, |
| + std::string interface_name) { |
| + JSApp* app = JSApp::From(args.isolate()); |
| + CHECK(app); |
| + return app->ConnectToService(application_url, interface_name).release(); |
| +} |
| + |
| +void Quit(const gin::Arguments& args) { |
| + JSApp* app = JSApp::From(args.isolate()); |
| + CHECK(app); |
| + app->Quit(); |
| +} |
| + |
| +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.
|
| + |
| +} // namespace |
| + |
| +const char Mojo::kModuleName[] = "mojo"; |
| + |
| +v8::Local<v8::Value> Mojo::GetModule(v8::Isolate* isolate) { |
| + gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| + v8::Local<v8::ObjectTemplate> templ = |
| + data->GetObjectTemplate(&g_wrapper_info); |
| + |
| + if (templ.IsEmpty()) { |
| + templ = gin::ObjectTemplateBuilder(isolate) |
| + .SetMethod("connectToService", ConnectToService) |
| + .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()
|
| + .SetMethod("quit", Quit) |
|
Aaron Boodman
2014/09/10 02:22:10
It seems like https://code.google.com/p/chromium/c
|
| + .Build(); |
| + data->SetObjectTemplate(&g_wrapper_info, templ); |
| + } |
| + |
| + return templ->NewInstance(); |
| +} |
| + |
| +} // namespace apps |
| +} // namespace mojo |