OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 if (!IsStringASCII(string)) | 20 if (!IsStringASCII(string)) |
20 return std::string(); | 21 return std::string(); |
21 return UTF16ToASCII(string); | 22 return UTF16ToASCII(string); |
22 } | 23 } |
23 | 24 |
25 // Contains the types in mime_util.cc:supported_media_types that are | |
26 // conditionally compiled based on defined(GOOGLE_CHROME_BUILD) or | |
27 // defined(USE_PROPRIETARY_CODECS). | |
28 static const char* const conditional_media_types[] = { | |
scherkus (not reviewing)
2012/04/02 19:22:25
s/conditional/blacklisted/ ?
also the comments sh
ddorwin
2012/04/02 19:44:42
Done.
| |
29 // MPEG-4. | |
30 "video/mp4", | |
31 "video/x-m4v", | |
32 "audio/mp4", | |
33 "audio/x-m4a", | |
34 | |
35 // MP3. | |
36 "audio/mp3", | |
37 "audio/x-mp3", | |
38 "audio/mpeg", | |
39 }; | |
40 | |
41 // Contains the types in mime_util.cc:supported_media_codecs that are | |
42 // conditionally compiled based on defined(GOOGLE_CHROME_BUILD) or | |
43 // defined(USE_PROPRIETARY_CODECS). | |
44 static const char* const conditional_media_codecs[] = { | |
45 "avc1", | |
46 "mp4a", | |
47 }; | |
48 | |
24 } // namespace | 49 } // namespace |
25 | 50 |
26 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { | 51 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { |
27 // Claim we support Ogg+Theora/Vorbis. | 52 for (size_t i = 0; i < arraysize(conditional_media_types); ++i) |
28 media_map_.insert("video/ogg"); | 53 conditional_media_map_.insert(conditional_media_types[i]); |
29 media_map_.insert("audio/ogg"); | |
30 media_map_.insert("application/ogg"); | |
31 codecs_map_.insert("theora"); | |
32 codecs_map_.insert("vorbis"); | |
33 | 54 |
34 // Claim we support WAV. | 55 for (size_t i = 0; i < arraysize(conditional_media_codecs); ++i) |
35 media_map_.insert("audio/wav"); | 56 conditional_codecs_map_.insert(conditional_media_codecs[i]); |
36 media_map_.insert("audio/x-wav"); | |
37 codecs_map_.insert("1"); // PCM for WAV. | |
38 } | 57 } |
39 | 58 |
40 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} | 59 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} |
41 | 60 |
61 // Returns IsNotSupported if mime_type or any of the codecs are not supported. | |
62 // Otherwse, defers to the real registry. | |
42 WebMimeRegistry::SupportsType | 63 WebMimeRegistry::SupportsType |
43 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( | 64 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( |
44 const WebString& mime_type, const WebString& codecs) { | 65 const WebString& mime_type, const WebString& codecs) { |
45 // Not supporting the container is a flat-out no. | 66 if (IsConditionalMediaMimeType(ToASCIIOrEmpty(mime_type).c_str())) |
46 if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type).c_str())) | |
47 return IsNotSupported; | 67 return IsNotSupported; |
48 | 68 |
49 // If we don't recognize the codec, it's possible we support it. | |
50 std::vector<std::string> parsed_codecs; | 69 std::vector<std::string> parsed_codecs; |
51 net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &parsed_codecs, true); | 70 net::ParseCodecString(ToASCIIOrEmpty(codecs).c_str(), &parsed_codecs, true); |
52 if (!AreSupportedMediaCodecs(parsed_codecs)) | 71 if (HasConditionalMediaCodecs(parsed_codecs)) |
53 return MayBeSupported; | 72 return IsNotSupported; |
54 | 73 |
55 // Otherwise we have a perfect match. | 74 return SimpleWebMimeRegistryImpl::supportsMediaMIMEType(mime_type, codecs); |
56 return IsSupported; | |
57 } | 75 } |
58 | 76 |
59 bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType( | 77 bool TestShellWebMimeRegistryImpl::IsConditionalMediaMimeType( |
60 const std::string& mime_type) { | 78 const std::string& mime_type) { |
61 return media_map_.find(mime_type) != media_map_.end(); | 79 return conditional_media_map_.find(mime_type) != conditional_media_map_.end(); |
62 } | 80 } |
63 | 81 |
64 bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs( | 82 bool TestShellWebMimeRegistryImpl::HasConditionalMediaCodecs( |
65 const std::vector<std::string>& codecs) { | 83 const std::vector<std::string>& codecs) { |
66 for (size_t i = 0; i < codecs.size(); ++i) { | 84 for (size_t i = 0; i < codecs.size(); ++i) { |
67 if (codecs_map_.find(codecs[i]) == codecs_map_.end()) { | 85 if (conditional_codecs_map_.find(codecs[i]) != |
68 return false; | 86 conditional_codecs_map_.end()) { |
87 return true; | |
69 } | 88 } |
70 } | 89 } |
71 return true; | 90 return false; |
72 } | 91 } |
OLD | NEW |