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/handle.h" | 20 #include "mojo/bindings/js/handle.h" |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
22 namespace js { | 23 namespace js { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 MojoResult CloseHandle(gin::Handle<gin::HandleWrapper> handle) { | 27 MojoResult CloseHandle(gin::Handle<gin::HandleWrapper> handle) { |
27 if (!handle->get().is_valid()) | 28 if (!handle->get().is_valid()) |
28 return MOJO_RESULT_INVALID_ARGUMENT; | 29 return MOJO_RESULT_INVALID_ARGUMENT; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 215 |
215 result = MojoReadData(handle.value(), buffer.bytes(), &num_bytes, flags); | 216 result = MojoReadData(handle.value(), buffer.bytes(), &num_bytes, flags); |
216 CHECK_EQ(num_bytes, buffer.num_bytes()); | 217 CHECK_EQ(num_bytes, buffer.num_bytes()); |
217 | 218 |
218 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); | 219 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); |
219 dictionary.Set("result", result); | 220 dictionary.Set("result", result); |
220 dictionary.Set("buffer", array_buffer); | 221 dictionary.Set("buffer", array_buffer); |
221 return dictionary; | 222 return dictionary; |
222 } | 223 } |
223 | 224 |
| 225 v8::Handle<v8::Value> DoDrainData(gin::Arguments* args, mojo::Handle handle) { |
| 226 return (new DrainData(args->isolate(), handle))->GetPromise(); |
| 227 } |
| 228 |
224 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | 229 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |
225 | 230 |
226 } // namespace | 231 } // namespace |
227 | 232 |
228 const char Core::kModuleName[] = "mojo/public/js/bindings/core"; | 233 const char Core::kModuleName[] = "mojo/public/js/bindings/core"; |
229 | 234 |
230 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { | 235 v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) { |
231 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 236 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
232 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 237 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
233 &g_wrapper_info); | 238 &g_wrapper_info); |
234 | 239 |
235 if (templ.IsEmpty()) { | 240 if (templ.IsEmpty()) { |
236 templ = gin::ObjectTemplateBuilder(isolate) | 241 templ = gin::ObjectTemplateBuilder(isolate) |
237 // TODO(mpcomplete): Should these just be methods on the JS Handle | 242 // TODO(mpcomplete): Should these just be methods on the JS Handle |
238 // object? | 243 // object? |
239 .SetMethod("close", CloseHandle) | 244 .SetMethod("close", CloseHandle) |
240 .SetMethod("wait", WaitHandle) | 245 .SetMethod("wait", WaitHandle) |
241 .SetMethod("waitMany", WaitMany) | 246 .SetMethod("waitMany", WaitMany) |
242 .SetMethod("createMessagePipe", CreateMessagePipe) | 247 .SetMethod("createMessagePipe", CreateMessagePipe) |
243 .SetMethod("writeMessage", WriteMessage) | 248 .SetMethod("writeMessage", WriteMessage) |
244 .SetMethod("readMessage", ReadMessage) | 249 .SetMethod("readMessage", ReadMessage) |
245 .SetMethod("createDataPipe", CreateDataPipe) | 250 .SetMethod("createDataPipe", CreateDataPipe) |
246 .SetMethod("writeData", WriteData) | 251 .SetMethod("writeData", WriteData) |
247 .SetMethod("readData", ReadData) | 252 .SetMethod("readData", ReadData) |
| 253 .SetMethod("drainData", DoDrainData) |
248 | 254 |
249 .SetValue("RESULT_OK", MOJO_RESULT_OK) | 255 .SetValue("RESULT_OK", MOJO_RESULT_OK) |
250 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED) | 256 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED) |
251 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN) | 257 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN) |
252 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT) | 258 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT) |
253 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED) | 259 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED) |
254 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND) | 260 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND) |
255 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS) | 261 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS) |
256 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED) | 262 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED) |
257 .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED) | 263 .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 .Build(); | 303 .Build(); |
298 | 304 |
299 data->SetObjectTemplate(&g_wrapper_info, templ); | 305 data->SetObjectTemplate(&g_wrapper_info, templ); |
300 } | 306 } |
301 | 307 |
302 return templ->NewInstance(); | 308 return templ->NewInstance(); |
303 } | 309 } |
304 | 310 |
305 } // namespace js | 311 } // namespace js |
306 } // namespace mojo | 312 } // namespace mojo |
OLD | NEW |