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_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "chrome/browser/chromeos/login/oobe_screen.h" | 17 #include "chrome/browser/chromeos/login/oobe_screen.h" |
18 #include "chrome/browser/chromeos/settings/shutdown_policy_handler.h" | 18 #include "chrome/browser/chromeos/settings/shutdown_policy_handler.h" |
| 19 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h" |
19 #include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h" | 20 #include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h" |
20 #include "content/public/browser/web_ui_controller.h" | 21 #include "content/public/browser/web_ui_controller.h" |
21 | 22 |
22 namespace ash { | 23 namespace ash { |
23 class ScreenDimmer; | 24 class ScreenDimmer; |
24 } | 25 } |
25 | 26 |
26 namespace base { | 27 namespace base { |
27 class DictionaryValue; | 28 class DictionaryValue; |
28 } // namespace base | 29 } // namespace base |
29 | 30 |
30 namespace chromeos { | 31 namespace chromeos { |
31 class AppLaunchSplashScreenActor; | 32 class AppLaunchSplashScreenActor; |
32 class ArcKioskSplashScreenActor; | 33 class ArcKioskSplashScreenActor; |
33 class ArcTermsOfServiceScreenActor; | 34 class ArcTermsOfServiceScreenActor; |
34 class AutoEnrollmentCheckScreenActor; | 35 class AutoEnrollmentCheckScreenActor; |
35 class BaseScreenHandler; | |
36 class ControllerPairingScreenActor; | 36 class ControllerPairingScreenActor; |
37 class CoreOobeActor; | 37 class CoreOobeActor; |
38 class DeviceDisabledScreenActor; | 38 class DeviceDisabledScreenActor; |
39 class EnableDebuggingScreenActor; | 39 class EnableDebuggingScreenActor; |
40 class EnrollmentScreenActor; | 40 class EnrollmentScreenActor; |
41 class EulaView; | 41 class EulaView; |
42 class ErrorScreen; | 42 class ErrorScreen; |
43 class ErrorScreenHandler; | 43 class ErrorScreenHandler; |
44 class GaiaScreenHandler; | 44 class GaiaScreenHandler; |
45 class HIDDetectionView; | 45 class HIDDetectionView; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 159 } |
160 | 160 |
161 NetworkStateInformer* network_state_informer_for_test() const { | 161 NetworkStateInformer* network_state_informer_for_test() const { |
162 return network_state_informer_.get(); | 162 return network_state_informer_.get(); |
163 } | 163 } |
164 | 164 |
165 // Does ReloadContent() if needed (for example, if material design mode has | 165 // Does ReloadContent() if needed (for example, if material design mode has |
166 // changed). | 166 // changed). |
167 void UpdateLocalizedStringsIfNeeded(); | 167 void UpdateLocalizedStringsIfNeeded(); |
168 | 168 |
| 169 // Executes javascript calls that were deferred while the instance was not |
| 170 // initialized yet. |
| 171 void ExecuteDeferredJSCalls(); |
| 172 |
| 173 // Calls javascript method if the instance is already initialized, or defers |
| 174 // the call until it gets initialized. |
| 175 template <typename... Args> |
| 176 void CallJSOrDefer(const std::string& function_name, |
| 177 BaseScreenHandler* screen_handler, |
| 178 const Args&... args) { |
| 179 if (is_initialized_) { |
| 180 screen_handler->CallJS(function_name, args...); |
| 181 } else { |
| 182 // Note that std::conditional is used here in order to obtain a sequence |
| 183 // of base::Value types with the length equal to sizeof...(Args); the C++ |
| 184 // template parameter pack expansion rules require that the name of the |
| 185 // parameter pack appears in the pattern, even though the elements of the |
| 186 // Args pack are not actually in this code. |
| 187 deferred_js_calls_.push_back(base::Bind( |
| 188 &OobeUI::ExecuteDeferredJSCall< |
| 189 typename std::conditional<true, base::Value, Args>::type...>, |
| 190 base::Unretained(this), function_name, screen_handler, |
| 191 base::Passed(::login::MakeValue(args).CreateDeepCopy())...)); |
| 192 } |
| 193 } |
| 194 |
169 private: | 195 private: |
| 196 // Calls javascript method. |
| 197 // |
| 198 // Note that the Args template parameter pack should consist of types |
| 199 // convertible to base::Value. |
| 200 template <typename... Args> |
| 201 void ExecuteDeferredJSCall(const std::string& function_name, |
| 202 BaseScreenHandler* screen_handler, |
| 203 std::unique_ptr<Args>... args) { |
| 204 screen_handler->CallJS(function_name, *args...); |
| 205 } |
| 206 |
170 void AddScreenHandler(std::unique_ptr<BaseScreenHandler> handler); | 207 void AddScreenHandler(std::unique_ptr<BaseScreenHandler> handler); |
171 | 208 |
172 // CoreOobeHandler::Delegate implementation: | 209 // CoreOobeHandler::Delegate implementation: |
173 void OnCurrentScreenChanged(OobeScreen screen) override; | 210 void OnCurrentScreenChanged(OobeScreen screen) override; |
174 | 211 |
175 // Type of UI. | 212 // Type of UI. |
176 std::string display_type_; | 213 std::string display_type_; |
177 | 214 |
178 // Reference to NetworkStateInformer that handles changes in network | 215 // Reference to NetworkStateInformer that handles changes in network |
179 // state. | 216 // state. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 std::vector<base::Closure> ready_callbacks_; | 288 std::vector<base::Closure> ready_callbacks_; |
252 | 289 |
253 // List of registered observers. | 290 // List of registered observers. |
254 base::ObserverList<Observer> observer_list_; | 291 base::ObserverList<Observer> observer_list_; |
255 | 292 |
256 // Observer of CrosSettings watching the kRebootOnShutdown policy. | 293 // Observer of CrosSettings watching the kRebootOnShutdown policy. |
257 std::unique_ptr<ShutdownPolicyHandler> shutdown_policy_handler_; | 294 std::unique_ptr<ShutdownPolicyHandler> shutdown_policy_handler_; |
258 | 295 |
259 std::unique_ptr<ash::ScreenDimmer> screen_dimmer_; | 296 std::unique_ptr<ash::ScreenDimmer> screen_dimmer_; |
260 | 297 |
| 298 // Whether the instance is initialized. |
| 299 // |
| 300 // The instance becomes initialized after the corresponding message is |
| 301 // received from javascript side. |
| 302 bool is_initialized_ = false; |
| 303 |
| 304 // Javascript calls that have been deferred while the instance was not |
| 305 // initialized yet. |
| 306 std::vector<base::Closure> deferred_js_calls_; |
| 307 |
261 DISALLOW_COPY_AND_ASSIGN(OobeUI); | 308 DISALLOW_COPY_AND_ASSIGN(OobeUI); |
262 }; | 309 }; |
263 | 310 |
264 } // namespace chromeos | 311 } // namespace chromeos |
265 | 312 |
266 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_ | 313 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_ |
OLD | NEW |