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/network/network_state_handler_observer.h"
14#include "ui/gfx/native_widget_types.h"
15
16class Browser;
17class PrefService;
18
19namespace chromeos {
20class DeviceState;
21class NetworkState;
22class NetworkStateHandlerObserver;
23}
24
25namespace gfx {
26class ImageSkia;
27}
28
29namespace views {
30class WidgetDelegate;
31}
32
33namespace chromeos {
34namespace options {
35
36// ChromeOS internet options page UI handler.
37class InternetOptionsHandler
38    : public ::options::OptionsPageUIHandler,
39      public chromeos::NetworkStateHandlerObserver {
40 public:
41  InternetOptionsHandler();
42  virtual ~InternetOptionsHandler();
43
44 private:
45  // OptionsPageUIHandler
46  virtual void GetLocalizedValues(
47      base::DictionaryValue* localized_strings) OVERRIDE;
48  virtual void InitializePage() OVERRIDE;
49
50  // WebUIMessageHandler (from OptionsPageUIHandler)
51  virtual void RegisterMessages() OVERRIDE;
52
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);
62
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);
70
71  // Retrieves a data url for a resource.
72  std::string GetIconDataUrl(int resource_id) const;
73
74  // Refreshes the display of network information.
75  void RefreshNetworkData();
76
77  // Updates the display of network connection information for the details page
78  // if visible.
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.
84  void UpdateCarrier();
85
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;
95
96  // Updates the logged in user type.
97  void UpdateLoggedInUserType();
98
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);
107
108  // Retrieves the properties for |service_path| and calls sendNetworkDetails
109  // with the results.
110  void PopulateDictionaryDetailsCallback(
111      const std::string& service_path,
112      const base::DictionaryValue& shill_properties);
113
114  // Gets the native window for hosting dialogs, etc.
115  gfx::NativeWindow GetNativeWindow() const;
116
117  // Gets the UI scale factor.
118  float GetScaleFactor() const;
119
120  // Gets the user PrefService associated with the WebUI.
121  const PrefService* GetPrefs() const;
122
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);
128
129  // Helper functions called by NetworkCommandCallback(...)
130  void AddConnection(const std::string& type);
131  void SendShowDetailedInfo(const std::string& service_path);
132
133  // Creates the map of wired networks.
134  base::ListValue* GetWiredList();
135
136  // Creates the map of wireless networks.
137  base::ListValue* GetWirelessList();
138
139  // Creates the map of virtual networks.
140  base::ListValue* GetVPNList();
141
142  // Creates the map of remembered networks.
143  base::ListValue* GetRememberedList();
144
145  // Fills network information into JS dictionary for displaying network lists.
146  void FillNetworkInfo(base::DictionaryValue* dictionary);
147
148  // Keep track of the service path for the network shown in the Details view.
149  std::string details_path_;
150
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
153  // of this object.
154  base::WeakPtrFactory<InternetOptionsHandler> weak_factory_;
155
156  DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
157};
158
159}  // namespace options
160}  // namespace chromeos
161
162#endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_INTERNET_OPTIONS_HANDLER_H_
163