Chromium Code Reviews| 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 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "net/base/mime_util.h" | 18 #include "net/base/mime_util.h" |
| 19 #include "net/base/platform_mime_util.h" | 19 #include "net/base/platform_mime_util.h" |
| 20 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
| 21 | 21 |
| 22 #if defined(OS_ANDROID) | |
| 23 #include "base/android/build_info.h" | |
| 24 #endif | |
| 25 | |
| 26 using std::string; | 22 using std::string; |
| 27 | 23 |
| 28 namespace net { | 24 namespace net { |
| 29 | 25 |
| 30 // Singleton utility class for mime types. | 26 // Singleton utility class for mime types. |
| 31 class MimeUtil : public PlatformMimeUtil { | 27 class MimeUtil : public PlatformMimeUtil { |
| 32 public: | 28 public: |
| 33 enum Codec { | |
| 34 INVALID_CODEC, | |
| 35 PCM, | |
| 36 MP3, | |
| 37 MPEG2_AAC_LC, | |
| 38 MPEG2_AAC_MAIN, | |
| 39 MPEG2_AAC_SSR, | |
| 40 MPEG4_AAC_LC, | |
| 41 MPEG4_AAC_SBR_v1, | |
| 42 MPEG4_AAC_SBR_PS_v2, | |
| 43 VORBIS, | |
| 44 OPUS, | |
| 45 H264_BASELINE, | |
| 46 H264_MAIN, | |
| 47 H264_HIGH, | |
| 48 VP8, | |
| 49 VP9, | |
| 50 THEORA | |
| 51 }; | |
| 52 | |
| 53 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 29 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 54 std::string* mime_type) const; | 30 std::string* mime_type) const; |
| 55 | 31 |
| 56 bool GetMimeTypeFromFile(const base::FilePath& file_path, | 32 bool GetMimeTypeFromFile(const base::FilePath& file_path, |
| 57 std::string* mime_type) const; | 33 std::string* mime_type) const; |
| 58 | 34 |
| 59 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, | 35 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 60 std::string* mime_type) const; | 36 std::string* mime_type) const; |
| 61 | 37 |
| 62 bool IsSupportedImageMimeType(const std::string& mime_type) const; | 38 bool IsSupportedImageMimeType(const std::string& mime_type) const; |
| 63 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | |
| 64 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; | 39 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; |
| 65 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; | 40 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; |
| 66 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; | 41 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; |
| 67 | 42 |
| 68 bool IsSupportedMimeType(const std::string& mime_type) const; | 43 bool IsSupportedMimeType_deprecated(const std::string& mime_type) const; |
| 69 | 44 |
| 70 bool MatchesMimeType(const std::string &mime_type_pattern, | 45 bool MatchesMimeType(const std::string &mime_type_pattern, |
| 71 const std::string &mime_type) const; | 46 const std::string &mime_type) const; |
| 72 | 47 |
| 73 bool ParseMimeTypeWithoutParameter(const std::string& type_string, | 48 bool ParseMimeTypeWithoutParameter(const std::string& type_string, |
| 74 std::string* top_level_type, | 49 std::string* top_level_type, |
| 75 std::string* subtype) const; | 50 std::string* subtype) const; |
| 76 | 51 |
| 77 bool IsValidTopLevelMimeType(const std::string& type_string) const; | 52 bool IsValidTopLevelMimeType(const std::string& type_string) const; |
| 78 | 53 |
| 79 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | |
| 80 | |
| 81 void ParseCodecString(const std::string& codecs, | |
| 82 std::vector<std::string>* codecs_out, | |
| 83 bool strip); | |
| 84 | |
| 85 bool IsStrictMediaMimeType(const std::string& mime_type) const; | |
| 86 SupportsType IsSupportedStrictMediaMimeType( | |
| 87 const std::string& mime_type, | |
| 88 const std::vector<std::string>& codecs) const; | |
| 89 | |
| 90 void RemoveProprietaryMediaTypesAndCodecsForTests(); | |
| 91 | |
| 92 private: | 54 private: |
| 93 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; | 55 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; |
| 94 | 56 |
| 95 typedef base::hash_set<std::string> MimeMappings; | 57 typedef base::hash_set<std::string> MimeMappings; |
| 96 | 58 |
| 97 typedef base::hash_set<int> CodecSet; | |
| 98 typedef std::map<std::string, CodecSet> StrictMappings; | |
| 99 struct CodecEntry { | |
| 100 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} | |
| 101 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} | |
| 102 Codec codec; | |
| 103 bool is_ambiguous; | |
| 104 }; | |
| 105 typedef std::map<std::string, CodecEntry> StringToCodecMappings; | |
| 106 | |
| 107 MimeUtil(); | 59 MimeUtil(); |
| 108 | 60 |
| 109 // Returns IsSupported if all codec IDs in |codecs| are unambiguous | |
| 110 // and are supported by the platform. MayBeSupported is returned if | |
| 111 // at least one codec ID in |codecs| is ambiguous but all the codecs | |
| 112 // are supported by the platform. IsNotSupported is returned if at | |
| 113 // least one codec ID is not supported by the platform. | |
| 114 SupportsType AreSupportedCodecs( | |
| 115 const CodecSet& supported_codecs, | |
| 116 const std::vector<std::string>& codecs) const; | |
| 117 | |
| 118 // For faster lookup, keep hash sets. | 61 // For faster lookup, keep hash sets. |
| 119 void InitializeMimeTypeMaps(); | 62 void InitializeMimeTypeMaps(); |
| 120 | 63 |
| 121 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, | 64 bool GetMimeTypeFromExtensionHelper(const base::FilePath::StringType& ext, |
| 122 bool include_platform_types, | 65 bool include_platform_types, |
| 123 std::string* mime_type) const; | 66 std::string* mime_type) const; |
| 124 | 67 |
| 125 // Converts a codec ID into an Codec enum value and indicates | |
| 126 // whether the conversion was ambiguous. | |
| 127 // Returns true if this method was able to map |codec_id| to a specific | |
| 128 // Codec enum value. |codec| and |is_ambiguous| are only valid if true | |
| 129 // is returned. Otherwise their value is undefined after the call. | |
| 130 // |is_ambiguous| is true if |codec_id| did not have enough information to | |
| 131 // unambiguously determine the proper Codec enum value. If |is_ambiguous| | |
| 132 // is true |codec| contains the best guess for the intended Codec enum value. | |
| 133 bool StringToCodec(const std::string& codec_id, | |
| 134 Codec* codec, | |
| 135 bool* is_ambiguous) const; | |
| 136 | |
| 137 // Returns true if |codec| is supported by the platform. | |
| 138 // Note: This method will return false if the platform supports proprietary | |
| 139 // codecs but |allow_proprietary_codecs_| is set to false. | |
| 140 bool IsCodecSupported(Codec codec) const; | |
| 141 | |
| 142 // Returns true if |codec| refers to a proprietary codec. | |
| 143 bool IsCodecProprietary(Codec codec) const; | |
| 144 | |
| 145 // Returns true and sets |*default_codec| if |mime_type| has a default codec | |
| 146 // associated with it. Returns false otherwise and the value of | |
| 147 // |*default_codec| is undefined. | |
| 148 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | |
| 149 Codec* default_codec) const; | |
| 150 | |
| 151 // Returns true if |mime_type_lower_case| has a default codec associated with | |
| 152 // it and IsCodecSupported() returns true for that particular codec. | |
| 153 bool IsDefaultCodecSupportedLowerCase( | |
| 154 const std::string& mime_type_lower_case) const; | |
| 155 | |
| 156 MimeMappings image_map_; | 68 MimeMappings image_map_; |
| 157 MimeMappings media_map_; | |
| 158 MimeMappings non_image_map_; | 69 MimeMappings non_image_map_; |
| 159 MimeMappings unsupported_text_map_; | 70 MimeMappings unsupported_text_map_; |
| 160 MimeMappings javascript_map_; | 71 MimeMappings javascript_map_; |
| 161 | |
| 162 // A map of mime_types and hash map of the supported codecs for the mime_type. | |
| 163 StrictMappings strict_format_map_; | |
| 164 | |
| 165 // Keeps track of whether proprietary codec support should be | |
| 166 // advertised to callers. | |
| 167 bool allow_proprietary_codecs_; | |
| 168 | |
| 169 // Lookup table for string compare based string -> Codec mappings. | |
| 170 StringToCodecMappings string_to_codec_map_; | |
| 171 }; // class MimeUtil | 72 }; // class MimeUtil |
| 172 | 73 |
| 173 // This variable is Leaky because we need to access it from WorkerPool threads. | 74 // This variable is Leaky because we need to access it from WorkerPool threads. |
| 174 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 75 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
| 175 LAZY_INSTANCE_INITIALIZER; | 76 LAZY_INSTANCE_INITIALIZER; |
| 176 | 77 |
| 177 struct MimeInfo { | 78 struct MimeInfo { |
| 178 const char* const mime_type; | 79 const char* const mime_type; |
| 179 const char* const extensions; // comma separated list | 80 const char* const extensions; // comma separated list |
| 180 }; | 81 }; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 "image/jpg", | 215 "image/jpg", |
| 315 "image/webp", | 216 "image/webp", |
| 316 "image/png", | 217 "image/png", |
| 317 "image/gif", | 218 "image/gif", |
| 318 "image/bmp", | 219 "image/bmp", |
| 319 "image/vnd.microsoft.icon", // ico | 220 "image/vnd.microsoft.icon", // ico |
| 320 "image/x-icon", // ico | 221 "image/x-icon", // ico |
| 321 "image/x-xbitmap", // xbm | 222 "image/x-xbitmap", // xbm |
| 322 "image/x-png" | 223 "image/x-png" |
| 323 }; | 224 }; |
| 324 | 225 |
|
ddorwin
2015/03/13 20:44:59
Proposal:
1) Revert this removal of common_media_t
| |
| 325 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type | |
| 326 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php | |
| 327 // This set of codecs is supported by all variations of Chromium. | |
| 328 static const char* const common_media_types[] = { | |
| 329 // Ogg. | |
| 330 "audio/ogg", | |
| 331 "application/ogg", | |
| 332 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. | |
| 333 "video/ogg", | |
| 334 #endif | |
| 335 | |
| 336 // WebM. | |
| 337 "video/webm", | |
| 338 "audio/webm", | |
| 339 | |
| 340 // Wav. | |
| 341 "audio/wav", | |
| 342 "audio/x-wav", | |
| 343 | |
| 344 #if defined(OS_ANDROID) | |
| 345 // HLS. Supported by Android ICS and above. | |
| 346 "application/vnd.apple.mpegurl", | |
| 347 "application/x-mpegurl", | |
| 348 #endif | |
| 349 }; | |
| 350 | |
| 351 // List of proprietary types only supported by Google Chrome. | |
| 352 static const char* const proprietary_media_types[] = { | |
| 353 // MPEG-4. | |
| 354 "video/mp4", | |
| 355 "video/x-m4v", | |
| 356 "audio/mp4", | |
| 357 "audio/x-m4a", | |
| 358 | |
| 359 // MP3. | |
| 360 "audio/mp3", | |
| 361 "audio/x-mp3", | |
| 362 "audio/mpeg", | |
| 363 "audio/aac", | |
| 364 | |
| 365 #if defined(ENABLE_MPEG2TS_STREAM_PARSER) | |
| 366 // MPEG-2 TS. | |
| 367 "video/mp2t", | |
| 368 #endif | |
| 369 }; | |
| 370 | |
| 371 // Note: | 226 // Note: |
| 372 // - does not include javascript types list (see supported_javascript_types) | 227 // - does not include javascript types list (see supported_javascript_types) |
| 373 // - does not include types starting with "text/" (see | 228 // - does not include types starting with "text/" (see |
| 374 // IsSupportedNonImageMimeType()) | 229 // IsSupportedNonImageMimeType()) |
| 375 static const char* const supported_non_image_types[] = { | 230 static const char* const supported_non_image_types[] = { |
| 376 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type | 231 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type |
| 377 "application/xml", | 232 "application/xml", |
| 378 "application/atom+xml", | 233 "application/atom+xml", |
| 379 "application/rss+xml", | 234 "application/rss+xml", |
| 380 "application/xhtml+xml", | 235 "application/xhtml+xml", |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 "application/javascript", | 296 "application/javascript", |
| 442 "application/ecmascript", | 297 "application/ecmascript", |
| 443 "application/x-javascript", | 298 "application/x-javascript", |
| 444 "text/javascript1.1", | 299 "text/javascript1.1", |
| 445 "text/javascript1.2", | 300 "text/javascript1.2", |
| 446 "text/javascript1.3", | 301 "text/javascript1.3", |
| 447 "text/jscript", | 302 "text/jscript", |
| 448 "text/livescript" | 303 "text/livescript" |
| 449 }; | 304 }; |
| 450 | 305 |
| 451 #if defined(OS_ANDROID) | 306 MimeUtil::MimeUtil() { |
|
ddorwin
2015/03/13 20:44:59
Proposal: Revert the removal of IsMimeTypeSupporte
| |
| 452 static bool IsCodecSupportedOnAndroid(MimeUtil::Codec codec) { | |
| 453 switch (codec) { | |
| 454 case MimeUtil::INVALID_CODEC: | |
| 455 return false; | |
| 456 | |
| 457 case MimeUtil::PCM: | |
| 458 case MimeUtil::MP3: | |
| 459 case MimeUtil::MPEG4_AAC_LC: | |
| 460 case MimeUtil::MPEG4_AAC_SBR_v1: | |
| 461 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | |
| 462 case MimeUtil::H264_BASELINE: | |
| 463 case MimeUtil::H264_MAIN: | |
| 464 case MimeUtil::H264_HIGH: | |
| 465 case MimeUtil::VP8: | |
| 466 case MimeUtil::VORBIS: | |
| 467 return true; | |
| 468 | |
| 469 case MimeUtil::MPEG2_AAC_LC: | |
| 470 case MimeUtil::MPEG2_AAC_MAIN: | |
| 471 case MimeUtil::MPEG2_AAC_SSR: | |
| 472 // MPEG-2 variants of AAC are not supported on Android. | |
| 473 return false; | |
| 474 | |
| 475 case MimeUtil::VP9: | |
| 476 // VP9 is supported only in KitKat+ (API Level 19). | |
| 477 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | |
| 478 | |
| 479 case MimeUtil::OPUS: | |
| 480 // Opus is supported only in Lollipop+ (API Level 21). | |
| 481 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | |
| 482 | |
| 483 case MimeUtil::THEORA: | |
| 484 return false; | |
| 485 } | |
| 486 | |
| 487 return false; | |
| 488 } | |
| 489 | |
| 490 static bool IsMimeTypeSupportedOnAndroid(const std::string& mimeType) { | |
| 491 // HLS codecs are supported in ICS and above (API level 14) | |
| 492 if ((!mimeType.compare("application/vnd.apple.mpegurl") || | |
| 493 !mimeType.compare("application/x-mpegurl")) && | |
| 494 base::android::BuildInfo::GetInstance()->sdk_int() < 14) { | |
| 495 return false; | |
| 496 } | |
| 497 return true; | |
| 498 } | |
| 499 #endif | |
| 500 | |
| 501 struct MediaFormatStrict { | |
| 502 const char* const mime_type; | |
| 503 const char* const codecs_list; | |
| 504 }; | |
| 505 | |
| 506 // Following is the list of RFC 6381 compliant codecs: | |
| 507 // mp4a.66 - MPEG-2 AAC MAIN | |
| 508 // mp4a.67 - MPEG-2 AAC LC | |
| 509 // mp4a.68 - MPEG-2 AAC SSR | |
| 510 // mp4a.69 - MPEG-2 extension to MPEG-1 | |
| 511 // mp4a.6B - MPEG-1 audio | |
| 512 // mp4a.40.2 - MPEG-4 AAC LC | |
| 513 // mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for compatibility) | |
| 514 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) | |
| 515 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for | |
| 516 // compatibility) | |
| 517 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) | |
| 518 // | |
| 519 // avc1.42E0xx - H.264 Baseline | |
| 520 // avc1.4D40xx - H.264 Main | |
| 521 // avc1.6400xx - H.264 High | |
| 522 static const char kMP4AudioCodecsExpression[] = | |
| 523 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | |
| 524 "mp4a.40.05,mp4a.40.29"; | |
| 525 static const char kMP4VideoCodecsExpression[] = | |
| 526 // This is not a complete list of supported avc1 codecs. It is simply used | |
| 527 // to register support for the corresponding Codec enum. Instead of using | |
| 528 // strings in these three arrays, we should use the Codec enum values. | |
| 529 // This will avoid confusion and unnecessary parsing at runtime. | |
| 530 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only | |
| 531 // mapping from strings to codecs. See crbug.com/461009. | |
| 532 "avc1.42E00A,avc1.4D400A,avc1.64000A," | |
| 533 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | |
| 534 "mp4a.40.05,mp4a.40.29"; | |
| 535 | |
| 536 // These containers are also included in | |
| 537 // common_media_types/proprietary_media_types. See crbug.com/461012. | |
| 538 static const MediaFormatStrict format_codec_mappings[] = { | |
| 539 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | |
| 540 {"audio/webm", "opus,vorbis"}, | |
| 541 {"audio/wav", "1"}, | |
| 542 {"audio/x-wav", "1"}, | |
| 543 // Android does not support Opus in Ogg container. | |
| 544 #if defined(OS_ANDROID) | |
| 545 {"video/ogg", "theora,vorbis"}, | |
| 546 {"audio/ogg", "vorbis"}, | |
| 547 {"application/ogg", "theora,vorbis"}, | |
| 548 #else | |
| 549 {"video/ogg", "opus,theora,vorbis"}, | |
| 550 {"audio/ogg", "opus,vorbis"}, | |
| 551 {"application/ogg", "opus,theora,vorbis"}, | |
| 552 #endif | |
| 553 {"audio/mpeg", "mp3"}, | |
| 554 {"audio/mp3", ""}, | |
| 555 {"audio/x-mp3", ""}, | |
| 556 {"audio/mp4", kMP4AudioCodecsExpression}, | |
| 557 {"audio/x-m4a", kMP4AudioCodecsExpression}, | |
| 558 {"video/mp4", kMP4VideoCodecsExpression}, | |
| 559 {"video/x-m4v", kMP4VideoCodecsExpression}, | |
| 560 {"application/x-mpegurl", kMP4VideoCodecsExpression}, | |
| 561 {"application/vnd.apple.mpegurl", kMP4VideoCodecsExpression}}; | |
| 562 | |
| 563 struct CodecIDMappings { | |
| 564 const char* const codec_id; | |
| 565 MimeUtil::Codec codec; | |
| 566 }; | |
| 567 | |
| 568 // List of codec IDs that provide enough information to determine the | |
| 569 // codec and profile being requested. | |
| 570 // | |
| 571 // The "mp4a" strings come from RFC 6381. | |
| 572 static const CodecIDMappings kUnambiguousCodecStringMap[] = { | |
| 573 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. | |
| 574 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseH264CodecID(). | |
| 575 {"mp3", MimeUtil::MP3}, | |
| 576 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, | |
| 577 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, | |
| 578 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, | |
| 579 {"mp4a.69", MimeUtil::MP3}, | |
| 580 {"mp4a.6B", MimeUtil::MP3}, | |
| 581 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, | |
| 582 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, | |
| 583 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, | |
| 584 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, | |
| 585 {"mp4a.40.29", MimeUtil::MPEG4_AAC_SBR_PS_v2}, | |
| 586 {"vorbis", MimeUtil::VORBIS}, | |
| 587 {"opus", MimeUtil::OPUS}, | |
| 588 {"vp8", MimeUtil::VP8}, | |
| 589 {"vp8.0", MimeUtil::VP8}, | |
| 590 {"vp9", MimeUtil::VP9}, | |
| 591 {"vp9.0", MimeUtil::VP9}, | |
| 592 {"theora", MimeUtil::THEORA}}; | |
| 593 | |
| 594 // List of codec IDs that are ambiguous and don't provide | |
| 595 // enough information to determine the codec and profile. | |
| 596 // The codec in these entries indicate the codec and profile | |
| 597 // we assume the user is trying to indicate. | |
| 598 static const CodecIDMappings kAmbiguousCodecStringMap[] = { | |
| 599 {"mp4a.40", MimeUtil::MPEG4_AAC_LC}, | |
| 600 {"avc1", MimeUtil::H264_BASELINE}, | |
| 601 {"avc3", MimeUtil::H264_BASELINE}, | |
| 602 // avc1/avc3.XXXXXX may be ambiguous; handled by ParseH264CodecID(). | |
| 603 }; | |
| 604 | |
| 605 MimeUtil::MimeUtil() : allow_proprietary_codecs_(false) { | |
| 606 InitializeMimeTypeMaps(); | 307 InitializeMimeTypeMaps(); |
| 607 } | 308 } |
| 608 | 309 |
| 609 SupportsType MimeUtil::AreSupportedCodecs( | |
| 610 const CodecSet& supported_codecs, | |
| 611 const std::vector<std::string>& codecs) const { | |
| 612 DCHECK(!supported_codecs.empty()); | |
| 613 DCHECK(!codecs.empty()); | |
| 614 | |
| 615 SupportsType result = IsSupported; | |
| 616 for (size_t i = 0; i < codecs.size(); ++i) { | |
| 617 bool is_ambiguous = true; | |
| 618 Codec codec = INVALID_CODEC; | |
| 619 if (!StringToCodec(codecs[i], &codec, &is_ambiguous)) | |
| 620 return IsNotSupported; | |
| 621 | |
| 622 if (!IsCodecSupported(codec) || | |
| 623 supported_codecs.find(codec) == supported_codecs.end()) { | |
| 624 return IsNotSupported; | |
| 625 } | |
| 626 | |
| 627 if (is_ambiguous) | |
| 628 result = MayBeSupported; | |
| 629 } | |
| 630 | |
| 631 return result; | |
| 632 } | |
| 633 | |
| 634 void MimeUtil::InitializeMimeTypeMaps() { | 310 void MimeUtil::InitializeMimeTypeMaps() { |
| 635 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 311 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
| 636 image_map_.insert(supported_image_types[i]); | 312 image_map_.insert(supported_image_types[i]); |
| 637 | 313 |
| 638 // Initialize the supported non-image types. | 314 // Initialize the supported non-image types. |
| 639 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 315 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
| 640 non_image_map_.insert(supported_non_image_types[i]); | 316 non_image_map_.insert(supported_non_image_types[i]); |
| 641 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) | 317 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) |
| 642 non_image_map_.insert(supported_certificate_types[i].mime_type); | 318 non_image_map_.insert(supported_certificate_types[i].mime_type); |
| 643 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) | 319 for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) |
| 644 unsupported_text_map_.insert(unsupported_text_types[i]); | 320 unsupported_text_map_.insert(unsupported_text_types[i]); |
| 645 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 321 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
| 646 non_image_map_.insert(supported_javascript_types[i]); | 322 non_image_map_.insert(supported_javascript_types[i]); |
|
ddorwin
2015/03/13 20:44:59
Proposal: Revert the code that inserts *_media_typ
| |
| 647 for (size_t i = 0; i < arraysize(common_media_types); ++i) { | |
| 648 #if defined(OS_ANDROID) | |
| 649 if (!IsMimeTypeSupportedOnAndroid(common_media_types[i])) | |
| 650 continue; | |
| 651 #endif | |
| 652 non_image_map_.insert(common_media_types[i]); | |
| 653 } | |
| 654 #if defined(USE_PROPRIETARY_CODECS) | |
| 655 allow_proprietary_codecs_ = true; | |
| 656 | |
| 657 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | |
| 658 non_image_map_.insert(proprietary_media_types[i]); | |
| 659 #endif | |
| 660 | |
| 661 // Initialize the supported media types. | |
| 662 for (size_t i = 0; i < arraysize(common_media_types); ++i) { | |
| 663 #if defined(OS_ANDROID) | |
| 664 if (!IsMimeTypeSupportedOnAndroid(common_media_types[i])) | |
| 665 continue; | |
| 666 #endif | |
| 667 media_map_.insert(common_media_types[i]); | |
| 668 } | |
| 669 #if defined(USE_PROPRIETARY_CODECS) | |
| 670 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | |
| 671 media_map_.insert(proprietary_media_types[i]); | |
| 672 #endif | |
| 673 | 323 |
| 674 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 324 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
| 675 javascript_map_.insert(supported_javascript_types[i]); | 325 javascript_map_.insert(supported_javascript_types[i]); |
| 676 | |
| 677 for (size_t i = 0; i < arraysize(kUnambiguousCodecStringMap); ++i) { | |
| 678 string_to_codec_map_[kUnambiguousCodecStringMap[i].codec_id] = | |
| 679 CodecEntry(kUnambiguousCodecStringMap[i].codec, false); | |
| 680 } | |
| 681 | |
| 682 for (size_t i = 0; i < arraysize(kAmbiguousCodecStringMap); ++i) { | |
| 683 string_to_codec_map_[kAmbiguousCodecStringMap[i].codec_id] = | |
| 684 CodecEntry(kAmbiguousCodecStringMap[i].codec, true); | |
| 685 } | |
| 686 | |
| 687 // Initialize the strict supported media types. | |
| 688 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | |
| 689 std::vector<std::string> mime_type_codecs; | |
| 690 ParseCodecString(format_codec_mappings[i].codecs_list, | |
| 691 &mime_type_codecs, | |
| 692 false); | |
| 693 | |
| 694 CodecSet codecs; | |
| 695 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | |
| 696 Codec codec = INVALID_CODEC; | |
| 697 bool is_ambiguous = true; | |
| 698 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); | |
| 699 DCHECK(!is_ambiguous); | |
| 700 codecs.insert(codec); | |
| 701 } | |
| 702 | |
| 703 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | |
| 704 } | |
| 705 } | 326 } |
| 706 | 327 |
| 707 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 328 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
| 708 return image_map_.find(base::StringToLowerASCII(mime_type)) != | 329 return image_map_.find(base::StringToLowerASCII(mime_type)) != |
| 709 image_map_.end(); | 330 image_map_.end(); |
| 710 } | 331 } |
| 711 | 332 |
| 712 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | |
| 713 return media_map_.find(base::StringToLowerASCII(mime_type)) != | |
| 714 media_map_.end(); | |
| 715 } | |
| 716 | |
| 717 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 333 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { |
| 718 return non_image_map_.find(base::StringToLowerASCII(mime_type)) != | 334 return non_image_map_.find(base::StringToLowerASCII(mime_type)) != |
| 719 non_image_map_.end() || | 335 non_image_map_.end() || |
| 720 (StartsWithASCII(mime_type, "text/", false /* case insensitive */) && | 336 (StartsWithASCII(mime_type, "text/", false /* case insensitive */) && |
| 721 !IsUnsupportedTextMimeType(mime_type)) || | 337 !IsUnsupportedTextMimeType(mime_type)) || |
| 722 (StartsWithASCII(mime_type, "application/", false) && | 338 (StartsWithASCII(mime_type, "application/", false) && |
| 723 MatchesMimeType("application/*+json", mime_type)); | 339 MatchesMimeType("application/*+json", mime_type)); |
| 724 } | 340 } |
| 725 | 341 |
| 726 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 342 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { |
| 727 return unsupported_text_map_.find(base::StringToLowerASCII(mime_type)) != | 343 return unsupported_text_map_.find(base::StringToLowerASCII(mime_type)) != |
| 728 unsupported_text_map_.end(); | 344 unsupported_text_map_.end(); |
| 729 } | 345 } |
| 730 | 346 |
| 731 bool MimeUtil::IsSupportedJavascriptMimeType( | 347 bool MimeUtil::IsSupportedJavascriptMimeType( |
| 732 const std::string& mime_type) const { | 348 const std::string& mime_type) const { |
| 733 return javascript_map_.find(mime_type) != javascript_map_.end(); | 349 return javascript_map_.find(mime_type) != javascript_map_.end(); |
| 734 } | 350 } |
| 735 | 351 |
| 736 // Mirrors WebViewImpl::CanShowMIMEType() | 352 // Mirrors WebViewImpl::CanShowMIMEType() |
| 737 bool MimeUtil::IsSupportedMimeType(const std::string& mime_type) const { | 353 bool MimeUtil::IsSupportedMimeType_deprecated( |
| 354 const std::string& mime_type) const { | |
| 738 return (StartsWithASCII(mime_type, "image/", false) && | 355 return (StartsWithASCII(mime_type, "image/", false) && |
| 739 IsSupportedImageMimeType(mime_type)) || | 356 IsSupportedImageMimeType(mime_type)) || |
| 740 IsSupportedNonImageMimeType(mime_type); | 357 IsSupportedNonImageMimeType(mime_type); |
| 741 } | 358 } |
| 742 | 359 |
| 743 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| | 360 // Tests for MIME parameter equality. Each parameter in the |mime_type_pattern| |
| 744 // must be matched by a parameter in the |mime_type|. If there are no | 361 // must be matched by a parameter in the |mime_type|. If there are no |
| 745 // parameters in the pattern, the match is a success. | 362 // parameters in the pattern, the match is a success. |
| 746 // | 363 // |
| 747 // According rfc2045 keys of parameters are case-insensitive, while values may | 364 // According rfc2045 keys of parameters are case-insensitive, while values may |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const { | 491 bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const { |
| 875 std::string lower_type = base::StringToLowerASCII(type_string); | 492 std::string lower_type = base::StringToLowerASCII(type_string); |
| 876 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { | 493 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { |
| 877 if (lower_type.compare(legal_top_level_types[i]) == 0) | 494 if (lower_type.compare(legal_top_level_types[i]) == 0) |
| 878 return true; | 495 return true; |
| 879 } | 496 } |
| 880 | 497 |
| 881 return type_string.size() > 2 && StartsWithASCII(type_string, "x-", false); | 498 return type_string.size() > 2 && StartsWithASCII(type_string, "x-", false); |
| 882 } | 499 } |
| 883 | 500 |
| 884 bool MimeUtil::AreSupportedMediaCodecs( | |
| 885 const std::vector<std::string>& codecs) const { | |
| 886 for (size_t i = 0; i < codecs.size(); ++i) { | |
| 887 Codec codec = INVALID_CODEC; | |
| 888 bool is_ambiguous = true; | |
| 889 if (!StringToCodec(codecs[i], &codec, &is_ambiguous) || | |
| 890 !IsCodecSupported(codec)) { | |
| 891 return false; | |
| 892 } | |
| 893 } | |
| 894 return true; | |
| 895 } | |
| 896 | |
| 897 void MimeUtil::ParseCodecString(const std::string& codecs, | |
| 898 std::vector<std::string>* codecs_out, | |
| 899 bool strip) { | |
| 900 std::string no_quote_codecs; | |
| 901 base::TrimString(codecs, "\"", &no_quote_codecs); | |
| 902 base::SplitString(no_quote_codecs, ',', codecs_out); | |
| 903 | |
| 904 if (!strip) | |
| 905 return; | |
| 906 | |
| 907 // Strip everything past the first '.' | |
| 908 for (std::vector<std::string>::iterator it = codecs_out->begin(); | |
| 909 it != codecs_out->end(); | |
| 910 ++it) { | |
| 911 size_t found = it->find_first_of('.'); | |
| 912 if (found != std::string::npos) | |
| 913 it->resize(found); | |
| 914 } | |
| 915 } | |
| 916 | |
| 917 bool MimeUtil::IsStrictMediaMimeType(const std::string& mime_type) const { | |
| 918 return strict_format_map_.find(base::StringToLowerASCII(mime_type)) != | |
| 919 strict_format_map_.end(); | |
| 920 } | |
| 921 | |
| 922 SupportsType MimeUtil::IsSupportedStrictMediaMimeType( | |
| 923 const std::string& mime_type, | |
| 924 const std::vector<std::string>& codecs) const { | |
| 925 const std::string mime_type_lower_case = base::StringToLowerASCII(mime_type); | |
| 926 StrictMappings::const_iterator it_strict_map = | |
| 927 strict_format_map_.find(mime_type_lower_case); | |
| 928 if (it_strict_map == strict_format_map_.end()) | |
| 929 return codecs.empty() ? MayBeSupported : IsNotSupported; | |
| 930 | |
| 931 if (it_strict_map->second.empty()) { | |
| 932 // We get here if the mimetype does not expect a codecs parameter. | |
| 933 return (codecs.empty() && | |
| 934 IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) | |
| 935 ? IsSupported | |
| 936 : IsNotSupported; | |
| 937 } | |
| 938 | |
| 939 if (codecs.empty()) { | |
| 940 // We get here if the mimetype expects to get a codecs parameter, | |
| 941 // but didn't get one. If |mime_type_lower_case| does not have a default | |
| 942 // codec the best we can do is say "maybe" because we don't have enough | |
| 943 // information. | |
| 944 Codec default_codec = INVALID_CODEC; | |
| 945 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | |
| 946 return MayBeSupported; | |
| 947 | |
| 948 return IsCodecSupported(default_codec) ? IsSupported : IsNotSupported; | |
| 949 } | |
| 950 | |
| 951 return AreSupportedCodecs(it_strict_map->second, codecs); | |
| 952 } | |
| 953 | |
| 954 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | |
| 955 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | |
| 956 non_image_map_.erase(proprietary_media_types[i]); | |
| 957 media_map_.erase(proprietary_media_types[i]); | |
| 958 } | |
| 959 allow_proprietary_codecs_ = false; | |
| 960 } | |
| 961 | |
| 962 // Returns true iff |profile_str| conforms to hex string "42y0", where y is one | |
| 963 // of [8..F]. Requiring constraint_set0_flag be set and profile_idc be 0x42 is | |
| 964 // taken from ISO-14496-10 7.3.2.1, 7.4.2.1, and Annex A.2.1. | |
| 965 // | |
| 966 // |profile_str| is the first four characters of the H.264 suffix string | |
| 967 // (ignoring the last 2 characters of the full 6 character suffix that are | |
| 968 // level_idc). From ISO-14496-10 7.3.2.1, it consists of: | |
| 969 // 8 bits: profile_idc: required to be 0x42 here. | |
| 970 // 1 bit: constraint_set0_flag : required to be true here. | |
| 971 // 1 bit: constraint_set1_flag : ignored here. | |
| 972 // 1 bit: constraint_set2_flag : ignored here. | |
| 973 // 1 bit: constraint_set3_flag : ignored here. | |
| 974 // 4 bits: reserved : required to be 0 here. | |
| 975 // | |
| 976 // The spec indicates other ways, not implemented here, that a |profile_str| | |
| 977 // can indicate a baseline conforming decoder is sufficient for decode in Annex | |
| 978 // A.2.1: "[profile_idc not necessarily 0x42] with constraint_set0_flag set and | |
| 979 // in which level_idc and constraint_set3_flag represent a level less than or | |
| 980 // equal to the specified level." | |
| 981 static bool IsValidH264BaselineProfile(const std::string& profile_str) { | |
| 982 uint32 constraint_set_bits; | |
| 983 if (profile_str.size() != 4 || | |
| 984 profile_str[0] != '4' || | |
| 985 profile_str[1] != '2' || | |
| 986 profile_str[3] != '0' || | |
| 987 !base::HexStringToUInt(base::StringPiece(profile_str.c_str() + 2, 1), | |
| 988 &constraint_set_bits)) { | |
| 989 return false; | |
| 990 } | |
| 991 | |
| 992 return constraint_set_bits >= 8; | |
| 993 } | |
| 994 | |
| 995 static bool IsValidH264Level(const std::string& level_str) { | |
| 996 uint32 level; | |
| 997 if (level_str.size() != 2 || !base::HexStringToUInt(level_str, &level)) | |
| 998 return false; | |
| 999 | |
| 1000 // Valid levels taken from Table A-1 in ISO-14496-10. | |
| 1001 // Essentially |level_str| is toHex(10 * level). | |
| 1002 return ((level >= 10 && level <= 13) || | |
| 1003 (level >= 20 && level <= 22) || | |
| 1004 (level >= 30 && level <= 32) || | |
| 1005 (level >= 40 && level <= 42) || | |
| 1006 (level >= 50 && level <= 51)); | |
| 1007 } | |
| 1008 | |
| 1009 // Handle parsing H.264 codec IDs as outlined in RFC 6381 and ISO-14496-10. | |
| 1010 // avc1.42y0xx, y >= 8 - H.264 Baseline | |
| 1011 // avc1.4D40xx - H.264 Main | |
| 1012 // avc1.6400xx - H.264 High | |
| 1013 // | |
| 1014 // avc1.xxxxxx & avc3.xxxxxx are considered ambiguous forms that are trying to | |
| 1015 // signal H.264 Baseline. For example, the idc_level, profile_idc and | |
| 1016 // constraint_set3_flag pieces may explicitly require decoder to conform to | |
| 1017 // baseline profile at the specified level (see Annex A and constraint_set0 in | |
| 1018 // ISO-14496-10). | |
| 1019 static bool ParseH264CodecID(const std::string& codec_id, | |
| 1020 MimeUtil::Codec* codec, | |
| 1021 bool* is_ambiguous) { | |
| 1022 // Make sure we have avc1.xxxxxx or avc3.xxxxxx | |
| 1023 if (codec_id.size() != 11 || | |
| 1024 (!StartsWithASCII(codec_id, "avc1.", true) && | |
| 1025 !StartsWithASCII(codec_id, "avc3.", true))) { | |
| 1026 return false; | |
| 1027 } | |
| 1028 | |
| 1029 std::string profile = StringToUpperASCII(codec_id.substr(5, 4)); | |
| 1030 if (IsValidH264BaselineProfile(profile)) { | |
| 1031 *codec = MimeUtil::H264_BASELINE; | |
| 1032 } else if (profile == "4D40") { | |
| 1033 *codec = MimeUtil::H264_MAIN; | |
| 1034 } else if (profile == "6400") { | |
| 1035 *codec = MimeUtil::H264_HIGH; | |
| 1036 } else { | |
| 1037 *codec = MimeUtil::H264_BASELINE; | |
| 1038 *is_ambiguous = true; | |
| 1039 return true; | |
| 1040 } | |
| 1041 | |
| 1042 *is_ambiguous = !IsValidH264Level(StringToUpperASCII(codec_id.substr(9))); | |
| 1043 return true; | |
| 1044 } | |
| 1045 | |
| 1046 bool MimeUtil::StringToCodec(const std::string& codec_id, | |
| 1047 Codec* codec, | |
| 1048 bool* is_ambiguous) const { | |
| 1049 StringToCodecMappings::const_iterator itr = | |
| 1050 string_to_codec_map_.find(codec_id); | |
| 1051 if (itr != string_to_codec_map_.end()) { | |
| 1052 *codec = itr->second.codec; | |
| 1053 *is_ambiguous = itr->second.is_ambiguous; | |
| 1054 return true; | |
| 1055 } | |
| 1056 | |
| 1057 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | |
| 1058 // an H.264 codec ID because currently those are the only ones that can't be | |
| 1059 // stored in the |string_to_codec_map_| and require parsing. | |
| 1060 return ParseH264CodecID(codec_id, codec, is_ambiguous); | |
| 1061 } | |
| 1062 | |
| 1063 bool MimeUtil::IsCodecSupported(Codec codec) const { | |
| 1064 DCHECK_NE(codec, INVALID_CODEC); | |
| 1065 | |
| 1066 #if defined(OS_ANDROID) | |
| 1067 if (!IsCodecSupportedOnAndroid(codec)) | |
| 1068 return false; | |
| 1069 #endif | |
| 1070 | |
| 1071 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | |
| 1072 } | |
| 1073 | |
| 1074 bool MimeUtil::IsCodecProprietary(Codec codec) const { | |
| 1075 switch (codec) { | |
| 1076 case INVALID_CODEC: | |
| 1077 case MP3: | |
| 1078 case MPEG2_AAC_LC: | |
| 1079 case MPEG2_AAC_MAIN: | |
| 1080 case MPEG2_AAC_SSR: | |
| 1081 case MPEG4_AAC_LC: | |
| 1082 case MPEG4_AAC_SBR_v1: | |
| 1083 case MPEG4_AAC_SBR_PS_v2: | |
| 1084 case H264_BASELINE: | |
| 1085 case H264_MAIN: | |
| 1086 case H264_HIGH: | |
| 1087 return true; | |
| 1088 | |
| 1089 case PCM: | |
| 1090 case VORBIS: | |
| 1091 case OPUS: | |
| 1092 case VP8: | |
| 1093 case VP9: | |
| 1094 case THEORA: | |
| 1095 return false; | |
| 1096 } | |
| 1097 | |
| 1098 return true; | |
| 1099 } | |
| 1100 | |
| 1101 bool MimeUtil::GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | |
| 1102 Codec* default_codec) const { | |
| 1103 if (mime_type_lower_case == "audio/mpeg" || | |
| 1104 mime_type_lower_case == "audio/mp3" || | |
| 1105 mime_type_lower_case == "audio/x-mp3") { | |
| 1106 *default_codec = MimeUtil::MP3; | |
| 1107 return true; | |
| 1108 } | |
| 1109 | |
| 1110 return false; | |
| 1111 } | |
| 1112 | |
| 1113 bool MimeUtil::IsDefaultCodecSupportedLowerCase( | |
| 1114 const std::string& mime_type_lower_case) const { | |
| 1115 Codec default_codec = Codec::INVALID_CODEC; | |
| 1116 if (!GetDefaultCodecLowerCase(mime_type_lower_case, &default_codec)) | |
| 1117 return false; | |
| 1118 return IsCodecSupported(default_codec); | |
| 1119 } | |
| 1120 | |
| 1121 //---------------------------------------------------------------------------- | 501 //---------------------------------------------------------------------------- |
| 1122 // Wrappers for the singleton | 502 // Wrappers for the singleton |
| 1123 //---------------------------------------------------------------------------- | 503 //---------------------------------------------------------------------------- |
| 1124 | 504 |
| 1125 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 505 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 1126 std::string* mime_type) { | 506 std::string* mime_type) { |
| 1127 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); | 507 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); |
| 1128 } | 508 } |
| 1129 | 509 |
| 1130 bool GetMimeTypeFromFile(const base::FilePath& file_path, | 510 bool GetMimeTypeFromFile(const base::FilePath& file_path, |
| 1131 std::string* mime_type) { | 511 std::string* mime_type) { |
| 1132 return g_mime_util.Get().GetMimeTypeFromFile(file_path, mime_type); | 512 return g_mime_util.Get().GetMimeTypeFromFile(file_path, mime_type); |
| 1133 } | 513 } |
| 1134 | 514 |
| 1135 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, | 515 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 1136 std::string* mime_type) { | 516 std::string* mime_type) { |
| 1137 return g_mime_util.Get().GetWellKnownMimeTypeFromExtension(ext, mime_type); | 517 return g_mime_util.Get().GetWellKnownMimeTypeFromExtension(ext, mime_type); |
| 1138 } | 518 } |
| 1139 | 519 |
| 1140 bool GetPreferredExtensionForMimeType(const std::string& mime_type, | 520 bool GetPreferredExtensionForMimeType(const std::string& mime_type, |
| 1141 base::FilePath::StringType* extension) { | 521 base::FilePath::StringType* extension) { |
| 1142 return g_mime_util.Get().GetPreferredExtensionForMimeType(mime_type, | 522 return g_mime_util.Get().GetPreferredExtensionForMimeType(mime_type, |
| 1143 extension); | 523 extension); |
| 1144 } | 524 } |
| 1145 | 525 |
| 1146 bool IsSupportedImageMimeType(const std::string& mime_type) { | 526 bool IsSupportedImageMimeType(const std::string& mime_type) { |
| 1147 return g_mime_util.Get().IsSupportedImageMimeType(mime_type); | 527 return g_mime_util.Get().IsSupportedImageMimeType(mime_type); |
| 1148 } | 528 } |
| 1149 | 529 |
| 1150 bool IsSupportedMediaMimeType(const std::string& mime_type) { | |
| 1151 return g_mime_util.Get().IsSupportedMediaMimeType(mime_type); | |
| 1152 } | |
| 1153 | |
| 1154 bool IsSupportedNonImageMimeType(const std::string& mime_type) { | 530 bool IsSupportedNonImageMimeType(const std::string& mime_type) { |
| 1155 return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type); | 531 return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type); |
| 1156 } | 532 } |
| 1157 | 533 |
| 1158 bool IsUnsupportedTextMimeType(const std::string& mime_type) { | 534 bool IsUnsupportedTextMimeType(const std::string& mime_type) { |
| 1159 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); | 535 return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); |
| 1160 } | 536 } |
| 1161 | 537 |
| 1162 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { | 538 bool IsSupportedJavascriptMimeType(const std::string& mime_type) { |
| 1163 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); | 539 return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); |
| 1164 } | 540 } |
| 1165 | 541 |
| 1166 bool IsSupportedMimeType(const std::string& mime_type) { | 542 bool IsSupportedMimeType_deprecated(const std::string& mime_type) { |
| 1167 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 543 return g_mime_util.Get().IsSupportedMimeType_deprecated(mime_type); |
| 1168 } | 544 } |
| 1169 | 545 |
| 1170 bool MatchesMimeType(const std::string& mime_type_pattern, | 546 bool MatchesMimeType(const std::string& mime_type_pattern, |
| 1171 const std::string& mime_type) { | 547 const std::string& mime_type) { |
| 1172 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); | 548 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
| 1173 } | 549 } |
| 1174 | 550 |
| 1175 bool ParseMimeTypeWithoutParameter(const std::string& type_string, | 551 bool ParseMimeTypeWithoutParameter(const std::string& type_string, |
| 1176 std::string* top_level_type, | 552 std::string* top_level_type, |
| 1177 std::string* subtype) { | 553 std::string* subtype) { |
| 1178 return g_mime_util.Get().ParseMimeTypeWithoutParameter( | 554 return g_mime_util.Get().ParseMimeTypeWithoutParameter( |
| 1179 type_string, top_level_type, subtype); | 555 type_string, top_level_type, subtype); |
| 1180 } | 556 } |
| 1181 | 557 |
| 1182 bool IsValidTopLevelMimeType(const std::string& type_string) { | 558 bool IsValidTopLevelMimeType(const std::string& type_string) { |
| 1183 return g_mime_util.Get().IsValidTopLevelMimeType(type_string); | 559 return g_mime_util.Get().IsValidTopLevelMimeType(type_string); |
| 1184 } | 560 } |
| 1185 | 561 |
| 1186 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { | |
| 1187 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); | |
| 1188 } | |
| 1189 | |
| 1190 bool IsStrictMediaMimeType(const std::string& mime_type) { | |
| 1191 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); | |
| 1192 } | |
| 1193 | |
| 1194 SupportsType IsSupportedStrictMediaMimeType( | |
| 1195 const std::string& mime_type, | |
| 1196 const std::vector<std::string>& codecs) { | |
| 1197 return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); | |
| 1198 } | |
| 1199 | |
| 1200 void ParseCodecString(const std::string& codecs, | |
| 1201 std::vector<std::string>* codecs_out, | |
| 1202 const bool strip) { | |
| 1203 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | |
| 1204 } | |
| 1205 | |
| 1206 namespace { | 562 namespace { |
| 1207 | 563 |
| 1208 // From http://www.w3schools.com/media/media_mimeref.asp and | 564 // From http://www.w3schools.com/media/media_mimeref.asp and |
| 1209 // http://plugindoc.mozdev.org/winmime.php | 565 // http://plugindoc.mozdev.org/winmime.php |
| 1210 static const char* const kStandardImageTypes[] = { | 566 static const char* const kStandardImageTypes[] = { |
| 1211 "image/bmp", | 567 "image/bmp", |
| 1212 "image/cis-cod", | 568 "image/cis-cod", |
| 1213 "image/gif", | 569 "image/gif", |
| 1214 "image/ief", | 570 "image/ief", |
| 1215 "image/jpeg", | 571 "image/jpeg", |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1378 | 734 |
| 1379 GetExtensionsFromHardCodedMappings(secondary_mappings, | 735 GetExtensionsFromHardCodedMappings(secondary_mappings, |
| 1380 arraysize(secondary_mappings), | 736 arraysize(secondary_mappings), |
| 1381 mime_type, | 737 mime_type, |
| 1382 &unique_extensions); | 738 &unique_extensions); |
| 1383 } | 739 } |
| 1384 | 740 |
| 1385 HashSetToVector(&unique_extensions, extensions); | 741 HashSetToVector(&unique_extensions, extensions); |
| 1386 } | 742 } |
| 1387 | 743 |
| 1388 void RemoveProprietaryMediaTypesAndCodecsForTests() { | |
| 1389 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | |
| 1390 } | |
| 1391 | |
| 1392 CertificateMimeType GetCertificateMimeTypeForMimeType( | 744 CertificateMimeType GetCertificateMimeTypeForMimeType( |
| 1393 const std::string& mime_type) { | 745 const std::string& mime_type) { |
| 1394 // Don't create a map, there is only one entry in the table, | 746 // Don't create a map, there is only one entry in the table, |
| 1395 // except on Android. | 747 // except on Android. |
| 1396 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | 748 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { |
| 1397 if (base::strcasecmp(mime_type.c_str(), | 749 if (base::strcasecmp(mime_type.c_str(), |
| 1398 net::supported_certificate_types[i].mime_type) == 0) { | 750 net::supported_certificate_types[i].mime_type) == 0) { |
| 1399 return net::supported_certificate_types[i].cert_type; | 751 return net::supported_certificate_types[i].cert_type; |
| 1400 } | 752 } |
| 1401 } | 753 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1427 post_data->append("\r\n" + value + "\r\n"); | 779 post_data->append("\r\n" + value + "\r\n"); |
| 1428 } | 780 } |
| 1429 | 781 |
| 1430 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 782 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1431 std::string* post_data) { | 783 std::string* post_data) { |
| 1432 DCHECK(post_data); | 784 DCHECK(post_data); |
| 1433 post_data->append("--" + mime_boundary + "--\r\n"); | 785 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1434 } | 786 } |
| 1435 | 787 |
| 1436 } // namespace net | 788 } // namespace net |
| OLD | NEW |