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

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

Issue 17447011: Shuffle media-related WebMimeRegistry code from webkit/ to content/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forgot some diffs Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/base/mime_util.h ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 void ParseCodecString(const std::string& codecs, 71 void ParseCodecString(const std::string& codecs,
72 std::vector<std::string>* codecs_out, 72 std::vector<std::string>* codecs_out,
73 bool strip); 73 bool strip);
74 74
75 bool IsStrictMediaMimeType(const std::string& mime_type) const; 75 bool IsStrictMediaMimeType(const std::string& mime_type) const;
76 bool IsSupportedStrictMediaMimeType( 76 bool IsSupportedStrictMediaMimeType(
77 const std::string& mime_type, 77 const std::string& mime_type,
78 const std::vector<std::string>& codecs) const; 78 const std::vector<std::string>& codecs) const;
79 79
80 void RemoveProprietaryMediaTypesAndCodecsForTests();
81
80 private: 82 private:
81 friend struct base::DefaultLazyInstanceTraits<MimeUtil>; 83 friend struct base::DefaultLazyInstanceTraits<MimeUtil>;
82 84
83 typedef base::hash_set<std::string> MimeMappings; 85 typedef base::hash_set<std::string> MimeMappings;
84 typedef std::map<std::string, MimeMappings> StrictMappings; 86 typedef std::map<std::string, MimeMappings> StrictMappings;
85 87
86 MimeUtil(); 88 MimeUtil();
87 89
88 // Returns true if |codecs| is nonempty and all the items in it are present in 90 // Returns true if |codecs| is nonempty and all the items in it are present in
89 // |supported_codecs|. 91 // |supported_codecs|.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 "image/x-xbitmap" // xbm 259 "image/x-xbitmap" // xbm
258 }; 260 };
259 261
260 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type 262 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type
261 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php 263 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php
262 // This set of codecs is supported by all variations of Chromium. 264 // This set of codecs is supported by all variations of Chromium.
263 static const char* const common_media_types[] = { 265 static const char* const common_media_types[] = {
264 // Ogg. 266 // Ogg.
265 "audio/ogg", 267 "audio/ogg",
266 "application/ogg", 268 "application/ogg",
267 #if defined(ENABLE_MEDIA_CODEC_THEORA) 269 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
268 "video/ogg", 270 "video/ogg",
269 #endif 271 #endif
270 272
271 // WebM. 273 // WebM.
272 "video/webm", 274 "video/webm",
273 "audio/webm", 275 "audio/webm",
274 276
275 // Wav. 277 // Wav.
276 "audio/wav", 278 "audio/wav",
277 "audio/x-wav", 279 "audio/x-wav",
(...skipping 15 matching lines...) Expand all
293 295
294 // List of supported codecs when passed in with <source type="...">. 296 // List of supported codecs when passed in with <source type="...">.
295 // This set of codecs is supported by all variations of Chromium. 297 // This set of codecs is supported by all variations of Chromium.
296 // 298 //
297 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support 299 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support
298 // for more information. 300 // for more information.
299 // 301 //
300 // The codecs for WAV are integers as defined in Appendix A of RFC2361: 302 // The codecs for WAV are integers as defined in Appendix A of RFC2361:
301 // http://tools.ietf.org/html/rfc2361 303 // http://tools.ietf.org/html/rfc2361
302 static const char* const common_media_codecs[] = { 304 static const char* const common_media_codecs[] = {
303 #if defined(ENABLE_MEDIA_CODEC_THEORA) 305 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora.
304 "theora", 306 "theora",
305 #endif 307 #endif
306 "vorbis", 308 "vorbis",
307 "vp8", 309 "vp8",
308 "vp9", 310 "vp9",
309 "1" // WAVE_FORMAT_PCM. 311 "1" // WAVE_FORMAT_PCM.
310 }; 312 };
311 313
312 // List of proprietary codecs only supported by Google Chrome. 314 // List of proprietary codecs only supported by Google Chrome.
313 static const char* const proprietary_media_codecs[] = { 315 static const char* const proprietary_media_codecs[] = {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } 670 }
669 671
670 bool MimeUtil::IsSupportedStrictMediaMimeType( 672 bool MimeUtil::IsSupportedStrictMediaMimeType(
671 const std::string& mime_type, 673 const std::string& mime_type,
672 const std::vector<std::string>& codecs) const { 674 const std::vector<std::string>& codecs) const {
673 StrictMappings::const_iterator it = strict_format_map_.find(mime_type); 675 StrictMappings::const_iterator it = strict_format_map_.find(mime_type);
674 return (it != strict_format_map_.end()) && 676 return (it != strict_format_map_.end()) &&
675 AreSupportedCodecs(it->second, codecs); 677 AreSupportedCodecs(it->second, codecs);
676 } 678 }
677 679
680 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() {
681 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) {
682 non_image_map_.erase(proprietary_media_types[i]);
683 media_map_.erase(proprietary_media_types[i]);
684 }
685 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
686 codecs_map_.erase(proprietary_media_codecs[i]);
687 }
688
678 //---------------------------------------------------------------------------- 689 //----------------------------------------------------------------------------
679 // Wrappers for the singleton 690 // Wrappers for the singleton
680 //---------------------------------------------------------------------------- 691 //----------------------------------------------------------------------------
681 692
682 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 693 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
683 std::string* mime_type) { 694 std::string* mime_type) {
684 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); 695 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type);
685 } 696 }
686 697
687 bool GetMimeTypeFromFile(const base::FilePath& file_path, 698 bool GetMimeTypeFromFile(const base::FilePath& file_path,
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 938
928 GetExtensionsFromHardCodedMappings(secondary_mappings, 939 GetExtensionsFromHardCodedMappings(secondary_mappings,
929 arraysize(secondary_mappings), 940 arraysize(secondary_mappings),
930 mime_type, 941 mime_type,
931 &unique_extensions); 942 &unique_extensions);
932 } 943 }
933 944
934 HashSetToVector(&unique_extensions, extensions); 945 HashSetToVector(&unique_extensions, extensions);
935 } 946 }
936 947
937 void GetMediaTypesBlacklistedForTests(std::vector<std::string>* types) { 948 void RemoveProprietaryMediaTypesAndCodecsForTests() {
938 types->clear(); 949 g_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests();
939
940 // Unless/until WebM files are added to the media layout tests, we need to avoid
941 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary
942 // codecs are) so that the media tests can still run.
943 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS)
944 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i)
945 types->push_back(proprietary_media_types[i]);
946 #endif
947 }
948
949 void GetMediaCodecsBlacklistedForTests(std::vector<std::string>* codecs) {
950 codecs->clear();
951
952 // Unless/until WebM files are added to the media layout tests, we need to avoid
953 // blacklisting mp4 and H.264 when Theora is not supported (and proprietary
954 // codecs are) so that the media tests can still run.
955 #if defined(ENABLE_MEDIA_CODEC_THEORA) || !defined(USE_PROPRIETARY_CODECS)
956 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i)
957 codecs->push_back(proprietary_media_codecs[i]);
958 #endif
959 } 950 }
960 951
961 const std::string GetIANAMediaType(const std::string& mime_type) { 952 const std::string GetIANAMediaType(const std::string& mime_type) {
962 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) { 953 for (size_t i = 0; i < arraysize(kIanaMediaTypes); ++i) {
963 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) { 954 if (StartsWithASCII(mime_type, kIanaMediaTypes[i].matcher, true)) {
964 return kIanaMediaTypes[i].name; 955 return kIanaMediaTypes[i].name;
965 } 956 }
966 } 957 }
967 return std::string(); 958 return std::string();
968 } 959 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 post_data->append("\r\n" + value + "\r\n"); 994 post_data->append("\r\n" + value + "\r\n");
1004 } 995 }
1005 996
1006 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 997 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1007 std::string* post_data) { 998 std::string* post_data) {
1008 DCHECK(post_data); 999 DCHECK(post_data);
1009 post_data->append("--" + mime_boundary + "--\r\n"); 1000 post_data->append("--" + mime_boundary + "--\r\n");
1010 } 1001 }
1011 1002
1012 } // namespace net 1003 } // namespace net
OLDNEW
« no previous file with comments | « net/base/mime_util.h ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698