| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/bindings/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/apps/js/bindings/handle.h" | |
| 16 #include "mojo/apps/js/bindings/waiting_callback.h" | |
| 17 #include "mojo/public/environment/default_async_waiter.h" | |
| 18 #include "mojo/public/system/core_cpp.h" | |
| 19 | |
| 20 namespace mojo { | |
| 21 namespace js { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 WaitingCallback* AsyncWait(const gin::Arguments& args, mojo::Handle handle, | |
| 26 MojoWaitFlags flags, | |
| 27 v8::Handle<v8::Function> callback) { | |
| 28 gin::Handle<WaitingCallback> waiting_callback = | |
| 29 WaitingCallback::Create(args.isolate(), callback); | |
| 30 | |
| 31 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter(); | |
| 32 MojoAsyncWaitID wait_id = waiter->AsyncWait( | |
| 33 waiter, | |
| 34 handle.value(), | |
| 35 flags, | |
| 36 MOJO_DEADLINE_INDEFINITE, | |
| 37 &WaitingCallback::CallOnHandleReady, | |
| 38 waiting_callback.get()); | |
| 39 | |
| 40 waiting_callback->set_wait_id(wait_id); | |
| 41 | |
| 42 return waiting_callback.get(); | |
| 43 } | |
| 44 | |
| 45 void CancelWait(WaitingCallback* waiting_callback) { | |
| 46 if (!waiting_callback->wait_id()) | |
| 47 return; | |
| 48 | |
| 49 MojoAsyncWaiter* waiter = GetDefaultAsyncWaiter(); | |
| 50 waiter->CancelWait(waiter, waiting_callback->wait_id()); | |
| 51 waiting_callback->set_wait_id(0); | |
| 52 } | |
| 53 | |
| 54 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 const char Support::kModuleName[] = "mojo/apps/js/bindings/support"; | |
| 59 | |
| 60 v8::Local<v8::Value> Support::GetModule(v8::Isolate* isolate) { | |
| 61 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | |
| 62 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | |
| 63 &g_wrapper_info); | |
| 64 | |
| 65 if (templ.IsEmpty()) { | |
| 66 templ = gin::ObjectTemplateBuilder(isolate) | |
| 67 .SetMethod("asyncWait", AsyncWait) | |
| 68 .SetMethod("cancelWait", CancelWait) | |
| 69 .Build(); | |
| 70 | |
| 71 data->SetObjectTemplate(&g_wrapper_info, templ); | |
| 72 } | |
| 73 | |
| 74 return templ->NewInstance(); | |
| 75 } | |
| 76 | |
| 77 } // namespace js | |
| 78 } // namespace mojo | |
| OLD | NEW |