Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / chromeos / login / network_screen_handler.h
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.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_
7
8 #include <string>
9
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"
20
21 class PrefRegistrySimple;
22
23 namespace chromeos {
24
25 class CoreOobeActor;
26 class IdleDetector;
27
28 struct NetworkScreenHandlerOnLanguageChangedCallbackData;
29
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 {
36  public:
37   explicit NetworkScreenHandler(CoreOobeActor* core_oobe_actor);
38   virtual ~NetworkScreenHandler();
39
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;
50
51   // BaseScreenHandler implementation:
52   virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
53   virtual void GetAdditionalParameters(base::DictionaryValue* dict) OVERRIDE;
54   virtual void Initialize() OVERRIDE;
55
56   // WebUIMessageHandler implementation:
57   virtual void RegisterMessages() OVERRIDE;
58
59   // ComponentExtensionIMEManager::Observer implementation:
60   virtual void OnImeComponentExtensionInitialized() OVERRIDE;
61
62   // InputMethodManager::Observer implementation:
63   virtual void InputMethodChanged(input_method::InputMethodManager* manager,
64                                   bool show_message) OVERRIDE;
65
66   // Registers the preference for derelict state.
67   static void RegisterPrefs(PrefRegistrySimple* registry);
68
69   // Reloads localized contents.
70   void ReloadLocalizedContent();
71
72  private:
73   // Handles moving off the screen.
74   void HandleOnExit();
75
76   // Handles change of the language.
77   void HandleOnLanguageChanged(const std::string& locale);
78
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,
84       const bool success);
85
86   // Handles change of the input method.
87   void HandleOnInputMethodChanged(const std::string& id);
88
89   // Handles change of the time zone
90   void HandleOnTimezoneChanged(const std::string& timezone);
91
92   // Callback when the system timezone settings is changed.
93   void OnSystemTimezoneChanged();
94
95   // Demo mode detection methods.
96   void StartIdleDetection();
97   void StartOobeTimer();
98   void OnIdle();
99   void OnOobeTimerUpdate();
100   void SetupTimeouts();
101   bool IsDerelict();
102
103   // Returns available languages. Caller gets the ownership. Note, it does
104   // depend on the current locale.
105   base::ListValue* GetLanguageList();
106
107   // Returns available input methods. Caller gets the ownership. Note, it does
108   // depend on the current locale.
109   static base::ListValue* GetInputMethods();
110
111   // Returns available timezones. Caller gets the ownership.
112   static base::ListValue* GetTimezoneList();
113
114   NetworkScreenActor::Delegate* screen_;
115   CoreOobeActor* core_oobe_actor_;
116
117   bool is_continue_enabled_;
118
119   // Total time this machine has spent on OOBE.
120   base::TimeDelta time_on_oobe_;
121
122   // Keeps whether screen should be shown right after initialization.
123   bool show_on_init_;
124
125   // Position of the network control.
126   gfx::Point network_control_pos_;
127
128   scoped_ptr<CrosSettings::ObserverSubscription> timezone_subscription_;
129
130   scoped_ptr<IdleDetector> idle_detector_;
131
132   base::RepeatingTimer<NetworkScreenHandler> oobe_timer_;
133
134   // Timeout to detect if the machine is in a derelict state.
135   base::TimeDelta derelict_detection_timeout_;
136
137   // Timeout before showing our demo app if the machine is in a derelict state.
138   base::TimeDelta derelict_idle_timeout_;
139
140   // Time between updating our total time on oobe.
141   base::TimeDelta oobe_timer_update_interval_;
142
143   // True if should reinitialize language and keyboard list once the page
144   // is ready.
145   bool should_reinitialize_language_keyboard_list_;
146
147   // The exact language code selected by user in the menu.
148   std::string selected_language_code_;
149
150   base::WeakPtrFactory<NetworkScreenHandler> weak_ptr_factory_;
151
152   DISALLOW_COPY_AND_ASSIGN(NetworkScreenHandler);
153 };
154
155 }  // namespace chromeos
156
157 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_