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/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"
23 class NetworkStateHandlerObserver;
37 // ChromeOS internet options page UI handler.
38 class InternetOptionsHandler
39 : public ::options::OptionsPageUIHandler,
40 public chromeos::NetworkStateHandlerObserver,
41 public chromeos::LoginState::Observer {
43 InternetOptionsHandler();
44 virtual ~InternetOptionsHandler();
47 // OptionsPageUIHandler
48 virtual void GetLocalizedValues(
49 base::DictionaryValue* localized_strings) OVERRIDE;
50 virtual void InitializePage() OVERRIDE;
52 // WebUIMessageHandler (from OptionsPageUIHandler)
53 virtual void RegisterMessages() OVERRIDE;
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);
74 // Retrieves a data url for a resource.
75 std::string GetIconDataUrl(int resource_id) const;
77 // Refreshes the display of network information.
78 void RefreshNetworkData();
80 // Updates the display of network connection information for the details page
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.
89 // NetworkStateHandlerObserver
90 virtual void DeviceListChanged() OVERRIDE;
91 virtual void NetworkListChanged() OVERRIDE;
92 virtual void NetworkConnectionStateChanged(
93 const chromeos::NetworkState* network) OVERRIDE;
94 virtual void NetworkPropertiesUpdated(
95 const chromeos::NetworkState* network) OVERRIDE;
97 // chromeos::LoginState::Observer
98 virtual void LoggedInStateChanged() OVERRIDE;
100 // Updates the logged in user type.
101 void UpdateLoggedInUserType();
103 // content::NotificationObserver (from OptionsPageUIHandler)
104 virtual void Observe(int type,
105 const content::NotificationSource& source,
106 const content::NotificationDetails& details) OVERRIDE;
108 // Additional callbacks to set network state properties.
109 void SetServerHostnameCallback(const base::ListValue* args);
110 void SetPreferNetworkCallback(const base::ListValue* args);
111 void SetAutoConnectCallback(const base::ListValue* args);
112 void SetIPConfigCallback(const base::ListValue* args);
113 void SetIPConfigProperties(const base::ListValue* args,
114 const std::string& service_path,
115 const base::DictionaryValue& shill_properties);
117 // Retrieves the properties for |service_path| and calls showDetailedInfo
119 void PopulateDictionaryDetailsCallback(
120 const std::string& service_path,
121 const base::DictionaryValue& shill_properties);
123 // Gets the native window for hosting dialogs, etc.
124 gfx::NativeWindow GetNativeWindow() const;
126 // Handle various network commands and clicks on a network item
127 // in the network list.
128 // |args| must be { network_type, service_path, command } with 'command'
129 // one of: [ add, forget, options, connect disconnect, activate ]
130 void NetworkCommandCallback(const base::ListValue* args);
132 // Helper functions called by NetworkCommandCallback(...)
133 void AddConnection(const std::string& type);
135 // Creates the map of wired networks.
136 base::ListValue* GetWiredList();
138 // Creates the map of wireless networks.
139 base::ListValue* GetWirelessList();
141 // Creates the map of virtual networks.
142 base::ListValue* GetVPNList();
144 // Creates the map of remembered networks.
145 base::ListValue* GetRememberedList();
147 // Fills network information into JS dictionary for displaying network lists.
148 void FillNetworkInfo(base::DictionaryValue* dictionary);
150 content::NotificationRegistrar registrar_;
152 // Keep track of the service path for the network shown in the Details view.
153 std::string details_path_;
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
158 base::WeakPtrFactory<InternetOptionsHandler> weak_factory_;
160 DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
163 } // namespace options
164 } // namespace chromeos
166 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_