OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ios/web/web_state/ui/web_view_js_utils.h" | 5 #import "ios/web/web_state/ui/web_view_js_utils.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 DCHECK(result->IsType(base::Value::TYPE_BOOLEAN)); | 43 DCHECK(result->IsType(base::Value::TYPE_BOOLEAN)); |
44 } else if (result_type == CFNullGetTypeID()) { | 44 } else if (result_type == CFNullGetTypeID()) { |
45 result = base::Value::CreateNullValue(); | 45 result = base::Value::CreateNullValue(); |
46 DCHECK(result->IsType(base::Value::TYPE_NULL)); | 46 DCHECK(result->IsType(base::Value::TYPE_NULL)); |
47 } else if (result_type == CFDictionaryGetTypeID()) { | 47 } else if (result_type == CFDictionaryGetTypeID()) { |
48 std::unique_ptr<base::DictionaryValue> dictionary = | 48 std::unique_ptr<base::DictionaryValue> dictionary = |
49 base::MakeUnique<base::DictionaryValue>(); | 49 base::MakeUnique<base::DictionaryValue>(); |
50 for (id key in wk_result) { | 50 for (id key in wk_result) { |
51 NSString* obj_c_string = base::mac::ObjCCast<NSString>(key); | 51 NSString* obj_c_string = base::mac::ObjCCast<NSString>(key); |
52 const std::string path = base::SysNSStringToUTF8(obj_c_string); | 52 const std::string path = base::SysNSStringToUTF8(obj_c_string); |
53 std::unique_ptr<base::Value> value = ValueResultFromWKResult( | 53 std::unique_ptr<base::Value> value = |
54 [wk_result objectForKey:obj_c_string], max_depth - 1); | 54 ValueResultFromWKResult(wk_result[obj_c_string], max_depth - 1); |
55 if (value) { | 55 if (value) { |
56 dictionary->Set(path, std::move(value)); | 56 dictionary->Set(path, std::move(value)); |
57 } | 57 } |
58 } | 58 } |
59 result = std::move(dictionary); | 59 result = std::move(dictionary); |
| 60 } else if (result_type == CFArrayGetTypeID()) { |
| 61 std::unique_ptr<base::ListValue> list = base::MakeUnique<base::ListValue>(); |
| 62 for (id list_item in wk_result) { |
| 63 std::unique_ptr<base::Value> value = |
| 64 ValueResultFromWKResult(list_item, max_depth - 1); |
| 65 if (value) { |
| 66 list->Append(std::move(value)); |
| 67 } |
| 68 } |
| 69 result = std::move(list); |
60 } else { | 70 } else { |
61 NOTREACHED(); // Convert other types as needed. | 71 NOTREACHED(); // Convert other types as needed. |
62 } | 72 } |
63 return result; | 73 return result; |
64 } | 74 } |
65 | 75 |
66 } // namespace | 76 } // namespace |
67 | 77 |
68 namespace web { | 78 namespace web { |
69 | 79 |
(...skipping 18 matching lines...) Expand all Loading... |
88 userInfo:@{NSLocalizedDescriptionKey : error_message}]); | 98 userInfo:@{NSLocalizedDescriptionKey : error_message}]); |
89 completion_handler(nil, error); | 99 completion_handler(nil, error); |
90 }); | 100 }); |
91 return; | 101 return; |
92 } | 102 } |
93 | 103 |
94 [web_view evaluateJavaScript:script completionHandler:completion_handler]; | 104 [web_view evaluateJavaScript:script completionHandler:completion_handler]; |
95 } | 105 } |
96 | 106 |
97 } // namespace web | 107 } // namespace web |
OLD | NEW |