Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1162)

Unified Diff: mojo/apps/js/mojo_module.cc

Issue 467263006: JavaScript Content Handler Version 0.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes per review feedback. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..af8dd7023e0670e11f16982ba6b90e7a4b0d8dad
--- /dev/null
+++ b/mojo/apps/js/mojo_module.cc
@@ -0,0 +1,63 @@
+// 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) {
+ // TODO(hansmuller); if !pipe.is_valid() throw an error.
+ DataPipeConsumerHandle handle(source.value());
+ ScopedDataPipeConsumerHandle scoped_handle(handle);
+ std::string result;
+ if (mojo::common::BlockingCopyToString(scoped_handle.Pass(), &result))
+ return result;
+
+ args.isolate()->ThrowException(v8::Exception::Error(
+ gin::StringToV8(args.isolate(), "unable to read data pipe")));
+ return "";
+}
+
+gin::WrapperInfo g_wrapper_info = {gin::kEmbedderNativeGin};
+
+} // namespace
+
+const char Mojo::kModuleName[] = "mojo";
Aaron Boodman 2014/09/11 05:24:53 This is not used.
hansmuller 2014/09/11 16:44:44 It's used by the mojo AddBuiltinModule() call, whi
+
+v8::Local<v8::Value> Mojo::GetModule(JSApp* js_app, v8::Isolate* isolate) {
+ gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
+ v8::Local<v8::ObjectTemplate> templ =
+ data->GetObjectTemplate(&g_wrapper_info);
+
+ // The lifetime of the the js_app is managed by the content_handler_app_.
+ if (templ.IsEmpty()) {
+ templ = gin::ObjectTemplateBuilder(isolate)
+ .SetMethod("connectToService",
+ base::Bind(&JSApp::ConnectToService,
+ base::Unretained(js_app)))
+ .SetMethod("copyToString", CopyToString)
+ .SetMethod("quit",
+ base::Bind(&JSApp::Quit, base::Unretained(js_app)))
+ .Build();
+ data->SetObjectTemplate(&g_wrapper_info, templ);
+ }
+
+ return templ->NewInstance();
+}
+
+} // namespace apps
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698