| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/edk/js/support.h" | 5 #include "mojo/edk/js/support.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "gin/arguments.h" | 8 #include "gin/arguments.h" |
| 9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
| 10 #include "gin/function_template.h" | 10 #include "gin/function_template.h" |
| 11 #include "gin/object_template_builder.h" | 11 #include "gin/object_template_builder.h" |
| 12 #include "gin/per_isolate_data.h" | 12 #include "gin/per_isolate_data.h" |
| 13 #include "gin/public/wrapper_info.h" | 13 #include "gin/public/wrapper_info.h" |
| 14 #include "gin/wrappable.h" | 14 #include "gin/wrappable.h" |
| 15 #include "mojo/edk/js/handle.h" | 15 #include "mojo/edk/js/handle.h" |
| 16 #include "mojo/edk/js/waiting_callback.h" | 16 #include "mojo/edk/js/waiting_callback.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 17 #include "mojo/public/cpp/system/core.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 namespace edk { | 20 namespace edk { |
| 21 namespace js { | 21 namespace js { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 WaitingCallback* AsyncWait(const gin::Arguments& args, | 25 WaitingCallback* AsyncWait(const gin::Arguments& args, |
| 26 gin::Handle<HandleWrapper> handle, | 26 gin::Handle<HandleWrapper> handle, |
| 27 MojoHandleSignals signals, | 27 MojoHandleSignals signals, |
| 28 v8::Handle<v8::Function> callback) { | 28 v8::Handle<v8::Function> callback) { |
| 29 return WaitingCallback::Create(args.isolate(), callback, handle, signals) | 29 return WaitingCallback::Create( |
| 30 .get(); | 30 args.isolate(), callback, handle, signals, true /* one_shot */).get(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void CancelWait(WaitingCallback* waiting_callback) { | 33 void CancelWait(WaitingCallback* waiting_callback) { |
| 34 waiting_callback->Cancel(); | 34 waiting_callback->Cancel(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 WaitingCallback* Watch(const gin::Arguments& args, |
| 38 gin::Handle<HandleWrapper> handle, |
| 39 MojoHandleSignals signals, |
| 40 v8::Handle<v8::Function> callback) { |
| 41 return WaitingCallback::Create( |
| 42 args.isolate(), callback, handle, signals, false /* one_shot */).get(); |
| 43 } |
| 44 |
| 45 void CancelWatch(WaitingCallback* waiting_callback) { |
| 46 waiting_callback->Cancel(); |
| 47 } |
| 48 |
| 37 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | 49 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |
| 38 | 50 |
| 39 } // namespace | 51 } // namespace |
| 40 | 52 |
| 41 const char Support::kModuleName[] = "mojo/public/js/support"; | 53 const char Support::kModuleName[] = "mojo/public/js/support"; |
| 42 | 54 |
| 43 v8::Local<v8::Value> Support::GetModule(v8::Isolate* isolate) { | 55 v8::Local<v8::Value> Support::GetModule(v8::Isolate* isolate) { |
| 44 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 56 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 45 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 57 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
| 46 &g_wrapper_info); | 58 &g_wrapper_info); |
| 47 | 59 |
| 48 if (templ.IsEmpty()) { | 60 if (templ.IsEmpty()) { |
| 49 templ = gin::ObjectTemplateBuilder(isolate) | 61 templ = gin::ObjectTemplateBuilder(isolate) |
| 62 // TODO(rockot): Remove asyncWait and cancelWait. |
| 50 .SetMethod("asyncWait", AsyncWait) | 63 .SetMethod("asyncWait", AsyncWait) |
| 51 .SetMethod("cancelWait", CancelWait) | 64 .SetMethod("cancelWait", CancelWait) |
| 65 .SetMethod("watch", Watch) |
| 66 .SetMethod("cancelWatch", CancelWatch) |
| 52 .Build(); | 67 .Build(); |
| 53 | 68 |
| 54 data->SetObjectTemplate(&g_wrapper_info, templ); | 69 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 55 } | 70 } |
| 56 | 71 |
| 57 return templ->NewInstance(); | 72 return templ->NewInstance(); |
| 58 } | 73 } |
| 59 | 74 |
| 60 } // namespace js | 75 } // namespace js |
| 61 } // namespace edk | 76 } // namespace edk |
| 62 } // namespace mojo | 77 } // namespace mojo |
| OLD | NEW |