| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQUES
T_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 class HttpRequestHeaders; | 15 class HttpRequestHeaders; |
| 16 class HttpResponseHeaders; | 16 class HttpResponseHeaders; |
| 17 class ProxyServer; | 17 class ProxyServer; |
| 18 class URLRequest; | 18 class URLRequest; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace data_reduction_proxy { | 21 namespace data_reduction_proxy { |
| 22 | 22 |
| 23 extern const char kProtocolVersion[]; | 23 #if defined(OS_ANDROID) |
| 24 extern const char kAndroidWebViewProtocolVersion[]; |
| 25 #endif |
| 24 | 26 |
| 25 extern const char kClientAndroidWebview[]; | 27 extern const char kClientAndroidWebview[]; |
| 26 extern const char kClientChromeAndroid[]; | 28 extern const char kClientChromeAndroid[]; |
| 27 extern const char kClientChromeIOS[]; | 29 extern const char kClientChromeIOS[]; |
| 28 | 30 |
| 29 class DataReductionProxyParams; | 31 class DataReductionProxyParams; |
| 30 | 32 |
| 31 class DataReductionProxyAuthRequestHandler { | 33 class DataReductionProxyAuthRequestHandler { |
| 32 public: | 34 public: |
| 33 static bool IsKeySetOnCommandLine(); | 35 static bool IsKeySetOnCommandLine(); |
| 34 | 36 |
| 35 // Constructs an authentication request handler. | 37 // Constructs an authentication request handler. Client is the canonical name |
| 36 explicit DataReductionProxyAuthRequestHandler( | 38 // for the client. Client names should be defined in this file as one of |
| 39 // |kClient...|. Version is the authentication protocol version that the |
| 40 // client uses, which should be |kProtocolVersion| unless the client expects |
| 41 // to be handled differently from the standard behavior. |
| 42 DataReductionProxyAuthRequestHandler( |
| 43 const std::string& client, |
| 44 const std::string& version, |
| 37 DataReductionProxyParams* params); | 45 DataReductionProxyParams* params); |
| 38 | 46 |
| 39 virtual ~DataReductionProxyAuthRequestHandler(); | 47 virtual ~DataReductionProxyAuthRequestHandler(); |
| 40 | 48 |
| 41 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction | 49 // Adds a 'Chrome-Proxy' header to |request_headers| with the data reduction |
| 42 // proxy authentication credentials. Only adds this header if the provided | 50 // proxy authentication credentials. Only adds this header if the provided |
| 43 // |proxy_server| is a data reduction proxy. | 51 // |proxy_server| is a data reduction proxy. |
| 44 void MaybeAddRequestHeader(net::URLRequest* request, | 52 void MaybeAddRequestHeader(net::URLRequest* request, |
| 45 const net::ProxyServer& proxy_server, | 53 const net::ProxyServer& proxy_server, |
| 46 net::HttpRequestHeaders* request_headers); | 54 net::HttpRequestHeaders* request_headers); |
| 47 | 55 |
| 48 // Sets a new authentication key. This must be called for platforms that do | 56 // Sets a new authentication key. This must be called for platforms that do |
| 49 // not have a default key defined. See the constructor implementation for | 57 // not have a default key defined. See the constructor implementation for |
| 50 // those platforms. Client is the canonical name for the client. Client names | 58 // those platforms. |
| 51 // should be defined in this file as one of |kClient...|. Version is the | 59 void SetKey(const std::string& key); |
| 52 // authentication protocol version that the client uses, which should be | |
| 53 // |kProtocolVersion| unless the client expects to be handled differently from | |
| 54 // the standard behavior. | |
| 55 void SetKey(const std::string& key, | |
| 56 const std::string& client, | |
| 57 const std::string& version); | |
| 58 | 60 |
| 59 protected: | 61 protected: |
| 60 void Init(); | 62 void Init(); |
| 61 void InitAuthentication(const std::string& key); | 63 void InitAuthentication(const std::string& key); |
| 62 | 64 |
| 63 void AddAuthorizationHeader(net::HttpRequestHeaders* headers); | 65 void AddAuthorizationHeader(net::HttpRequestHeaders* headers); |
| 64 | 66 |
| 65 // Returns a UTF16 string that's the hash of the configured authentication | 67 // Returns a UTF16 string that's the hash of the configured authentication |
| 66 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or | 68 // |key| and |salt|. Returns an empty UTF16 string if no key is configured or |
| 67 // the data reduction proxy feature isn't available. | 69 // the data reduction proxy feature isn't available. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 89 std::string client_; | 91 std::string client_; |
| 90 std::string version_; | 92 std::string version_; |
| 91 | 93 |
| 92 DataReductionProxyParams* data_reduction_proxy_params_; | 94 DataReductionProxyParams* data_reduction_proxy_params_; |
| 93 | 95 |
| 94 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); | 96 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyAuthRequestHandler); |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 } // namespace data_reduction_proxy | 99 } // namespace data_reduction_proxy |
| 98 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ | 100 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_AUTH_REQ
UEST_HANDLER_H_ |
| OLD | NEW |