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

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: Whitespace and comments 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
« chrome/renderer/dom_ui_bindings.cc ('K') | « webkit/glue/cpp_variant.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/cpp_variant.cc
diff --git a/webkit/glue/cpp_variant.cc b/webkit/glue/cpp_variant.cc
index eca554bcafe0a37e51b758de96fc5b4c35363fe1..090355cda2f08be7195336b12b98732215c22b5d 100644
--- a/webkit/glue/cpp_variant.cc
+++ b/webkit/glue/cpp_variant.cc
@@ -252,6 +252,46 @@ std::vector<std::string> CppVariant::ToStringVector() const {
return string_vector;
}
+std::vector<CppVariant> CppVariant::ToVector() const {
+ DCHECK(isObject());
evanm 2011/01/25 18:24:56 two space tabs
arv (Not doing code reviews) 2011/01/26 00:50:32 Done.
+ 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.
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
+ 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/renderer/dom_ui_bindings.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