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/bindings/js/core.h" | 5 #include "mojo/bindings/js/core.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
10 #include "gin/array_buffer.h" | 10 #include "gin/array_buffer.h" |
11 #include "gin/converter.h" | 11 #include "gin/converter.h" |
12 #include "gin/dictionary.h" | 12 #include "gin/dictionary.h" |
13 #include "gin/function_template.h" | 13 #include "gin/function_template.h" |
14 #include "gin/handle.h" | 14 #include "gin/handle.h" |
15 #include "gin/object_template_builder.h" | 15 #include "gin/object_template_builder.h" |
16 #include "gin/per_isolate_data.h" | 16 #include "gin/per_isolate_data.h" |
17 #include "gin/public/wrapper_info.h" | 17 #include "gin/public/wrapper_info.h" |
18 #include "gin/wrappable.h" | 18 #include "gin/wrappable.h" |
19 #include "mojo/bindings/js/drain_data.h" | 19 #include "mojo/bindings/js/drain_data.h" |
20 #include "mojo/bindings/js/handle.h" | 20 #include "mojo/bindings/js/handle.h" |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 namespace js { | 23 namespace js { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 MojoResult CloseHandle(gin::Handle<gin::HandleWrapper> handle) { | 27 MojoResult CloseHandle(gin::Handle<HandleWrapper> handle) { |
28 if (!handle->get().is_valid()) | 28 if (!handle->get().is_valid()) |
29 return MOJO_RESULT_INVALID_ARGUMENT; | 29 return MOJO_RESULT_INVALID_ARGUMENT; |
30 handle->Close(); | 30 handle->Close(); |
31 return MOJO_RESULT_OK; | 31 return MOJO_RESULT_OK; |
32 } | 32 } |
33 | 33 |
34 MojoResult WaitHandle(mojo::Handle handle, | 34 MojoResult WaitHandle(mojo::Handle handle, |
35 MojoHandleSignals signals, | 35 MojoHandleSignals signals, |
36 MojoDeadline deadline) { | 36 MojoDeadline deadline) { |
37 return MojoWait(handle.value(), signals, deadline); | 37 return MojoWait(handle.value(), signals, deadline); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 dictionary.Set("result", result); | 78 dictionary.Set("result", result); |
79 dictionary.Set("handle0", mojo::Handle(handle0)); | 79 dictionary.Set("handle0", mojo::Handle(handle0)); |
80 dictionary.Set("handle1", mojo::Handle(handle1)); | 80 dictionary.Set("handle1", mojo::Handle(handle1)); |
81 return dictionary; | 81 return dictionary; |
82 } | 82 } |
83 | 83 |
84 MojoResult WriteMessage( | 84 MojoResult WriteMessage( |
85 mojo::Handle handle, | 85 mojo::Handle handle, |
86 const gin::ArrayBufferView& buffer, | 86 const gin::ArrayBufferView& buffer, |
87 const std::vector<gin::Handle<gin::HandleWrapper> >& handles, | 87 const std::vector<gin::Handle<HandleWrapper> >& handles, |
88 MojoWriteMessageFlags flags) { | 88 MojoWriteMessageFlags flags) { |
89 std::vector<MojoHandle> raw_handles(handles.size()); | 89 std::vector<MojoHandle> raw_handles(handles.size()); |
90 for (size_t i = 0; i < handles.size(); ++i) | 90 for (size_t i = 0; i < handles.size(); ++i) |
91 raw_handles[i] = handles[i]->get().value(); | 91 raw_handles[i] = handles[i]->get().value(); |
92 MojoResult rv = MojoWriteMessage(handle.value(), | 92 MojoResult rv = MojoWriteMessage(handle.value(), |
93 buffer.bytes(), | 93 buffer.bytes(), |
94 static_cast<uint32_t>(buffer.num_bytes()), | 94 static_cast<uint32_t>(buffer.num_bytes()), |
95 raw_handles.empty() ? NULL : &raw_handles[0], | 95 raw_handles.empty() ? NULL : &raw_handles[0], |
96 static_cast<uint32_t>(raw_handles.size()), | 96 static_cast<uint32_t>(raw_handles.size()), |
97 flags); | 97 flags); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 224 |
225 // Asynchronously read all of the data available for the specified data pipe | 225 // Asynchronously read all of the data available for the specified data pipe |
226 // consumer handle until the remote handle is closed or an error occurs. A | 226 // consumer handle until the remote handle is closed or an error occurs. A |
227 // Promise is returned whose settled value is an object like this: | 227 // Promise is returned whose settled value is an object like this: |
228 // {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed, | 228 // {result: core.RESULT_OK, buffer: dataArrayBuffer}. If the read failed, |
229 // then the Promise is rejected, the result will be the actual error code, | 229 // then the Promise is rejected, the result will be the actual error code, |
230 // and the buffer will contain whatever was read before the error occurred. | 230 // and the buffer will contain whatever was read before the error occurred. |
231 // The drainData data pipe handle argument is closed automatically. | 231 // The drainData data pipe handle argument is closed automatically. |
232 | 232 |
233 v8::Handle<v8::Value> DoDrainData(gin::Arguments* args, | 233 v8::Handle<v8::Value> DoDrainData(gin::Arguments* args, |
234 gin::Handle<gin::HandleWrapper> handle) { | 234 gin::Handle<HandleWrapper> handle) { |
235 return (new DrainData(args->isolate(), handle->release()))->GetPromise(); | 235 return (new DrainData(args->isolate(), handle->release()))->GetPromise(); |
236 } | 236 } |
237 | 237 |
238 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | 238 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |
239 | 239 |
240 } // namespace | 240 } // namespace |
241 | 241 |
242 const char Core::kModuleName[] = "mojo/public/js/bindings/core"; | 242 const char Core::kModuleName[] = "mojo/public/js/bindings/core"; |
243 | 243 |
244 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { | 244 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 .Build(); | 312 .Build(); |
313 | 313 |
314 data->SetObjectTemplate(&g_wrapper_info, templ); | 314 data->SetObjectTemplate(&g_wrapper_info, templ); |
315 } | 315 } |
316 | 316 |
317 return templ->NewInstance(); | 317 return templ->NewInstance(); |
318 } | 318 } |
319 | 319 |
320 } // namespace js | 320 } // namespace js |
321 } // namespace mojo | 321 } // namespace mojo |
OLD | NEW |