| 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 <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" |
| 11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
| 18 #include "net/base/platform_mime_util.h" | 18 #include "net/base/platform_mime_util.h" |
| 19 | 19 |
| 20 #if defined(OS_ANDROID) |
| 21 #include "base/android/build_info.h" |
| 22 #endif |
| 23 |
| 20 using std::string; | 24 using std::string; |
| 21 | 25 |
| 22 namespace { | 26 namespace { |
| 23 | 27 |
| 24 struct MediaType { | 28 struct MediaType { |
| 25 const char name[12]; | 29 const char name[12]; |
| 26 const char matcher[13]; | 30 const char matcher[13]; |
| 27 }; | 31 }; |
| 28 | 32 |
| 29 static const MediaType kIanaMediaTypes[] = { | 33 static const MediaType kIanaMediaTypes[] = { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // This set of codecs is supported by all variations of Chromium. | 301 // This set of codecs is supported by all variations of Chromium. |
| 298 // | 302 // |
| 299 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support | 303 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support |
| 300 // for more information. | 304 // for more information. |
| 301 // | 305 // |
| 302 // The codecs for WAV are integers as defined in Appendix A of RFC2361: | 306 // The codecs for WAV are integers as defined in Appendix A of RFC2361: |
| 303 // http://tools.ietf.org/html/rfc2361 | 307 // http://tools.ietf.org/html/rfc2361 |
| 304 static const char* const common_media_codecs[] = { | 308 static const char* const common_media_codecs[] = { |
| 305 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. | 309 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. |
| 306 "theora", | 310 "theora", |
| 307 "vp9", // TODO(tomfinegan): Move vp9 back down with vp8 once VP9 is supported | |
| 308 // on Android. https://crbug.com/285016 | |
| 309 #endif | 311 #endif |
| 310 "vorbis", | 312 "vorbis", |
| 311 "vp8", | 313 "vp8", |
| 314 "vp9", |
| 312 "1" // WAVE_FORMAT_PCM. | 315 "1" // WAVE_FORMAT_PCM. |
| 313 }; | 316 }; |
| 314 | 317 |
| 315 // List of proprietary codecs only supported by Google Chrome. | 318 // List of proprietary codecs only supported by Google Chrome. |
| 316 static const char* const proprietary_media_codecs[] = { | 319 static const char* const proprietary_media_codecs[] = { |
| 317 "avc1", | 320 "avc1", |
| 318 "avc3", | 321 "avc3", |
| 319 "mp4a" | 322 "mp4a" |
| 320 }; | 323 }; |
| 321 | 324 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 "application/javascript", | 405 "application/javascript", |
| 403 "application/ecmascript", | 406 "application/ecmascript", |
| 404 "application/x-javascript", | 407 "application/x-javascript", |
| 405 "text/javascript1.1", | 408 "text/javascript1.1", |
| 406 "text/javascript1.2", | 409 "text/javascript1.2", |
| 407 "text/javascript1.3", | 410 "text/javascript1.3", |
| 408 "text/jscript", | 411 "text/jscript", |
| 409 "text/livescript" | 412 "text/livescript" |
| 410 }; | 413 }; |
| 411 | 414 |
| 415 #if defined(OS_ANDROID) |
| 416 static bool IsCodecSupportedOnAndroid(const std::string& codec) { |
| 417 // VP9 is supported only in KitKat+ (API Level 19). |
| 418 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && |
| 419 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { |
| 420 return false; |
| 421 } |
| 422 return true; |
| 423 } |
| 424 #endif |
| 425 |
| 412 struct MediaFormatStrict { | 426 struct MediaFormatStrict { |
| 413 const char* mime_type; | 427 const char* mime_type; |
| 414 const char* codecs_list; | 428 const char* codecs_list; |
| 415 }; | 429 }; |
| 416 | 430 |
| 417 static const MediaFormatStrict format_codec_mappings[] = { | 431 static const MediaFormatStrict format_codec_mappings[] = { |
| 418 // TODO(tomfinegan): Remove this if/else when VP9 is supported on Android. | |
| 419 // https://crbug.com/285016 | |
| 420 #if !defined(OS_ANDROID) | |
| 421 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0" }, | 432 { "video/webm", "vorbis,vp8,vp8.0,vp9,vp9.0" }, |
| 422 #else | |
| 423 { "video/webm", "vorbis,vp8,vp8.0" }, | |
| 424 #endif | |
| 425 { "audio/webm", "vorbis" }, | 433 { "audio/webm", "vorbis" }, |
| 426 { "audio/wav", "1" } | 434 { "audio/wav", "1" } |
| 427 }; | 435 }; |
| 428 | 436 |
| 429 MimeUtil::MimeUtil() { | 437 MimeUtil::MimeUtil() { |
| 430 InitializeMimeTypeMaps(); | 438 InitializeMimeTypeMaps(); |
| 431 } | 439 } |
| 432 | 440 |
| 433 // static | 441 // static |
| 434 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, | 442 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 464 for (size_t i = 0; i < arraysize(common_media_types); ++i) | 472 for (size_t i = 0; i < arraysize(common_media_types); ++i) |
| 465 media_map_.insert(common_media_types[i]); | 473 media_map_.insert(common_media_types[i]); |
| 466 #if defined(USE_PROPRIETARY_CODECS) | 474 #if defined(USE_PROPRIETARY_CODECS) |
| 467 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) | 475 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) |
| 468 media_map_.insert(proprietary_media_types[i]); | 476 media_map_.insert(proprietary_media_types[i]); |
| 469 #endif | 477 #endif |
| 470 | 478 |
| 471 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) | 479 for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
| 472 javascript_map_.insert(supported_javascript_types[i]); | 480 javascript_map_.insert(supported_javascript_types[i]); |
| 473 | 481 |
| 474 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) | 482 for (size_t i = 0; i < arraysize(common_media_codecs); ++i) { |
| 483 #if defined(OS_ANDROID) |
| 484 if (!IsCodecSupportedOnAndroid(common_media_codecs[i])) |
| 485 continue; |
| 486 #endif |
| 475 codecs_map_.insert(common_media_codecs[i]); | 487 codecs_map_.insert(common_media_codecs[i]); |
| 488 } |
| 476 #if defined(USE_PROPRIETARY_CODECS) | 489 #if defined(USE_PROPRIETARY_CODECS) |
| 477 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 490 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
| 478 codecs_map_.insert(proprietary_media_codecs[i]); | 491 codecs_map_.insert(proprietary_media_codecs[i]); |
| 479 #endif | 492 #endif |
| 480 | 493 |
| 481 // Initialize the strict supported media types. | 494 // Initialize the strict supported media types. |
| 482 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | 495 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
| 483 std::vector<std::string> mime_type_codecs; | 496 std::vector<std::string> mime_type_codecs; |
| 484 ParseCodecString(format_codec_mappings[i].codecs_list, | 497 ParseCodecString(format_codec_mappings[i].codecs_list, |
| 485 &mime_type_codecs, | 498 &mime_type_codecs, |
| 486 false); | 499 false); |
| 487 | 500 |
| 488 MimeMappings codecs; | 501 MimeMappings codecs; |
| 489 for (size_t j = 0; j < mime_type_codecs.size(); ++j) | 502 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
| 503 #if defined(OS_ANDROID) |
| 504 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) |
| 505 continue; |
| 506 #endif |
| 490 codecs.insert(mime_type_codecs[j]); | 507 codecs.insert(mime_type_codecs[j]); |
| 508 } |
| 491 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 509 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
| 492 } | 510 } |
| 493 } | 511 } |
| 494 | 512 |
| 495 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 513 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
| 496 return image_map_.find(mime_type) != image_map_.end(); | 514 return image_map_.find(mime_type) != image_map_.end(); |
| 497 } | 515 } |
| 498 | 516 |
| 499 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 517 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
| 500 return media_map_.find(mime_type) != media_map_.end(); | 518 return media_map_.find(mime_type) != media_map_.end(); |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 post_data->append("\r\n" + value + "\r\n"); | 1018 post_data->append("\r\n" + value + "\r\n"); |
| 1001 } | 1019 } |
| 1002 | 1020 |
| 1003 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1021 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1004 std::string* post_data) { | 1022 std::string* post_data) { |
| 1005 DCHECK(post_data); | 1023 DCHECK(post_data); |
| 1006 post_data->append("--" + mime_boundary + "--\r\n"); | 1024 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1007 } | 1025 } |
| 1008 | 1026 |
| 1009 } // namespace net | 1027 } // namespace net |
| OLD | NEW |