Home | History | Annotate | Download | only in chromeos
      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_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/memory/weak_ptr.h"
     12 #include "chrome/browser/ui/webui/options/options_ui.h"
     13 #include "chromeos/login/login_state.h"
     14 #include "chromeos/network/network_state_handler_observer.h"
     15 #include "content/public/browser/notification_registrar.h"
     16 #include "ui/gfx/native_widget_types.h"
     17 
     18 class Browser;
     19 
     20 namespace chromeos {
     21 class DeviceState;
     22 class NetworkState;
     23 class NetworkStateHandlerObserver;
     24 }
     25 
     26 namespace gfx {
     27 class ImageSkia;
     28 }
     29 
     30 namespace views {
     31 class WidgetDelegate;
     32 }
     33 
     34 namespace chromeos {
     35 namespace options {
     36 
     37 // ChromeOS internet options page UI handler.
     38 class InternetOptionsHandler
     39     : public ::options::OptionsPageUIHandler,
     40       public chromeos::NetworkStateHandlerObserver,
     41       public chromeos::LoginState::Observer {
     42  public:
     43   InternetOptionsHandler();
     44   virtual ~InternetOptionsHandler();
     45 
     46  private:
     47   // OptionsPageUIHandler
     48   virtual void GetLocalizedValues(
     49       base::DictionaryValue* localized_strings) OVERRIDE;
     50   virtual void InitializePage() OVERRIDE;
     51 
     52   // WebUIMessageHandler (from OptionsPageUIHandler)
     53   virtual void RegisterMessages() OVERRIDE;
     54 
     55   // Callbacks to set network state properties.
     56   void EnableWifiCallback(const base::ListValue* args);
     57   void DisableWifiCallback(const base::ListValue* args);
     58   void EnableCellularCallback(const base::ListValue* args);
     59   void DisableCellularCallback(const base::ListValue* args);
     60   void EnableWimaxCallback(const base::ListValue* args);
     61   void DisableWimaxCallback(const base::ListValue* args);
     62   void ShowMorePlanInfoCallback(const base::ListValue* args);
     63   void BuyDataPlanCallback(const base::ListValue* args);
     64   void SetApnCallback(const base::ListValue* args);
     65   void SetApnProperties(const base::ListValue* args,
     66                         const std::string& service_path,
     67                         const base::DictionaryValue& shill_properties);
     68   void CarrierStatusCallback();
     69   void SetCarrierCallback(const base::ListValue* args);
     70   void SetSimCardLockCallback(const base::ListValue* args);
     71   void ChangePinCallback(const base::ListValue* args);
     72   void RefreshNetworksCallback(const base::ListValue* args);
     73 
     74   // Retrieves a data url for a resource.
     75   std::string GetIconDataUrl(int resource_id) const;
     76 
     77   // Refreshes the display of network information.
     78   void RefreshNetworkData();
     79 
     80   // Updates the display of network connection information for the details page
     81   // if visible.
     82   void UpdateConnectionData(const std::string& service_path);
     83   void UpdateConnectionDataCallback(
     84       const std::string& service_path,
     85       const base::DictionaryValue& shill_properties);
     86   // Called when carrier data has been updated to informs the JS.
     87   void UpdateCarrier();
     88 
     89   // NetworkStateHandlerObserver
     90   virtual void NetworkManagerChanged() OVERRIDE;
     91   virtual void NetworkListChanged() OVERRIDE;
     92   virtual void NetworkPropertiesUpdated(
     93       const chromeos::NetworkState* network) OVERRIDE;
     94 
     95   // chromeos::LoginState::Observer
     96   virtual void LoggedInStateChanged(
     97       chromeos::LoginState::LoggedInState) OVERRIDE;
     98 
     99   // Updates the logged in user type.
    100   void UpdateLoggedInUserType();
    101 
    102   // content::NotificationObserver (from OptionsPageUIHandler)
    103   virtual void Observe(int type,
    104                        const content::NotificationSource& source,
    105                        const content::NotificationDetails& details) OVERRIDE;
    106 
    107   // Additional callbacks to set network state properties.
    108   void SetServerHostnameCallback(const base::ListValue* args);
    109   void SetPreferNetworkCallback(const base::ListValue* args);
    110   void SetAutoConnectCallback(const base::ListValue* args);
    111   void SetIPConfigCallback(const base::ListValue* args);
    112   void SetIPConfigProperties(const base::ListValue* args,
    113                              const std::string& service_path,
    114                              const base::DictionaryValue& shill_properties);
    115 
    116   // Retrieves the properties for |service_path| and calls showDetailedInfo
    117   // with the results.
    118   void PopulateDictionaryDetailsCallback(
    119       const std::string& service_path,
    120       const base::DictionaryValue& shill_properties);
    121 
    122   // Gets the native window for hosting dialogs, etc.
    123   gfx::NativeWindow GetNativeWindow() const;
    124 
    125   // Returns the last active browser. If there is no such browser, creates a new
    126   // browser window with an empty tab and returns it.
    127   Browser* GetAppropriateBrowser();
    128 
    129   // Handle various network commands and clicks on a network item
    130   // in the network list.
    131   // |args| must be { network_type, service_path, command } with 'command'
    132   // one of: [ add, forget, options, connect disconnect, activate ]
    133   void NetworkCommandCallback(const base::ListValue* args);
    134 
    135   // Helper functions called by NetworkCommandCallback(...)
    136   void AddConnection(const std::string& type);
    137 
    138   // Creates the map of wired networks.
    139   base::ListValue* GetWiredList();
    140 
    141   // Creates the map of wireless networks.
    142   base::ListValue* GetWirelessList();
    143 
    144   // Creates the map of virtual networks.
    145   base::ListValue* GetVPNList();
    146 
    147   // Creates the map of remembered networks.
    148   base::ListValue* GetRememberedList();
    149 
    150   // Fills network information into JS dictionary for displaying network lists.
    151   void FillNetworkInfo(base::DictionaryValue* dictionary);
    152 
    153   content::NotificationRegistrar registrar_;
    154 
    155   // Weak pointer factory so we can start connections at a later time
    156   // without worrying that they will actually try to happen after the lifetime
    157   // of this object.
    158   base::WeakPtrFactory<InternetOptionsHandler> weak_factory_;
    159 
    160   DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
    161 };
    162 
    163 }  // namespace options
    164 }  // namespace chromeos
    165 
    166 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
    167