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

Unified Diff: ios/web/web_state/ui/web_view_js_utils.mm

Issue 2275513002: Support having javascript return dictionaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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: ios/web/web_state/ui/web_view_js_utils.mm
diff --git a/ios/web/web_state/ui/web_view_js_utils.mm b/ios/web/web_state/ui/web_view_js_utils.mm
index 48d65aac362036905e388e4e92a6f1bf3284afbb..36f0cb4a65a3e43ebed9fa4eecc76cec1c50727f 100644
--- a/ios/web/web_state/ui/web_view_js_utils.mm
+++ b/ios/web/web_state/ui/web_view_js_utils.mm
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/mac/scoped_nsobject.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/values.h"
@@ -62,6 +63,16 @@ std::unique_ptr<base::Value> ValueResultFromWKResult(id wk_result) {
} else if (result_type == CFNullGetTypeID()) {
result = base::Value::CreateNullValue();
DCHECK(result->IsType(base::Value::TYPE_NULL));
+ } else if (result_type == CFDictionaryGetTypeID()) {
+ std::unique_ptr<base::DictionaryValue> dictionnary =
marq (ping after 24h) 2016/08/23 12:28:26 Spelling: "dictionary".
jif 2016/08/23 12:59:12 Done.
+ base::MakeUnique<base::DictionaryValue>();
+ for (id key in wk_result) {
+ DCHECK([key respondsToSelector:@selector(UTF8String)]);
+ const std::string& path([key UTF8String]);
+ dictionnary->Set(path,
+ ValueResultFromWKResult([wk_result objectForKey:key]));
+ }
+ result = std::move(dictionnary);
} else {
NOTREACHED(); // Convert other types as needed.
}
« no previous file with comments | « no previous file | ios/web/web_state/ui/web_view_js_utils_unittest.mm » ('j') | ios/web/web_state/ui/web_view_js_utils_unittest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698