Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: mojo/bindings/js/core.cc

Issue 392923002: Add support for MojoCreateMessagePipeOptions struct to JS bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/bindings/js/core_unittests.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 26 matching lines...) Expand all
37 } 37 }
38 38
39 MojoResult WaitMany( 39 MojoResult WaitMany(
40 const std::vector<mojo::Handle>& handles, 40 const std::vector<mojo::Handle>& handles,
41 const std::vector<MojoHandleSignals>& signals, 41 const std::vector<MojoHandleSignals>& signals,
42 MojoDeadline deadline) { 42 MojoDeadline deadline) {
43 return mojo::WaitMany(handles, signals, deadline); 43 return mojo::WaitMany(handles, signals, deadline);
44 } 44 }
45 45
46 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { 46 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) {
47 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
48 dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
49
47 MojoHandle handle0 = MOJO_HANDLE_INVALID; 50 MojoHandle handle0 = MOJO_HANDLE_INVALID;
48 MojoHandle handle1 = MOJO_HANDLE_INVALID; 51 MojoHandle handle1 = MOJO_HANDLE_INVALID;
49 // TODO(vtl): Add support for the options struct. 52 MojoResult result = MOJO_RESULT_OK;
50 MojoResult result = MojoCreateMessagePipe(NULL, &handle0, &handle1);
51 CHECK(result == MOJO_RESULT_OK);
52 53
53 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 54 v8::Handle<v8::Value> options_value = args.PeekNext();
55 if (options_value.IsEmpty() || options_value->IsNull() ||
56 options_value->IsUndefined()) {
57 result = MojoCreateMessagePipe(NULL, &handle0, &handle1);
58 } else if (options_value->IsObject()) {
59 gin::Dictionary options_dict(args.isolate(), options_value->ToObject());
60 MojoCreateMessagePipeOptions options;
61 // For future struct_size, we can probably infer that from the presence of
62 // properties in options_dict. For now, it's always 8.
63 options.struct_size = 8;
64 // Ideally these would be optional. But the interface makes it hard to
65 // typecheck them then.
66 if (!options_dict.Get("flags", &options.flags)) {
67 return dictionary;
68 }
69
70 result = MojoCreateMessagePipe(&options, &handle0, &handle1);
71 } else {
72 return dictionary;
73 }
74
75 CHECK_EQ(MOJO_RESULT_OK, result);
76
77 dictionary.Set("result", result);
54 dictionary.Set("handle0", mojo::Handle(handle0)); 78 dictionary.Set("handle0", mojo::Handle(handle0));
55 dictionary.Set("handle1", mojo::Handle(handle1)); 79 dictionary.Set("handle1", mojo::Handle(handle1));
56 return dictionary; 80 return dictionary;
57 } 81 }
58 82
59 MojoResult WriteMessage( 83 MojoResult WriteMessage(
60 mojo::Handle handle, 84 mojo::Handle handle,
61 const gin::ArrayBufferView& buffer, 85 const gin::ArrayBufferView& buffer,
62 const std::vector<gin::Handle<gin::HandleWrapper> >& handles, 86 const std::vector<gin::Handle<gin::HandleWrapper> >& handles,
63 MojoWriteMessageFlags flags) { 87 MojoWriteMessageFlags flags) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 CHECK(buffer.num_bytes() == num_bytes); 135 CHECK(buffer.num_bytes() == num_bytes);
112 CHECK(handles.size() == num_handles); 136 CHECK(handles.size() == num_handles);
113 137
114 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 138 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
115 dictionary.Set("result", result); 139 dictionary.Set("result", result);
116 dictionary.Set("buffer", array_buffer); 140 dictionary.Set("buffer", array_buffer);
117 dictionary.Set("handles", handles); 141 dictionary.Set("handles", handles);
118 return dictionary; 142 return dictionary;
119 } 143 }
120 144
121 gin::Dictionary CreateDataPipe(const gin::Arguments& args, 145 gin::Dictionary CreateDataPipe(const gin::Arguments& args) {
122 v8::Handle<v8::Value> options_value) {
123 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate()); 146 gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(args.isolate());
124 dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT); 147 dictionary.Set("result", MOJO_RESULT_INVALID_ARGUMENT);
125 148
126 MojoHandle producer_handle = MOJO_HANDLE_INVALID; 149 MojoHandle producer_handle = MOJO_HANDLE_INVALID;
127 MojoHandle consumer_handle = MOJO_HANDLE_INVALID; 150 MojoHandle consumer_handle = MOJO_HANDLE_INVALID;
128 MojoResult result = MOJO_RESULT_OK; 151 MojoResult result = MOJO_RESULT_OK;
129 152
130 if (options_value->IsObject()) { 153 v8::Handle<v8::Value> options_value = args.PeekNext();
154 if (options_value.IsEmpty() || options_value->IsNull() ||
155 options_value->IsUndefined()) {
156 result = MojoCreateDataPipe(NULL, &producer_handle, &consumer_handle);
157 } else if (options_value->IsObject()) {
131 gin::Dictionary options_dict(args.isolate(), options_value->ToObject()); 158 gin::Dictionary options_dict(args.isolate(), options_value->ToObject());
132 MojoCreateDataPipeOptions options; 159 MojoCreateDataPipeOptions options;
133 // For future struct_size, we can probably infer that from the presence of 160 // For future struct_size, we can probably infer that from the presence of
134 // properties in options_dict. For now, it's always 16. 161 // properties in options_dict. For now, it's always 16.
135 options.struct_size = 16; 162 options.struct_size = 16;
136 // Ideally these would be optional. But the interface makes it hard to 163 // Ideally these would be optional. But the interface makes it hard to
137 // typecheck them then. 164 // typecheck them then.
138 if (!options_dict.Get("flags", &options.flags) || 165 if (!options_dict.Get("flags", &options.flags) ||
139 !options_dict.Get("elementNumBytes", &options.element_num_bytes) || 166 !options_dict.Get("elementNumBytes", &options.element_num_bytes) ||
140 !options_dict.Get("capacityNumBytes", &options.capacity_num_bytes)) { 167 !options_dict.Get("capacityNumBytes", &options.capacity_num_bytes)) {
141 return dictionary; 168 return dictionary;
142 } 169 }
143 170
144 result = MojoCreateDataPipe(&options, &producer_handle, &consumer_handle); 171 result = MojoCreateDataPipe(&options, &producer_handle, &consumer_handle);
145 } else if (options_value->IsNull() || options_value->IsUndefined()) {
146 result = MojoCreateDataPipe(NULL, &producer_handle, &consumer_handle);
147 } else { 172 } else {
148 return dictionary; 173 return dictionary;
149 } 174 }
150 175
151 CHECK_EQ(MOJO_RESULT_OK, result); 176 CHECK_EQ(MOJO_RESULT_OK, result);
152 177
153 dictionary.Set("result", result); 178 dictionary.Set("result", result);
154 dictionary.Set("producerHandle", mojo::Handle(producer_handle)); 179 dictionary.Set("producerHandle", mojo::Handle(producer_handle));
155 dictionary.Set("consumerHandle", mojo::Handle(consumer_handle)); 180 dictionary.Set("consumerHandle", mojo::Handle(consumer_handle));
156 return dictionary; 181 return dictionary;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS) 264 .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS)
240 .SetValue("RESULT_BUSY", MOJO_RESULT_BUSY) 265 .SetValue("RESULT_BUSY", MOJO_RESULT_BUSY)
241 .SetValue("RESULT_SHOULD_WAIT", MOJO_RESULT_SHOULD_WAIT) 266 .SetValue("RESULT_SHOULD_WAIT", MOJO_RESULT_SHOULD_WAIT)
242 267
243 .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE) 268 .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE)
244 269
245 .SetValue("HANDLE_SIGNAL_NONE", MOJO_HANDLE_SIGNAL_NONE) 270 .SetValue("HANDLE_SIGNAL_NONE", MOJO_HANDLE_SIGNAL_NONE)
246 .SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE) 271 .SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE)
247 .SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE) 272 .SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE)
248 273
274 .SetValue("CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE",
275 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE)
276
249 .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE) 277 .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE)
250 278
251 .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE) 279 .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE)
252 .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD", 280 .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD",
253 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD) 281 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)
254 282
255 .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_NONE", 283 .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_NONE",
256 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE) 284 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE)
257 .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD", 285 .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD",
258 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD) 286 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD)
(...skipping 10 matching lines...) Expand all
269 .Build(); 297 .Build();
270 298
271 data->SetObjectTemplate(&g_wrapper_info, templ); 299 data->SetObjectTemplate(&g_wrapper_info, templ);
272 } 300 }
273 301
274 return templ->NewInstance(); 302 return templ->NewInstance();
275 } 303 }
276 304
277 } // namespace js 305 } // namespace js
278 } // namespace mojo 306 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/bindings/js/core_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698