| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome_frame/http_negotiate.h" | 5 #include "chrome_frame/http_negotiate.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <atlcom.h> | 8 #include <atlcom.h> |
| 9 #include <htiframe.h> | 9 #include <htiframe.h> |
| 10 | 10 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 new_headers += "User-Agent: " + user_agent_value; | 128 new_headers += "User-Agent: " + user_agent_value; |
| 129 new_headers += "\r\n"; | 129 new_headers += "\r\n"; |
| 130 return new_headers; | 130 return new_headers; |
| 131 } | 131 } |
| 132 | 132 |
| 133 std::string ReplaceOrAddUserAgent(LPCWSTR headers, | 133 std::string ReplaceOrAddUserAgent(LPCWSTR headers, |
| 134 const std::string& user_agent_value) { | 134 const std::string& user_agent_value) { |
| 135 DCHECK(headers); | 135 DCHECK(headers); |
| 136 using net::HttpUtil; | 136 using net::HttpUtil; |
| 137 | 137 |
| 138 std::string ascii_headers(WideToASCII(headers)); | 138 if (headers) { |
| 139 std::string ascii_headers(WideToASCII(headers)); |
| 139 | 140 |
| 140 // Extract "User-Agent" from the headers. | 141 // Extract "User-Agent" from the headers. |
| 141 HttpUtil::HeadersIterator headers_iterator(ascii_headers.begin(), | 142 HttpUtil::HeadersIterator headers_iterator(ascii_headers.begin(), |
| 142 ascii_headers.end(), "\r\n"); | 143 ascii_headers.end(), "\r\n"); |
| 143 | 144 |
| 144 // Build new headers, skip the existing user agent value from | 145 // Build new headers, skip the existing user agent value from |
| 145 // existing headers. | 146 // existing headers. |
| 146 std::string new_headers; | 147 std::string new_headers; |
| 147 while (headers_iterator.GetNext()) { | 148 while (headers_iterator.GetNext()) { |
| 148 std::string name(headers_iterator.name()); | 149 std::string name(headers_iterator.name()); |
| 149 if (!LowerCaseEqualsASCII(name, kLowerCaseUserAgent)) { | 150 if (!LowerCaseEqualsASCII(name, kLowerCaseUserAgent)) { |
| 150 new_headers += name + ": " + headers_iterator.values() + "\r\n"; | 151 new_headers += name + ": " + headers_iterator.values() + "\r\n"; |
| 152 } |
| 151 } | 153 } |
| 152 } | 154 } |
| 153 | |
| 154 new_headers += "User-Agent: " + user_agent_value; | 155 new_headers += "User-Agent: " + user_agent_value; |
| 155 new_headers += "\r\n"; | 156 new_headers += "\r\n"; |
| 156 return new_headers; | 157 return new_headers; |
| 157 } | 158 } |
| 158 | 159 |
| 159 HttpNegotiatePatch::HttpNegotiatePatch() { | 160 HttpNegotiatePatch::HttpNegotiatePatch() { |
| 160 } | 161 } |
| 161 | 162 |
| 162 HttpNegotiatePatch::~HttpNegotiatePatch() { | 163 HttpNegotiatePatch::~HttpNegotiatePatch() { |
| 163 } | 164 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 DLOG(WARNING) << __FUNCTION__ << " Delegate returned an error"; | 229 DLOG(WARNING) << __FUNCTION__ << " Delegate returned an error"; |
| 229 return hr; | 230 return hr; |
| 230 } | 231 } |
| 231 std::string updated(AppendCFUserAgentString(headers, *additional_headers)); | 232 std::string updated(AppendCFUserAgentString(headers, *additional_headers)); |
| 232 *additional_headers = reinterpret_cast<wchar_t*>(::CoTaskMemRealloc( | 233 *additional_headers = reinterpret_cast<wchar_t*>(::CoTaskMemRealloc( |
| 233 *additional_headers, (updated.length() + 1) * sizeof(wchar_t))); | 234 *additional_headers, (updated.length() + 1) * sizeof(wchar_t))); |
| 234 lstrcpyW(*additional_headers, ASCIIToWide(updated).c_str()); | 235 lstrcpyW(*additional_headers, ASCIIToWide(updated).c_str()); |
| 235 return S_OK; | 236 return S_OK; |
| 236 } | 237 } |
| 237 | 238 |
| OLD | NEW |