Home | History | Annotate | Download | only in chromeos
      1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/network_library.h"
     11 #include "chrome/browser/ui/webui/options/chromeos/cros_options_page_ui_handler.h"
     12 #include "content/common/notification_registrar.h"
     13 #include "ui/gfx/native_widget_types.h"
     14 
     15 class SkBitmap;
     16 namespace views {
     17 class WindowDelegate;
     18 }
     19 
     20 // ChromeOS internet options page UI handler.
     21 class InternetOptionsHandler
     22   : public chromeos::CrosOptionsPageUIHandler,
     23     public chromeos::NetworkLibrary::NetworkManagerObserver,
     24     public chromeos::NetworkLibrary::NetworkObserver,
     25     public chromeos::NetworkLibrary::CellularDataPlanObserver {
     26  public:
     27   InternetOptionsHandler();
     28   virtual ~InternetOptionsHandler();
     29 
     30   // OptionsPageUIHandler implementation.
     31   virtual void GetLocalizedValues(DictionaryValue* localized_strings);
     32   virtual void Initialize();
     33 
     34   // WebUIMessageHandler implementation.
     35   virtual void RegisterMessages();
     36 
     37   // NetworkLibrary::NetworkManagerObserver implementation.
     38   virtual void OnNetworkManagerChanged(chromeos::NetworkLibrary* network_lib);
     39   // NetworkLibrary::NetworkObserver implementation.
     40   virtual void OnNetworkChanged(chromeos::NetworkLibrary* network_lib,
     41                                 const chromeos::Network* network);
     42   // NetworkLibrary::CellularDataPlanObserver implementation.
     43   virtual void OnCellularDataPlanChanged(chromeos::NetworkLibrary* network_lib);
     44 
     45   // NotificationObserver implementation.
     46   virtual void Observe(NotificationType type,
     47                        const NotificationSource& source,
     48                        const NotificationDetails& details) OVERRIDE;
     49 
     50  private:
     51   // Opens a modal popup dialog.
     52   void CreateModalPopup(views::WindowDelegate* view);
     53   gfx::NativeWindow GetNativeWindow() const;
     54 
     55   // Passes data needed to show details overlay for network.
     56   // |args| will be [ network_type, service_path, command ]
     57   // And command is one of 'options', 'connect', disconnect', 'activate' or
     58   // 'forget'
     59   // Handle{Wifi,Cellular}ButtonClick handles button click on a wireless
     60   // network item and a cellular network item respectively.
     61   void ButtonClickCallback(const ListValue* args);
     62   void HandleWifiButtonClick(const std::string& service_path,
     63                              const std::string& command);
     64   void HandleCellularButtonClick(const std::string& service_path,
     65                                  const std::string& command);
     66   void HandleVPNButtonClick(const std::string& service_path,
     67                             const std::string& command);
     68 
     69   // Initiates cellular plan data refresh. The results from libcros will be
     70   // passed through CellularDataPlanChanged() callback method.
     71   // |args| will be [ service_path ]
     72   void RefreshCellularPlanCallback(const ListValue* args);
     73   void SetActivationButtonVisibility(
     74       const chromeos::CellularNetwork* cellular,
     75       DictionaryValue* dictionary);
     76 
     77   void LoginCallback(const ListValue* args);
     78   void LoginCertCallback(const ListValue* args);
     79   void LoginToOtherCallback(const ListValue* args);
     80   void SetDetailsCallback(const ListValue* args);
     81   void EnableWifiCallback(const ListValue* args);
     82   void DisableWifiCallback(const ListValue* args);
     83   void EnableCellularCallback(const ListValue* args);
     84   void DisableCellularCallback(const ListValue* args);
     85   void BuyDataPlanCallback(const ListValue* args);
     86   void SetApnCallback(const ListValue* args);
     87   void SetSimCardLockCallback(const ListValue* args);
     88   void ChangePinCallback(const ListValue* args);
     89 
     90   // Populates the ui with the details of the given device path. This forces
     91   // an overlay to be displayed in the UI.
     92   void PopulateDictionaryDetails(const chromeos::Network* net,
     93                                  chromeos::NetworkLibrary* cros);
     94   void PopulateWifiDetails(const chromeos::WifiNetwork* wifi,
     95                            DictionaryValue* dictionary);
     96   void PopulateCellularDetails(chromeos::NetworkLibrary* cros,
     97                                const chromeos::CellularNetwork* cellular,
     98                                DictionaryValue* dictionary);
     99   void PopulateVPNDetails(const chromeos::VirtualNetwork* vpn,
    100                           DictionaryValue* dictionary);
    101 
    102   // Converts CellularDataPlan structure into dictionary for JS. Formats plan
    103   // settings into human readable texts.
    104   DictionaryValue* CellularDataPlanToDictionary(
    105       const chromeos::CellularDataPlan* plan);
    106   // Creates the map of a network.
    107   ListValue* GetNetwork(const std::string& service_path,
    108                         const SkBitmap& icon,
    109                         const std::string& name,
    110                         bool connecting,
    111                         bool connected,
    112                         bool connectable,
    113                         chromeos::ConnectionType connection_type,
    114                         bool remembered,
    115                         chromeos::ActivationState activation_state,
    116                         bool restricted_ip);
    117 
    118   // Creates the map of wired networks.
    119   ListValue* GetWiredList();
    120   // Creates the map of wireless networks.
    121   ListValue* GetWirelessList();
    122   // Creates the map of remembered networks.
    123   ListValue* GetRememberedList();
    124   // Fills network information into JS dictionary for displaying network lists.
    125   void FillNetworkInfo(DictionaryValue* dictionary,
    126                        chromeos::NetworkLibrary* cros);
    127   // Refreshes the display of network information.
    128   void RefreshNetworkData(chromeos::NetworkLibrary* cros);
    129   // Adds observers for wireless networks, if any, so that we can dynamically
    130   // display the correct icon for that network's signal strength and, in the
    131   // case of cellular networks, network technology and roaming status.
    132   void MonitorNetworks(chromeos::NetworkLibrary* cros);
    133 
    134   // A boolean flag of whether to use WebUI for connect UI. True to use WebUI
    135   // and false to use Views dialogs.
    136   bool use_settings_ui_;
    137 
    138   NotificationRegistrar registrar_;
    139 
    140   DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
    141 };
    142 
    143 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
    144