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

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: Addressed comments. 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
« no previous file with comments | « no previous file | ios/web/web_state/ui/web_view_js_utils_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..78ce1d861694ff252cc6eaa73f6282b25d8e678e 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> dictionary =
+ base::MakeUnique<base::DictionaryValue>();
+ for (id key in wk_result) {
+ DCHECK([key respondsToSelector:@selector(UTF8String)]);
+ const std::string& path([key UTF8String]);
Eugene But (OOO till 7-30) 2016/09/09 15:26:21 Please use sys_string_conversions instead of |UTF8
jif-google 2016/09/09 17:54:45 Acknowledged.
Eugene But (OOO till 7-30) 2016/09/09 18:28:57 [key UTF8String] may return nil, which will crash
+ dictionary->Set(path,
+ ValueResultFromWKResult([wk_result objectForKey:key]));
Eugene But (OOO till 7-30) 2016/09/09 15:26:21 This JSON is coming from internet, which means tha
jif-google 2016/09/09 17:54:45 When does the JSON come from the internet?
Eugene But (OOO till 7-30) 2016/09/09 18:28:57 wk_result is the result of script evaluation, for
+ }
+ result = std::move(dictionary);
} 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698