Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: net/base/mime_util.cc

Issue 228823003: Adding check for MIME types that do not take codecs parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 void ParseCodecString(const std::string& codecs, 76 void ParseCodecString(const std::string& codecs,
77 std::vector<std::string>* codecs_out, 77 std::vector<std::string>* codecs_out,
78 bool strip); 78 bool strip);
79 79
80 bool IsStrictMediaMimeType(const std::string& mime_type) const; 80 bool IsStrictMediaMimeType(const std::string& mime_type) const;
81 bool IsSupportedStrictMediaMimeType( 81 bool IsSupportedStrictMediaMimeType(
82 const std::string& mime_type, 82 const std::string& mime_type,
83 const std::vector<std::string>& codecs) const; 83 const std::vector<std::string>& codecs) const;
84 84
85 bool MimeTypeDoesNotNeedCodecs(const std::string& mime_type) const;
86
85 void RemoveProprietaryMediaTypesAndCodecsForTests(); 87 void RemoveProprietaryMediaTypesAndCodecsForTests();
86 88
87 private: 89 private:
88 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; 90 friend struct base::DefaultLazyInstanceTraits<MimeUtil>;
89 91
90 typedef base::hash_set<std::string> MimeMappings; 92 typedef base::hash_set<std::string> MimeMappings;
91 typedef std::map<std::string, MimeMappings> StrictMappings; 93 typedef std::map<std::string, MimeMappings> StrictMappings;
92 94
93 MimeUtil(); 95 MimeUtil();
94 96
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 const char* codecs_list; 433 const char* codecs_list;
432 }; 434 };
433 435
434 static const MediaFormatStrict format_codec_mappings[] = { 436 static const MediaFormatStrict format_codec_mappings[] = {
435 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, 437 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" },
436 { "audio/webm", "opus,vorbis" }, 438 { "audio/webm", "opus,vorbis" },
437 { "audio/wav", "1" }, 439 { "audio/wav", "1" },
438 { "audio/x-wav", "1" }, 440 { "audio/x-wav", "1" },
439 { "video/ogg", "opus,theora,vorbis" }, 441 { "video/ogg", "opus,theora,vorbis" },
440 { "audio/ogg", "opus,vorbis" }, 442 { "audio/ogg", "opus,vorbis" },
441 { "application/ogg", "opus,theora,vorbis" } 443 { "application/ogg", "opus,theora,vorbis" },
444 { "audio/mpeg", "" },
445 { "audio/mp3", "" },
446 { "audio/x-mp3", "" }
442 }; 447 };
443 448
444 MimeUtil::MimeUtil() { 449 MimeUtil::MimeUtil() {
445 InitializeMimeTypeMaps(); 450 InitializeMimeTypeMaps();
446 } 451 }
447 452
448 // static 453 // static
449 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, 454 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs,
450 const std::vector<std::string>& codecs) { 455 const std::vector<std::string>& codecs) {
451 for (size_t i = 0; i < codecs.size(); ++i) { 456 for (size_t i = 0; i < codecs.size(); ++i) {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 } 708 }
704 709
705 bool MimeUtil::IsSupportedStrictMediaMimeType( 710 bool MimeUtil::IsSupportedStrictMediaMimeType(
706 const std::string& mime_type, 711 const std::string& mime_type,
707 const std::vector<std::string>& codecs) const { 712 const std::vector<std::string>& codecs) const {
708 StrictMappings::const_iterator it = strict_format_map_.find(mime_type); 713 StrictMappings::const_iterator it = strict_format_map_.find(mime_type);
709 return (it != strict_format_map_.end()) && 714 return (it != strict_format_map_.end()) &&
710 AreSupportedCodecs(it->second, codecs); 715 AreSupportedCodecs(it->second, codecs);
711 } 716 }
712 717
718 bool MimeUtil::MimeTypeDoesNotNeedCodecs(const std::string& mime_type) const {
719 StrictMappings::const_iterator it = strict_format_map_.find(mime_type);
720 return (it != strict_format_map_.end()) && it->second.empty();
721 }
722
713 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { 723 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() {
714 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { 724 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) {
715 non_image_map_.erase(proprietary_media_types[i]); 725 non_image_map_.erase(proprietary_media_types[i]);
716 media_map_.erase(proprietary_media_types[i]); 726 media_map_.erase(proprietary_media_types[i]);
717 } 727 }
718 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) 728 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
719 codecs_map_.erase(proprietary_media_codecs[i]); 729 codecs_map_.erase(proprietary_media_codecs[i]);
720 } 730 }
721 731
722 //---------------------------------------------------------------------------- 732 //----------------------------------------------------------------------------
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 793
784 bool IsStrictMediaMimeType(const std::string& mime_type) { 794 bool IsStrictMediaMimeType(const std::string& mime_type) {
785 return g_mime_util.Get().IsStrictMediaMimeType(mime_type); 795 return g_mime_util.Get().IsStrictMediaMimeType(mime_type);
786 } 796 }
787 797
788 bool IsSupportedStrictMediaMimeType(const std::string& mime_type, 798 bool IsSupportedStrictMediaMimeType(const std::string& mime_type,
789 const std::vector<std::string>& codecs) { 799 const std::vector<std::string>& codecs) {
790 return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); 800 return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs);
791 } 801 }
792 802
803 bool MimeTypeDoesNotNeedCodecs(const std::string& mime_type) {
804 return g_mime_util.Get().MimeTypeDoesNotNeedCodecs(mime_type);
805 }
806
793 void ParseCodecString(const std::string& codecs, 807 void ParseCodecString(const std::string& codecs,
794 std::vector<std::string>* codecs_out, 808 std::vector<std::string>* codecs_out,
795 const bool strip) { 809 const bool strip) {
796 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); 810 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip);
797 } 811 }
798 812
799 namespace { 813 namespace {
800 814
801 // From http://www.w3schools.com/media/media_mimeref.asp and 815 // From http://www.w3schools.com/media/media_mimeref.asp and
802 // http://plugindoc.mozdev.org/winmime.php 816 // http://plugindoc.mozdev.org/winmime.php
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 post_data->append("\r\n" + value + "\r\n"); 1042 post_data->append("\r\n" + value + "\r\n");
1029 } 1043 }
1030 1044
1031 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1045 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1032 std::string* post_data) { 1046 std::string* post_data) {
1033 DCHECK(post_data); 1047 DCHECK(post_data);
1034 post_data->append("--" + mime_boundary + "--\r\n"); 1048 post_data->append("--" + mime_boundary + "--\r\n");
1035 } 1049 }
1036 1050
1037 } // namespace net 1051 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698