| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "net/base/mime_util.h" | 7 #include "net/base/mime_util.h" |
| 8 #include "net/base/platform_mime_util.h" | 8 #include "net/base/platform_mime_util.h" |
| 9 | 9 |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 bool IsSupportedNonImageMimeType(const char* mime_type) const; | 30 bool IsSupportedNonImageMimeType(const char* mime_type) const; |
| 31 bool IsSupportedJavascriptMimeType(const char* mime_type) const; | 31 bool IsSupportedJavascriptMimeType(const char* mime_type) const; |
| 32 | 32 |
| 33 bool IsViewSourceMimeType(const char* mime_type) const; | 33 bool IsViewSourceMimeType(const char* mime_type) const; |
| 34 | 34 |
| 35 bool IsSupportedMimeType(const std::string& mime_type) const; | 35 bool IsSupportedMimeType(const std::string& mime_type) const; |
| 36 | 36 |
| 37 bool MatchesMimeType(const std::string &mime_type_pattern, | 37 bool MatchesMimeType(const std::string &mime_type_pattern, |
| 38 const std::string &mime_type) const; | 38 const std::string &mime_type) const; |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 friend struct DefaultSingletonTraits<MimeUtil>; | 41 friend struct DefaultSingletonTraits<MimeUtil>; |
| 42 MimeUtil() { | 42 MimeUtil() { |
| 43 InitializeMimeTypeMaps(); | 43 InitializeMimeTypeMaps(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // For faster lookup, keep hash sets. | 46 // For faster lookup, keep hash sets. |
| 47 void InitializeMimeTypeMaps(); | 47 void InitializeMimeTypeMaps(); |
| 48 | 48 |
| 49 typedef base::hash_set<std::string> MimeMappings; | 49 typedef base::hash_set<std::string> MimeMappings; |
| 50 MimeMappings image_map_; | 50 MimeMappings image_map_; |
| 51 MimeMappings media_map_; | 51 MimeMappings media_map_; |
| 52 MimeMappings non_image_map_; | 52 MimeMappings non_image_map_; |
| 53 MimeMappings javascript_map_; | 53 MimeMappings javascript_map_; |
| 54 MimeMappings view_source_map_; | 54 MimeMappings view_source_map_; |
| 55 }; // class MimeUtil | 55 }; // class MimeUtil |
| 56 | 56 |
| 57 struct MimeInfo { | 57 struct MimeInfo { |
| 58 const char* mime_type; | 58 const char* mime_type; |
| 59 const char* extensions; // comma separated list | 59 const char* extensions; // comma separated list |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 static const MimeInfo primary_mappings[] = { | 62 static const MimeInfo primary_mappings[] = { |
| 63 { "text/html", "html,htm" }, | 63 { "text/html", "html,htm" }, |
| 64 { "text/css", "css" }, | 64 { "text/css", "css" }, |
| 65 { "text/xml", "xml" }, | 65 { "text/xml", "xml" }, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 "audio/aac", | 189 "audio/aac", |
| 190 "audio/x-aac" | 190 "audio/x-aac" |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 // Note: does not include javascript types list (see supported_javascript_types) | 193 // Note: does not include javascript types list (see supported_javascript_types) |
| 194 static const char* const supported_non_image_types[] = { | 194 static const char* const supported_non_image_types[] = { |
| 195 "text/html", | 195 "text/html", |
| 196 "text/xml", | 196 "text/xml", |
| 197 "text/xsl", | 197 "text/xsl", |
| 198 "text/plain", | 198 "text/plain", |
| 199 // Many users complained about css files served for |
| 200 // download instead of displaying in the browser: |
| 201 // http://code.google.com/p/chromium/issues/detail?id=7192 |
| 202 // So, by including "text/css" into this list we choose Firefox |
| 203 // behavior - css files will be displayed: |
| 204 "text/css", |
| 199 "text/", | 205 "text/", |
| 200 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type | 206 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type |
| 201 "application/xml", | 207 "application/xml", |
| 202 "application/xhtml+xml", | 208 "application/xhtml+xml", |
| 203 "application/rss+xml", | 209 "application/rss+xml", |
| 204 "application/atom+xml", | 210 "application/atom+xml", |
| 205 "multipart/x-mixed-replace" | 211 "multipart/x-mixed-replace" |
| 206 }; | 212 }; |
| 207 | 213 |
| 208 // Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript. | 214 // Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript. |
| 209 // Mozilla 1.8 accepts application/javascript, application/ecmascript, and | 215 // Mozilla 1.8 accepts application/javascript, application/ecmascript, and |
| 210 // application/x-javascript, but WinIE 7 doesn't. | 216 // application/x-javascript, but WinIE 7 doesn't. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 bool IsSupportedMimeType(const std::string& mime_type) { | 375 bool IsSupportedMimeType(const std::string& mime_type) { |
| 370 return GetMimeUtil()->IsSupportedMimeType(mime_type); | 376 return GetMimeUtil()->IsSupportedMimeType(mime_type); |
| 371 } | 377 } |
| 372 | 378 |
| 373 bool MatchesMimeType(const std::string &mime_type_pattern, | 379 bool MatchesMimeType(const std::string &mime_type_pattern, |
| 374 const std::string &mime_type) { | 380 const std::string &mime_type) { |
| 375 return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type); | 381 return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type); |
| 376 } | 382 } |
| 377 | 383 |
| 378 } // namespace net | 384 } // namespace net |
| OLD | NEW |