OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "extensions/renderer/api_binding.h" | 5 #include "extensions/renderer/api_binding.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 stripped_id = id.substr(api_name_.size() + 1); // +1 for trailing '.' | 178 stripped_id = id.substr(api_name_.size() + 1); // +1 for trailing '.' |
179 std::vector<EnumEntry>& entries = | 179 std::vector<EnumEntry>& entries = |
180 enums_[stripped_id ? *stripped_id : id]; | 180 enums_[stripped_id ? *stripped_id : id]; |
181 entries.reserve(enum_values.size()); | 181 entries.reserve(enum_values.size()); |
182 for (const auto& enum_value : enum_values) { | 182 for (const auto& enum_value : enum_values) { |
183 entries.push_back( | 183 entries.push_back( |
184 std::make_pair(enum_value, GetJSEnumEntryName(enum_value))); | 184 std::make_pair(enum_value, GetJSEnumEntryName(enum_value))); |
185 } | 185 } |
186 } | 186 } |
187 type_refs->AddSpec(id, std::move(argument_spec)); | 187 type_refs->AddSpec(id, std::move(argument_spec)); |
| 188 // Some types, like storage.StorageArea, have functions associated with |
| 189 // them. Cache the function signatures in the type map. |
| 190 const base::ListValue* type_functions = nullptr; |
| 191 if (type_dict->GetList("functions", &type_functions)) { |
| 192 for (const auto& func : *type_functions) { |
| 193 const base::DictionaryValue* func_dict = nullptr; |
| 194 CHECK(func->GetAsDictionary(&func_dict)); |
| 195 std::string function_name; |
| 196 CHECK(func_dict->GetString("name", &function_name)); |
| 197 |
| 198 const base::ListValue* params = nullptr; |
| 199 CHECK(func_dict->GetList("parameters", ¶ms)); |
| 200 type_refs->AddTypeMethodSignature( |
| 201 base::StringPrintf("%s.%s", id.c_str(), function_name.c_str()), |
| 202 base::MakeUnique<APISignature>(*params)); |
| 203 } |
| 204 } |
188 } | 205 } |
189 } | 206 } |
190 | 207 |
191 if (event_definitions) { | 208 if (event_definitions) { |
192 events_.reserve(event_definitions->GetSize()); | 209 events_.reserve(event_definitions->GetSize()); |
193 for (const auto& event : *event_definitions) { | 210 for (const auto& event : *event_definitions) { |
194 const base::DictionaryValue* event_dict = nullptr; | 211 const base::DictionaryValue* event_dict = nullptr; |
195 CHECK(event->GetAsDictionary(&event_dict)); | 212 CHECK(event->GetAsDictionary(&event_dict)); |
196 std::string name; | 213 std::string name; |
197 CHECK(event_dict->GetString("name", &name)); | 214 CHECK(event_dict->GetString("name", &name)); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 if (invalid_invocation) { | 469 if (invalid_invocation) { |
453 arguments->ThrowTypeError("Invalid invocation"); | 470 arguments->ThrowTypeError("Invalid invocation"); |
454 return; | 471 return; |
455 } | 472 } |
456 | 473 |
457 request_handler_->StartRequest(context, name, std::move(converted_arguments), | 474 request_handler_->StartRequest(context, name, std::move(converted_arguments), |
458 callback, custom_callback); | 475 callback, custom_callback); |
459 } | 476 } |
460 | 477 |
461 } // namespace extensions | 478 } // namespace extensions |
OLD | NEW |