OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/html_viewer/web_mime_registry_impl.h" | 5 #include "components/html_viewer/web_mime_registry_impl.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/mime_util/mime_util.h" | 11 #include "components/mime_util/mime_util.h" |
12 #include "media/base/key_systems.h" | 12 #include "media/base/key_systems.h" |
| 13 #include "media/base/mime_util.h" |
13 #include "media/filters/stream_parser_factory.h" | 14 #include "media/filters/stream_parser_factory.h" |
14 #include "net/base/mime_util.h" | 15 #include "net/base/mime_util.h" |
15 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
16 | 17 |
17 namespace html_viewer { | 18 namespace html_viewer { |
18 namespace { | 19 namespace { |
19 | 20 |
20 std::string ToASCIIOrEmpty(const blink::WebString& string) { | 21 std::string ToASCIIOrEmpty(const blink::WebString& string) { |
21 return base::IsStringASCII(string) ? base::UTF16ToASCII(string) | 22 return base::IsStringASCII(string) ? base::UTF16ToASCII(string) |
22 : std::string(); | 23 : std::string(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ? blink::WebMimeRegistry::IsSupported | 57 ? blink::WebMimeRegistry::IsSupported |
57 : blink::WebMimeRegistry::IsNotSupported; | 58 : blink::WebMimeRegistry::IsNotSupported; |
58 } | 59 } |
59 | 60 |
60 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType( | 61 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType( |
61 const blink::WebString& mime_type, | 62 const blink::WebString& mime_type, |
62 const blink::WebString& codecs, | 63 const blink::WebString& codecs, |
63 const blink::WebString& key_system) { | 64 const blink::WebString& key_system) { |
64 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 65 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); |
65 // Not supporting the container is a flat-out no. | 66 // Not supporting the container is a flat-out no. |
66 if (!net::IsSupportedMediaMimeType(mime_type_ascii)) | 67 if (!media::IsSupportedMediaMimeType(mime_type_ascii)) |
67 return IsNotSupported; | 68 return IsNotSupported; |
68 | 69 |
69 // Mojo does not currently support any key systems. | 70 // Mojo does not currently support any key systems. |
70 if (!key_system.isEmpty()) | 71 if (!key_system.isEmpty()) |
71 return IsNotSupported; | 72 return IsNotSupported; |
72 | 73 |
73 // Check list of strict codecs to see if it is supported. | 74 // Check list of strict codecs to see if it is supported. |
74 if (net::IsStrictMediaMimeType(mime_type_ascii)) { | 75 if (media::IsStrictMediaMimeType(mime_type_ascii)) { |
75 // Check if the codecs are a perfect match. | 76 // Check if the codecs are a perfect match. |
76 std::vector<std::string> strict_codecs; | 77 std::vector<std::string> strict_codecs; |
77 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); | 78 media::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); |
78 return static_cast<WebMimeRegistry::SupportsType>( | 79 return static_cast<WebMimeRegistry::SupportsType>( |
79 net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)); | 80 media::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)); |
80 } | 81 } |
81 | 82 |
82 // If we don't recognize the codec, it's possible we support it. | 83 // If we don't recognize the codec, it's possible we support it. |
83 std::vector<std::string> parsed_codecs; | 84 std::vector<std::string> parsed_codecs; |
84 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); | 85 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); |
85 if (!net::AreSupportedMediaCodecs(parsed_codecs)) | 86 if (!media::AreSupportedMediaCodecs(parsed_codecs)) |
86 return MayBeSupported; | 87 return MayBeSupported; |
87 | 88 |
88 // Otherwise we have a perfect match. | 89 // Otherwise we have a perfect match. |
89 return IsSupported; | 90 return IsSupported; |
90 } | 91 } |
91 | 92 |
92 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType( | 93 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType( |
93 const blink::WebString& mime_type, | 94 const blink::WebString& mime_type, |
94 const blink::WebString& codecs) { | 95 const blink::WebString& codecs) { |
95 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 96 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); |
96 if (mime_type_ascii.empty()) | 97 if (mime_type_ascii.empty()) |
97 return false; | 98 return false; |
98 | 99 |
99 std::vector<std::string> parsed_codec_ids; | 100 std::vector<std::string> parsed_codec_ids; |
100 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); | 101 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); |
101 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, | 102 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, |
102 parsed_codec_ids); | 103 parsed_codec_ids); |
103 } | 104 } |
104 | 105 |
105 blink::WebMimeRegistry::SupportsType | 106 blink::WebMimeRegistry::SupportsType |
106 WebMimeRegistryImpl::supportsNonImageMIMEType( | 107 WebMimeRegistryImpl::supportsNonImageMIMEType( |
107 const blink::WebString& mime_type) { | 108 const blink::WebString& mime_type) { |
108 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) | 109 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) |
109 ? blink::WebMimeRegistry::IsSupported | 110 ? blink::WebMimeRegistry::IsSupported |
110 : blink::WebMimeRegistry::IsNotSupported; | 111 : blink::WebMimeRegistry::IsNotSupported; |
(...skipping 17 matching lines...) Expand all Loading... |
128 | 129 |
129 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile( | 130 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile( |
130 const blink::WebString& file_path) { | 131 const blink::WebString& file_path) { |
131 std::string mime_type; | 132 std::string mime_type; |
132 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), | 133 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), |
133 &mime_type); | 134 &mime_type); |
134 return blink::WebString::fromUTF8(mime_type); | 135 return blink::WebString::fromUTF8(mime_type); |
135 } | 136 } |
136 | 137 |
137 } // namespace html_viewer | 138 } // namespace html_viewer |
OLD | NEW |