Chromium Code Reviews| 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()); | |
|
evanm
2011/01/25 18:24:56
two space tabs
arv (Not doing code reviews)
2011/01/26 00:50:32
Done.
| |
| 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, | |
| 264 &length_value)) { | |
| 265 int length = 0; | |
| 266 // The length is a double in some cases. | |
|
evanm
2011/01/25 18:24:56
This code looks pasted from above. Should you ref
arv (Not doing code reviews)
2011/01/26 00:50:32
Talked offline and agreed to remove ToStringVector
| |
| 267 if (NPVARIANT_IS_DOUBLE(length_value)) | |
| 268 length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value)); | |
| 269 else if (NPVARIANT_IS_INT32(length_value)) | |
| 270 length = NPVARIANT_TO_INT32(length_value); | |
| 271 WebBindings::releaseVariantValue(&length_value); | |
| 272 | |
| 273 // For sanity, only allow 60000 items. | |
| 274 length = std::min(60000, length); | |
| 275 for (int i = 0; i < length; ++i) { | |
| 276 // Get each of the items. | |
| 277 std::string index = base::StringPrintf("%d", i); | |
| 278 NPIdentifier index_id = | |
| 279 WebBindings::getStringIdentifier(index.c_str()); | |
| 280 if (WebBindings::hasProperty(NULL, np_value, index_id)) { | |
| 281 CppVariant index_value; | |
| 282 if (WebBindings::getProperty(NULL, np_value, index_id, | |
| 283 &index_value)) { | |
| 284 vector.push_back(index_value); | |
| 285 } | |
| 286 // CppVariant has a destructor which calls | |
| 287 // releaseVariantValue. | |
| 288 } | |
| 289 } | |
| 290 } | |
| 291 } | |
| 292 return vector; | |
| 293 } | |
| 294 | |
| 255 bool CppVariant::Invoke(const std::string& method, const CppVariant* args, | 295 bool CppVariant::Invoke(const std::string& method, const CppVariant* args, |
| 256 uint32 arg_count, CppVariant& result) const { | 296 uint32 arg_count, CppVariant& result) const { |
| 257 DCHECK(isObject()); | 297 DCHECK(isObject()); |
| 258 NPIdentifier method_name = WebBindings::getStringIdentifier(method.c_str()); | 298 NPIdentifier method_name = WebBindings::getStringIdentifier(method.c_str()); |
| 259 NPObject* np_object = value.objectValue; | 299 NPObject* np_object = value.objectValue; |
| 260 if (WebBindings::hasMethod(NULL, np_object, method_name)) { | 300 if (WebBindings::hasMethod(NULL, np_object, method_name)) { |
| 261 NPVariant r; | 301 NPVariant r; |
| 262 bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_co unt, &r); | 302 bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_co unt, &r); |
| 263 result.Set(r); | 303 result.Set(r); |
| 264 return status; | 304 return status; |
| 265 } else { | 305 } else { |
| 266 return false; | 306 return false; |
| 267 } | 307 } |
| 268 } | 308 } |
| OLD | NEW |