OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file contains definitions for CppVariant. | 5 // This file contains definitions for CppVariant. |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
9 #include "webkit/glue/cpp_variant.h" | 9 #include "webkit/glue/cpp_variant.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 245 } |
246 WebBindings::releaseVariantValue(&index_value); | 246 WebBindings::releaseVariantValue(&index_value); |
247 } | 247 } |
248 } | 248 } |
249 } | 249 } |
250 } | 250 } |
251 } | 251 } |
252 return string_vector; | 252 return string_vector; |
253 } | 253 } |
254 | 254 |
| 255 std::vector<CppVariant> CppVariant::ToVector() const { |
| 256 DCHECK(isObject()); |
| 257 std::vector<CppVariant> vector; |
| 258 NPObject* np_value = value.objectValue; |
| 259 NPIdentifier length_id = WebBindings::getStringIdentifier("length"); |
| 260 |
| 261 if (WebBindings::hasProperty(NULL, np_value, length_id)) { |
| 262 NPVariant length_value; |
| 263 if (WebBindings::getProperty(NULL, np_value, length_id, &length_value))
{ |
| 264 int length = 0; |
| 265 // The length is a double in some cases. |
| 266 if (NPVARIANT_IS_DOUBLE(length_value)) |
| 267 length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value)); |
| 268 else if (NPVARIANT_IS_INT32(length_value)) |
| 269 length = NPVARIANT_TO_INT32(length_value); |
| 270 WebBindings::releaseVariantValue(&length_value); |
| 271 |
| 272 // For sanity, only allow 60000 items. |
| 273 length = std::min(60000, length); |
| 274 for (int i = 0; i < length; ++i) { |
| 275 // Get each of the items. |
| 276 std::string index = base::StringPrintf("%d", i); |
| 277 NPIdentifier index_id = WebBindings::getStringIdentifier(index.c
_str()); |
| 278 if (WebBindings::hasProperty(NULL, np_value, index_id)) { |
| 279 CppVariant index_value; |
| 280 if (WebBindings::getProperty(NULL, np_value, index_id, &inde
x_value)) { |
| 281 vector.push_back(index_value); |
| 282 } |
| 283 // CppVariant has a destructor which calls releaseVariantVal
ue. |
| 284 } |
| 285 } |
| 286 } |
| 287 } |
| 288 return vector; |
| 289 } |
| 290 |
255 bool CppVariant::Invoke(const std::string& method, const CppVariant* args, | 291 bool CppVariant::Invoke(const std::string& method, const CppVariant* args, |
256 uint32 arg_count, CppVariant& result) const { | 292 uint32 arg_count, CppVariant& result) const { |
257 DCHECK(isObject()); | 293 DCHECK(isObject()); |
258 NPIdentifier method_name = WebBindings::getStringIdentifier(method.c_str()); | 294 NPIdentifier method_name = WebBindings::getStringIdentifier(method.c_str()); |
259 NPObject* np_object = value.objectValue; | 295 NPObject* np_object = value.objectValue; |
260 if (WebBindings::hasMethod(NULL, np_object, method_name)) { | 296 if (WebBindings::hasMethod(NULL, np_object, method_name)) { |
261 NPVariant r; | 297 NPVariant r; |
262 bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_co
unt, &r); | 298 bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_co
unt, &r); |
263 result.Set(r); | 299 result.Set(r); |
264 return status; | 300 return status; |
265 } else { | 301 } else { |
266 return false; | 302 return false; |
267 } | 303 } |
268 } | 304 } |
OLD | NEW |