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 bool MimeUtil::IsStringMimeType(const std::string& type_string) const { | |
rvargas (doing something else)
2012/06/01 01:51:14
Shouldn't this build upon IsSupportedMimeType inst
Greg Billock
2012/06/01 04:58:22
How so? I think this function would basically have
rvargas (doing something else)
2012/06/01 19:11:25
You're right, the "supported" part makes all the d
| |
492 // MIME types are always ASCII and case-insensitive (at least, the top-level | |
493 // and secondary types we care about). | |
494 if (!IsStringASCII(type_string)) | |
495 return false; | |
496 std::string raw_type = type_string; | |
497 StringToLowerASCII(&raw_type); | |
rvargas (doing something else)
2012/06/01 19:11:25
either this is not needed, or the comparisons shou
Greg Billock
2012/06/05 01:08:56
Done.
| |
498 | |
499 // See http://www.iana.org/assignments/media-types/index.html | |
500 if (StartsWithASCII(raw_type, "application/", false) || | |
rvargas (doing something else)
2012/06/01 19:11:25
Then let's follow the pattern of this class and ma
Greg Billock
2012/06/05 01:08:56
Done.
| |
501 StartsWithASCII(raw_type, "audio/", false) || | |
502 StartsWithASCII(raw_type, "example/", false) || | |
503 StartsWithASCII(raw_type, "image/", false) || | |
504 StartsWithASCII(raw_type, "message/", false) || | |
505 StartsWithASCII(raw_type, "model/", false) || | |
506 StartsWithASCII(raw_type, "multipart/", false) || | |
507 StartsWithASCII(raw_type, "text/", false) || | |
508 StartsWithASCII(raw_type, "video/", false) || | |
509 raw_type == "*/*" || raw_type == "*") { | |
510 return true; | |
511 } | |
512 | |
513 // If there's a "/" separator character, and the token before it is | |
rvargas (doing something else)
2012/06/01 01:51:14
If we have no code to cover this case maybe we can
| |
514 // "x-" + (ascii characters), it is also a MIME type. | |
515 size_t slash = raw_type.find('/'); | |
516 if (slash < 3 || slash == std::string::npos || slash == raw_type.length() - 1) | |
517 return false; | |
518 | |
519 if (StartsWithASCII(raw_type, "x-", false)) | |
520 return true; | |
521 | |
522 return false; | |
523 } | |
524 | |
489 bool MimeUtil::AreSupportedMediaCodecs( | 525 bool MimeUtil::AreSupportedMediaCodecs( |
490 const std::vector<std::string>& codecs) const { | 526 const std::vector<std::string>& codecs) const { |
491 return AreSupportedCodecs(codecs_map_, codecs); | 527 return AreSupportedCodecs(codecs_map_, codecs); |
492 } | 528 } |
493 | 529 |
494 void MimeUtil::ParseCodecString(const std::string& codecs, | 530 void MimeUtil::ParseCodecString(const std::string& codecs, |
495 std::vector<std::string>* codecs_out, | 531 std::vector<std::string>* codecs_out, |
496 bool strip) { | 532 bool strip) { |
497 std::string no_quote_codecs; | 533 std::string no_quote_codecs; |
498 TrimString(codecs, "\"", &no_quote_codecs); | 534 TrimString(codecs, "\"", &no_quote_codecs); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 607 |
572 bool IsSupportedMimeType(const std::string& mime_type) { | 608 bool IsSupportedMimeType(const std::string& mime_type) { |
573 return g_mime_util.Get().IsSupportedMimeType(mime_type); | 609 return g_mime_util.Get().IsSupportedMimeType(mime_type); |
574 } | 610 } |
575 | 611 |
576 bool MatchesMimeType(const std::string& mime_type_pattern, | 612 bool MatchesMimeType(const std::string& mime_type_pattern, |
577 const std::string& mime_type) { | 613 const std::string& mime_type) { |
578 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); | 614 return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
579 } | 615 } |
580 | 616 |
617 bool IsStringMimeType(const std::string& type_string) { | |
618 return g_mime_util.Get().IsStringMimeType(type_string); | |
619 } | |
620 | |
581 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { | 621 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { |
582 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); | 622 return g_mime_util.Get().AreSupportedMediaCodecs(codecs); |
583 } | 623 } |
584 | 624 |
585 bool IsStrictMediaMimeType(const std::string& mime_type) { | 625 bool IsStrictMediaMimeType(const std::string& mime_type) { |
586 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); | 626 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); |
587 } | 627 } |
588 | 628 |
589 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, | 629 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, |
590 const std::vector<std::string>& codecs) { | 630 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 | 819 // 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 | 820 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary |
781 // codecs are) so that the media tests can still run. | 821 // codecs are) so that the media tests can still run. |
782 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) | 822 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS) |
783 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 823 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
784 codecs->push_back(proprietary_media_codecs[i]); | 824 codecs->push_back(proprietary_media_codecs[i]); |
785 #endif | 825 #endif |
786 } | 826 } |
787 | 827 |
788 } // namespace net | 828 } // namespace net |
OLD | NEW |