Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Unified Diff: webkit/glue/cpp_variant.cc

Issue 6254018: Allow chrome.send to pass number, boolean, null and arrays of those (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename function and fix indentation Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/glue/cpp_variant.cc
diff --git a/webkit/glue/cpp_variant.cc b/webkit/glue/cpp_variant.cc
index eca554bcafe0a37e51b758de96fc5b4c35363fe1..a281c97ce9f2e3b131a9f6e08ff1df1c80da5e4d 100644
--- a/webkit/glue/cpp_variant.cc
+++ b/webkit/glue/cpp_variant.cc
@@ -252,6 +252,42 @@ std::vector<std::string> CppVariant::ToStringVector() const {
return string_vector;
}
+std::vector<CppVariant> CppVariant::ToVector() const {
+ DCHECK(isObject());
+ std::vector<CppVariant> vector;
+ NPObject* np_value = value.objectValue;
+ NPIdentifier length_id = WebBindings::getStringIdentifier("length");
+
+ if (WebBindings::hasProperty(NULL, np_value, length_id)) {
+ NPVariant length_value;
+ if (WebBindings::getProperty(NULL, np_value, length_id, &length_value)) {
+ int length = 0;
+ // The length is a double in some cases.
+ if (NPVARIANT_IS_DOUBLE(length_value))
+ length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value));
+ else if (NPVARIANT_IS_INT32(length_value))
+ length = NPVARIANT_TO_INT32(length_value);
+ WebBindings::releaseVariantValue(&length_value);
+
+ // For sanity, only allow 60000 items.
+ length = std::min(60000, length);
+ for (int i = 0; i < length; ++i) {
+ // Get each of the items.
+ std::string index = base::StringPrintf("%d", i);
+ NPIdentifier index_id = WebBindings::getStringIdentifier(index.c_str());
+ if (WebBindings::hasProperty(NULL, np_value, index_id)) {
+ CppVariant index_value;
+ if (WebBindings::getProperty(NULL, np_value, index_id, &index_value)) {
+ vector.push_back(index_value);
+ }
+ // CppVariant has a destructor which calls releaseVariantValue.
+ }
+ }
+ }
+ }
+ return vector;
+}
+
bool CppVariant::Invoke(const std::string& method, const CppVariant* args,
uint32 arg_count, CppVariant& result) const {
DCHECK(isObject());
« chrome/browser/dom_ui/shown_sections_handler.cc ('K') | « webkit/glue/cpp_variant.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698