OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ppapi/shared_impl/var_value_conversions.h" | 5 #include "ppapi/shared_impl/var_value_conversions.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <set> | 8 #include <set> |
9 #include <stack> | 9 #include <stack> |
10 | 10 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return NULL; | 242 return NULL; |
243 | 243 |
244 DCHECK(top.value->GetType() == base::Value::TYPE_DICTIONARY); | 244 DCHECK(top.value->GetType() == base::Value::TYPE_DICTIONARY); |
245 base::DictionaryValue* dict_value = | 245 base::DictionaryValue* dict_value = |
246 static_cast<base::DictionaryValue*>(top.value); | 246 static_cast<base::DictionaryValue*>(top.value); |
247 | 247 |
248 for (DictionaryVar::KeyValueMap::const_iterator iter = | 248 for (DictionaryVar::KeyValueMap::const_iterator iter = |
249 dict_var->key_value_map().begin(); | 249 dict_var->key_value_map().begin(); |
250 iter != dict_var->key_value_map().end(); | 250 iter != dict_var->key_value_map().end(); |
251 ++iter) { | 251 ++iter) { |
252 // Skip the key-value pair if the value is undefined. | 252 // Skip the key-value pair if the value is undefined or null. |
253 if (iter->second.get().type == PP_VARTYPE_UNDEFINED) | 253 if (iter->second.get().type == PP_VARTYPE_UNDEFINED || |
| 254 iter->second.get().type == PP_VARTYPE_NULL) { |
254 continue; | 255 continue; |
| 256 } |
255 | 257 |
256 scoped_ptr<base::Value> child_value; | 258 scoped_ptr<base::Value> child_value; |
257 if (!CreateValueFromVarHelper(parent_ids, iter->second.get(), | 259 if (!CreateValueFromVarHelper(parent_ids, iter->second.get(), |
258 &child_value, &state)) { | 260 &child_value, &state)) { |
259 return NULL; | 261 return NULL; |
260 } | 262 } |
261 | 263 |
262 dict_value->SetWithoutPathExpansion(iter->first, child_value.release()); | 264 dict_value->SetWithoutPathExpansion(iter->first, child_value.release()); |
263 } | 265 } |
264 } else if (top.var.type == PP_VARTYPE_ARRAY) { | 266 } else if (top.var.type == PP_VARTYPE_ARRAY) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 array_var->elements().push_back(child_var); | 335 array_var->elements().push_back(child_var); |
334 } | 336 } |
335 } else { | 337 } else { |
336 NOTREACHED(); | 338 NOTREACHED(); |
337 return PP_MakeUndefined(); | 339 return PP_MakeUndefined(); |
338 } | 340 } |
339 } | 341 } |
340 | 342 |
341 return root_var.Release(); | 343 return root_var.Release(); |
342 } | 344 } |
| 345 |
| 346 base::ListValue* CreateListValueFromVarVector( |
| 347 const std::vector<PP_Var>& vars) { |
| 348 scoped_ptr<base::ListValue> list_value(new base::ListValue()); |
| 349 |
| 350 for (std::vector<PP_Var>::const_iterator iter = vars.begin(); |
| 351 iter != vars.end(); |
| 352 ++iter) { |
| 353 base::Value* value = CreateValueFromVar(*iter); |
| 354 if (!value) |
| 355 return NULL; |
| 356 list_value->Append(value); |
| 357 } |
| 358 return list_value.release(); |
| 359 } |
| 360 |
| 361 bool CreateVarVectorFromListValue(const base::ListValue& list_value, |
| 362 std::vector<PP_Var>* vars) { |
| 363 if (!vars) |
| 364 return false; |
| 365 |
| 366 std::vector<ScopedPPVar> result; |
| 367 result.reserve(list_value.GetSize()); |
| 368 for (base::ListValue::const_iterator iter = list_value.begin(); |
| 369 iter != list_value.end(); |
| 370 ++iter) { |
| 371 ScopedPPVar child_var(ScopedPPVar::PassRef(), |
| 372 CreateVarFromValue(**iter)); |
| 373 if (child_var.get().type == PP_VARTYPE_UNDEFINED) |
| 374 return false; |
| 375 |
| 376 result.push_back(child_var); |
| 377 } |
| 378 |
| 379 vars->clear(); |
| 380 vars->reserve(result.size()); |
| 381 for (std::vector<ScopedPPVar>::iterator iter = result.begin(); |
| 382 iter != result.end(); |
| 383 ++iter) { |
| 384 vars->push_back(iter->Release()); |
| 385 } |
| 386 |
| 387 return true; |
| 388 } |
| 389 |
343 } // namespace ppapi | 390 } // namespace ppapi |
344 | 391 |
OLD | NEW |