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