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" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 }; | 434 }; |
435 | 435 |
436 static const MediaFormatStrict format_codec_mappings[] = { | 436 static const MediaFormatStrict format_codec_mappings[] = { |
437 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, | 437 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, |
438 { "audio/webm", "opus,vorbis" }, | 438 { "audio/webm", "opus,vorbis" }, |
439 { "audio/wav", "1" }, | 439 { "audio/wav", "1" }, |
440 { "audio/x-wav", "1" }, | 440 { "audio/x-wav", "1" }, |
441 { "video/ogg", "opus,theora,vorbis" }, | 441 { "video/ogg", "opus,theora,vorbis" }, |
442 { "audio/ogg", "opus,vorbis" }, | 442 { "audio/ogg", "opus,vorbis" }, |
443 { "application/ogg", "opus,theora,vorbis" }, | 443 { "application/ogg", "opus,theora,vorbis" }, |
444 { "audio/mpeg", "" }, | 444 { "audio/mpeg", ",mp3" }, // Note: The comma before the 'mp3'results in an |
| 445 // empty string codec ID and indicates |
| 446 // a missing codecs= parameter is also valid. |
| 447 // The presense of 'mp3' is not RFC compliant, |
| 448 // but is common in the wild so it is a defacto |
| 449 // standard. |
445 { "audio/mp3", "" }, | 450 { "audio/mp3", "" }, |
446 { "audio/x-mp3", "" } | 451 { "audio/x-mp3", "" } |
447 }; | 452 }; |
448 | 453 |
449 MimeUtil::MimeUtil() { | 454 MimeUtil::MimeUtil() { |
450 InitializeMimeTypeMaps(); | 455 InitializeMimeTypeMaps(); |
451 } | 456 } |
452 | 457 |
453 // static | 458 // static |
454 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, | 459 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, |
455 const std::vector<std::string>& codecs) { | 460 const std::vector<std::string>& codecs) { |
456 if (supported_codecs.empty()) | 461 if (supported_codecs.empty()) |
457 return codecs.empty(); | 462 return codecs.empty(); |
458 | 463 |
| 464 // If no codecs are specified in the mimetype, check to see if a missing |
| 465 // codecs parameter is allowed. |
| 466 if (codecs.empty()) |
| 467 return supported_codecs.find(std::string()) != supported_codecs.end(); |
| 468 |
459 for (size_t i = 0; i < codecs.size(); ++i) { | 469 for (size_t i = 0; i < codecs.size(); ++i) { |
460 if (supported_codecs.find(codecs[i]) == supported_codecs.end()) | 470 if (codecs[i].empty() || |
| 471 supported_codecs.find(codecs[i]) == supported_codecs.end()) { |
461 return false; | 472 return false; |
| 473 } |
462 } | 474 } |
463 return !codecs.empty(); | 475 |
| 476 return true; |
464 } | 477 } |
465 | 478 |
466 void MimeUtil::InitializeMimeTypeMaps() { | 479 void MimeUtil::InitializeMimeTypeMaps() { |
467 for (size_t i = 0; i < arraysize(supported_image_types); ++i) | 480 for (size_t i = 0; i < arraysize(supported_image_types); ++i) |
468 image_map_.insert(supported_image_types[i]); | 481 image_map_.insert(supported_image_types[i]); |
469 | 482 |
470 // Initialize the supported non-image types. | 483 // Initialize the supported non-image types. |
471 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) | 484 for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
472 non_image_map_.insert(supported_non_image_types[i]); | 485 non_image_map_.insert(supported_non_image_types[i]); |
473 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) | 486 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 post_data->append("\r\n" + value + "\r\n"); | 1049 post_data->append("\r\n" + value + "\r\n"); |
1037 } | 1050 } |
1038 | 1051 |
1039 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 1052 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
1040 std::string* post_data) { | 1053 std::string* post_data) { |
1041 DCHECK(post_data); | 1054 DCHECK(post_data); |
1042 post_data->append("--" + mime_boundary + "--\r\n"); | 1055 post_data->append("--" + mime_boundary + "--\r\n"); |
1043 } | 1056 } |
1044 | 1057 |
1045 } // namespace net | 1058 } // namespace net |
OLD | NEW |