• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 // These classes implement the chrome.networkingPrivate JavaScript extension
6 // API.
7 
8 #ifndef CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_API_H_
9 #define CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_API_H_
10 
11 #include <string>
12 
13 #include "base/memory/ref_counted.h"
14 #include "base/values.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
16 #include "chromeos/dbus/dbus_method_call_status.h"
17 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
18 
19 // Implements the chrome.networkingPrivate.getProperties method.
20 class NetworkingPrivateGetPropertiesFunction
21     : public ChromeAsyncExtensionFunction {
22  public:
NetworkingPrivateGetPropertiesFunction()23   NetworkingPrivateGetPropertiesFunction() {}
24   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getProperties",
25                              NETWORKINGPRIVATE_GETPROPERTIES);
26 
27  protected:
28   virtual ~NetworkingPrivateGetPropertiesFunction();
29 
30   // AsyncExtensionFunction overrides.
31   virtual bool RunImpl() OVERRIDE;
32 
33  private:
34   void GetPropertiesSuccess(const std::string& service_path,
35                             const base::DictionaryValue& result);
36   void GetPropertiesFailed(const std::string& error_name,
37                            scoped_ptr<base::DictionaryValue> error_data);
38   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetPropertiesFunction);
39 };
40 
41 // Implements the chrome.networkingPrivate.getManagedProperties method.
42 class NetworkingPrivateGetManagedPropertiesFunction
43     : public ChromeAsyncExtensionFunction {
44  public:
NetworkingPrivateGetManagedPropertiesFunction()45   NetworkingPrivateGetManagedPropertiesFunction() {}
46   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getManagedProperties",
47                              NETWORKINGPRIVATE_GETMANAGEDPROPERTIES);
48 
49  protected:
50   virtual ~NetworkingPrivateGetManagedPropertiesFunction();
51 
52   // AsyncExtensionFunction overrides.
53   virtual bool RunImpl() OVERRIDE;
54 
55  private:
56   // Callbacks for ManagedNetworkConfigurationHandler::GetManagedProperties.
57   void Success(const std::string& service_path,
58                const base::DictionaryValue& result);
59   void Failure(const std::string& error_name,
60               scoped_ptr<base::DictionaryValue> error_data);
61 
62   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetManagedPropertiesFunction);
63 };
64 
65 // Implements the chrome.networkingPrivate.getState method.
66 class NetworkingPrivateGetStateFunction : public ChromeAsyncExtensionFunction {
67  public:
NetworkingPrivateGetStateFunction()68   NetworkingPrivateGetStateFunction() {}
69   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getState",
70                              NETWORKINGPRIVATE_GETSTATE);
71 
72  protected:
73   virtual ~NetworkingPrivateGetStateFunction();
74 
75   // AsyncExtensionFunction overrides.
76   virtual bool RunImpl() OVERRIDE;
77 
78  private:
79   void Success(const std::string& service_path,
80                const base::DictionaryValue& result);
81   void Failure(const std::string& error_name,
82                scoped_ptr<base::DictionaryValue> error_data);
83 
84   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetStateFunction);
85 };
86 
87 // Implements the chrome.networkingPrivate.setProperties method.
88 class NetworkingPrivateSetPropertiesFunction
89     : public ChromeAsyncExtensionFunction {
90  public:
NetworkingPrivateSetPropertiesFunction()91   NetworkingPrivateSetPropertiesFunction() {}
92   DECLARE_EXTENSION_FUNCTION("networkingPrivate.setProperties",
93                              NETWORKINGPRIVATE_SETPROPERTIES);
94 
95  protected:
96   virtual ~NetworkingPrivateSetPropertiesFunction();
97 
98   // AsyncExtensionFunction overrides.
99   virtual bool RunImpl() OVERRIDE;
100 
101  private:
102   void ErrorCallback(const std::string& error_name,
103                      const scoped_ptr<base::DictionaryValue> error_data);
104   void ResultCallback();
105   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateSetPropertiesFunction);
106 };
107 
108 // Implements the chrome.networkingPrivate.createNetwork method.
109 class NetworkingPrivateCreateNetworkFunction
110     : public ChromeAsyncExtensionFunction {
111  public:
NetworkingPrivateCreateNetworkFunction()112   NetworkingPrivateCreateNetworkFunction() {}
113   DECLARE_EXTENSION_FUNCTION("networkingPrivate.createNetwork",
114                              NETWORKINGPRIVATE_CREATENETWORK);
115 
116  protected:
117   virtual ~NetworkingPrivateCreateNetworkFunction();
118 
119   // AsyncExtensionFunction overrides.
120   virtual bool RunImpl() OVERRIDE;
121 
122  private:
123   void ErrorCallback(const std::string& error_name,
124                      const scoped_ptr<base::DictionaryValue> error_data);
125   void ResultCallback(const std::string& guid);
126   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateCreateNetworkFunction);
127 };
128 
129 // Implements the chrome.networkingPrivate.getVisibleNetworks method.
130 class NetworkingPrivateGetVisibleNetworksFunction
131     : public ChromeAsyncExtensionFunction {
132  public:
NetworkingPrivateGetVisibleNetworksFunction()133   NetworkingPrivateGetVisibleNetworksFunction() {}
134   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getVisibleNetworks",
135                              NETWORKINGPRIVATE_GETVISIBLENETWORKS);
136 
137  protected:
138   virtual ~NetworkingPrivateGetVisibleNetworksFunction();
139 
140   // AsyncExtensionFunction overrides.
141   virtual bool RunImpl() OVERRIDE;
142 
143  private:
144   void ResultCallback(const base::ListValue& network_list);
145 
146   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetVisibleNetworksFunction);
147 };
148 
149 // Implements the chrome.networkingPrivate.getEnabledNetworkTypes method.
150 class NetworkingPrivateGetEnabledNetworkTypesFunction
151     : public ChromeSyncExtensionFunction {
152  public:
NetworkingPrivateGetEnabledNetworkTypesFunction()153   NetworkingPrivateGetEnabledNetworkTypesFunction() {}
154   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getEnabledNetworkTypes",
155                              NETWORKINGPRIVATE_GETENABLEDNETWORKTYPES);
156 
157  protected:
158   virtual ~NetworkingPrivateGetEnabledNetworkTypesFunction();
159 
160   // SyncExtensionFunction overrides.
161   virtual bool RunImpl() OVERRIDE;
162 
163  private:
164   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetEnabledNetworkTypesFunction);
165 };
166 
167 // Implements the chrome.networkingPrivate.enableNetworkType method.
168 class NetworkingPrivateEnableNetworkTypeFunction
169     : public ChromeSyncExtensionFunction {
170  public:
NetworkingPrivateEnableNetworkTypeFunction()171   NetworkingPrivateEnableNetworkTypeFunction() {}
172   DECLARE_EXTENSION_FUNCTION("networkingPrivate.enableNetworkType",
173                              NETWORKINGPRIVATE_ENABLENETWORKTYPE);
174 
175  protected:
176   virtual ~NetworkingPrivateEnableNetworkTypeFunction();
177 
178   // SyncExtensionFunction overrides.
179   virtual bool RunImpl() OVERRIDE;
180 
181  private:
182   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateEnableNetworkTypeFunction);
183 };
184 
185 // Implements the chrome.networkingPrivate.disableNetworkType method.
186 class NetworkingPrivateDisableNetworkTypeFunction
187     : public ChromeSyncExtensionFunction {
188  public:
NetworkingPrivateDisableNetworkTypeFunction()189   NetworkingPrivateDisableNetworkTypeFunction() {}
190   DECLARE_EXTENSION_FUNCTION("networkingPrivate.disableNetworkType",
191                              NETWORKINGPRIVATE_DISABLENETWORKTYPE);
192 
193  protected:
194   virtual ~NetworkingPrivateDisableNetworkTypeFunction();
195 
196   // SyncExtensionFunction overrides.
197   virtual bool RunImpl() OVERRIDE;
198 
199  private:
200   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDisableNetworkTypeFunction);
201 };
202 
203 // Implements the chrome.networkingPrivate.requestNetworkScan method.
204 class NetworkingPrivateRequestNetworkScanFunction
205     : public ChromeSyncExtensionFunction {
206  public:
NetworkingPrivateRequestNetworkScanFunction()207   NetworkingPrivateRequestNetworkScanFunction() {}
208   DECLARE_EXTENSION_FUNCTION("networkingPrivate.requestNetworkScan",
209                              NETWORKINGPRIVATE_REQUESTNETWORKSCAN);
210 
211  protected:
212   virtual ~NetworkingPrivateRequestNetworkScanFunction();
213 
214   // SyncExtensionFunction overrides.
215   virtual bool RunImpl() OVERRIDE;
216 
217  private:
218   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateRequestNetworkScanFunction);
219 };
220 
221 
222 // Implements the chrome.networkingPrivate.startConnect method.
223 class NetworkingPrivateStartConnectFunction
224     : public ChromeAsyncExtensionFunction {
225  public:
NetworkingPrivateStartConnectFunction()226   NetworkingPrivateStartConnectFunction() {}
227   DECLARE_EXTENSION_FUNCTION("networkingPrivate.startConnect",
228                              NETWORKINGPRIVATE_STARTCONNECT);
229 
230  protected:
231   virtual ~NetworkingPrivateStartConnectFunction();
232 
233   // AsyncExtensionFunction overrides.
234   virtual bool RunImpl() OVERRIDE;
235 
236  private:
237   // Called when the request to connect succeeds. Doesn't mean that the connect
238   // itself succeeded, just that the request did.
239   void ConnectionStartSuccess();
240 
241   void ConnectionStartFailed(
242       const std::string& error_name,
243       const scoped_ptr<base::DictionaryValue> error_data);
244 
245   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateStartConnectFunction);
246 };
247 
248 // Implements the chrome.networkingPrivate.startDisconnect method.
249 class NetworkingPrivateStartDisconnectFunction
250     : public ChromeAsyncExtensionFunction {
251  public:
NetworkingPrivateStartDisconnectFunction()252   NetworkingPrivateStartDisconnectFunction() {}
253   DECLARE_EXTENSION_FUNCTION("networkingPrivate.startDisconnect",
254                              NETWORKINGPRIVATE_STARTDISCONNECT);
255 
256  protected:
257   virtual ~NetworkingPrivateStartDisconnectFunction();
258 
259   // AsyncExtensionFunction overrides.
260   virtual bool RunImpl() OVERRIDE;
261 
262  private:
263   // Called when the request to disconnect succeeds. Doesn't mean that the
264   // disconnect itself succeeded, just that the request did.
265   void DisconnectionStartSuccess();
266 
267   void DisconnectionStartFailed(
268       const std::string& error_name,
269       const scoped_ptr<base::DictionaryValue> error_data);
270 
271   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateStartDisconnectFunction);
272 };
273 
274 // Implements the chrome.networkingPrivate.verifyDestination method.
275 class NetworkingPrivateVerifyDestinationFunction
276     : public ChromeAsyncExtensionFunction {
277  public:
NetworkingPrivateVerifyDestinationFunction()278   NetworkingPrivateVerifyDestinationFunction() {}
279   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyDestination",
280                              NETWORKINGPRIVATE_VERIFYDESTINATION);
281 
282  protected:
283   virtual ~NetworkingPrivateVerifyDestinationFunction();
284 
285   // AsyncExtensionFunction overrides.
286   virtual bool RunImpl() OVERRIDE;
287 
288   void ResultCallback(bool result);
289   void ErrorCallback(const std::string& error_name, const std::string& error);
290 
291  private:
292   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateVerifyDestinationFunction);
293 };
294 
295 // Implements the chrome.networkingPrivate.verifyAndEncryptCredentials method.
296 class NetworkingPrivateVerifyAndEncryptCredentialsFunction
297     : public ChromeAsyncExtensionFunction {
298  public:
NetworkingPrivateVerifyAndEncryptCredentialsFunction()299   NetworkingPrivateVerifyAndEncryptCredentialsFunction() {}
300   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyAndEncryptCredentials",
301                              NETWORKINGPRIVATE_VERIFYANDENCRYPTCREDENTIALS);
302 
303  protected:
304   virtual ~NetworkingPrivateVerifyAndEncryptCredentialsFunction();
305 
306   // AsyncExtensionFunction overrides.
307   virtual bool RunImpl() OVERRIDE;
308 
309   void ResultCallback(const std::string& result);
310   void ErrorCallback(const std::string& error_name, const std::string& error);
311 
312  private:
313   DISALLOW_COPY_AND_ASSIGN(
314       NetworkingPrivateVerifyAndEncryptCredentialsFunction);
315 };
316 
317 // Implements the chrome.networkingPrivate.verifyAndEncryptData method.
318 class NetworkingPrivateVerifyAndEncryptDataFunction
319     : public ChromeAsyncExtensionFunction {
320  public:
NetworkingPrivateVerifyAndEncryptDataFunction()321   NetworkingPrivateVerifyAndEncryptDataFunction() {}
322   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyAndEncryptData",
323                              NETWORKINGPRIVATE_VERIFYANDENCRYPTDATA);
324 
325  protected:
326   virtual ~NetworkingPrivateVerifyAndEncryptDataFunction();
327 
328   // AsyncExtensionFunction overrides.
329   virtual bool RunImpl() OVERRIDE;
330 
331   void ResultCallback(const std::string& result);
332   void ErrorCallback(const std::string& error_name, const std::string& error);
333 
334  private:
335   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateVerifyAndEncryptDataFunction);
336 };
337 
338 #endif  // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_API_H_
339