| 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/WebKit/chromium/public/WebBindings.h" | 8 #include "third_party/WebKit/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" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 | 14 |
| 14 using WebKit::WebBindings; | 15 using WebKit::WebBindings; |
| 15 | 16 |
| 16 CppVariant::CppVariant() { | 17 CppVariant::CppVariant() { |
| 17 type = NPVariantType_Null; | 18 type = NPVariantType_Null; |
| 18 } | 19 } |
| 19 | 20 |
| 20 // Note that Set() performs a deep copy, which is necessary to safely | 21 // Note that Set() performs a deep copy, which is necessary to safely |
| 21 // call FreeData() on the value in the destructor. | 22 // call FreeData() on the value in the destructor. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (NPVARIANT_IS_DOUBLE(length_value)) | 226 if (NPVARIANT_IS_DOUBLE(length_value)) |
| 226 length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value)); | 227 length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value)); |
| 227 else if (NPVARIANT_IS_INT32(length_value)) | 228 else if (NPVARIANT_IS_INT32(length_value)) |
| 228 length = NPVARIANT_TO_INT32(length_value); | 229 length = NPVARIANT_TO_INT32(length_value); |
| 229 WebBindings::releaseVariantValue(&length_value); | 230 WebBindings::releaseVariantValue(&length_value); |
| 230 | 231 |
| 231 // For sanity, only allow 60000 items. | 232 // For sanity, only allow 60000 items. |
| 232 length = std::min(60000, length); | 233 length = std::min(60000, length); |
| 233 for (int i = 0; i < length; ++i) { | 234 for (int i = 0; i < length; ++i) { |
| 234 // Get each of the items. | 235 // Get each of the items. |
| 235 std::string index = StringPrintf("%d", i); | 236 std::string index = base::StringPrintf("%d", i); |
| 236 NPIdentifier index_id = WebBindings::getStringIdentifier(index.c_str()); | 237 NPIdentifier index_id = WebBindings::getStringIdentifier(index.c_str()); |
| 237 if (WebBindings::hasProperty(NULL, np_value, index_id)) { | 238 if (WebBindings::hasProperty(NULL, np_value, index_id)) { |
| 238 NPVariant index_value; | 239 NPVariant index_value; |
| 239 if (WebBindings::getProperty(NULL, np_value, index_id, &index_value))
{ | 240 if (WebBindings::getProperty(NULL, np_value, index_id, &index_value))
{ |
| 240 if (NPVARIANT_IS_STRING(index_value)) { | 241 if (NPVARIANT_IS_STRING(index_value)) { |
| 241 std::string string( | 242 std::string string( |
| 242 NPVARIANT_TO_STRING(index_value).UTF8Characters, | 243 NPVARIANT_TO_STRING(index_value).UTF8Characters, |
| 243 NPVARIANT_TO_STRING(index_value).UTF8Length); | 244 NPVARIANT_TO_STRING(index_value).UTF8Length); |
| 244 wstring_vector.push_back(UTF8ToWide(string)); | 245 wstring_vector.push_back(UTF8ToWide(string)); |
| 245 } | 246 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 259 NPObject* np_object = value.objectValue; | 260 NPObject* np_object = value.objectValue; |
| 260 if (WebBindings::hasMethod(NULL, np_object, method_name)) { | 261 if (WebBindings::hasMethod(NULL, np_object, method_name)) { |
| 261 NPVariant r; | 262 NPVariant r; |
| 262 bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_co
unt, &r); | 263 bool status = WebBindings::invoke(NULL, np_object, method_name, args, arg_co
unt, &r); |
| 263 result.Set(r); | 264 result.Set(r); |
| 264 return status; | 265 return status; |
| 265 } else { | 266 } else { |
| 266 return false; | 267 return false; |
| 267 } | 268 } |
| 268 } | 269 } |
| OLD | NEW |