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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "base/timer/timer.h"
14 #include "chrome/browser/chromeos/login/screens/network_screen_actor.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
17 #include "chromeos/ime/component_extension_ime_manager.h"
18 #include "chromeos/ime/input_method_manager.h"
19 #include "ui/gfx/point.h"
21 class PrefRegistrySimple;
28 struct NetworkScreenHandlerOnLanguageChangedCallbackData;
30 // WebUI implementation of NetworkScreenActor. It is used to interact with
31 // the welcome screen (part of the page) of the OOBE.
32 class NetworkScreenHandler : public NetworkScreenActor,
33 public BaseScreenHandler,
34 public ComponentExtensionIMEManager::Observer,
35 public input_method::InputMethodManager::Observer {
37 explicit NetworkScreenHandler(CoreOobeActor* core_oobe_actor);
38 virtual ~NetworkScreenHandler();
40 // NetworkScreenActor implementation:
41 virtual void SetDelegate(NetworkScreenActor::Delegate* screen) OVERRIDE;
42 virtual void PrepareToShow() OVERRIDE;
43 virtual void Show() OVERRIDE;
44 virtual void Hide() OVERRIDE;
45 virtual void ShowError(const base::string16& message) OVERRIDE;
46 virtual void ClearErrors() OVERRIDE;
47 virtual void ShowConnectingStatus(bool connecting,
48 const base::string16& network_id) OVERRIDE;
49 virtual void EnableContinue(bool enabled) OVERRIDE;
51 // BaseScreenHandler implementation:
52 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
53 virtual void GetAdditionalParameters(base::DictionaryValue* dict) OVERRIDE;
54 virtual void Initialize() OVERRIDE;
56 // WebUIMessageHandler implementation:
57 virtual void RegisterMessages() OVERRIDE;
59 // ComponentExtensionIMEManager::Observer implementation:
60 virtual void OnImeComponentExtensionInitialized() OVERRIDE;
62 // InputMethodManager::Observer implementation:
63 virtual void InputMethodChanged(input_method::InputMethodManager* manager,
64 bool show_message) OVERRIDE;
66 // Registers the preference for derelict state.
67 static void RegisterPrefs(PrefRegistrySimple* registry);
69 // Reloads localized contents.
70 void ReloadLocalizedContent();
73 // Handles moving off the screen.
76 // Handles change of the language.
77 void HandleOnLanguageChanged(const std::string& locale);
79 // Async callback after ReloadResourceBundle(locale) completed.
80 static void OnLanguageChangedCallback(
81 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context,
82 const std::string& requested_locale,
83 const std::string& loaded_locale,
86 // Handles change of the input method.
87 void HandleOnInputMethodChanged(const std::string& id);
89 // Handles change of the time zone
90 void HandleOnTimezoneChanged(const std::string& timezone);
92 // Callback when the system timezone settings is changed.
93 void OnSystemTimezoneChanged();
95 // Demo mode detection methods.
96 void StartIdleDetection();
97 void StartOobeTimer();
99 void OnOobeTimerUpdate();
100 void SetupTimeouts();
103 // Returns available languages. Caller gets the ownership. Note, it does
104 // depend on the current locale.
105 base::ListValue* GetLanguageList();
107 // Returns available input methods. Caller gets the ownership. Note, it does
108 // depend on the current locale.
109 static base::ListValue* GetInputMethods();
111 // Returns available timezones. Caller gets the ownership.
112 static base::ListValue* GetTimezoneList();
114 NetworkScreenActor::Delegate* screen_;
115 CoreOobeActor* core_oobe_actor_;
117 bool is_continue_enabled_;
119 // Total time this machine has spent on OOBE.
120 base::TimeDelta time_on_oobe_;
122 // Keeps whether screen should be shown right after initialization.
125 // Position of the network control.
126 gfx::Point network_control_pos_;
128 scoped_ptr<CrosSettings::ObserverSubscription> timezone_subscription_;
130 scoped_ptr<IdleDetector> idle_detector_;
132 base::RepeatingTimer<NetworkScreenHandler> oobe_timer_;
134 // Timeout to detect if the machine is in a derelict state.
135 base::TimeDelta derelict_detection_timeout_;
137 // Timeout before showing our demo app if the machine is in a derelict state.
138 base::TimeDelta derelict_idle_timeout_;
140 // Time between updating our total time on oobe.
141 base::TimeDelta oobe_timer_update_interval_;
143 // True if should reinitialize language and keyboard list once the page
145 bool should_reinitialize_language_keyboard_list_;
147 // The exact language code selected by user in the menu.
148 std::string selected_language_code_;
150 base::WeakPtrFactory<NetworkScreenHandler> weak_ptr_factory_;
152 DISALLOW_COPY_AND_ASSIGN(NetworkScreenHandler);
155 } // namespace chromeos
157 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_