OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 6 #define CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 } | 70 } |
71 }; | 71 }; |
72 | 72 |
73 namespace javascript_utils { | 73 namespace javascript_utils { |
74 | 74 |
75 // Converts |arg| to a JSON string. | 75 // Converts |arg| to a JSON string. |
76 template <typename T> | 76 template <typename T> |
77 std::string JSONStringify(const T& arg) { | 77 std::string JSONStringify(const T& arg) { |
78 std::string javascript; | 78 std::string javascript; |
79 scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValueFrom(arg)); | 79 scoped_ptr<Value> value(ValueConversionTraits<T>::CreateValueFrom(arg)); |
80 base::JSONWriter::Write(value.get(), false, &javascript); | 80 base::JSONWriter::Write(value.get(), &javascript); |
81 return javascript; | 81 return javascript; |
82 } | 82 } |
83 | 83 |
84 // Converts |arg| to a JSON string and returns a string formatted as | 84 // Converts |arg| to a JSON string and returns a string formatted as |
85 // |format| specifies. |format| should only expect string arguments. | 85 // |format| specifies. |format| should only expect string arguments. |
86 template <typename T> | 86 template <typename T> |
87 std::string JavaScriptPrintf(const std::string& format, const T& arg) { | 87 std::string JavaScriptPrintf(const std::string& format, const T& arg) { |
88 return base::StringPrintf(format.c_str(), JSONStringify(arg).c_str()); | 88 return base::StringPrintf(format.c_str(), JSONStringify(arg).c_str()); |
89 } | 89 } |
90 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
103 const T2& arg2, const T3& arg3) { | 103 const T2& arg2, const T3& arg3) { |
104 return base::StringPrintf(format.c_str(), | 104 return base::StringPrintf(format.c_str(), |
105 JSONStringify(arg1).c_str(), | 105 JSONStringify(arg1).c_str(), |
106 JSONStringify(arg2).c_str(), | 106 JSONStringify(arg2).c_str(), |
107 JSONStringify(arg3).c_str()); | 107 JSONStringify(arg3).c_str()); |
108 } | 108 } |
109 | 109 |
110 } // namespace javascript_utils | 110 } // namespace javascript_utils |
111 | 111 |
112 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ | 112 #endif // CHROME_TEST_AUTOMATION_JAVASCRIPT_MESSAGE_UTILS_H_ |
OLD | NEW |