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 IsStringMimeType(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::IsStringMimeType(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 bool top_level_legal = false; | |
514 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { | |
515 if (StartsWithASCII(type_string, legal_top_level_types[i], false) && | |
516 type_string.length() > strlen(legal_top_level_types[i])) { | |
517 top_level_legal = true; | |
rvargas (doing something else)
2012/06/05 17:54:07
Why not return true instead?
Greg Billock
2012/06/05 18:09:53
Thanks, I failed the refactor there.
| |
518 break; | |
519 } | |
520 } | |
521 if (top_level_legal) | |
522 return true; | |
523 | |
524 // If there's a "/" separator character, and the token before it is | |
525 // "x-" + (ascii characters), it is also a MIME type. | |
526 size_t slash = type_string.find('/'); | |
527 if (slash < 3 || | |
528 slash == std::string::npos || slash == type_string.length() - 1) | |
529 return false; | |
rvargas (doing something else)
2012/06/05 17:54:07
nit: use {} here.
Greg Billock
2012/06/05 18:09:53
Done.
| |
530 | |
531 if (StartsWithASCII(type_string, "x-", false)) | |
532 return true; | |
533 | |
534 return false; | |
535 } | |
536 | |
489 bool MimeUtil::AreSupportedMediaCodecs( | 537 bool MimeUtil::AreSupportedMediaCodecs( |
490 const std::vector<std::string>& codecs) const { | 538 const std::vector<std::string>& codecs) const { |
491 return AreSupportedCodecs(codecs_map_, codecs); | 539 return AreSupportedCodecs(codecs_map_, codecs); |
492 } | 540 } |
493 | 541 |
494 void MimeUtil::ParseCodecString(const std::string& codecs, | 542 void MimeUtil::ParseCodecString(const std::string& codecs, |
495 std::vector<std::string>* codecs_out, | 543 std::vector<std::string>* codecs_out, |
496 bool strip) { | 544 bool strip) { |
497 std::string no_quote_codecs; | 545 std::string no_quote_codecs; |
498 TrimString(codecs, "\"", &no_quote_codecs); | 546 TrimString(codecs, "\"", &no_quote_codecs); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 619 |
572 bool IsSupportedMimeType(const std::string& mime_type) { | 620 bool IsSupportedMimeType(const std::string& mime_type) { |
573 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 621 return g_mime_util.Get().IsSupportedMimeType(mime_type); |
574 } | 622 } |
575 | 623 |
576 bool MatchesMimeType(const std::string& mime_type_pattern, | 624 bool MatchesMimeType(const std::string& mime_type_pattern, |
577 const std::string& mime_type) { | 625 const std::string& mime_type) { |
578 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); | 626 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
579 } | 627 } |
580 | 628 |
629 bool IsStringMimeType(const std::string& type_string) { | |
630 return g_mime_util.Get().IsStringMimeType(type_string); | |
631 } | |
632 | |
581 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { | 633 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { |
582 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); | 634 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); |
583 } | 635 } |
584 | 636 |
585 bool IsStrictMediaMimeType(const std::string& mime_type) { | 637 bool IsStrictMediaMimeType(const std::string& mime_type) { |
586 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); | 638 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); |
587 } | 639 } |
588 | 640 |
589 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, | 641 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, |
590 const std::vector<std::string>& codecs) { | 642 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 | 831 // 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 | 832 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary |
781 // codecs are) so that the media tests can still run. | 833 // codecs are) so that the media tests can still run. |
782 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) | 834 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) |
783 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 835 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
784 codecs->push_back(proprietary_media_codecs[i]); | 836 codecs->push_back(proprietary_media_codecs[i]); |
785 #endif | 837 #endif |
786 } | 838 } |
787 | 839 |
788 } // namespace net | 840 } // namespace net |
OLD | NEW |