• 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/keyed_service/core/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 RunAsync() 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 RunAsync() 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 RunAsync() 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 RunAsync() 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 RunAsync() 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.getNetworks method.
130 class NetworkingPrivateGetNetworksFunction
131     : public ChromeAsyncExtensionFunction {
132  public:
NetworkingPrivateGetNetworksFunction()133   NetworkingPrivateGetNetworksFunction() {}
134   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getNetworks",
135                              NETWORKINGPRIVATE_GETNETWORKS);
136 
137  protected:
138   virtual ~NetworkingPrivateGetNetworksFunction();
139 
140   // AsyncExtensionFunction overrides.
141   virtual bool RunAsync() OVERRIDE;
142 
143  private:
144   void ResultCallback(const base::ListValue& network_list);
145 
146   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetNetworksFunction);
147 };
148 
149 // Implements the chrome.networkingPrivate.getVisibleNetworks method.
150 class NetworkingPrivateGetVisibleNetworksFunction
151     : public ChromeAsyncExtensionFunction {
152  public:
NetworkingPrivateGetVisibleNetworksFunction()153   NetworkingPrivateGetVisibleNetworksFunction() {}
154   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getVisibleNetworks",
155                              NETWORKINGPRIVATE_GETVISIBLENETWORKS);
156 
157  protected:
158   virtual ~NetworkingPrivateGetVisibleNetworksFunction();
159 
160   // AsyncExtensionFunction overrides.
161   virtual bool RunAsync() OVERRIDE;
162 
163  private:
164   void ResultCallback(const base::ListValue& network_list);
165 
166   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetVisibleNetworksFunction);
167 };
168 
169 // Implements the chrome.networkingPrivate.getEnabledNetworkTypes method.
170 class NetworkingPrivateGetEnabledNetworkTypesFunction
171     : public ChromeSyncExtensionFunction {
172  public:
NetworkingPrivateGetEnabledNetworkTypesFunction()173   NetworkingPrivateGetEnabledNetworkTypesFunction() {}
174   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getEnabledNetworkTypes",
175                              NETWORKINGPRIVATE_GETENABLEDNETWORKTYPES);
176 
177  protected:
178   virtual ~NetworkingPrivateGetEnabledNetworkTypesFunction();
179 
180   // SyncExtensionFunction overrides.
181   virtual bool RunSync() OVERRIDE;
182 
183  private:
184   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetEnabledNetworkTypesFunction);
185 };
186 
187 // Implements the chrome.networkingPrivate.enableNetworkType method.
188 class NetworkingPrivateEnableNetworkTypeFunction
189     : public ChromeSyncExtensionFunction {
190  public:
NetworkingPrivateEnableNetworkTypeFunction()191   NetworkingPrivateEnableNetworkTypeFunction() {}
192   DECLARE_EXTENSION_FUNCTION("networkingPrivate.enableNetworkType",
193                              NETWORKINGPRIVATE_ENABLENETWORKTYPE);
194 
195  protected:
196   virtual ~NetworkingPrivateEnableNetworkTypeFunction();
197 
198   // SyncExtensionFunction overrides.
199   virtual bool RunSync() OVERRIDE;
200 
201  private:
202   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateEnableNetworkTypeFunction);
203 };
204 
205 // Implements the chrome.networkingPrivate.disableNetworkType method.
206 class NetworkingPrivateDisableNetworkTypeFunction
207     : public ChromeSyncExtensionFunction {
208  public:
NetworkingPrivateDisableNetworkTypeFunction()209   NetworkingPrivateDisableNetworkTypeFunction() {}
210   DECLARE_EXTENSION_FUNCTION("networkingPrivate.disableNetworkType",
211                              NETWORKINGPRIVATE_DISABLENETWORKTYPE);
212 
213  protected:
214   virtual ~NetworkingPrivateDisableNetworkTypeFunction();
215 
216   // SyncExtensionFunction overrides.
217   virtual bool RunSync() OVERRIDE;
218 
219  private:
220   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateDisableNetworkTypeFunction);
221 };
222 
223 // Implements the chrome.networkingPrivate.requestNetworkScan method.
224 class NetworkingPrivateRequestNetworkScanFunction
225     : public ChromeSyncExtensionFunction {
226  public:
NetworkingPrivateRequestNetworkScanFunction()227   NetworkingPrivateRequestNetworkScanFunction() {}
228   DECLARE_EXTENSION_FUNCTION("networkingPrivate.requestNetworkScan",
229                              NETWORKINGPRIVATE_REQUESTNETWORKSCAN);
230 
231  protected:
232   virtual ~NetworkingPrivateRequestNetworkScanFunction();
233 
234   // SyncExtensionFunction overrides.
235   virtual bool RunSync() OVERRIDE;
236 
237  private:
238   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateRequestNetworkScanFunction);
239 };
240 
241 
242 // Implements the chrome.networkingPrivate.startConnect method.
243 class NetworkingPrivateStartConnectFunction
244     : public ChromeAsyncExtensionFunction {
245  public:
NetworkingPrivateStartConnectFunction()246   NetworkingPrivateStartConnectFunction() {}
247   DECLARE_EXTENSION_FUNCTION("networkingPrivate.startConnect",
248                              NETWORKINGPRIVATE_STARTCONNECT);
249 
250  protected:
251   virtual ~NetworkingPrivateStartConnectFunction();
252 
253   // AsyncExtensionFunction overrides.
254   virtual bool RunAsync() OVERRIDE;
255 
256  private:
257   // Called when the request to connect succeeds. Doesn't mean that the connect
258   // itself succeeded, just that the request did.
259   void ConnectionStartSuccess();
260 
261   void ConnectionStartFailed(
262       const std::string& error_name,
263       const scoped_ptr<base::DictionaryValue> error_data);
264 
265   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateStartConnectFunction);
266 };
267 
268 // Implements the chrome.networkingPrivate.startDisconnect method.
269 class NetworkingPrivateStartDisconnectFunction
270     : public ChromeAsyncExtensionFunction {
271  public:
NetworkingPrivateStartDisconnectFunction()272   NetworkingPrivateStartDisconnectFunction() {}
273   DECLARE_EXTENSION_FUNCTION("networkingPrivate.startDisconnect",
274                              NETWORKINGPRIVATE_STARTDISCONNECT);
275 
276  protected:
277   virtual ~NetworkingPrivateStartDisconnectFunction();
278 
279   // AsyncExtensionFunction overrides.
280   virtual bool RunAsync() OVERRIDE;
281 
282  private:
283   // Called when the request to disconnect succeeds. Doesn't mean that the
284   // disconnect itself succeeded, just that the request did.
285   void DisconnectionStartSuccess();
286 
287   void DisconnectionStartFailed(
288       const std::string& error_name,
289       const scoped_ptr<base::DictionaryValue> error_data);
290 
291   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateStartDisconnectFunction);
292 };
293 
294 // Implements the chrome.networkingPrivate.verifyDestination method.
295 class NetworkingPrivateVerifyDestinationFunction
296     : public ChromeAsyncExtensionFunction {
297  public:
NetworkingPrivateVerifyDestinationFunction()298   NetworkingPrivateVerifyDestinationFunction() {}
299   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyDestination",
300                              NETWORKINGPRIVATE_VERIFYDESTINATION);
301 
302  protected:
303   virtual ~NetworkingPrivateVerifyDestinationFunction();
304 
305   // AsyncExtensionFunction overrides.
306   virtual bool RunAsync() OVERRIDE;
307 
308   void ResultCallback(bool result);
309   void ErrorCallback(const std::string& error_name, const std::string& error);
310 
311  private:
312   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateVerifyDestinationFunction);
313 };
314 
315 // Implements the chrome.networkingPrivate.verifyAndEncryptCredentials method.
316 class NetworkingPrivateVerifyAndEncryptCredentialsFunction
317     : public ChromeAsyncExtensionFunction {
318  public:
NetworkingPrivateVerifyAndEncryptCredentialsFunction()319   NetworkingPrivateVerifyAndEncryptCredentialsFunction() {}
320   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyAndEncryptCredentials",
321                              NETWORKINGPRIVATE_VERIFYANDENCRYPTCREDENTIALS);
322 
323  protected:
324   virtual ~NetworkingPrivateVerifyAndEncryptCredentialsFunction();
325 
326   // AsyncExtensionFunction overrides.
327   virtual bool RunAsync() OVERRIDE;
328 
329   void ResultCallback(const std::string& result);
330   void ErrorCallback(const std::string& error_name, const std::string& error);
331 
332  private:
333   DISALLOW_COPY_AND_ASSIGN(
334       NetworkingPrivateVerifyAndEncryptCredentialsFunction);
335 };
336 
337 // Implements the chrome.networkingPrivate.verifyAndEncryptData method.
338 class NetworkingPrivateVerifyAndEncryptDataFunction
339     : public ChromeAsyncExtensionFunction {
340  public:
NetworkingPrivateVerifyAndEncryptDataFunction()341   NetworkingPrivateVerifyAndEncryptDataFunction() {}
342   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyAndEncryptData",
343                              NETWORKINGPRIVATE_VERIFYANDENCRYPTDATA);
344 
345  protected:
346   virtual ~NetworkingPrivateVerifyAndEncryptDataFunction();
347 
348   // AsyncExtensionFunction overrides.
349   virtual bool RunAsync() OVERRIDE;
350 
351   void ResultCallback(const std::string& result);
352   void ErrorCallback(const std::string& error_name, const std::string& error);
353 
354  private:
355   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateVerifyAndEncryptDataFunction);
356 };
357 
358 // Implements the chrome.networkingPrivate.setWifiTDLSEnabledState method.
359 class NetworkingPrivateSetWifiTDLSEnabledStateFunction
360     : public ChromeAsyncExtensionFunction {
361  public:
NetworkingPrivateSetWifiTDLSEnabledStateFunction()362   NetworkingPrivateSetWifiTDLSEnabledStateFunction() {}
363   DECLARE_EXTENSION_FUNCTION("networkingPrivate.setWifiTDLSEnabledState",
364                              NETWORKINGPRIVATE_SETWIFITDLSENABLEDSTATE);
365 
366  protected:
367   virtual ~NetworkingPrivateSetWifiTDLSEnabledStateFunction();
368 
369   // AsyncExtensionFunction overrides.
370   virtual bool RunAsync() OVERRIDE;
371 
372   void Success(const std::string& result);
373   void Failure(const std::string& error_name,
374                scoped_ptr<base::DictionaryValue> error_data);
375 
376  private:
377   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateSetWifiTDLSEnabledStateFunction);
378 };
379 
380 // Implements the chrome.networkingPrivate.getWifiTDLSStatus method.
381 class NetworkingPrivateGetWifiTDLSStatusFunction
382     : public ChromeAsyncExtensionFunction {
383  public:
NetworkingPrivateGetWifiTDLSStatusFunction()384   NetworkingPrivateGetWifiTDLSStatusFunction() {}
385   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getWifiTDLSStatus",
386                              NETWORKINGPRIVATE_GETWIFITDLSSTATUS);
387 
388  protected:
389   virtual ~NetworkingPrivateGetWifiTDLSStatusFunction();
390 
391   // AsyncExtensionFunction overrides.
392   virtual bool RunAsync() OVERRIDE;
393 
394   void Success(const std::string& result);
395   void Failure(const std::string& error_name,
396                scoped_ptr<base::DictionaryValue> error_data);
397 
398  private:
399   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetWifiTDLSStatusFunction);
400 };
401 
402 class NetworkingPrivateGetCaptivePortalStatusFunction
403     : public ChromeAsyncExtensionFunction {
404  public:
NetworkingPrivateGetCaptivePortalStatusFunction()405   NetworkingPrivateGetCaptivePortalStatusFunction() {}
406   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getCaptivePortalStatus",
407                              NETWORKINGPRIVATE_GETCAPTIVEPORTALSTATUS);
408 
409   // AsyncExtensionFunction overrides.
410   virtual bool RunAsync() OVERRIDE;
411 
412  protected:
413   virtual ~NetworkingPrivateGetCaptivePortalStatusFunction();
414 
415  private:
416   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetCaptivePortalStatusFunction);
417 };
418 
419 #endif  // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_API_H_
420