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 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { | 25 TestShellWebMimeRegistryImpl::TestShellWebMimeRegistryImpl() { |
25 // Claim we support Ogg+Theora/Vorbis. | 26 const std::vector<std::string> blacklisted_media_types = |
26 media_map_.insert("video/ogg"); | 27 net::GetProprietaryMediaTypes(); |
27 media_map_.insert("audio/ogg"); | 28 for (size_t i = 0; i < blacklisted_media_types.size(); ++i) |
28 media_map_.insert("application/ogg"); | 29 blacklisted_media_map_.insert(blacklisted_media_types[i]); |
29 codecs_map_.insert("theora"); | |
30 codecs_map_.insert("vorbis"); | |
31 | 30 |
32 // Claim we support WAV. | 31 const std::vector<std::string> blacklisted_media_codecs = |
33 media_map_.insert("audio/wav"); | 32 net::GetProprietaryMediaCodecs(); |
34 media_map_.insert("audio/x-wav"); | 33 for (size_t i = 0; i < blacklisted_media_codecs.size(); ++i) |
35 codecs_map_.insert("1"); // PCM for WAV. | 34 blacklisted_codecs_map_.insert(blacklisted_media_codecs[i]); |
36 } | 35 } |
37 | 36 |
38 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} | 37 TestShellWebMimeRegistryImpl::~TestShellWebMimeRegistryImpl() {} |
39 | 38 |
| 39 // Returns IsNotSupported if mime_type or any of the codecs are not supported. |
| 40 // Otherwse, defers to the real registry. |
40 WebMimeRegistry::SupportsType | 41 WebMimeRegistry::SupportsType |
41 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( | 42 TestShellWebMimeRegistryImpl::supportsMediaMIMEType( |
42 const WebString& mime_type, | 43 const WebString& mime_type, |
43 const WebString& codecs) { | 44 const WebString& codecs) { |
44 // Not supporting the container is a flat-out no. | 45 if (IsBlacklistedMediaMimeType(ToASCIIOrEmpty(mime_type))) |
45 if (!IsSupportedMediaMimeType(ToASCIIOrEmpty(mime_type))) | |
46 return IsNotSupported; | 46 return IsNotSupported; |
47 | 47 |
48 // If we don't recognize the codec, it's possible we support it. | |
49 std::vector<std::string> parsed_codecs; | 48 std::vector<std::string> parsed_codecs; |
50 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); | 49 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); |
51 if (!AreSupportedMediaCodecs(parsed_codecs)) | 50 if (HasBlacklistedMediaCodecs(parsed_codecs)) |
52 return MayBeSupported; | 51 return IsNotSupported; |
53 | 52 |
54 // Otherwise we have a perfect match. | 53 return SimpleWebMimeRegistryImpl::supportsMediaMIMEType(mime_type, codecs); |
55 return IsSupported; | |
56 } | 54 } |
57 | 55 |
58 bool TestShellWebMimeRegistryImpl::IsSupportedMediaMimeType( | 56 bool TestShellWebMimeRegistryImpl::IsBlacklistedMediaMimeType( |
59 const std::string& mime_type) { | 57 const std::string& mime_type) { |
60 return media_map_.find(mime_type) != media_map_.end(); | 58 return blacklisted_media_map_.find(mime_type) != blacklisted_media_map_.end(); |
61 } | 59 } |
62 | 60 |
63 bool TestShellWebMimeRegistryImpl::AreSupportedMediaCodecs( | 61 bool TestShellWebMimeRegistryImpl::HasBlacklistedMediaCodecs( |
64 const std::vector<std::string>& codecs) { | 62 const std::vector<std::string>& codecs) { |
65 for (size_t i = 0; i < codecs.size(); ++i) { | 63 for (size_t i = 0; i < codecs.size(); ++i) { |
66 if (codecs_map_.find(codecs[i]) == codecs_map_.end()) | 64 if (blacklisted_codecs_map_.find(codecs[i]) != |
67 return false; | 65 blacklisted_codecs_map_.end()) |
| 66 return true; |
68 } | 67 } |
69 return !codecs.empty(); | 68 return false; |
70 } | 69 } |
OLD | NEW |