OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 std::string ret; | 335 std::string ret; |
336 DWORD size = MAX_PATH; // NOLINT | 336 DWORD size = MAX_PATH; // NOLINT |
337 HRESULT hr = E_OUTOFMEMORY; | 337 HRESULT hr = E_OUTOFMEMORY; |
338 for (int retries = 1; hr == E_OUTOFMEMORY && retries <= 10; ++retries) { | 338 for (int retries = 1; hr == E_OUTOFMEMORY && retries <= 10; ++retries) { |
339 hr = ::ObtainUserAgentString(0, WriteInto(&ret, size + 1), &size); | 339 hr = ::ObtainUserAgentString(0, WriteInto(&ret, size + 1), &size); |
340 if (hr == E_OUTOFMEMORY) { | 340 if (hr == E_OUTOFMEMORY) { |
341 size = MAX_PATH * retries; | 341 size = MAX_PATH * retries; |
342 } else if (SUCCEEDED(hr)) { | 342 } else if (SUCCEEDED(hr)) { |
343 // Truncate the extra allocation. | 343 // Truncate the extra allocation. |
344 DCHECK(size > 0); // NOLINT | 344 DCHECK(size > 0); // NOLINT |
345 ret.resize(size - 1); // NOLINT | 345 ret.resize(size - sizeof(char)); // NOLINT |
346 } | 346 } |
347 } | 347 } |
348 | 348 |
349 if (FAILED(hr)) { | 349 if (FAILED(hr)) { |
350 NOTREACHED() << StringPrintf("ObtainUserAgentString==0x%08X", hr); | 350 NOTREACHED() << StringPrintf("ObtainUserAgentString==0x%08X", hr); |
351 return std::string(); | 351 return ""; |
| 352 } else { |
| 353 DCHECK(ret.length() == lstrlenA(ret.c_str())); |
352 } | 354 } |
353 | 355 |
354 return ret; | 356 return ret; |
355 } | 357 } |
356 | 358 |
357 bool HasFrameBustingHeader(const std::string& http_headers) { | 359 bool HasFrameBustingHeader(const std::string& http_headers) { |
358 net::HttpUtil::HeadersIterator it( | 360 net::HttpUtil::HeadersIterator it( |
359 http_headers.begin(), http_headers.end(), "\r\n"); | 361 http_headers.begin(), http_headers.end(), "\r\n"); |
360 while (it.GetNext()) { | 362 while (it.GetNext()) { |
361 if (lstrcmpiA(it.name().c_str(), kXFrameOptionsHeader) == 0) { | 363 if (lstrcmpiA(it.name().c_str(), kXFrameOptionsHeader) == 0) { |
362 std::string allow_all(kXFrameOptionsValueAllowAll); | 364 std::string allow_all(kXFrameOptionsValueAllowAll); |
363 if (it.values_end() - it.values_begin() != | 365 if (it.values_end() - it.values_begin() != allow_all.length() || |
364 static_cast<int>(allow_all.length()) || | |
365 !std::equal(it.values_begin(), it.values_end(), | 366 !std::equal(it.values_begin(), it.values_end(), |
366 allow_all.begin(), | 367 allow_all.begin(), |
367 CaseInsensitiveCompareASCII<const char>())) { | 368 CaseInsensitiveCompareASCII<const char>())) { |
368 return true; | 369 return true; |
369 } | 370 } |
370 } | 371 } |
371 } | 372 } |
372 | 373 |
373 return false; | 374 return false; |
374 } | 375 } |
375 | 376 |
376 } // namespace http_utils | 377 } // namespace http_utils |
OLD | NEW |