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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
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 "ui/gfx/native_widget_types.h"
22 class NetworkStateHandlerObserver;
36 // ChromeOS internet options page UI handler.
37 class InternetOptionsHandler
38 : public ::options::OptionsPageUIHandler,
39 public chromeos::NetworkStateHandlerObserver {
41 InternetOptionsHandler();
42 virtual ~InternetOptionsHandler();
45 // OptionsPageUIHandler
46 virtual void GetLocalizedValues(
47 base::DictionaryValue* localized_strings) OVERRIDE;
48 virtual void InitializePage() OVERRIDE;
50 // WebUIMessageHandler (from OptionsPageUIHandler)
51 virtual void RegisterMessages() OVERRIDE;
53 // Callbacks to set network state properties.
54 void EnableWifiCallback(const base::ListValue* args);
55 void DisableWifiCallback(const base::ListValue* args);
56 void EnableCellularCallback(const base::ListValue* args);
57 void DisableCellularCallback(const base::ListValue* args);
58 void EnableWimaxCallback(const base::ListValue* args);
59 void DisableWimaxCallback(const base::ListValue* args);
60 void ShowMorePlanInfoCallback(const base::ListValue* args);
61 void BuyDataPlanCallback(const base::ListValue* args);
62 void SetApnCallback(const base::ListValue* args);
63 void SetApnProperties(const base::ListValue* args,
64 const std::string& service_path,
65 const base::DictionaryValue& shill_properties);
66 void CarrierStatusCallback();
67 void SetCarrierCallback(const base::ListValue* args);
68 void SetSimCardLockCallback(const base::ListValue* args);
69 void ChangePinCallback(const base::ListValue* args);
70 void RefreshNetworksCallback(const base::ListValue* args);
72 // Retrieves a data url for a resource.
73 std::string GetIconDataUrl(int resource_id) const;
75 // Refreshes the display of network information.
76 void RefreshNetworkData();
78 // Updates the display of network connection information for the details page
80 void UpdateConnectionData(const std::string& service_path);
81 void UpdateConnectionDataCallback(
82 const std::string& service_path,
83 const base::DictionaryValue& shill_properties);
84 // Called when carrier data has been updated to informs the JS.
87 // NetworkStateHandlerObserver
88 virtual void DeviceListChanged() OVERRIDE;
89 virtual void NetworkListChanged() OVERRIDE;
90 virtual void NetworkConnectionStateChanged(
91 const chromeos::NetworkState* network) OVERRIDE;
92 virtual void NetworkPropertiesUpdated(
93 const chromeos::NetworkState* network) OVERRIDE;
94 virtual void DevicePropertiesUpdated(
95 const chromeos::DeviceState* device) OVERRIDE;
97 // Updates the logged in user type.
98 void UpdateLoggedInUserType();
100 // Additional callbacks to set network state properties.
101 void SetServerHostnameCallback(const base::ListValue* args);
102 void SetPreferNetworkCallback(const base::ListValue* args);
103 void SetAutoConnectCallback(const base::ListValue* args);
104 void SetIPConfigCallback(const base::ListValue* args);
105 void SetIPConfigProperties(const base::ListValue* args,
106 const std::string& service_path,
107 const base::DictionaryValue& shill_properties);
109 // Retrieves the properties for |service_path| and calls showDetailedInfo
111 void PopulateDictionaryDetailsCallback(
112 const std::string& service_path,
113 const base::DictionaryValue& shill_properties);
115 // Gets the native window for hosting dialogs, etc.
116 gfx::NativeWindow GetNativeWindow() const;
118 // Gets the UI scale factor.
119 float GetScaleFactor() const;
121 // Gets the user PrefService associated with the WebUI.
122 const PrefService* GetPrefs() const;
124 // Handle various network commands and clicks on a network item
125 // in the network list.
126 // |args| must be { network_type, service_path, command } with 'command'
127 // one of: [ add, forget, options, connect disconnect, activate ]
128 void NetworkCommandCallback(const base::ListValue* args);
130 // Helper functions called by NetworkCommandCallback(...)
131 void AddConnection(const std::string& type);
133 // Creates the map of wired networks.
134 base::ListValue* GetWiredList();
136 // Creates the map of wireless networks.
137 base::ListValue* GetWirelessList();
139 // Creates the map of virtual networks.
140 base::ListValue* GetVPNList();
142 // Creates the map of remembered networks.
143 base::ListValue* GetRememberedList();
145 // Fills network information into JS dictionary for displaying network lists.
146 void FillNetworkInfo(base::DictionaryValue* dictionary);
148 // Keep track of the service path for the network shown in the Details view.
149 std::string details_path_;
151 // Weak pointer factory so we can start connections at a later time
152 // without worrying that they will actually try to happen after the lifetime
154 base::WeakPtrFactory<InternetOptionsHandler> weak_factory_;
156 DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
159 } // namespace options
160 } // namespace chromeos
162 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_