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 "chrome/browser/chromeos/login/screens/network_screen_actor.h"
13#include "chrome/browser/chromeos/settings/cros_settings.h"
14#include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
15#include "chromeos/ime/component_extension_ime_manager.h"
16#include "chromeos/ime/input_method_manager.h"
17#include "ui/gfx/point.h"
18
19namespace chromeos {
20
21class CoreOobeActor;
22class IdleDetector;
23
24struct NetworkScreenHandlerOnLanguageChangedCallbackData;
25
26// WebUI implementation of NetworkScreenActor. It is used to interact with
27// the welcome screen (part of the page) of the OOBE.
28class NetworkScreenHandler : public NetworkScreenActor,
29                             public BaseScreenHandler,
30                             public input_method::InputMethodManager::Observer {
31 public:
32  explicit NetworkScreenHandler(CoreOobeActor* core_oobe_actor);
33  virtual ~NetworkScreenHandler();
34
35  // NetworkScreenActor implementation:
36  virtual void SetDelegate(NetworkScreenActor::Delegate* screen) OVERRIDE;
37  virtual void PrepareToShow() OVERRIDE;
38  virtual void Show() OVERRIDE;
39  virtual void Hide() OVERRIDE;
40  virtual void ShowError(const base::string16& message) OVERRIDE;
41  virtual void ClearErrors() OVERRIDE;
42  virtual void ShowConnectingStatus(bool connecting,
43                                    const base::string16& network_id) OVERRIDE;
44  virtual void EnableContinue(bool enabled) OVERRIDE;
45
46  // BaseScreenHandler implementation:
47  virtual void DeclareLocalizedValues(LocalizedValuesBuilder* builder) OVERRIDE;
48  virtual void GetAdditionalParameters(base::DictionaryValue* dict) OVERRIDE;
49  virtual void Initialize() OVERRIDE;
50
51  // WebUIMessageHandler implementation:
52  virtual void RegisterMessages() OVERRIDE;
53
54  // InputMethodManager::Observer implementation:
55  virtual void InputMethodChanged(input_method::InputMethodManager* manager,
56                                  bool show_message) OVERRIDE;
57
58  // Reloads localized contents.
59  void ReloadLocalizedContent();
60
61 private:
62  // Handles moving off the screen.
63  void HandleOnExit();
64
65  // Handles change of the language.
66  void HandleOnLanguageChanged(const std::string& locale);
67
68  // Async callback after ReloadResourceBundle(locale) completed.
69  static void OnLanguageChangedCallback(
70      scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context,
71      const std::string& requested_locale,
72      const std::string& loaded_locale,
73      const bool success);
74
75  // Handles change of the input method.
76  void HandleOnInputMethodChanged(const std::string& id);
77
78  // Handles change of the time zone
79  void HandleOnTimezoneChanged(const std::string& timezone);
80
81  // Callback when the system timezone settings is changed.
82  void OnSystemTimezoneChanged();
83
84  // Returns available timezones. Caller gets the ownership.
85  static base::ListValue* GetTimezoneList();
86
87  NetworkScreenActor::Delegate* screen_;
88  CoreOobeActor* core_oobe_actor_;
89
90  bool is_continue_enabled_;
91
92  // Keeps whether screen should be shown right after initialization.
93  bool show_on_init_;
94
95  // Position of the network control.
96  gfx::Point network_control_pos_;
97
98  scoped_ptr<CrosSettings::ObserverSubscription> timezone_subscription_;
99
100  // The exact language code selected by user in the menu.
101  std::string selected_language_code_;
102
103  base::WeakPtrFactory<NetworkScreenHandler> weak_ptr_factory_;
104
105  DISALLOW_COPY_AND_ASSIGN(NetworkScreenHandler);
106};
107
108}  // namespace chromeos
109
110#endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_
111