Home | History | Annotate | Download | only in networking_private
      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/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 : public AsyncExtensionFunction {
     21  public:
     22   NetworkingPrivateGetPropertiesFunction() {}
     23   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getProperties",
     24                              NETWORKINGPRIVATE_GETPROPERTIES);
     25 
     26  protected:
     27   virtual ~NetworkingPrivateGetPropertiesFunction();
     28 
     29   // AsyncExtensionFunction overrides.
     30   virtual bool RunImpl() OVERRIDE;
     31 
     32  private:
     33   void GetPropertiesSuccess(const std::string& service_path,
     34                             const base::DictionaryValue& result);
     35   void GetPropertiesFailed(const std::string& error_name,
     36                            scoped_ptr<base::DictionaryValue> error_data);
     37   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetPropertiesFunction);
     38 };
     39 
     40 // Implements the chrome.networkingPrivate.getManagedProperties method.
     41 class NetworkingPrivateGetManagedPropertiesFunction
     42     : public AsyncExtensionFunction {
     43  public:
     44   NetworkingPrivateGetManagedPropertiesFunction() {}
     45   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getManagedProperties",
     46                              NETWORKINGPRIVATE_GETMANAGEDPROPERTIES);
     47 
     48  protected:
     49   virtual ~NetworkingPrivateGetManagedPropertiesFunction();
     50 
     51   // AsyncExtensionFunction overrides.
     52   virtual bool RunImpl() OVERRIDE;
     53 
     54  private:
     55   // Callbacks for ManagedNetworkConfigurationHandler::GetManagedProperties.
     56   void Success(const std::string& service_path,
     57                const base::DictionaryValue& result);
     58   void Failure(const std::string& error_name,
     59               scoped_ptr<base::DictionaryValue> error_data);
     60 
     61   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetManagedPropertiesFunction);
     62 };
     63 
     64 // Implements the chrome.networkingPrivate.getState method.
     65 class NetworkingPrivateGetStateFunction : public AsyncExtensionFunction {
     66  public:
     67   NetworkingPrivateGetStateFunction() {}
     68   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getState",
     69                              NETWORKINGPRIVATE_GETSTATE);
     70 
     71  protected:
     72   virtual ~NetworkingPrivateGetStateFunction();
     73 
     74   // AsyncExtensionFunction overrides.
     75   virtual bool RunImpl() OVERRIDE;
     76 
     77  private:
     78   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetStateFunction);
     79 };
     80 
     81 // Implements the chrome.networkingPrivate.setProperties method.
     82 class NetworkingPrivateSetPropertiesFunction : public AsyncExtensionFunction {
     83  public:
     84   NetworkingPrivateSetPropertiesFunction() {}
     85   DECLARE_EXTENSION_FUNCTION("networkingPrivate.setProperties",
     86                              NETWORKINGPRIVATE_SETPROPERTIES);
     87 
     88  protected:
     89   virtual ~NetworkingPrivateSetPropertiesFunction();
     90 
     91   // AsyncExtensionFunction overrides.
     92   virtual bool RunImpl() OVERRIDE;
     93 
     94  private:
     95   void ErrorCallback(const std::string& error_name,
     96                      const scoped_ptr<base::DictionaryValue> error_data);
     97   void ResultCallback();
     98   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateSetPropertiesFunction);
     99 };
    100 
    101 // Implements the chrome.networkingPrivate.getVisibleNetworks method.
    102 class NetworkingPrivateGetVisibleNetworksFunction
    103     : public SyncExtensionFunction {
    104  public:
    105   NetworkingPrivateGetVisibleNetworksFunction() {}
    106   DECLARE_EXTENSION_FUNCTION("networkingPrivate.getVisibleNetworks",
    107                              NETWORKINGPRIVATE_GETVISIBLENETWORKS);
    108 
    109  protected:
    110   virtual ~NetworkingPrivateGetVisibleNetworksFunction();
    111 
    112   // SyncExtensionFunction overrides.
    113   virtual bool RunImpl() OVERRIDE;
    114 
    115  private:
    116   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateGetVisibleNetworksFunction);
    117 };
    118 
    119 // Implements the chrome.networkingPrivate.requestNetworkScan method.
    120 class NetworkingPrivateRequestNetworkScanFunction
    121     : public SyncExtensionFunction {
    122  public:
    123   NetworkingPrivateRequestNetworkScanFunction() {}
    124   DECLARE_EXTENSION_FUNCTION("networkingPrivate.requestNetworkScan",
    125                              NETWORKINGPRIVATE_REQUESTNETWORKSCAN);
    126 
    127  protected:
    128   virtual ~NetworkingPrivateRequestNetworkScanFunction();
    129 
    130   // SyncExtensionFunction overrides.
    131   virtual bool RunImpl() OVERRIDE;
    132 
    133  private:
    134   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateRequestNetworkScanFunction);
    135 };
    136 
    137 
    138 // Implements the chrome.networkingPrivate.startConnect method.
    139 class NetworkingPrivateStartConnectFunction : public AsyncExtensionFunction {
    140  public:
    141   NetworkingPrivateStartConnectFunction() {}
    142   DECLARE_EXTENSION_FUNCTION("networkingPrivate.startConnect",
    143                              NETWORKINGPRIVATE_STARTCONNECT);
    144 
    145  protected:
    146   virtual ~NetworkingPrivateStartConnectFunction();
    147 
    148   // AsyncExtensionFunction overrides.
    149   virtual bool RunImpl() OVERRIDE;
    150 
    151  private:
    152   // Called when the request to connect succeeds. Doesn't mean that the connect
    153   // itself succeeded, just that the request did.
    154   void ConnectionStartSuccess();
    155 
    156   void ConnectionStartFailed(
    157       const std::string& error_name,
    158       const scoped_ptr<base::DictionaryValue> error_data);
    159 
    160   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateStartConnectFunction);
    161 };
    162 
    163 // Implements the chrome.networkingPrivate.startDisconnect method.
    164 class NetworkingPrivateStartDisconnectFunction
    165     : public AsyncExtensionFunction {
    166  public:
    167   NetworkingPrivateStartDisconnectFunction() {}
    168   DECLARE_EXTENSION_FUNCTION("networkingPrivate.startDisconnect",
    169                              NETWORKINGPRIVATE_STARTDISCONNECT);
    170 
    171  protected:
    172   virtual ~NetworkingPrivateStartDisconnectFunction();
    173 
    174   // AsyncExtensionFunction overrides.
    175   virtual bool RunImpl() OVERRIDE;
    176 
    177  private:
    178   // Called when the request to disconnect succeeds. Doesn't mean that the
    179   // disconnect itself succeeded, just that the request did.
    180   void DisconnectionStartSuccess();
    181 
    182   void DisconnectionStartFailed(
    183       const std::string& error_name,
    184       const scoped_ptr<base::DictionaryValue> error_data);
    185 
    186   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateStartDisconnectFunction);
    187 };
    188 
    189 // Implements the chrome.networkingPrivate.verifyDestination method.
    190 class NetworkingPrivateVerifyDestinationFunction
    191     : public AsyncExtensionFunction {
    192  public:
    193   NetworkingPrivateVerifyDestinationFunction() {}
    194   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyDestination",
    195                              NETWORKINGPRIVATE_VERIFYDESTINATION);
    196 
    197  protected:
    198   virtual ~NetworkingPrivateVerifyDestinationFunction();
    199 
    200   // AsyncExtensionFunction overrides.
    201   virtual bool RunImpl() OVERRIDE;
    202 
    203   void ResultCallback(bool result);
    204   void ErrorCallback(const std::string& error_name, const std::string& error);
    205 
    206  private:
    207   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateVerifyDestinationFunction);
    208 };
    209 
    210 // Implements the chrome.networkingPrivate.verifyAndEncryptCredentials method.
    211 class NetworkingPrivateVerifyAndEncryptCredentialsFunction
    212     : public AsyncExtensionFunction {
    213  public:
    214   NetworkingPrivateVerifyAndEncryptCredentialsFunction() {}
    215   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyAndEncryptCredentials",
    216                              NETWORKINGPRIVATE_VERIFYANDENCRYPTCREDENTIALS);
    217 
    218  protected:
    219   virtual ~NetworkingPrivateVerifyAndEncryptCredentialsFunction();
    220 
    221   // AsyncExtensionFunction overrides.
    222   virtual bool RunImpl() OVERRIDE;
    223 
    224   void ResultCallback(const std::string& result);
    225   void ErrorCallback(const std::string& error_name, const std::string& error);
    226 
    227  private:
    228   DISALLOW_COPY_AND_ASSIGN(
    229       NetworkingPrivateVerifyAndEncryptCredentialsFunction);
    230 };
    231 
    232 // Implements the chrome.networkingPrivate.verifyAndEncryptData method.
    233 class NetworkingPrivateVerifyAndEncryptDataFunction
    234     : public AsyncExtensionFunction {
    235  public:
    236   NetworkingPrivateVerifyAndEncryptDataFunction() {}
    237   DECLARE_EXTENSION_FUNCTION("networkingPrivate.verifyAndEncryptData",
    238                              NETWORKINGPRIVATE_VERIFYANDENCRYPTDATA);
    239 
    240  protected:
    241   virtual ~NetworkingPrivateVerifyAndEncryptDataFunction();
    242 
    243   // AsyncExtensionFunction overrides.
    244   virtual bool RunImpl() OVERRIDE;
    245 
    246   void ResultCallback(const std::string& result);
    247   void ErrorCallback(const std::string& error_name, const std::string& error);
    248 
    249  private:
    250   DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateVerifyAndEncryptDataFunction);
    251 };
    252 
    253 #endif  // CHROME_BROWSER_EXTENSIONS_API_NETWORKING_PRIVATE_NETWORKING_PRIVATE_API_H_
    254 
    255