| 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h" | 14 #include "components/login/base_screen_handler_utils.h" |
| 15 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
| 16 #include "content/public/browser/web_ui_message_handler.h" | 16 #include "content/public/browser/web_ui_message_handler.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class DictionaryValue; | 20 class DictionaryValue; |
| 21 class ListValue; | 21 class ListValue; |
| 22 class Value; | 22 class Value; |
| 23 } | 23 } |
| 24 | 24 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Subclasses can override these methods to pass additional parameters | 108 // Subclasses can override these methods to pass additional parameters |
| 109 // to loadTimeData. Generally, it is a bad approach, and it should be replaced | 109 // to loadTimeData. Generally, it is a bad approach, and it should be replaced |
| 110 // with Context at some point. | 110 // with Context at some point. |
| 111 virtual void GetAdditionalParameters(base::DictionaryValue* parameters); | 111 virtual void GetAdditionalParameters(base::DictionaryValue* parameters); |
| 112 | 112 |
| 113 // Shortcut for calling JS methods on WebUI side. | 113 // Shortcut for calling JS methods on WebUI side. |
| 114 void CallJS(const std::string& method); | 114 void CallJS(const std::string& method); |
| 115 | 115 |
| 116 template<typename A1> | 116 template<typename A1> |
| 117 void CallJS(const std::string& method, const A1& arg1) { | 117 void CallJS(const std::string& method, const A1& arg1) { |
| 118 web_ui()->CallJavascriptFunction(FullMethodPath(method), MakeValue(arg1)); | 118 web_ui()->CallJavascriptFunction(FullMethodPath(method), |
| 119 ::login::MakeValue(arg1)); |
| 119 } | 120 } |
| 120 | 121 |
| 121 template<typename A1, typename A2> | 122 template<typename A1, typename A2> |
| 122 void CallJS(const std::string& method, const A1& arg1, const A2& arg2) { | 123 void CallJS(const std::string& method, const A1& arg1, const A2& arg2) { |
| 123 web_ui()->CallJavascriptFunction(FullMethodPath(method), MakeValue(arg1), | 124 web_ui()->CallJavascriptFunction(FullMethodPath(method), |
| 124 MakeValue(arg2)); | 125 ::login::MakeValue(arg1), |
| 126 ::login::MakeValue(arg2)); |
| 125 } | 127 } |
| 126 | 128 |
| 127 template<typename A1, typename A2, typename A3> | 129 template<typename A1, typename A2, typename A3> |
| 128 void CallJS(const std::string& method, | 130 void CallJS(const std::string& method, |
| 129 const A1& arg1, | 131 const A1& arg1, |
| 130 const A2& arg2, | 132 const A2& arg2, |
| 131 const A3& arg3) { | 133 const A3& arg3) { |
| 132 web_ui()->CallJavascriptFunction(FullMethodPath(method), | 134 web_ui()->CallJavascriptFunction(FullMethodPath(method), |
| 133 MakeValue(arg1), | 135 ::login::MakeValue(arg1), |
| 134 MakeValue(arg2), | 136 ::login::MakeValue(arg2), |
| 135 MakeValue(arg3)); | 137 ::login::MakeValue(arg3)); |
| 136 } | 138 } |
| 137 | 139 |
| 138 template<typename A1, typename A2, typename A3, typename A4> | 140 template<typename A1, typename A2, typename A3, typename A4> |
| 139 void CallJS(const std::string& method, | 141 void CallJS(const std::string& method, |
| 140 const A1& arg1, | 142 const A1& arg1, |
| 141 const A2& arg2, | 143 const A2& arg2, |
| 142 const A3& arg3, | 144 const A3& arg3, |
| 143 const A4& arg4) { | 145 const A4& arg4) { |
| 144 web_ui()->CallJavascriptFunction(FullMethodPath(method), | 146 web_ui()->CallJavascriptFunction(FullMethodPath(method), |
| 145 MakeValue(arg1), | 147 ::login::MakeValue(arg1), |
| 146 MakeValue(arg2), | 148 ::login::MakeValue(arg2), |
| 147 MakeValue(arg3), | 149 ::login::MakeValue(arg3), |
| 148 MakeValue(arg4)); | 150 ::login::MakeValue(arg4)); |
| 149 } | 151 } |
| 150 | 152 |
| 151 // Shortcut methods for adding WebUI callbacks. | 153 // Shortcut methods for adding WebUI callbacks. |
| 152 template<typename T> | 154 template<typename T> |
| 153 void AddRawCallback(const std::string& name, | 155 void AddRawCallback(const std::string& name, |
| 154 void (T::*method)(const base::ListValue* args)) { | 156 void (T::*method)(const base::ListValue* args)) { |
| 155 web_ui()->RegisterMessageCallback( | 157 web_ui()->RegisterMessageCallback( |
| 156 name, | 158 name, |
| 157 base::Bind(method, base::Unretained(static_cast<T*>(this)))); | 159 base::Bind(method, base::Unretained(static_cast<T*>(this)))); |
| 158 } | 160 } |
| 159 | 161 |
| 160 template<typename T> | 162 template<typename T> |
| 161 void AddCallback(const std::string& name, void (T::*method)()) { | 163 void AddCallback(const std::string& name, void (T::*method)()) { |
| 162 base::Callback<void()> callback = | 164 base::Callback<void()> callback = |
| 163 base::Bind(method, base::Unretained(static_cast<T*>(this))); | 165 base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| 164 web_ui()->RegisterMessageCallback( | 166 web_ui()->RegisterMessageCallback( |
| 165 name, base::Bind(&CallbackWrapper0, callback)); | 167 name, base::Bind(&::login::CallbackWrapper0, callback)); |
| 166 } | 168 } |
| 167 | 169 |
| 168 template<typename T, typename A1> | 170 template<typename T, typename A1> |
| 169 void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) { | 171 void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) { |
| 170 base::Callback<void(A1)> callback = | 172 base::Callback<void(A1)> callback = |
| 171 base::Bind(method, base::Unretained(static_cast<T*>(this))); | 173 base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| 172 web_ui()->RegisterMessageCallback( | 174 web_ui()->RegisterMessageCallback( |
| 173 name, base::Bind(&CallbackWrapper1<A1>, callback)); | 175 name, base::Bind(&::login::CallbackWrapper1<A1>, callback)); |
| 174 } | 176 } |
| 175 | 177 |
| 176 template<typename T, typename A1, typename A2> | 178 template<typename T, typename A1, typename A2> |
| 177 void AddCallback(const std::string& name, | 179 void AddCallback(const std::string& name, |
| 178 void (T::*method)(A1 arg1, A2 arg2)) { | 180 void (T::*method)(A1 arg1, A2 arg2)) { |
| 179 base::Callback<void(A1, A2)> callback = | 181 base::Callback<void(A1, A2)> callback = |
| 180 base::Bind(method, base::Unretained(static_cast<T*>(this))); | 182 base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| 181 web_ui()->RegisterMessageCallback( | 183 web_ui()->RegisterMessageCallback( |
| 182 name, base::Bind(&CallbackWrapper2<A1, A2>, callback)); | 184 name, base::Bind(&::login::CallbackWrapper2<A1, A2>, callback)); |
| 183 } | 185 } |
| 184 | 186 |
| 185 template<typename T, typename A1, typename A2, typename A3> | 187 template<typename T, typename A1, typename A2, typename A3> |
| 186 void AddCallback(const std::string& name, | 188 void AddCallback(const std::string& name, |
| 187 void (T::*method)(A1 arg1, A2 arg2, A3 arg3)) { | 189 void (T::*method)(A1 arg1, A2 arg2, A3 arg3)) { |
| 188 base::Callback<void(A1, A2, A3)> callback = | 190 base::Callback<void(A1, A2, A3)> callback = |
| 189 base::Bind(method, base::Unretained(static_cast<T*>(this))); | 191 base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| 190 web_ui()->RegisterMessageCallback( | 192 web_ui()->RegisterMessageCallback( |
| 191 name, base::Bind(&CallbackWrapper3<A1, A2, A3>, callback)); | 193 name, base::Bind(&::login::CallbackWrapper3<A1, A2, A3>, callback)); |
| 192 } | 194 } |
| 193 | 195 |
| 194 template<typename T, typename A1, typename A2, typename A3, typename A4> | 196 template<typename T, typename A1, typename A2, typename A3, typename A4> |
| 195 void AddCallback(const std::string& name, | 197 void AddCallback(const std::string& name, |
| 196 void (T::*method)(A1 arg1, A2 arg2, A3 arg3, A4 arg4)) { | 198 void (T::*method)(A1 arg1, A2 arg2, A3 arg3, A4 arg4)) { |
| 197 base::Callback<void(A1, A2, A3, A4)> callback = | 199 base::Callback<void(A1, A2, A3, A4)> callback = |
| 198 base::Bind(method, base::Unretained(static_cast<T*>(this))); | 200 base::Bind(method, base::Unretained(static_cast<T*>(this))); |
| 199 web_ui()->RegisterMessageCallback( | 201 web_ui()->RegisterMessageCallback( |
| 200 name, base::Bind(&CallbackWrapper4<A1, A2, A3, A4>, callback)); | 202 name, base::Bind(&::login::CallbackWrapper4<A1, A2, A3, A4>, callback)); |
| 201 } | 203 } |
| 202 | 204 |
| 203 template <typename Method> | 205 template <typename Method> |
| 204 void AddPrefixedCallback(const std::string& unprefixed_name, | 206 void AddPrefixedCallback(const std::string& unprefixed_name, |
| 205 const Method& method) { | 207 const Method& method) { |
| 206 AddCallback(FullMethodPath(unprefixed_name), method); | 208 AddCallback(FullMethodPath(unprefixed_name), method); |
| 207 } | 209 } |
| 208 | 210 |
| 209 // Called when the page is ready and handler can do initialization. | 211 // Called when the page is ready and handler can do initialization. |
| 210 virtual void Initialize() = 0; | 212 virtual void Initialize() = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 238 // non empty value, the Initialize will be deferred until the underlying load | 240 // non empty value, the Initialize will be deferred until the underlying load |
| 239 // is finished. | 241 // is finished. |
| 240 std::string async_assets_load_id_; | 242 std::string async_assets_load_id_; |
| 241 | 243 |
| 242 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); | 244 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); |
| 243 }; | 245 }; |
| 244 | 246 |
| 245 } // namespace chromeos | 247 } // namespace chromeos |
| 246 | 248 |
| 247 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 249 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
| OLD | NEW |