| 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 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_split.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" | 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
| 15 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 16 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
| 16 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
| 17 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" | 18 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h
" |
| 18 #include "crypto/random.h" | 19 #include "crypto/random.h" |
| 19 #include "net/proxy/proxy_server.h" | 20 #include "net/proxy/proxy_server.h" |
| 20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace data_reduction_proxy { | 24 namespace data_reduction_proxy { |
| 24 | 25 |
| 25 // The empty version for the authentication protocol. Currently used by | 26 // The empty version for the authentication protocol. Currently used by |
| 26 // Android webview. | 27 // Android webview. |
| 27 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 28 const char kAndroidWebViewProtocolVersion[] = "0"; | 29 const char kAndroidWebViewProtocolVersion[] = ""; |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 // The clients supported by the data reduction proxy. | 32 // The clients supported by the data reduction proxy. |
| 32 const char kClientAndroidWebview[] = "webview"; | 33 const char kClientAndroidWebview[] = "webview"; |
| 33 const char kClientChromeAndroid[] = "android"; | 34 const char kClientChromeAndroid[] = "android"; |
| 34 const char kClientChromeIOS[] = "ios"; | 35 const char kClientChromeIOS[] = "ios"; |
| 35 | 36 |
| 36 // static | 37 // static |
| 37 bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { | 38 bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { |
| 38 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 39 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 39 return command_line.HasSwitch( | 40 return command_line.HasSwitch( |
| 40 data_reduction_proxy::switches::kDataReductionProxyKey); | 41 data_reduction_proxy::switches::kDataReductionProxyKey); |
| 41 } | 42 } |
| 42 | 43 |
| 43 DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( | 44 DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( |
| 44 const std::string& client, | 45 const std::string& client, |
| 45 const std::string& version, | 46 const std::string& version, |
| 46 DataReductionProxyParams* params, | 47 DataReductionProxyParams* params, |
| 47 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) | 48 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) |
| 48 : data_reduction_proxy_params_(params), | 49 : data_reduction_proxy_params_(params), |
| 49 network_task_runner_(network_task_runner) { | 50 network_task_runner_(network_task_runner) { |
| 50 client_ = client; | 51 client_ = client; |
| 51 version_ = version; | 52 GetChromiumBuildAndPatch(version, &build_number_, &patch_number_); |
| 52 Init(); | 53 Init(); |
| 53 } | 54 } |
| 54 | 55 |
| 56 void DataReductionProxyAuthRequestHandler::GetChromiumBuildAndPatch( |
| 57 const std::string& version, |
| 58 std::string* build, |
| 59 std::string* patch) { |
| 60 std::vector<std::string> version_parts; |
| 61 base::SplitString(version, '.', &version_parts); |
| 62 if (version_parts.size() != 4) |
| 63 return; |
| 64 *build = version_parts[2]; |
| 65 *patch = version_parts[3]; |
| 66 } |
| 67 |
| 55 void DataReductionProxyAuthRequestHandler::Init() { | 68 void DataReductionProxyAuthRequestHandler::Init() { |
| 56 InitAuthenticationOnUI(GetDefaultKey()); | 69 InitAuthenticationOnUI(GetDefaultKey()); |
| 57 } | 70 } |
| 58 | 71 |
| 59 | 72 |
| 60 DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { | 73 DataReductionProxyAuthRequestHandler::~DataReductionProxyAuthRequestHandler() { |
| 61 } | 74 } |
| 62 | 75 |
| 63 // static | 76 // static |
| 64 base::string16 DataReductionProxyAuthRequestHandler::AuthHashForSalt( | 77 base::string16 DataReductionProxyAuthRequestHandler::AuthHashForSalt( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ComputeCredentials(last_update_time_, &session_, &credentials_); | 118 ComputeCredentials(last_update_time_, &session_, &credentials_); |
| 106 } | 119 } |
| 107 const char kChromeProxyHeader[] = "Chrome-Proxy"; | 120 const char kChromeProxyHeader[] = "Chrome-Proxy"; |
| 108 std::string header_value; | 121 std::string header_value; |
| 109 if (headers->HasHeader(kChromeProxyHeader)) { | 122 if (headers->HasHeader(kChromeProxyHeader)) { |
| 110 headers->GetHeader(kChromeProxyHeader, &header_value); | 123 headers->GetHeader(kChromeProxyHeader, &header_value); |
| 111 headers->RemoveHeader(kChromeProxyHeader); | 124 headers->RemoveHeader(kChromeProxyHeader); |
| 112 header_value += ", "; | 125 header_value += ", "; |
| 113 } | 126 } |
| 114 header_value += | 127 header_value += |
| 115 "ps=" + session_ + ", sid=" + credentials_ + ", v=" + version_; | 128 "ps=" + session_ + ", sid=" + credentials_; |
| 129 if (!build_number_.empty() && !patch_number_.empty()) |
| 130 header_value += ", b=" + build_number_ + ", p=" + patch_number_; |
| 116 if (!client_.empty()) | 131 if (!client_.empty()) |
| 117 header_value += ", c=" + client_; | 132 header_value += ", c=" + client_; |
| 118 headers->SetHeader(kChromeProxyHeader, header_value); | 133 headers->SetHeader(kChromeProxyHeader, header_value); |
| 119 } | 134 } |
| 120 | 135 |
| 121 void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI( | 136 void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI( |
| 122 const std::string& key) { | 137 const std::string& key) { |
| 123 network_task_runner_->PostTask(FROM_HERE, base::Bind( | 138 network_task_runner_->PostTask(FROM_HERE, base::Bind( |
| 124 &DataReductionProxyAuthRequestHandler::InitAuthentication, | 139 &DataReductionProxyAuthRequestHandler::InitAuthentication, |
| 125 base::Unretained(this), | 140 base::Unretained(this), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 std::string key = | 182 std::string key = |
| 168 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); | 183 command_line.GetSwitchValueASCII(switches::kDataReductionProxyKey); |
| 169 #if defined(SPDY_PROXY_AUTH_VALUE) | 184 #if defined(SPDY_PROXY_AUTH_VALUE) |
| 170 if (key.empty()) | 185 if (key.empty()) |
| 171 key = SPDY_PROXY_AUTH_VALUE; | 186 key = SPDY_PROXY_AUTH_VALUE; |
| 172 #endif | 187 #endif |
| 173 return key; | 188 return key; |
| 174 } | 189 } |
| 175 | 190 |
| 176 } // namespace data_reduction_proxy | 191 } // namespace data_reduction_proxy |
| OLD | NEW |