| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/html_utils.h" | 5 #include "chrome_frame/html_utils.h" |
| 6 | 6 |
| 7 #include <atlbase.h> | 7 #include <atlbase.h> |
| 8 #include <urlmon.h> | 8 #include <urlmon.h> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/string_tokenizer.h" | 11 #include "base/string_tokenizer.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 HIWORD(high_version), LOWORD(high_version), | 336 HIWORD(high_version), LOWORD(high_version), |
| 337 HIWORD(low_version), LOWORD(low_version)); | 337 HIWORD(low_version), LOWORD(low_version)); |
| 338 } | 338 } |
| 339 _pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock(); | 339 _pAtlModule->m_csStaticDataInitAndTypeInfo.Unlock(); |
| 340 } | 340 } |
| 341 return g_cf_user_agent; | 341 return g_cf_user_agent; |
| 342 } | 342 } |
| 343 | 343 |
| 344 std::string AddChromeFrameToUserAgentValue(const std::string& value) { | 344 std::string AddChromeFrameToUserAgentValue(const std::string& value) { |
| 345 if (value.empty()) { | 345 if (value.empty()) { |
| 346 DLOG(WARNING) << "empty user agent value"; | 346 return value; |
| 347 return ""; | |
| 348 } | 347 } |
| 349 | 348 |
| 350 DCHECK_EQ(false, StartsWithASCII(value, "User-Agent:", true)); | |
| 351 | |
| 352 if (value.find(kChromeFrameUserAgent) != std::string::npos) { | 349 if (value.find(kChromeFrameUserAgent) != std::string::npos) { |
| 353 // Our user agent has already been added. | 350 // Our user agent has already been added. |
| 354 return value; | 351 return value; |
| 355 } | 352 } |
| 356 | 353 |
| 357 std::string ret(value); | 354 std::string ret(value); |
| 358 std::string::size_type insert_position = ret.find(')'); | 355 size_t insert_position = ret.find(')'); |
| 359 if (insert_position != std::string::npos) { | 356 if (insert_position != std::string::npos) { |
| 360 if (insert_position > 1 && isalnum(ret[insert_position - 1])) | 357 if (insert_position > 1 && isalnum(ret[insert_position - 1])) |
| 361 ret.insert(insert_position++, ";"); | 358 ret.insert(insert_position++, ";"); |
| 362 ret.insert(insert_position++, " "); | 359 ret.insert(insert_position++, " "); |
| 363 ret.insert(insert_position, GetChromeFrameUserAgent()); | 360 ret.insert(insert_position, GetChromeFrameUserAgent()); |
| 364 } else { | 361 } else { |
| 365 ret += " "; | 362 ret += " "; |
| 366 ret += GetChromeFrameUserAgent(); | 363 ret += GetChromeFrameUserAgent(); |
| 367 } | 364 } |
| 368 | 365 |
| 369 return ret; | 366 return ret; |
| 370 } | 367 } |
| 371 | 368 |
| 369 std::string RemoveChromeFrameFromUserAgentValue(const std::string& value) { |
| 370 size_t cf_start = value.find(kChromeFrameUserAgent); |
| 371 if (cf_start == std::string::npos) { |
| 372 // The user agent is not present. |
| 373 return value; |
| 374 } |
| 375 |
| 376 size_t offset = 0; |
| 377 // If we prepended a '; ' or a ' ' then remove that in the output. |
| 378 if (cf_start > 1 && value[cf_start - 1] == ' ') |
| 379 ++offset; |
| 380 if (cf_start > 3 && |
| 381 value[cf_start - 2] == ';' && |
| 382 isalnum(value[cf_start - 3])) { |
| 383 ++offset; |
| 384 } |
| 385 |
| 386 std::string ret(value, 0, std::max(cf_start - offset, 0U)); |
| 387 cf_start += strlen(kChromeFrameUserAgent); |
| 388 while (cf_start < value.length() && |
| 389 ((value[cf_start] >= '0' && value[cf_start] <= '9') || |
| 390 value[cf_start] == '.' || |
| 391 value[cf_start] == '/')) { |
| 392 ++cf_start; |
| 393 } |
| 394 |
| 395 if (cf_start < value.length()) |
| 396 ret.append(value, cf_start, std::string::npos); |
| 397 |
| 398 return ret; |
| 399 } |
| 400 |
| 372 std::string GetDefaultUserAgentHeaderWithCFTag() { | 401 std::string GetDefaultUserAgentHeaderWithCFTag() { |
| 373 std::string ua(GetDefaultUserAgent()); | 402 std::string ua(GetDefaultUserAgent()); |
| 374 return "User-Agent: " + AddChromeFrameToUserAgentValue(ua); | 403 return "User-Agent: " + AddChromeFrameToUserAgentValue(ua); |
| 375 } | 404 } |
| 376 | 405 |
| 377 const char* GetChromeUserAgent() { | 406 const char* GetChromeUserAgent() { |
| 378 if (!g_chrome_user_agent[0]) { | 407 if (!g_chrome_user_agent[0]) { |
| 379 _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock(); | 408 _pAtlModule->m_csStaticDataInitAndTypeInfo.Lock(); |
| 380 if (!g_chrome_user_agent[0]) { | 409 if (!g_chrome_user_agent[0]) { |
| 381 std::string ua; | 410 std::string ua; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 const std::string& headers) { | 466 const std::string& headers) { |
| 438 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 467 net::HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
| 439 while (it.GetNext()) { | 468 while (it.GetNext()) { |
| 440 if (!lstrcmpiA(it.name().c_str(), header.c_str())) | 469 if (!lstrcmpiA(it.name().c_str(), header.c_str())) |
| 441 return std::string(it.values_begin(), it.values_end()); | 470 return std::string(it.values_begin(), it.values_end()); |
| 442 } | 471 } |
| 443 return std::string(); | 472 return std::string(); |
| 444 } | 473 } |
| 445 | 474 |
| 446 } // namespace http_utils | 475 } // namespace http_utils |
| OLD | NEW |