| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // definition and roughly the same as Firefox's definition. | 93 // definition and roughly the same as Firefox's definition. |
| 94 | 94 |
| 95 #include <string> | 95 #include <string> |
| 96 | 96 |
| 97 #include "net/base/mime_sniffer.h" | 97 #include "net/base/mime_sniffer.h" |
| 98 | 98 |
| 99 #include "base/basictypes.h" | 99 #include "base/basictypes.h" |
| 100 #include "base/logging.h" | 100 #include "base/logging.h" |
| 101 #include "base/metrics/histogram.h" | 101 #include "base/metrics/histogram.h" |
| 102 #include "base/strings/string_util.h" | 102 #include "base/strings/string_util.h" |
| 103 #include "net/base/mime_util.h" | |
| 104 #include "url/gurl.h" | 103 #include "url/gurl.h" |
| 105 | 104 |
| 106 namespace net { | 105 namespace net { |
| 107 | 106 |
| 108 // The number of content bytes we need to use all our magic numbers. Feel free | 107 // The number of content bytes we need to use all our magic numbers. Feel free |
| 109 // to increase this number if you add a longer magic number. | 108 // to increase this number if you add a longer magic number. |
| 110 static const size_t kBytesRequiredForMagic = 42; | 109 static const size_t kBytesRequiredForMagic = 42; |
| 111 | 110 |
| 112 struct MagicNumber { | 111 struct MagicNumber { |
| 113 const char* const mime_type; | 112 const char* const mime_type; |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 // First check the extra table. | 963 // First check the extra table. |
| 965 if (CheckForMagicNumbers(content, size, kExtraMagicNumbers, | 964 if (CheckForMagicNumbers(content, size, kExtraMagicNumbers, |
| 966 arraysize(kExtraMagicNumbers), NULL, result)) | 965 arraysize(kExtraMagicNumbers), NULL, result)) |
| 967 return true; | 966 return true; |
| 968 // Finally check the original table. | 967 // Finally check the original table. |
| 969 return CheckForMagicNumbers(content, size, kMagicNumbers, | 968 return CheckForMagicNumbers(content, size, kMagicNumbers, |
| 970 arraysize(kMagicNumbers), NULL, result); | 969 arraysize(kMagicNumbers), NULL, result); |
| 971 } | 970 } |
| 972 | 971 |
| 973 } // namespace net | 972 } // namespace net |
| OLD | NEW |