| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "ppapi/c/pp_bool.h" | 15 #include "ppapi/c/pp_bool.h" |
| 16 #include "ppapi/c/pp_stdint.h" | 16 #include "ppapi/c/pp_stdint.h" |
| 17 #include "ppapi/shared_impl/array_var.h" |
| 17 #include "ppapi/shared_impl/dictionary_var.h" | 18 #include "ppapi/shared_impl/dictionary_var.h" |
| 18 #include "ppapi/shared_impl/ppapi_globals.h" | 19 #include "ppapi/shared_impl/ppapi_globals.h" |
| 19 #include "ppapi/shared_impl/scoped_pp_var.h" | 20 #include "ppapi/shared_impl/scoped_pp_var.h" |
| 20 #include "ppapi/shared_impl/var.h" | 21 #include "ppapi/shared_impl/var.h" |
| 21 #include "ppapi/shared_impl/var_tracker.h" | 22 #include "ppapi/shared_impl/var_tracker.h" |
| 22 | 23 |
| 23 namespace ppapi { | 24 namespace ppapi { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 51 case PP_VARTYPE_OBJECT: { | 52 case PP_VARTYPE_OBJECT: { |
| 52 return NULL; | 53 return NULL; |
| 53 } | 54 } |
| 54 case PP_VARTYPE_ARRAY: { | 55 case PP_VARTYPE_ARRAY: { |
| 55 if (std::find(parent_ids->begin(), parent_ids->end(), var.value.as_id) != | 56 if (std::find(parent_ids->begin(), parent_ids->end(), var.value.as_id) != |
| 56 parent_ids->end()) { | 57 parent_ids->end()) { |
| 57 // A circular reference is found. | 58 // A circular reference is found. |
| 58 return NULL; | 59 return NULL; |
| 59 } | 60 } |
| 60 | 61 |
| 62 ArrayVar* array_var = ArrayVar::FromPPVar(var); |
| 63 if (!array_var) |
| 64 return NULL; |
| 65 |
| 61 scoped_ptr<base::ListValue> list_value(new base::ListValue()); | 66 scoped_ptr<base::ListValue> list_value(new base::ListValue()); |
| 62 parent_ids->push_back(var.value.as_id); | 67 parent_ids->push_back(var.value.as_id); |
| 63 | 68 |
| 64 // TODO(yzshen): Implement it once array var is supported. | 69 for (ArrayVar::ElementVector::const_iterator iter = |
| 70 array_var->elements().begin(); |
| 71 iter != array_var->elements().end(); ++iter) { |
| 72 base::Value* value = CreateValueFromVarImpl(iter->get(), parent_ids); |
| 73 if (!value) { |
| 74 parent_ids->pop_back(); |
| 75 return NULL; |
| 76 } |
| 77 |
| 78 list_value->Append(value); |
| 79 } |
| 65 | 80 |
| 66 parent_ids->pop_back(); | 81 parent_ids->pop_back(); |
| 67 return list_value.release(); | 82 return list_value.release(); |
| 68 } | 83 } |
| 69 case PP_VARTYPE_DICTIONARY: { | 84 case PP_VARTYPE_DICTIONARY: { |
| 70 if (std::find(parent_ids->begin(), parent_ids->end(), var.value.as_id) != | 85 if (std::find(parent_ids->begin(), parent_ids->end(), var.value.as_id) != |
| 71 parent_ids->end()) { | 86 parent_ids->end()) { |
| 72 // A circular reference is found. | 87 // A circular reference is found. |
| 73 return NULL; | 88 return NULL; |
| 74 } | 89 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 CreateVarFromValue(iter.value())); | 193 CreateVarFromValue(iter.value())); |
| 179 if (child_var.get().type == PP_VARTYPE_UNDEFINED || | 194 if (child_var.get().type == PP_VARTYPE_UNDEFINED || |
| 180 !dict_var->SetWithStringKey(iter.key(), child_var.get())) { | 195 !dict_var->SetWithStringKey(iter.key(), child_var.get())) { |
| 181 return PP_MakeUndefined(); | 196 return PP_MakeUndefined(); |
| 182 } | 197 } |
| 183 } | 198 } |
| 184 | 199 |
| 185 return dict_var->GetPPVar(); | 200 return dict_var->GetPPVar(); |
| 186 } | 201 } |
| 187 case base::Value::TYPE_LIST: { | 202 case base::Value::TYPE_LIST: { |
| 188 // TODO(yzshen): Add support once array var is supported. | 203 const base::ListValue& list_value = |
| 189 return PP_MakeUndefined(); | 204 static_cast<const base::ListValue&>(value); |
| 205 |
| 206 scoped_refptr<ArrayVar> array_var(new ArrayVar()); |
| 207 array_var->elements().reserve(list_value.GetSize()); |
| 208 for (base::ListValue::const_iterator iter = list_value.begin(); |
| 209 iter != list_value.end(); ++iter) { |
| 210 ScopedPPVar child_var(ScopedPPVar::PassRef(), |
| 211 CreateVarFromValue(**iter)); |
| 212 if (child_var.get().type == PP_VARTYPE_UNDEFINED) |
| 213 return PP_MakeUndefined(); |
| 214 |
| 215 array_var->elements().push_back(child_var); |
| 216 } |
| 217 |
| 218 return array_var->GetPPVar(); |
| 190 } | 219 } |
| 191 } | 220 } |
| 192 NOTREACHED(); | 221 NOTREACHED(); |
| 193 return PP_MakeUndefined(); | 222 return PP_MakeUndefined(); |
| 194 } | 223 } |
| 195 | 224 |
| 196 } // namespace ppapi | 225 } // namespace ppapi |
| 197 | 226 |
| OLD | NEW |