| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 const int kMaxTagIterations = 5; | 325 const int kMaxTagIterations = 5; |
| 326 for (int i = 0; i < kMaxTagIterations && pos < end; ++i) { | 326 for (int i = 0; i < kMaxTagIterations && pos < end; ++i) { |
| 327 pos = reinterpret_cast<const char*>(memchr(pos, '<', end - pos)); | 327 pos = reinterpret_cast<const char*>(memchr(pos, '<', end - pos)); |
| 328 if (!pos) | 328 if (!pos) |
| 329 return false; | 329 return false; |
| 330 | 330 |
| 331 if (base::strncasecmp(pos, "<?xml", sizeof("<?xml")-1) == 0) { | 331 if (base::strncasecmp(pos, "<?xml", sizeof("<?xml")-1) == 0) { |
| 332 // Skip XML declarations. | 332 // Skip XML declarations. |
| 333 ++pos; | 333 ++pos; |
| 334 continue; | 334 continue; |
| 335 } else if (base::strncasecmp(pos, "<!DOCTYPE", sizeof("<!DOCTYPE")-1) == 0)
{ | 335 } else if (base::strncasecmp(pos, "<!DOCTYPE", |
| 336 sizeof("<!DOCTYPE")-1) == 0) { |
| 336 // Skip DOCTYPE declarations. | 337 // Skip DOCTYPE declarations. |
| 337 ++pos; | 338 ++pos; |
| 338 continue; | 339 continue; |
| 339 } | 340 } |
| 340 | 341 |
| 341 if (CheckForMagicNumbers(pos, end - pos, | 342 if (CheckForMagicNumbers(pos, end - pos, |
| 342 kMagicXML, arraysize(kMagicXML), | 343 kMagicXML, arraysize(kMagicXML), |
| 343 &counter, result)) | 344 &counter, result)) |
| 344 return true; | 345 return true; |
| 345 | 346 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 result->assign("text/plain"); | 549 result->assign("text/plain"); |
| 549 // We could change our mind if a binary-looking byte appears later in | 550 // We could change our mind if a binary-looking byte appears later in |
| 550 // the content, so we only have enough content if we have the max. | 551 // the content, so we only have enough content if we have the max. |
| 551 return content_size >= kMaxBytesToSniff; | 552 return content_size >= kMaxBytesToSniff; |
| 552 } | 553 } |
| 553 | 554 |
| 554 return have_enough_content; | 555 return have_enough_content; |
| 555 } | 556 } |
| 556 | 557 |
| 557 } // namespace net | 558 } // namespace net |
| OLD | NEW |