internet_options_handler.h revision 58537e28ecd584eab876aee8be7156509866d23a
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
18class Browser;
19
20namespace chromeos {
21class DeviceState;
22class NetworkState;
23class NetworkStateHandlerObserver;
24}
25
26namespace gfx {
27class ImageSkia;
28}
29
30namespace views {
31class WidgetDelegate;
32}
33
34namespace chromeos {
35namespace options {
36
37// ChromeOS internet options page UI handler.
38class 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 NetworkManagerChanged() 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(
99      chromeos::LoginState::LoggedInState) OVERRIDE;
100
101  // Updates the logged in user type.
102  void UpdateLoggedInUserType();
103
104  // content::NotificationObserver (from OptionsPageUIHandler)
105  virtual void Observe(int type,
106                       const content::NotificationSource& source,
107                       const content::NotificationDetails& details) OVERRIDE;
108
109  // Additional callbacks to set network state properties.
110  void SetServerHostnameCallback(const base::ListValue* args);
111  void SetPreferNetworkCallback(const base::ListValue* args);
112  void SetAutoConnectCallback(const base::ListValue* args);
113  void SetIPConfigCallback(const base::ListValue* args);
114  void SetIPConfigProperties(const base::ListValue* args,
115                             const std::string& service_path,
116                             const base::DictionaryValue& shill_properties);
117
118  // Retrieves the properties for |service_path| and calls showDetailedInfo
119  // with the results.
120  void PopulateDictionaryDetailsCallback(
121      const std::string& service_path,
122      const base::DictionaryValue& shill_properties);
123
124  // Gets the native window for hosting dialogs, etc.
125  gfx::NativeWindow GetNativeWindow() const;
126
127  // Returns the last active browser. If there is no such browser, creates a new
128  // browser window with an empty tab and returns it.
129  Browser* GetAppropriateBrowser();
130
131  // Handle various network commands and clicks on a network item
132  // in the network list.
133  // |args| must be { network_type, service_path, command } with 'command'
134  // one of: [ add, forget, options, connect disconnect, activate ]
135  void NetworkCommandCallback(const base::ListValue* args);
136
137  // Helper functions called by NetworkCommandCallback(...)
138  void AddConnection(const std::string& type);
139
140  // Creates the map of wired networks.
141  base::ListValue* GetWiredList();
142
143  // Creates the map of wireless networks.
144  base::ListValue* GetWirelessList();
145
146  // Creates the map of virtual networks.
147  base::ListValue* GetVPNList();
148
149  // Creates the map of remembered networks.
150  base::ListValue* GetRememberedList();
151
152  // Fills network information into JS dictionary for displaying network lists.
153  void FillNetworkInfo(base::DictionaryValue* dictionary);
154
155  content::NotificationRegistrar registrar_;
156
157  // Keep track of the service path for the network shown in the Details view.
158  std::string details_path_;
159
160  // Weak pointer factory so we can start connections at a later time
161  // without worrying that they will actually try to happen after the lifetime
162  // of this object.
163  base::WeakPtrFactory<InternetOptionsHandler> weak_factory_;
164
165  DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
166};
167
168}  // namespace options
169}  // namespace chromeos
170
171#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
172