Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/public/bindings/js/core.h" | 5 #include "mojo/public/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/object_template_builder.h" | |
| 14 #include "gin/per_isolate_data.h" | 15 #include "gin/per_isolate_data.h" |
| 15 #include "gin/public/wrapper_info.h" | 16 #include "gin/public/wrapper_info.h" |
| 16 #include "mojo/public/bindings/js/handle.h" | 17 #include "mojo/public/bindings/js/handle.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 namespace js { | 20 namespace js { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { | 24 gin::Dictionary CreateMessagePipe(const gin::Arguments& args) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } // namespace | 86 } // namespace |
| 86 | 87 |
| 87 const char Core::kModuleName[] = "mojo/public/bindings/js/core"; | 88 const char Core::kModuleName[] = "mojo/public/bindings/js/core"; |
| 88 | 89 |
| 89 v8::Local<v8::ObjectTemplate> Core::GetTemplate(v8::Isolate* isolate) { | 90 v8::Local<v8::ObjectTemplate> Core::GetTemplate(v8::Isolate* isolate) { |
| 90 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 91 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |
| 91 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( | 92 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
| 92 &g_wrapper_info); | 93 &g_wrapper_info); |
| 93 | 94 |
| 94 if (templ.IsEmpty()) { | 95 if (templ.IsEmpty()) { |
| 95 templ = v8::ObjectTemplate::New(); | 96 gin::ObjectTemplateBuilder builder(isolate); |
| 97 templ = builder | |
| 98 .SetMethod("close", mojo::CloseRaw) | |
| 99 .SetMethod("wait", mojo::Wait) | |
|
abarth-chromium
2013/11/28 06:27:09
Oh, wow. The base::Bind is implicit?
Aaron Boodman
2013/11/28 18:25:22
Yeah, just a little sugar. There's an override tha
| |
| 100 .SetMethod("waitMany", mojo::WaitMany<std::vector<mojo::Handle>, | |
| 101 std::vector<MojoWaitFlags> >) | |
| 102 .SetMethod("createMessagePipe", CreateMessagePipe) | |
| 103 .SetMethod("writeMessage", WriteMessage) | |
| 104 .SetMethod("readMessage", ReadMessage) | |
| 96 | 105 |
| 97 templ->Set(gin::StringToSymbol(isolate, "close"), | 106 // TODO(vtl): Change name of "kInvalidHandle", now that there's no such |
| 98 gin::CreateFunctionTemplate(isolate, | 107 // C++ constant? |
| 99 base::Bind(mojo::CloseRaw))); | 108 .SetValue("kInvalidHandle", mojo::Handle()) |
| 100 templ->Set(gin::StringToSymbol(isolate, "wait"), | |
| 101 gin::CreateFunctionTemplate(isolate, | |
| 102 base::Bind(mojo::Wait))); | |
| 103 templ->Set(gin::StringToSymbol(isolate, "waitMany"), | |
| 104 gin::CreateFunctionTemplate(isolate, | |
| 105 base::Bind(mojo::WaitMany<std::vector<mojo::Handle>, | |
| 106 std::vector<MojoWaitFlags> >))); | |
| 107 templ->Set(gin::StringToSymbol(isolate, "createMessagePipe"), | |
| 108 gin::CreateFunctionTemplate(isolate, | |
| 109 base::Bind(CreateMessagePipe))); | |
| 110 templ->Set(gin::StringToSymbol(isolate, "writeMessage"), | |
| 111 gin::CreateFunctionTemplate(isolate, | |
| 112 base::Bind(WriteMessage))); | |
| 113 templ->Set(gin::StringToSymbol(isolate, "readMessage"), | |
| 114 gin::CreateFunctionTemplate(isolate, | |
| 115 base::Bind(ReadMessage))); | |
| 116 | 109 |
| 117 // TODO(vtl): Change name of "kInvalidHandle", now that there's no such C++ | 110 .SetValue("RESULT_OK", MOJO_RESULT_OK) |
| 118 // constant? | 111 .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED) |
| 119 templ->Set(gin::StringToSymbol(isolate, "kInvalidHandle"), | 112 .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN) |
| 120 gin::ConvertToV8(isolate, mojo::Handle())); | 113 .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT) |
| 114 .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED) | |
| 115 .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND) | |
| 116 .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS) | |
| 117 .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED) | |
| 118 .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED) | |
| 119 .SetValue("RESULT_FAILED_PRECONDITION", MOJO_RESULT_FAILED_PRECONDITION) | |
| 120 .SetValue("RESULT_ABORTED", MOJO_RESULT_ABORTED) | |
| 121 .SetValue("RESULT_OUT_OF_RANGE", MOJO_RESULT_OUT_OF_RANGE) | |
| 122 .SetValue("RESULT_UNIMPLEMENTED", MOJO_RESULT_UNIMPLEMENTED) | |
| 123 .SetValue("RESULT_INTERNAL", MOJO_RESULT_INTERNAL) | |
| 124 .SetValue("RESULT_UNAVAILABLE", MOJO_RESULT_UNAVAILABLE) | |
| 125 .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS) | |
| 121 | 126 |
| 122 templ->Set(gin::StringToSymbol(isolate, "RESULT_OK"), | 127 .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE) |
| 123 gin::ConvertToV8(isolate, MOJO_RESULT_OK)); | |
| 124 templ->Set(gin::StringToSymbol(isolate, "RESULT_CANCELLED"), | |
| 125 gin::ConvertToV8(isolate, MOJO_RESULT_CANCELLED)); | |
| 126 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNKNOWN"), | |
| 127 gin::ConvertToV8(isolate, MOJO_RESULT_UNKNOWN)); | |
| 128 templ->Set(gin::StringToSymbol(isolate, "RESULT_INVALID_ARGUMENT"), | |
| 129 gin::ConvertToV8(isolate, MOJO_RESULT_INVALID_ARGUMENT)); | |
| 130 templ->Set(gin::StringToSymbol(isolate, "RESULT_DEADLINE_EXCEEDED"), | |
| 131 gin::ConvertToV8(isolate, MOJO_RESULT_DEADLINE_EXCEEDED)); | |
| 132 templ->Set(gin::StringToSymbol(isolate, "RESULT_NOT_FOUND"), | |
| 133 gin::ConvertToV8(isolate, MOJO_RESULT_NOT_FOUND)); | |
| 134 templ->Set(gin::StringToSymbol(isolate, "RESULT_ALREADY_EXISTS"), | |
| 135 gin::ConvertToV8(isolate, MOJO_RESULT_ALREADY_EXISTS)); | |
| 136 templ->Set(gin::StringToSymbol(isolate, "RESULT_PERMISSION_DENIED"), | |
| 137 gin::ConvertToV8(isolate, MOJO_RESULT_PERMISSION_DENIED)); | |
| 138 templ->Set(gin::StringToSymbol(isolate, "RESULT_RESOURCE_EXHAUSTED"), | |
| 139 gin::ConvertToV8(isolate, MOJO_RESULT_RESOURCE_EXHAUSTED)); | |
| 140 templ->Set(gin::StringToSymbol(isolate, "RESULT_FAILED_PRECONDITION"), | |
| 141 gin::ConvertToV8(isolate, MOJO_RESULT_FAILED_PRECONDITION)); | |
| 142 templ->Set(gin::StringToSymbol(isolate, "RESULT_ABORTED"), | |
| 143 gin::ConvertToV8(isolate, MOJO_RESULT_ABORTED)); | |
| 144 templ->Set(gin::StringToSymbol(isolate, "RESULT_OUT_OF_RANGE"), | |
| 145 gin::ConvertToV8(isolate, MOJO_RESULT_OUT_OF_RANGE)); | |
| 146 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNIMPLEMENTED"), | |
| 147 gin::ConvertToV8(isolate, MOJO_RESULT_UNIMPLEMENTED)); | |
| 148 templ->Set(gin::StringToSymbol(isolate, "RESULT_INTERNAL"), | |
| 149 gin::ConvertToV8(isolate, MOJO_RESULT_INTERNAL)); | |
| 150 templ->Set(gin::StringToSymbol(isolate, "RESULT_UNAVAILABLE"), | |
| 151 gin::ConvertToV8(isolate, MOJO_RESULT_UNAVAILABLE)); | |
| 152 templ->Set(gin::StringToSymbol(isolate, "RESULT_DATA_LOSS"), | |
| 153 gin::ConvertToV8(isolate, MOJO_RESULT_DATA_LOSS)); | |
| 154 | 128 |
| 155 templ->Set(gin::StringToSymbol(isolate, "DEADLINE_INDEFINITE"), | 129 .SetValue("WAIT_FLAG_NONE", MOJO_WAIT_FLAG_NONE) |
| 156 gin::ConvertToV8(isolate, MOJO_DEADLINE_INDEFINITE)); | 130 .SetValue("WAIT_FLAG_READABLE", MOJO_WAIT_FLAG_READABLE) |
| 131 .SetValue("WAIT_FLAG_READABLE", MOJO_WAIT_FLAG_READABLE) | |
| 132 .SetValue("WAIT_FLAG_EVERYTHING", MOJO_WAIT_FLAG_EVERYTHING) | |
| 157 | 133 |
| 158 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_NONE"), | 134 .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE) |
| 159 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_NONE)); | |
| 160 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_READABLE"), | |
| 161 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_READABLE)); | |
| 162 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_READABLE"), | |
| 163 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_READABLE)); | |
| 164 templ->Set(gin::StringToSymbol(isolate, "WAIT_FLAG_EVERYTHING"), | |
| 165 gin::ConvertToV8(isolate, MOJO_WAIT_FLAG_EVERYTHING)); | |
| 166 | 135 |
| 167 templ->Set(gin::StringToSymbol(isolate, "WRITE_MESSAGE_FLAG_NONE"), | 136 .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE) |
| 168 gin::ConvertToV8(isolate, MOJO_WRITE_MESSAGE_FLAG_NONE)); | 137 .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD", |
| 169 | 138 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD) |
| 170 templ->Set(gin::StringToSymbol(isolate, "READ_MESSAGE_FLAG_NONE"), | 139 .Build(); |
| 171 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_NONE)); | |
| 172 templ->Set(gin::StringToSymbol(isolate, "READ_MESSAGE_FLAG_MAY_DISCARD"), | |
| 173 gin::ConvertToV8(isolate, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)); | |
| 174 | 140 |
| 175 data->SetObjectTemplate(&g_wrapper_info, templ); | 141 data->SetObjectTemplate(&g_wrapper_info, templ); |
| 176 } | 142 } |
| 177 | 143 |
| 178 return templ; | 144 return templ; |
| 179 } | 145 } |
| 180 | 146 |
| 181 } // namespace js | 147 } // namespace js |
| 182 } // namespace mojo | 148 } // namespace mojo |
| OLD | NEW |