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