Chromium Code Reviews| 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 "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" | 5 #include "webkit/tools/test_shell/test_shell_webmimeregistry_impl.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | |
| 7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 8 #include "net/base/mime_util.h" | 9 #include "net/base/mime_util.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 10 | 11 |
| 11 using WebKit::WebString; | 12 using WebKit::WebString; |
| 12 using WebKit::WebMimeRegistry; | 13 using WebKit::WebMimeRegistry; |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // Convert a WebString to ASCII, falling back on an empty string in the case | 17 // Convert a WebString to ASCII, falling back on an empty string in the case |
| 17 // of a non-ASCII string. | 18 // of a non-ASCII string. |
| 18 std::string ToASCIIOrEmpty(const WebString& string) { | 19 std::string ToASCIIOrEmpty(const WebString& string) { |
| 19 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); | 20 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); |
| 20 } | 21 } |
| 21 | 22 |
| 23 // Contains the types in mime_util.cc:supported_media_types that are | |
| 24 // conditionally compiled based on defined(GOOGLE_CHROME_BUILD) or | |
| 25 // defined(USE_PROPRIETARY_CODECS). These must be blacklisted to ensure | |
| 26 // consistent layout test results across all Chromium variations. | |
| 27 static const char* const blacklisted_media_types[] = { | |
|
darin (slow to review)
2012/04/03 23:01:14
seems unfortunate to replicate code between here a
ddorwin
2012/04/04 20:59:19
Since we already include mime_util.h, we can expos
| |
| 28 // MPEG-4. | |
| 29 "video/mp4", | |
| 30 "video/x-m4v", | |
| 31 "audio/mp4", | |
| 32 "audio/x-m4a", | |
| 33 | |
| 34 // MP3. | |
| 35 "audio/mp3", | |
| 36 "audio/x-mp3", | |
| 37 "audio/mpeg", | |
| 38 }; | |
| 39 | |
| 40 // Contains the types in mime_util.cc:supported_media_codecs that are | |
| 41 // conditionally compiled based on defined(GOOGLE_CHROME_BUILD) or | |
| 42 // defined(USE_PROPRIETARY_CODECS). These must be blacklisted to ensure | |
| 43 // consistent layout test results across all Chromium variations. | |
| 44 static const char* const blacklisted_media_codecs[] = { | |
| 45 "avc1", | |
| 46 "mp4a", | |
| 47 }; | |
| 48 | |
| 22 } // namespace | 49 } // namespace |
| 23 | 50 |
| 24 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { | 51 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { |
| 25 // Claim we support Ogg+Theora/Vorbis. | 52 for (size_t i = 0; i < arraysize(blacklisted_media_types); ++i) |
| 26 media_map_.insert("video/ogg"); | 53 blacklisted_media_map_.insert(blacklisted_media_types[i]); |
| 27 media_map_.insert("audio/ogg"); | |
| 28 media_map_.insert("application/ogg"); | |
| 29 codecs_map_.insert("theora"); | |
| 30 codecs_map_.insert("vorbis"); | |
| 31 | 54 |
| 32 // Claim we support WAV. | 55 for (size_t i = 0; i < arraysize(blacklisted_media_codecs); ++i) |
| 33 media_map_.insert("audio/wav"); | 56 blacklisted_codecs_map_.insert(blacklisted_media_codecs[i]); |
| 34 media_map_.insert("audio/x-wav"); | |
| 35 codecs_map_.insert("1"); // PCM for WAV. | |
| 36 } | 57 } |
| 37 | 58 |
| 38 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} | 59 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} |
| 39 | 60 |
| 61 // Returns IsNotSupported if mime_type or any of the codecs are not supported. | |
| 62 // Otherwse, defers to the real registry. | |
| 40 WebMimeRegistry::SupportsType | 63 WebMimeRegistry::SupportsType |
| 41 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( | 64 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( |
| 42 const WebString& mime_type, | 65 const WebString& mime_type, |
| 43 const WebString& codecs) { | 66 const WebString& codecs) { |
| 44 // Not supporting the container is a flat-out no. | 67 if (IsBlacklistedMediaMimeType(ToASCIIOrEmpty(mime_type))) |
| 45 if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type))) | |
| 46 return IsNotSupported; | 68 return IsNotSupported; |
| 47 | 69 |
| 48 // If we don't recognize the codec, it's possible we support it. | |
| 49 std::vector<std::string> parsed_codecs; | 70 std::vector<std::string> parsed_codecs; |
| 50 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); | 71 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); |
| 51 if (!AreSupportedMediaCodecs(parsed_codecs)) | 72 if (HasBlacklistedMediaCodecs(parsed_codecs)) |
| 52 return MayBeSupported; | 73 return IsNotSupported; |
| 53 | 74 |
| 54 // Otherwise we have a perfect match. | 75 return SimpleWebMimeRegistryImpl::supportsMediaMIMEType(mime_type, codecs); |
| 55 return IsSupported; | |
| 56 } | 76 } |
| 57 | 77 |
| 58 bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType( | 78 bool TestShellWebMimeRegistryImpl::IsBlacklistedMediaMimeType( |
| 59 const std::string& mime_type) { | 79 const std::string& mime_type) { |
| 60 return media_map_.find(mime_type) != media_map_.end(); | 80 return blacklisted_media_map_.find(mime_type) != blacklisted_media_map_.end(); |
| 61 } | 81 } |
| 62 | 82 |
| 63 bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs( | 83 bool TestShellWebMimeRegistryImpl::HasBlacklistedMediaCodecs( |
| 64 const std::vector<std::string>& codecs) { | 84 const std::vector<std::string>& codecs) { |
| 65 for (size_t i = 0; i < codecs.size(); ++i) { | 85 for (size_t i = 0; i < codecs.size(); ++i) { |
| 66 if (codecs_map_.find(codecs[i]) == codecs_map_.end()) | 86 if (blacklisted_codecs_map_.find(codecs[i]) != |
| 67 return false; | 87 blacklisted_codecs_map_.end()) |
| 88 return true; | |
| 68 } | 89 } |
| 69 return !codecs.empty(); | 90 return false; |
| 70 } | 91 } |
| OLD | NEW |