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/string16.h" | 13 #include "base/string16.h" |
14 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler_utils.h" | |
13 #include "content/public/browser/web_ui.h" | 15 #include "content/public/browser/web_ui.h" |
14 #include "content/public/browser/web_ui_message_handler.h" | 16 #include "content/public/browser/web_ui_message_handler.h" |
15 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class DictionaryValue; | 20 class DictionaryValue; |
19 class ListValue; | 21 class ListValue; |
20 class Value; | 22 class Value; |
21 } | 23 } |
22 | 24 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 void CallJS(const std::string& method, | 100 void CallJS(const std::string& method, |
99 const base::Value& arg1, | 101 const base::Value& arg1, |
100 const base::Value& arg2, | 102 const base::Value& arg2, |
101 const base::Value& arg3); | 103 const base::Value& arg3); |
102 void CallJS(const std::string& method, | 104 void CallJS(const std::string& method, |
103 const base::Value& arg1, | 105 const base::Value& arg1, |
104 const base::Value& arg2, | 106 const base::Value& arg2, |
105 const base::Value& arg3, | 107 const base::Value& arg3, |
106 const base::Value& arg4); | 108 const base::Value& arg4); |
107 | 109 |
108 // Shortcut method for adding WebUI callbacks. | 110 // Shortcut methods for adding WebUI callbacks. |
109 template<typename T> | 111 template<typename T> |
110 void AddCallback(const std::string& name, | 112 void AddCallback(const std::string& name, |
Denis Kuznetsov (DE-MUC)
2013/04/17 08:32:26
As now we have fast and nice way to unwrap paramet
ygorshenin1
2013/04/17 10:06:34
Great idea, Done.
On 2013/04/17 08:32:26, Denis K
| |
111 void (T::*callback)(const base::ListValue* args)) { | 113 void (T::*method)(const base::ListValue* args)) { |
112 web_ui()->RegisterMessageCallback(name, | 114 web_ui()->RegisterMessageCallback( |
113 base::Bind(callback, base::Unretained(static_cast<T*>(this)))); | 115 name, |
116 base::Bind(method, base::Unretained(static_cast<T*>(this)))); | |
117 } | |
118 | |
119 template<typename T> | |
120 void AddCallback(const std::string& name, void (T::*method)()) { | |
121 base::Callback<void()> callback = | |
122 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
123 web_ui()->RegisterMessageCallback( | |
124 name, base::Bind(&CallbackWrapper0, callback)); | |
125 } | |
126 | |
127 template<typename T, typename A1> | |
128 void AddCallback(const std::string& name, void (T::*method)(A1 arg1)) { | |
129 base::Callback<void(A1)> callback = | |
130 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
131 web_ui()->RegisterMessageCallback( | |
132 name, base::Bind(&CallbackWrapper1<A1>, callback)); | |
133 } | |
134 | |
135 template<typename T, typename A1, typename A2> | |
136 void AddCallback(const std::string& name, | |
137 void (T::*method)(A1 arg1, A2 arg2)) { | |
138 base::Callback<void(A1, A2)> callback = | |
139 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
140 web_ui()->RegisterMessageCallback( | |
141 name, base::Bind(&CallbackWrapper2<A1, A2>, callback)); | |
142 } | |
143 | |
144 template<typename T, typename A1, typename A2, typename A3> | |
145 void AddCallback(const std::string& name, | |
146 void (T::*method)(A1 arg1, A2 arg2, A3 arg3)) { | |
147 base::Callback<void(A1, A2, A3)> callback = | |
148 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
149 web_ui()->RegisterMessageCallback( | |
150 name, base::Bind(&CallbackWrapper3<A1, A2, A3>, callback)); | |
151 } | |
152 | |
153 template<typename T, typename A1, typename A2, typename A3, typename A4> | |
154 void AddCallback(const std::string& name, | |
155 void (T::*method)(A1 arg1, A2 arg2, A3 arg3, A4 arg4)) { | |
156 base::Callback<void(A1, A2, A3, A4)> callback = | |
157 base::Bind(method, base::Unretained(static_cast<T*>(this))); | |
158 web_ui()->RegisterMessageCallback( | |
159 name, base::Bind(&CallbackWrapper4<A1, A2, A3, A4>, callback)); | |
114 } | 160 } |
115 | 161 |
116 // Called when the page is ready and handler can do initialization. | 162 // Called when the page is ready and handler can do initialization. |
117 virtual void Initialize() = 0; | 163 virtual void Initialize() = 0; |
118 | 164 |
119 // Show selected WebUI |screen|. Optionally it can pass screen initialization | 165 // Show selected WebUI |screen|. Optionally it can pass screen initialization |
120 // data via |data| parameter. | 166 // data via |data| parameter. |
121 void ShowScreen(const char* screen, const base::DictionaryValue* data); | 167 void ShowScreen(const char* screen, const base::DictionaryValue* data); |
122 | 168 |
123 // Whether page is ready. | 169 // Whether page is ready. |
124 bool page_is_ready() const { return page_is_ready_; } | 170 bool page_is_ready() const { return page_is_ready_; } |
125 | 171 |
126 // Returns the window which shows us. | 172 // Returns the window which shows us. |
127 virtual gfx::NativeWindow GetNativeWindow(); | 173 virtual gfx::NativeWindow GetNativeWindow(); |
128 | 174 |
129 private: | 175 private: |
130 // Keeps whether page is ready. | 176 // Keeps whether page is ready. |
131 bool page_is_ready_; | 177 bool page_is_ready_; |
132 | 178 |
133 base::DictionaryValue* localized_values_; | 179 base::DictionaryValue* localized_values_; |
134 | 180 |
135 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); | 181 DISALLOW_COPY_AND_ASSIGN(BaseScreenHandler); |
136 }; | 182 }; |
137 | 183 |
138 } // namespace chromeos | 184 } // namespace chromeos |
139 | 185 |
140 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ | 186 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_BASE_SCREEN_HANDLER_H_ |
OLD | NEW |