internet_options_handler.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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 "chrome/browser/chromeos/cros/network_constants.h" 12#include "chrome/browser/chromeos/cros/network_library.h" 13#include "chrome/browser/ui/webui/options/options_ui.h" 14#include "chromeos/network/network_ui_data.h" 15#include "content/public/browser/notification_registrar.h" 16#include "ui/gfx/native_widget_types.h" 17 18class Browser; 19 20namespace gfx { 21class ImageSkia; 22} 23 24namespace views { 25class WidgetDelegate; 26} 27 28namespace options { 29 30// ChromeOS internet options page UI handler. 31class InternetOptionsHandler 32 : public OptionsPageUIHandler, 33 public chromeos::NetworkLibrary::NetworkManagerObserver, 34 public chromeos::NetworkLibrary::NetworkObserver { 35 public: 36 InternetOptionsHandler(); 37 virtual ~InternetOptionsHandler(); 38 39 // OptionsPageUIHandler implementation. 40 virtual void GetLocalizedValues( 41 base::DictionaryValue* localized_strings) OVERRIDE; 42 virtual void InitializePage() OVERRIDE; 43 44 // WebUIMessageHandler implementation. 45 virtual void RegisterMessages() OVERRIDE; 46 47 // NetworkLibrary::NetworkManagerObserver implementation. 48 virtual void OnNetworkManagerChanged( 49 chromeos::NetworkLibrary* network_lib) OVERRIDE; 50 // NetworkLibrary::NetworkObserver implementation. 51 virtual void OnNetworkChanged(chromeos::NetworkLibrary* network_lib, 52 const chromeos::Network* network) OVERRIDE; 53 54 // content::NotificationObserver implementation. 55 virtual void Observe(int type, 56 const content::NotificationSource& source, 57 const content::NotificationDetails& details) OVERRIDE; 58 59 private: 60 // Opens a modal popup dialog. 61 void CreateModalPopup(views::WidgetDelegate* view); 62 gfx::NativeWindow GetNativeWindow() const; 63 64 // Returns the last active browser. If there is no such browser, creates a new 65 // browser window with an empty tab and returns it. 66 Browser* GetAppropriateBrowser(); 67 68 // Handle various network commands and clicks on a network item 69 // in the network list. 70 // |args| has to be [ network_type, service_path, command ] 71 // and command is one of the strings 72 // options, connect disconnect, activate, forget, add 73 void NetworkCommandCallback(const base::ListValue* args); 74 75 // Helper functions called by NetworkCommandCallback(...) 76 void AddConnection(chromeos::ConnectionType type); 77 78 void SetCellularButtonsVisibility( 79 const chromeos::CellularNetwork* cellular, 80 const chromeos::NetworkDevice* device, 81 base::DictionaryValue* dictionary, 82 const std::string& carrier_id); 83 84 void SetServerHostnameCallback(const base::ListValue* args); 85 void SetPreferNetworkCallback(const base::ListValue* args); 86 void SetAutoConnectCallback(const base::ListValue* args); 87 void SetSharedCallback(const base::ListValue* args); 88 void SetIPConfigCallback(const base::ListValue* args); 89 void EnableWifiCallback(const base::ListValue* args); 90 void DisableWifiCallback(const base::ListValue* args); 91 void EnableCellularCallback(const base::ListValue* args); 92 void DisableCellularCallback(const base::ListValue* args); 93 void EnableWimaxCallback(const base::ListValue* args); 94 void DisableWimaxCallback(const base::ListValue* args); 95 void BuyDataPlanCallback(const base::ListValue* args); 96 void SetApnCallback(const base::ListValue* args); 97 void SetCarrierCallback(const base::ListValue* args); 98 void SetSimCardLockCallback(const base::ListValue* args); 99 void ChangePinCallback(const base::ListValue* args); 100 void ShareNetworkCallback(const base::ListValue* args); 101 void ShowMorePlanInfoCallback(const base::ListValue* args); 102 void RefreshNetworksCallback(const base::ListValue* args); 103 104 /** 105 * Toggle airplane mode. Disables all wireless networks when activated. 106 * Celluar and Bluetooth connections remain disabled while active, but 107 * Wi-Fi can be reactivated. |args| is unused. 108 */ 109 void ToggleAirplaneModeCallback(const ListValue* args); 110 111 // Populates the ui with the details of the given device path. This forces 112 // an overlay to be displayed in the UI. Called after the asynchronous 113 // request for Shill's service properties. 114 void PopulateDictionaryDetailsCallback( 115 const std::string& service_path, 116 const base::DictionaryValue* shill_properties); 117 void PopulateIPConfigsCallback( 118 const std::string& service_path, 119 base::DictionaryValue* shill_properties, 120 const chromeos::NetworkIPConfigVector& ipconfigs, 121 const std::string& hardware_address); 122 void PopulateConnectionDetails(const chromeos::Network* network, 123 base::DictionaryValue* dictionary); 124 void PopulateWifiDetails(const chromeos::WifiNetwork* wifi, 125 base::DictionaryValue* dictionary); 126 void PopulateWimaxDetails(const chromeos::WimaxNetwork* wimax, 127 base::DictionaryValue* dictionary); 128 void PopulateCellularDetails(const chromeos::CellularNetwork* cellular, 129 base::DictionaryValue* dictionary); 130 131 // Converts CellularApn stuct into dictionary for JS. 132 base::DictionaryValue* CreateDictionaryFromCellularApn( 133 const chromeos::CellularApn& apn); 134 135 // Creates the map of wired networks. 136 base::ListValue* GetWiredList(); 137 // Creates the map of wireless networks. 138 base::ListValue* GetWirelessList(); 139 // Creates the map of virtual networks. 140 base::ListValue* GetVPNList(); 141 // Creates the map of remembered networks. 142 base::ListValue* GetRememberedList(); 143 // Fills network information into JS dictionary for displaying network lists. 144 void FillNetworkInfo(base::DictionaryValue* dictionary); 145 // Refreshes the display of network information. 146 void RefreshNetworkData(); 147 // Updates the display of network connection information for the details page 148 // if it's up. 149 void UpdateConnectionData(const chromeos::Network* network); 150 // Updates the carrier change status. 151 void UpdateCarrier(); 152 // Adds observers for wireless networks, if any, so that we can dynamically 153 // display the correct icon for that network's signal strength and, in the 154 // case of cellular networks, network technology and roaming status. 155 void MonitorNetworks(); 156 157 // Callback for SetCarrier to notify once it's complete. 158 void CarrierStatusCallback( 159 const std::string& path, 160 chromeos::NetworkMethodErrorType error, 161 const std::string& error_message); 162 163 // Retrieves a data url for a resource. 164 std::string GetIconDataUrl(int resource_id) const; 165 166 // Convenience pointer to netwrok library (will not change). 167 chromeos::NetworkLibrary* cros_; 168 169 content::NotificationRegistrar registrar_; 170 171 // Weak pointer factory so we can start connections at a later time 172 // without worrying that they will actually try to happen after the lifetime 173 // of this object. 174 base::WeakPtrFactory<InternetOptionsHandler> weak_factory_; 175 176 DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler); 177}; 178 179} // namespace options 180 181#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_ 182