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

Side by Side Diff: extensions/renderer/api_binding.cc

Issue 2740143002: Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Comment Updates Created 3 years, 9 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
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 weak_factory_(this) { 142 weak_factory_(this) {
143 // TODO(devlin): It might make sense to instantiate the object_template_ 143 // TODO(devlin): It might make sense to instantiate the object_template_
144 // directly here, which would avoid the need to hold on to 144 // directly here, which would avoid the need to hold on to
145 // |property_definitions_| and |enums_|. However, there are *some* cases where 145 // |property_definitions_| and |enums_|. However, there are *some* cases where
146 // we don't immediately stamp out an API from the template following 146 // we don't immediately stamp out an API from the template following
147 // construction. 147 // construction.
148 148
149 if (function_definitions) { 149 if (function_definitions) {
150 for (const auto& func : *function_definitions) { 150 for (const auto& func : *function_definitions) {
151 const base::DictionaryValue* func_dict = nullptr; 151 const base::DictionaryValue* func_dict = nullptr;
152 CHECK(func->GetAsDictionary(&func_dict)); 152 CHECK(func.GetAsDictionary(&func_dict));
153 std::string name; 153 std::string name;
154 CHECK(func_dict->GetString("name", &name)); 154 CHECK(func_dict->GetString("name", &name));
155 155
156 const base::ListValue* params = nullptr; 156 const base::ListValue* params = nullptr;
157 CHECK(func_dict->GetList("parameters", &params)); 157 CHECK(func_dict->GetList("parameters", &params));
158 auto signature = base::MakeUnique<APISignature>(*params); 158 auto signature = base::MakeUnique<APISignature>(*params);
159 std::string full_name = 159 std::string full_name =
160 base::StringPrintf("%s.%s", api_name_.c_str(), name.c_str()); 160 base::StringPrintf("%s.%s", api_name_.c_str(), name.c_str());
161 methods_[name] = base::MakeUnique<MethodData>(full_name, signature.get()); 161 methods_[name] = base::MakeUnique<MethodData>(full_name, signature.get());
162 type_refs->AddAPIMethodSignature(full_name, std::move(signature)); 162 type_refs->AddAPIMethodSignature(full_name, std::move(signature));
163 } 163 }
164 } 164 }
165 165
166 if (type_definitions) { 166 if (type_definitions) {
167 for (const auto& type : *type_definitions) { 167 for (const auto& type : *type_definitions) {
168 const base::DictionaryValue* type_dict = nullptr; 168 const base::DictionaryValue* type_dict = nullptr;
169 CHECK(type->GetAsDictionary(&type_dict)); 169 CHECK(type.GetAsDictionary(&type_dict));
170 std::string id; 170 std::string id;
171 CHECK(type_dict->GetString("id", &id)); 171 CHECK(type_dict->GetString("id", &id));
172 auto argument_spec = base::MakeUnique<ArgumentSpec>(*type_dict); 172 auto argument_spec = base::MakeUnique<ArgumentSpec>(*type_dict);
173 const std::set<std::string>& enum_values = argument_spec->enum_values(); 173 const std::set<std::string>& enum_values = argument_spec->enum_values();
174 if (!enum_values.empty()) { 174 if (!enum_values.empty()) {
175 // Type names may be prefixed by the api name. If so, remove the prefix. 175 // Type names may be prefixed by the api name. If so, remove the prefix.
176 base::Optional<std::string> stripped_id; 176 base::Optional<std::string> stripped_id;
177 if (base::StartsWith(id, api_name_, base::CompareCase::SENSITIVE)) 177 if (base::StartsWith(id, api_name_, base::CompareCase::SENSITIVE))
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 188 // Some types, like storage.StorageArea, have functions associated with
189 // them. Cache the function signatures in the type map. 189 // them. Cache the function signatures in the type map.
190 const base::ListValue* type_functions = nullptr; 190 const base::ListValue* type_functions = nullptr;
191 if (type_dict->GetList("functions", &type_functions)) { 191 if (type_dict->GetList("functions", &type_functions)) {
192 for (const auto& func : *type_functions) { 192 for (const auto& func : *type_functions) {
193 const base::DictionaryValue* func_dict = nullptr; 193 const base::DictionaryValue* func_dict = nullptr;
194 CHECK(func->GetAsDictionary(&func_dict)); 194 CHECK(func.GetAsDictionary(&func_dict));
195 std::string function_name; 195 std::string function_name;
196 CHECK(func_dict->GetString("name", &function_name)); 196 CHECK(func_dict->GetString("name", &function_name));
197 197
198 const base::ListValue* params = nullptr; 198 const base::ListValue* params = nullptr;
199 CHECK(func_dict->GetList("parameters", &params)); 199 CHECK(func_dict->GetList("parameters", &params));
200 type_refs->AddTypeMethodSignature( 200 type_refs->AddTypeMethodSignature(
201 base::StringPrintf("%s.%s", id.c_str(), function_name.c_str()), 201 base::StringPrintf("%s.%s", id.c_str(), function_name.c_str()),
202 base::MakeUnique<APISignature>(*params)); 202 base::MakeUnique<APISignature>(*params));
203 } 203 }
204 } 204 }
205 } 205 }
206 } 206 }
207 207
208 if (event_definitions) { 208 if (event_definitions) {
209 events_.reserve(event_definitions->GetSize()); 209 events_.reserve(event_definitions->GetSize());
210 for (const auto& event : *event_definitions) { 210 for (const auto& event : *event_definitions) {
211 const base::DictionaryValue* event_dict = nullptr; 211 const base::DictionaryValue* event_dict = nullptr;
212 CHECK(event->GetAsDictionary(&event_dict)); 212 CHECK(event.GetAsDictionary(&event_dict));
213 std::string name; 213 std::string name;
214 CHECK(event_dict->GetString("name", &name)); 214 CHECK(event_dict->GetString("name", &name));
215 std::string full_name = 215 std::string full_name =
216 base::StringPrintf("%s.%s", api_name_.c_str(), name.c_str()); 216 base::StringPrintf("%s.%s", api_name_.c_str(), name.c_str());
217 events_.push_back(base::MakeUnique<EventData>( 217 events_.push_back(base::MakeUnique<EventData>(
218 std::move(name), std::move(full_name), event_handler)); 218 std::move(name), std::move(full_name), event_handler));
219 } 219 }
220 } 220 }
221 } 221 }
222 222
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (invalid_invocation) { 463 if (invalid_invocation) {
464 arguments->ThrowTypeError("Invalid invocation"); 464 arguments->ThrowTypeError("Invalid invocation");
465 return; 465 return;
466 } 466 }
467 467
468 request_handler_->StartRequest(context, name, std::move(converted_arguments), 468 request_handler_->StartRequest(context, name, std::move(converted_arguments),
469 callback, custom_callback); 469 callback, custom_callback);
470 } 470 }
471 471
472 } // namespace extensions 472 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698