| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/public/browser/web_ui_message_handler.h" | 5 #include "content/public/browser/web_ui_message_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 | 11 |
| 12 namespace content { | 12 namespace content { |
| 13 | 13 |
| 14 bool WebUIMessageHandler::ExtractIntegerValue(const ListValue* value, | 14 bool WebUIMessageHandler::ExtractIntegerValue(const base::ListValue* value, |
| 15 int* out_int) { | 15 int* out_int) { |
| 16 std::string string_value; | 16 std::string string_value; |
| 17 if (value->GetString(0, &string_value)) | 17 if (value->GetString(0, &string_value)) |
| 18 return base::StringToInt(string_value, out_int); | 18 return base::StringToInt(string_value, out_int); |
| 19 double double_value; | 19 double double_value; |
| 20 if (value->GetDouble(0, &double_value)) { | 20 if (value->GetDouble(0, &double_value)) { |
| 21 *out_int = static_cast<int>(double_value); | 21 *out_int = static_cast<int>(double_value); |
| 22 return true; | 22 return true; |
| 23 } | 23 } |
| 24 NOTREACHED(); | 24 NOTREACHED(); |
| 25 return false; | 25 return false; |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool WebUIMessageHandler::ExtractDoubleValue(const ListValue* value, | 28 bool WebUIMessageHandler::ExtractDoubleValue(const base::ListValue* value, |
| 29 double* out_value) { | 29 double* out_value) { |
| 30 std::string string_value; | 30 std::string string_value; |
| 31 if (value->GetString(0, &string_value)) | 31 if (value->GetString(0, &string_value)) |
| 32 return base::StringToDouble(string_value, out_value); | 32 return base::StringToDouble(string_value, out_value); |
| 33 if (value->GetDouble(0, out_value)) | 33 if (value->GetDouble(0, out_value)) |
| 34 return true; | 34 return true; |
| 35 NOTREACHED(); | 35 NOTREACHED(); |
| 36 return false; | 36 return false; |
| 37 } | 37 } |
| 38 | 38 |
| 39 base::string16 WebUIMessageHandler::ExtractStringValue(const ListValue* value) { | 39 base::string16 WebUIMessageHandler::ExtractStringValue( |
| 40 const base::ListValue* value) { |
| 40 base::string16 string16_value; | 41 base::string16 string16_value; |
| 41 if (value->GetString(0, &string16_value)) | 42 if (value->GetString(0, &string16_value)) |
| 42 return string16_value; | 43 return string16_value; |
| 43 NOTREACHED(); | 44 NOTREACHED(); |
| 44 return base::string16(); | 45 return base::string16(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace content | 48 } // namespace content |
| OLD | NEW |