Home | History | Annotate | Download | only in login
      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 
     19 class PrefRegistrySimple;
     20 
     21 namespace chromeos {
     22 
     23 class CoreOobeActor;
     24 class IdleDetector;
     25 
     26 struct NetworkScreenHandlerOnLanguageChangedCallbackData;
     27 
     28 // WebUI implementation of NetworkScreenActor. It is used to interact with
     29 // the welcome screen (part of the page) of the OOBE.
     30 class NetworkScreenHandler : public NetworkScreenActor,
     31                              public BaseScreenHandler,
     32                              public ComponentExtensionIMEManager::Observer,
     33                              public input_method::InputMethodManager::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   // InputMethodManager::Observer implementation:
     61   virtual void InputMethodChanged(input_method::InputMethodManager* manager,
     62                                   bool show_message) OVERRIDE;
     63 
     64   // Registers the preference for derelict state.
     65   static void RegisterPrefs(PrefRegistrySimple* registry);
     66 
     67   // Reloads localized contents.
     68   void ReloadLocalizedContent();
     69 
     70  private:
     71   // Handles moving off the screen.
     72   void HandleOnExit();
     73 
     74   // Handles change of the language.
     75   void HandleOnLanguageChanged(const std::string& locale);
     76 
     77   // Async callback after ReloadResourceBundle(locale) completed.
     78   static void OnLanguageChangedCallback(
     79       scoped_ptr<NetworkScreenHandlerOnLanguageChangedCallbackData> context,
     80       const std::string& requested_locale,
     81       const std::string& loaded_locale,
     82       const bool success);
     83 
     84   // Handles change of the input method.
     85   void HandleOnInputMethodChanged(const std::string& id);
     86 
     87   // Handles change of the time zone
     88   void HandleOnTimezoneChanged(const std::string& timezone);
     89 
     90   // Callback when the system timezone settings is changed.
     91   void OnSystemTimezoneChanged();
     92 
     93   // Returns available languages. Caller gets the ownership. Note, it does
     94   // depend on the current locale.
     95   base::ListValue* GetLanguageList();
     96 
     97   // Returns available input methods. Caller gets the ownership. Note, it does
     98   // depend on the current locale.
     99   static base::ListValue* GetInputMethods();
    100 
    101   // Returns available timezones. Caller gets the ownership.
    102   static base::ListValue* GetTimezoneList();
    103 
    104   NetworkScreenActor::Delegate* screen_;
    105   CoreOobeActor* core_oobe_actor_;
    106 
    107   bool is_continue_enabled_;
    108 
    109   // Keeps whether screen should be shown right after initialization.
    110   bool show_on_init_;
    111 
    112   // Position of the network control.
    113   gfx::Point network_control_pos_;
    114 
    115   scoped_ptr<CrosSettings::ObserverSubscription> timezone_subscription_;
    116 
    117   // True if should reinitialize language and keyboard list once the page
    118   // is ready.
    119   bool should_reinitialize_language_keyboard_list_;
    120 
    121   // The exact language code selected by user in the menu.
    122   std::string selected_language_code_;
    123 
    124   base::WeakPtrFactory<NetworkScreenHandler> weak_ptr_factory_;
    125 
    126   DISALLOW_COPY_AND_ASSIGN(NetworkScreenHandler);
    127 };
    128 
    129 }  // namespace chromeos
    130 
    131 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_
    132