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 "ui/gfx/point.h"
20 class PrefRegistrySimple;
27 struct NetworkScreenHandlerOnLanguageChangedCallbackData;
29 // WebUI implementation of NetworkScreenActor. It is used to interact with
30 // the welcome screen (part of the page) of the OOBE.
31 class NetworkScreenHandler : public NetworkScreenActor,
32 public BaseScreenHandler,
33 public ComponentExtensionIMEManager::Observer {
35 explicit NetworkScreenHandler(CoreOobeActor* core_oobe_actor);
36 virtual ~NetworkScreenHandler();
38 // NetworkScreenActor implementation:
39 virtual void SetDelegate(NetworkScreenActor::Delegate* screen) OVERRIDE;
40 virtual void PrepareToShow() OVERRIDE;
41 virtual void Show() OVERRIDE;
42 virtual void Hide() OVERRIDE;
43 virtual void ShowError(const base::string16& message) OVERRIDE;
44 virtual void ClearErrors() OVERRIDE;
45 virtual void ShowConnectingStatus(bool connecting,
46 const base::string16& network_id) OVERRIDE;
47 virtual void EnableContinue(bool enabled) OVERRIDE;
49 // BaseScreenHandler implementation:
50 virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
51 virtual void GetAdditionalParameters(base::DictionaryValue* dict) OVERRIDE;
52 virtual void Initialize() OVERRIDE;
54 // WebUIMessageHandler implementation:
55 virtual void RegisterMessages() OVERRIDE;
57 // ComponentExtensionIMEManager::Observer implementation:
58 virtual void OnImeComponentExtensionInitialized() OVERRIDE;
60 // Registers the preference for derelict state.
61 static void RegisterPrefs(PrefRegistrySimple* registry);
63 // Reloads localized contents.
64 void ReloadLocalizedContent();
67 // Handles moving off the screen.
70 // Handles change of the language.
71 void HandleOnLanguageChanged(const std::string& locale);
73 // Async callback after ReloadResourceBundle(locale) completed.
74 static void OnLanguageChangedCallback(
75 scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context,
76 const std::string& requested_locale,
77 const std::string& loaded_locale,
80 // Handles change of the input method.
81 void HandleOnInputMethodChanged(const std::string& id);
83 // Handles change of the time zone
84 void HandleOnTimezoneChanged(const std::string& timezone);
86 // Callback when the system timezone settings is changed.
87 void OnSystemTimezoneChanged();
89 // Demo mode detection methods.
90 void StartIdleDetection();
91 void StartOobeTimer();
93 void OnOobeTimerUpdate();
97 // Returns available languages. Caller gets the ownership. Note, it does
98 // depend on the current locale.
99 static base::ListValue* GetLanguageList();
101 // Returns available input methods. Caller gets the ownership. Note, it does
102 // depend on the current locale.
103 static base::ListValue* GetInputMethods();
105 // Returns available timezones. Caller gets the ownership.
106 static base::ListValue* GetTimezoneList();
108 NetworkScreenActor::Delegate* screen_;
109 CoreOobeActor* core_oobe_actor_;
111 bool is_continue_enabled_;
113 // Total time this machine has spent on OOBE.
114 base::TimeDelta time_on_oobe_;
116 // Keeps whether screen should be shown right after initialization.
119 // Position of the network control.
120 gfx::Point network_control_pos_;
122 scoped_ptr<CrosSettings::ObserverSubscription> timezone_subscription_;
124 scoped_ptr<IdleDetector> idle_detector_;
126 base::RepeatingTimer<NetworkScreenHandler> oobe_timer_;
128 // Timeout to detect if the machine is in a derelict state.
129 base::TimeDelta derelict_detection_timeout_;
131 // Timeout before showing our demo app if the machine is in a derelict state.
132 base::TimeDelta derelict_idle_timeout_;
134 // Time between updating our total time on oobe.
135 base::TimeDelta oobe_timer_update_interval_;
137 // True if should reinitialize language and keyboard list once the page
139 bool should_reinitialize_language_keyboard_list_;
141 base::WeakPtrFactory<NetworkScreenHandler> weak_ptr_factory_;
143 DISALLOW_COPY_AND_ASSIGN(NetworkScreenHandler);
146 } // namespace chromeos
148 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_