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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "net/base/mime_util.h" | 8 #include "net/base/mime_util.h" |
9 #include "net/base/platform_mime_util.h" | 9 #include "net/base/platform_mime_util.h" |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; | 36 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; |
37 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; | 37 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; |
38 | 38 |
39 bool IsViewSourceMimeType(const std::string& mime_type) const; | 39 bool IsViewSourceMimeType(const std::string& mime_type) const; |
40 | 40 |
41 bool IsSupportedMimeType(const std::string& mime_type) const; | 41 bool IsSupportedMimeType(const std::string& mime_type) const; |
42 | 42 |
43 bool MatchesMimeType(const std::string &mime_type_pattern, | 43 bool MatchesMimeType(const std::string &mime_type_pattern, |
44 const std::string &mime_type) const; | 44 const std::string &mime_type) const; |
45 | 45 |
| 46 bool IsMimeType(const std::string& type_string) const; |
| 47 |
46 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | 48 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
47 | 49 |
48 void ParseCodecString(const std::string& codecs, | 50 void ParseCodecString(const std::string& codecs, |
49 std::vector<std::string>* codecs_out, | 51 std::vector<std::string>* codecs_out, |
50 bool strip); | 52 bool strip); |
51 | 53 |
52 bool IsStrictMediaMimeType(const std::string& mime_type) const; | 54 bool IsStrictMediaMimeType(const std::string& mime_type) const; |
53 bool IsSupportedStrictMediaMimeType( | 55 bool IsSupportedStrictMediaMimeType( |
54 const std::string& mime_type, | 56 const std::string& mime_type, |
55 const std::vector<std::string>& codecs) const; | 57 const std::vector<std::string>& codecs) const; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 if (mime_type.find(left) != 0) | 481 if (mime_type.find(left) != 0) |
480 return false; | 482 return false; |
481 | 483 |
482 if (!right.empty() && | 484 if (!right.empty() && |
483 mime_type.rfind(right) != mime_type.length() - right.length()) | 485 mime_type.rfind(right) != mime_type.length() - right.length()) |
484 return false; | 486 return false; |
485 | 487 |
486 return true; | 488 return true; |
487 } | 489 } |
488 | 490 |
| 491 // See http://www.iana.org/assignments/media-types/index.html |
| 492 static const char* legal_top_level_types[] = { |
| 493 "application/", |
| 494 "audio/", |
| 495 "example/", |
| 496 "image/", |
| 497 "message/", |
| 498 "model/", |
| 499 "multipart/", |
| 500 "text/", |
| 501 "video/", |
| 502 }; |
| 503 |
| 504 bool MimeUtil::IsMimeType(const std::string& type_string) const { |
| 505 // MIME types are always ASCII and case-insensitive (at least, the top-level |
| 506 // and secondary types we care about). |
| 507 if (!IsStringASCII(type_string)) |
| 508 return false; |
| 509 |
| 510 if (type_string == "*/*" || type_string == "*") |
| 511 return true; |
| 512 |
| 513 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { |
| 514 if (StartsWithASCII(type_string, legal_top_level_types[i], false) && |
| 515 type_string.length() > strlen(legal_top_level_types[i])) { |
| 516 return true; |
| 517 } |
| 518 } |
| 519 |
| 520 // If there's a "/" separator character, and the token before it is |
| 521 // "x-" + (ascii characters), it is also a MIME type. |
| 522 size_t slash = type_string.find('/'); |
| 523 if (slash < 3 || |
| 524 slash == std::string::npos || slash == type_string.length() - 1) { |
| 525 return false; |
| 526 } |
| 527 |
| 528 if (StartsWithASCII(type_string, "x-", false)) |
| 529 return true; |
| 530 |
| 531 return false; |
| 532 } |
| 533 |
489 bool MimeUtil::AreSupportedMediaCodecs( | 534 bool MimeUtil::AreSupportedMediaCodecs( |
490 const std::vector<std::string>& codecs) const { | 535 const std::vector<std::string>& codecs) const { |
491 return AreSupportedCodecs(codecs_map_, codecs); | 536 return AreSupportedCodecs(codecs_map_, codecs); |
492 } | 537 } |
493 | 538 |
494 void MimeUtil::ParseCodecString(const std::string& codecs, | 539 void MimeUtil::ParseCodecString(const std::string& codecs, |
495 std::vector<std::string>* codecs_out, | 540 std::vector<std::string>* codecs_out, |
496 bool strip) { | 541 bool strip) { |
497 std::string no_quote_codecs; | 542 std::string no_quote_codecs; |
498 TrimString(codecs, "\"", &no_quote_codecs); | 543 TrimString(codecs, "\"", &no_quote_codecs); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 | 616 |
572 bool IsSupportedMimeType(const std::string& mime_type) { | 617 bool IsSupportedMimeType(const std::string& mime_type) { |
573 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 618 return g_mime_util.Get().IsSupportedMimeType(mime_type); |
574 } | 619 } |
575 | 620 |
576 bool MatchesMimeType(const std::string& mime_type_pattern, | 621 bool MatchesMimeType(const std::string& mime_type_pattern, |
577 const std::string& mime_type) { | 622 const std::string& mime_type) { |
578 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); | 623 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
579 } | 624 } |
580 | 625 |
| 626 bool IsMimeType(const std::string& type_string) { |
| 627 return g_mime_util.Get().IsMimeType(type_string); |
| 628 } |
| 629 |
581 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { | 630 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { |
582 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); | 631 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); |
583 } | 632 } |
584 | 633 |
585 bool IsStrictMediaMimeType(const std::string& mime_type) { | 634 bool IsStrictMediaMimeType(const std::string& mime_type) { |
586 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); | 635 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); |
587 } | 636 } |
588 | 637 |
589 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, | 638 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, |
590 const std::vector<std::string>& codecs) { | 639 const std::vector<std::string>& codecs) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 // Unless/until WebM files are added to the media layout tests, we need to avoid | 828 // Unless/until WebM files are added to the media layout tests, we need to avoid |
780 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary | 829 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary |
781 // codecs are) so that the media tests can still run. | 830 // codecs are) so that the media tests can still run. |
782 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) | 831 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) |
783 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 832 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
784 codecs->push_back(proprietary_media_codecs[i]); | 833 codecs->push_back(proprietary_media_codecs[i]); |
785 #endif | 834 #endif |
786 } | 835 } |
787 | 836 |
788 } // namespace net | 837 } // namespace net |
OLD | NEW |