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_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "ui/gfx/native_widget_types.h"
24 class NetworkStateHandlerObserver
;
38 // ChromeOS internet options page UI handler.
39 class InternetOptionsHandler
40 : public ::options::OptionsPageUIHandler
,
41 public chromeos::NetworkStateHandlerObserver
,
42 public chromeos::LoginState::Observer
,
43 public content::NotificationObserver
{
45 InternetOptionsHandler();
46 virtual ~InternetOptionsHandler();
49 // OptionsPageUIHandler
50 virtual void GetLocalizedValues(
51 base::DictionaryValue
* localized_strings
) OVERRIDE
;
52 virtual void InitializePage() OVERRIDE
;
54 // WebUIMessageHandler (from OptionsPageUIHandler)
55 virtual void RegisterMessages() OVERRIDE
;
57 // Callbacks to set network state properties.
58 void EnableWifiCallback(const base::ListValue
* args
);
59 void DisableWifiCallback(const base::ListValue
* args
);
60 void EnableCellularCallback(const base::ListValue
* args
);
61 void DisableCellularCallback(const base::ListValue
* args
);
62 void EnableWimaxCallback(const base::ListValue
* args
);
63 void DisableWimaxCallback(const base::ListValue
* args
);
64 void ShowMorePlanInfoCallback(const base::ListValue
* args
);
65 void BuyDataPlanCallback(const base::ListValue
* args
);
66 void SetApnCallback(const base::ListValue
* args
);
67 void SetApnProperties(const base::ListValue
* args
,
68 const std::string
& service_path
,
69 const base::DictionaryValue
& shill_properties
);
70 void CarrierStatusCallback();
71 void SetCarrierCallback(const base::ListValue
* args
);
72 void SetSimCardLockCallback(const base::ListValue
* args
);
73 void ChangePinCallback(const base::ListValue
* args
);
74 void RefreshNetworksCallback(const base::ListValue
* args
);
76 // Retrieves a data url for a resource.
77 std::string
GetIconDataUrl(int resource_id
) const;
79 // Refreshes the display of network information.
80 void RefreshNetworkData();
82 // Updates the display of network connection information for the details page
84 void UpdateConnectionData(const std::string
& service_path
);
85 void UpdateConnectionDataCallback(
86 const std::string
& service_path
,
87 const base::DictionaryValue
& shill_properties
);
88 // Called when carrier data has been updated to informs the JS.
91 // NetworkStateHandlerObserver
92 virtual void DeviceListChanged() OVERRIDE
;
93 virtual void NetworkListChanged() OVERRIDE
;
94 virtual void NetworkConnectionStateChanged(
95 const chromeos::NetworkState
* network
) OVERRIDE
;
96 virtual void NetworkPropertiesUpdated(
97 const chromeos::NetworkState
* network
) OVERRIDE
;
99 // chromeos::LoginState::Observer
100 virtual void LoggedInStateChanged() OVERRIDE
;
102 // Updates the logged in user type.
103 void UpdateLoggedInUserType();
105 // content::NotificationObserver
106 virtual void Observe(int type
,
107 const content::NotificationSource
& source
,
108 const content::NotificationDetails
& details
) OVERRIDE
;
110 // Additional callbacks to set network state properties.
111 void SetServerHostnameCallback(const base::ListValue
* args
);
112 void SetPreferNetworkCallback(const base::ListValue
* args
);
113 void SetAutoConnectCallback(const base::ListValue
* args
);
114 void SetIPConfigCallback(const base::ListValue
* args
);
115 void SetIPConfigProperties(const base::ListValue
* args
,
116 const std::string
& service_path
,
117 const base::DictionaryValue
& shill_properties
);
119 // Retrieves the properties for |service_path| and calls showDetailedInfo
121 void PopulateDictionaryDetailsCallback(
122 const std::string
& service_path
,
123 const base::DictionaryValue
& shill_properties
);
125 // Gets the native window for hosting dialogs, etc.
126 gfx::NativeWindow
GetNativeWindow() const;
128 // Handle various network commands and clicks on a network item
129 // in the network list.
130 // |args| must be { network_type, service_path, command } with 'command'
131 // one of: [ add, forget, options, connect disconnect, activate ]
132 void NetworkCommandCallback(const base::ListValue
* args
);
134 // Helper functions called by NetworkCommandCallback(...)
135 void AddConnection(const std::string
& type
);
137 // Creates the map of wired networks.
138 base::ListValue
* GetWiredList();
140 // Creates the map of wireless networks.
141 base::ListValue
* GetWirelessList();
143 // Creates the map of virtual networks.
144 base::ListValue
* GetVPNList();
146 // Creates the map of remembered networks.
147 base::ListValue
* GetRememberedList();
149 // Fills network information into JS dictionary for displaying network lists.
150 void FillNetworkInfo(base::DictionaryValue
* dictionary
);
152 content::NotificationRegistrar registrar_
;
154 // Keep track of the service path for the network shown in the Details view.
155 std::string details_path_
;
157 // Weak pointer factory so we can start connections at a later time
158 // without worrying that they will actually try to happen after the lifetime
160 base::WeakPtrFactory
<InternetOptionsHandler
> weak_factory_
;
162 DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler
);
165 } // namespace options
166 } // namespace chromeos
168 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_