- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / chromeos / internet_options_handler.h
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/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"
17
18 class Browser;
19
20 namespace chromeos {
21 class DeviceState;
22 class NetworkState;
23 class NetworkStateHandlerObserver;
24 }
25
26 namespace gfx {
27 class ImageSkia;
28 }
29
30 namespace views {
31 class WidgetDelegate;
32 }
33
34 namespace chromeos {
35 namespace options {
36
37 // ChromeOS internet options page UI handler.
38 class InternetOptionsHandler
39     : public ::options::OptionsPageUIHandler,
40       public chromeos::NetworkStateHandlerObserver,
41       public chromeos::LoginState::Observer {
42  public:
43   InternetOptionsHandler();
44   virtual ~InternetOptionsHandler();
45
46  private:
47   // OptionsPageUIHandler
48   virtual void GetLocalizedValues(
49       base::DictionaryValue* localized_strings) OVERRIDE;
50   virtual void InitializePage() OVERRIDE;
51
52   // WebUIMessageHandler (from OptionsPageUIHandler)
53   virtual void RegisterMessages() OVERRIDE;
54
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);
73
74   // Retrieves a data url for a resource.
75   std::string GetIconDataUrl(int resource_id) const;
76
77   // Refreshes the display of network information.
78   void RefreshNetworkData();
79
80   // Updates the display of network connection information for the details page
81   // if visible.
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.
87   void UpdateCarrier();
88
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;
96
97   // chromeos::LoginState::Observer
98   virtual void LoggedInStateChanged() OVERRIDE;
99
100   // Updates the logged in user type.
101   void UpdateLoggedInUserType();
102
103   // content::NotificationObserver (from OptionsPageUIHandler)
104   virtual void Observe(int type,
105                        const content::NotificationSource& source,
106                        const content::NotificationDetails& details) OVERRIDE;
107
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);
116
117   // Retrieves the properties for |service_path| and calls showDetailedInfo
118   // with the results.
119   void PopulateDictionaryDetailsCallback(
120       const std::string& service_path,
121       const base::DictionaryValue& shill_properties);
122
123   // Gets the native window for hosting dialogs, etc.
124   gfx::NativeWindow GetNativeWindow() const;
125
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);
131
132   // Helper functions called by NetworkCommandCallback(...)
133   void AddConnection(const std::string& type);
134
135   // Creates the map of wired networks.
136   base::ListValue* GetWiredList();
137
138   // Creates the map of wireless networks.
139   base::ListValue* GetWirelessList();
140
141   // Creates the map of virtual networks.
142   base::ListValue* GetVPNList();
143
144   // Creates the map of remembered networks.
145   base::ListValue* GetRememberedList();
146
147   // Fills network information into JS dictionary for displaying network lists.
148   void FillNetworkInfo(base::DictionaryValue* dictionary);
149
150   content::NotificationRegistrar registrar_;
151
152   // Keep track of the service path for the network shown in the Details view.
153   std::string details_path_;
154
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
157   // of this object.
158   base::WeakPtrFactory<InternetOptionsHandler> weak_factory_;
159
160   DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
161 };
162
163 }  // namespace options
164 }  // namespace chromeos
165
166 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_