| OLD | NEW |
| 1 // Copyright (c) 2012 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 // Detecting mime types is a tricky business because we need to balance | 5 // Detecting mime types is a tricky business because we need to balance |
| 6 // compatibility concerns with security issues. Here is a survey of how other | 6 // compatibility concerns with security issues. Here is a survey of how other |
| 7 // browsers behave and then a description of how we intend to behave. | 7 // browsers behave and then a description of how we intend to behave. |
| 8 // | 8 // |
| 9 // HTML payload, no Content-Type header: | 9 // HTML payload, no Content-Type header: |
| 10 // * IE 7: Render as HTML | 10 // * IE 7: Render as HTML |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 std::string* result) { | 398 std::string* result) { |
| 399 // For HTML, we are willing to consider up to 512 bytes. This may be overly | 399 // For HTML, we are willing to consider up to 512 bytes. This may be overly |
| 400 // conservative as IE only considers 256. | 400 // conservative as IE only considers 256. |
| 401 *have_enough_content &= TruncateSize(512, &size); | 401 *have_enough_content &= TruncateSize(512, &size); |
| 402 | 402 |
| 403 // We adopt a strategy similar to that used by Mozilla to sniff HTML tags, | 403 // We adopt a strategy similar to that used by Mozilla to sniff HTML tags, |
| 404 // but with some modifications to better match the HTML5 spec. | 404 // but with some modifications to better match the HTML5 spec. |
| 405 const char* const end = content + size; | 405 const char* const end = content + size; |
| 406 const char* pos; | 406 const char* pos; |
| 407 for (pos = content; pos < end; ++pos) { | 407 for (pos = content; pos < end; ++pos) { |
| 408 if (!IsAsciiWhitespace(*pos)) | 408 if (!base::IsAsciiWhitespace(*pos)) |
| 409 break; | 409 break; |
| 410 } | 410 } |
| 411 static base::HistogramBase* counter(NULL); | 411 static base::HistogramBase* counter(NULL); |
| 412 if (!counter) { | 412 if (!counter) { |
| 413 counter = UMASnifferHistogramGet("mime_sniffer.kSniffableTags2", | 413 counter = UMASnifferHistogramGet("mime_sniffer.kSniffableTags2", |
| 414 arraysize(kSniffableTags)); | 414 arraysize(kSniffableTags)); |
| 415 } | 415 } |
| 416 // |pos| now points to first non-whitespace character (or at end). | 416 // |pos| now points to first non-whitespace character (or at end). |
| 417 return CheckForMagicNumbers(pos, end - pos, | 417 return CheckForMagicNumbers(pos, end - pos, |
| 418 kSniffableTags, arraysize(kSniffableTags), | 418 kSniffableTags, arraysize(kSniffableTags), |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 ~(1u << '\t' | 1u << '\n' | 1u << '\r' | 1u << '\f' | 1u << '\x1b'); | 953 ~(1u << '\t' | 1u << '\n' | 1u << '\r' | 1u << '\f' | 1u << '\x1b'); |
| 954 for (size_t i = 0; i < size; ++i) { | 954 for (size_t i = 0; i < size; ++i) { |
| 955 uint8_t byte = static_cast<uint8_t>(content[i]); | 955 uint8_t byte = static_cast<uint8_t>(content[i]); |
| 956 if (byte < 0x20 && (kBinaryBits & (1u << byte))) | 956 if (byte < 0x20 && (kBinaryBits & (1u << byte))) |
| 957 return true; | 957 return true; |
| 958 } | 958 } |
| 959 return false; | 959 return false; |
| 960 } | 960 } |
| 961 | 961 |
| 962 } // namespace net | 962 } // namespace net |
| OLD | NEW |