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 ShowMorePlanInfoCallback(const base::ListValue* args);
55 void SetApnCallback(const base::ListValue* args);
56 void SetApnProperties(const base::ListValue* args,
57 const std::string& service_path,
58 const base::DictionaryValue& shill_properties);
59 void CarrierStatusCallback();
60 void SetCarrierCallback(const base::ListValue* args);
61 void SimOperationCallback(const base::ListValue* args);
63 // networkingPrvate callbacks
64 void DisableNetworkTypeCallback(const base::ListValue* args);
65 void EnableNetworkTypeCallback(const base::ListValue* args);
66 void GetManagedPropertiesCallback(const base::ListValue* args);
67 void RequestNetworkScanCallback(const base::ListValue* args);
68 void StartConnectCallback(const base::ListValue* args);
69 void StartDisconnectCallback(const base::ListValue* args);
71 // Retrieves a data url for a resource.
72 std::string GetIconDataUrl(int resource_id) const;
74 // Refreshes the display of network information.
75 void RefreshNetworkData();
77 // Updates the display of network connection information for the details page
79 void UpdateConnectionData(const std::string& service_path);
80 void UpdateConnectionDataCallback(
81 const std::string& service_path,
82 const base::DictionaryValue& shill_properties);
83 // Called when carrier data has been updated to informs the JS.
86 // NetworkStateHandlerObserver
87 virtual void DeviceListChanged() OVERRIDE;
88 virtual void NetworkListChanged() OVERRIDE;
89 virtual void NetworkConnectionStateChanged(
90 const chromeos::NetworkState* network) OVERRIDE;
91 virtual void NetworkPropertiesUpdated(
92 const chromeos::NetworkState* network) OVERRIDE;
93 virtual void DevicePropertiesUpdated(
94 const chromeos::DeviceState* device) OVERRIDE;
96 // Updates the logged in user type.
97 void UpdateLoggedInUserType();
99 // Additional callbacks to set network state properties.
100 void SetServerHostnameCallback(const base::ListValue* args);
101 void SetPreferNetworkCallback(const base::ListValue* args);
102 void SetAutoConnectCallback(const base::ListValue* args);
103 void SetIPConfigCallback(const base::ListValue* args);
104 void SetIPConfigProperties(const base::ListValue* args,
105 const std::string& service_path,
106 const base::DictionaryValue& shill_properties);
108 // Retrieves the properties for |service_path| and calls sendNetworkDetails
110 void PopulateDictionaryDetailsCallback(
111 const std::string& service_path,
112 const base::DictionaryValue& shill_properties);
114 // Gets the native window for hosting dialogs, etc.
115 gfx::NativeWindow GetNativeWindow() const;
117 // Gets the UI scale factor.
118 float GetScaleFactor() const;
120 // Gets the user PrefService associated with the WebUI.
121 const PrefService* GetPrefs() const;
123 // Handle various network commands and clicks on a network item
124 // in the network list.
125 // |args| must be { network_type, service_path, command } with 'command'
126 // one of: [ add, forget, options, connect disconnect, activate ]
127 void NetworkCommandCallback(const base::ListValue* args);
129 // Helper functions called by NetworkCommandCallback(...)
130 void AddConnection(const std::string& type);
131 void SendShowDetailedInfo(const std::string& service_path);
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_