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/bindings/js/support.h" 6 7 #include "base/bind.h" 8 #include "gin/arguments.h" 9 #include "gin/converter.h" 10 #include "gin/function_template.h" 11 #include "gin/object_template_builder.h" 12 #include "gin/per_isolate_data.h" 13 #include "gin/public/wrapper_info.h" 14 #include "gin/wrappable.h" 15 #include "mojo/bindings/js/handle.h" 16 #include "mojo/bindings/js/waiting_callback.h" 17 #include "mojo/public/cpp/system/core.h" 18 19 namespace mojo { 20 namespace js { 21 22 namespace { 23 24 WaitingCallback* AsyncWait(const gin::Arguments& args, mojo::Handle handle, 25 MojoHandleSignals signals, 26 v8::Handle<v8::Function> callback) { 27 return WaitingCallback::Create(args.isolate(), callback, handle, signals) 28 .get(); 29 } 30 31 void CancelWait(WaitingCallback* waiting_callback) { 32 waiting_callback->Cancel(); 33 } 34 35 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; 36 37 } // namespace 38 39 const char Support::kModuleName[] = "mojo/public/js/bindings/support"; 40 41 v8::Local<v8::Value> Support::GetModule(v8::Isolate* isolate) { 42 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); 43 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( 44 &g_wrapper_info); 45 46 if (templ.IsEmpty()) { 47 templ = gin::ObjectTemplateBuilder(isolate) 48 .SetMethod("asyncWait", AsyncWait) 49 .SetMethod("cancelWait", CancelWait) 50 .Build(); 51 52 data->SetObjectTemplate(&g_wrapper_info, templ); 53 } 54 55 return templ->NewInstance(); 56 } 57 58 } // namespace js 59 } // namespace mojo 60