| 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 15 matching lines...) Expand all Loading... |
| 26 std::unique_ptr<base::Value> result; | 26 std::unique_ptr<base::Value> result; |
| 27 | 27 |
| 28 if (max_depth < 0) { | 28 if (max_depth < 0) { |
| 29 DLOG(WARNING) << "JS maximum recursion depth exceeded."; | 29 DLOG(WARNING) << "JS maximum recursion depth exceeded."; |
| 30 return result; | 30 return result; |
| 31 } | 31 } |
| 32 | 32 |
| 33 CFTypeID result_type = CFGetTypeID(wk_result); | 33 CFTypeID result_type = CFGetTypeID(wk_result); |
| 34 if (result_type == CFStringGetTypeID()) { | 34 if (result_type == CFStringGetTypeID()) { |
| 35 result.reset(new base::StringValue(base::SysNSStringToUTF16(wk_result))); | 35 result.reset(new base::StringValue(base::SysNSStringToUTF16(wk_result))); |
| 36 DCHECK(result->IsType(base::Value::TYPE_STRING)); | 36 DCHECK(result->IsType(base::Value::Type::STRING)); |
| 37 } else if (result_type == CFNumberGetTypeID()) { | 37 } else if (result_type == CFNumberGetTypeID()) { |
| 38 result.reset(new base::FundamentalValue([wk_result doubleValue])); | 38 result.reset(new base::FundamentalValue([wk_result doubleValue])); |
| 39 DCHECK(result->IsType(base::Value::TYPE_DOUBLE)); | 39 DCHECK(result->IsType(base::Value::Type::DOUBLE)); |
| 40 } else if (result_type == CFBooleanGetTypeID()) { | 40 } else if (result_type == CFBooleanGetTypeID()) { |
| 41 result.reset( | 41 result.reset( |
| 42 new base::FundamentalValue(static_cast<bool>([wk_result boolValue]))); | 42 new base::FundamentalValue(static_cast<bool>([wk_result boolValue]))); |
| 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::NONE)); |
| 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 = | 53 std::unique_ptr<base::Value> value = |
| 54 ValueResultFromWKResult(wk_result[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)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 userInfo:@{NSLocalizedDescriptionKey : error_message}]); | 98 userInfo:@{NSLocalizedDescriptionKey : error_message}]); |
| 99 completion_handler(nil, error); | 99 completion_handler(nil, error); |
| 100 }); | 100 }); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 | 103 |
| 104 [web_view evaluateJavaScript:script completionHandler:completion_handler]; | 104 [web_view evaluateJavaScript:script completionHandler:completion_handler]; |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // namespace web | 107 } // namespace web |
| OLD | NEW |