| 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 "mojo/services/html_viewer/webmimeregistry_impl.h" | 5 #include "mojo/services/html_viewer/webmimeregistry_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 "content/common/mime_util.h" |
| 11 #include "media/base/key_systems.h" | 12 #include "media/base/key_systems.h" |
| 13 #include "media/base/mime_util.h" |
| 12 #include "media/filters/stream_parser_factory.h" | 14 #include "media/filters/stream_parser_factory.h" |
| 13 #include "net/base/mime_util.h" | |
| 14 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 15 | 16 |
| 16 namespace html_viewer { | 17 namespace html_viewer { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 std::string ToASCIIOrEmpty(const blink::WebString& string) { | 20 std::string ToASCIIOrEmpty(const blink::WebString& string) { |
| 20 return base::IsStringASCII(string) ? base::UTF16ToASCII(string) | 21 return base::IsStringASCII(string) ? base::UTF16ToASCII(string) |
| 21 : std::string(); | 22 : std::string(); |
| 22 } | 23 } |
| 23 | 24 |
| 24 } // namespace | 25 } // namespace |
| 25 | 26 |
| 26 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMIMEType( | 27 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMIMEType( |
| 27 const blink::WebString& mime_type) { | 28 const blink::WebString& mime_type) { |
| 28 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? | 29 return content::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 29 blink::WebMimeRegistry::IsSupported : | 30 blink::WebMimeRegistry::IsSupported : |
| 30 blink::WebMimeRegistry::IsNotSupported; | 31 blink::WebMimeRegistry::IsNotSupported; |
| 31 } | 32 } |
| 32 | 33 |
| 33 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsImageMIMEType( | 34 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsImageMIMEType( |
| 34 const blink::WebString& mime_type) { | 35 const blink::WebString& mime_type) { |
| 35 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? | 36 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 36 blink::WebMimeRegistry::IsSupported : | 37 blink::WebMimeRegistry::IsSupported : |
| 37 blink::WebMimeRegistry::IsNotSupported; | 38 blink::WebMimeRegistry::IsNotSupported; |
| 38 } | 39 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 blink::WebMimeRegistry::IsSupported : | 56 blink::WebMimeRegistry::IsSupported : |
| 56 blink::WebMimeRegistry::IsNotSupported; | 57 blink::WebMimeRegistry::IsNotSupported; |
| 57 } | 58 } |
| 58 | 59 |
| 59 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType( | 60 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType( |
| 60 const blink::WebString& mime_type, | 61 const blink::WebString& mime_type, |
| 61 const blink::WebString& codecs, | 62 const blink::WebString& codecs, |
| 62 const blink::WebString& key_system) { | 63 const blink::WebString& key_system) { |
| 63 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 64 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); |
| 64 // Not supporting the container is a flat-out no. | 65 // Not supporting the container is a flat-out no. |
| 65 if (!net::IsSupportedMediaMimeType(mime_type_ascii)) | 66 if (!media::IsSupportedMediaMimeType(mime_type_ascii)) |
| 66 return IsNotSupported; | 67 return IsNotSupported; |
| 67 | 68 |
| 68 // Mojo does not currently support any key systems. | 69 // Mojo does not currently support any key systems. |
| 69 if (!key_system.isEmpty()) | 70 if (!key_system.isEmpty()) |
| 70 return IsNotSupported; | 71 return IsNotSupported; |
| 71 | 72 |
| 72 // Check list of strict codecs to see if it is supported. | 73 // Check list of strict codecs to see if it is supported. |
| 73 if (net::IsStrictMediaMimeType(mime_type_ascii)) { | 74 if (media::IsStrictMediaMimeType(mime_type_ascii)) { |
| 74 // Check if the codecs are a perfect match. | 75 // Check if the codecs are a perfect match. |
| 75 std::vector<std::string> strict_codecs; | 76 std::vector<std::string> strict_codecs; |
| 76 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); | 77 media::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false); |
| 77 return static_cast<WebMimeRegistry::SupportsType>( | 78 return static_cast<WebMimeRegistry::SupportsType>( |
| 78 net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)); | 79 media::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs)); |
| 79 } | 80 } |
| 80 | 81 |
| 81 // If we don't recognize the codec, it's possible we support it. | 82 // If we don't recognize the codec, it's possible we support it. |
| 82 std::vector<std::string> parsed_codecs; | 83 std::vector<std::string> parsed_codecs; |
| 83 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); | 84 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true); |
| 84 if (!net::AreSupportedMediaCodecs(parsed_codecs)) | 85 if (!media::AreSupportedMediaCodecs(parsed_codecs)) |
| 85 return MayBeSupported; | 86 return MayBeSupported; |
| 86 | 87 |
| 87 // Otherwise we have a perfect match. | 88 // Otherwise we have a perfect match. |
| 88 return IsSupported; | 89 return IsSupported; |
| 89 } | 90 } |
| 90 | 91 |
| 91 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType( | 92 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType( |
| 92 const blink::WebString& mime_type, | 93 const blink::WebString& mime_type, |
| 93 const blink::WebString& codecs) { | 94 const blink::WebString& codecs) { |
| 94 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 95 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); |
| 95 if (mime_type_ascii.empty()) | 96 if (mime_type_ascii.empty()) |
| 96 return false; | 97 return false; |
| 97 | 98 |
| 98 std::vector<std::string> parsed_codec_ids; | 99 std::vector<std::string> parsed_codec_ids; |
| 99 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); | 100 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); |
| 100 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, | 101 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, |
| 101 parsed_codec_ids); | 102 parsed_codec_ids); |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool WebMimeRegistryImpl::supportsEncryptedMediaMIMEType( | 105 bool WebMimeRegistryImpl::supportsEncryptedMediaMIMEType( |
| 105 const blink::WebString& key_system, | 106 const blink::WebString& key_system, |
| 106 const blink::WebString& mime_type, | 107 const blink::WebString& mime_type, |
| 107 const blink::WebString& codecs) { | 108 const blink::WebString& codecs) { |
| 108 // Only supports ASCII parameters. | 109 // Only supports ASCII parameters. |
| 109 if (!base::IsStringASCII(key_system) || !base::IsStringASCII(mime_type) || | 110 if (!base::IsStringASCII(key_system) || !base::IsStringASCII(mime_type) || |
| 110 !base::IsStringASCII(codecs)) { | 111 !base::IsStringASCII(codecs)) { |
| 111 return false; | 112 return false; |
| 112 } | 113 } |
| 113 | 114 |
| 114 if (key_system.isEmpty()) | 115 if (key_system.isEmpty()) |
| 115 return false; | 116 return false; |
| 116 | 117 |
| 117 const std::string mime_type_ascii = base::UTF16ToASCII(mime_type); | 118 const std::string mime_type_ascii = base::UTF16ToASCII(mime_type); |
| 118 | 119 |
| 119 std::vector<std::string> codec_vector; | 120 std::vector<std::string> codec_vector; |
| 120 bool strip_suffix = !net::IsStrictMediaMimeType(mime_type_ascii); | 121 bool strip_suffix = !media::IsStrictMediaMimeType(mime_type_ascii); |
| 121 net::ParseCodecString(base::UTF16ToASCII(codecs), &codec_vector, | 122 media::ParseCodecString(base::UTF16ToASCII(codecs), &codec_vector, |
| 122 strip_suffix); | 123 strip_suffix); |
| 123 | 124 |
| 124 return media::IsSupportedKeySystemWithMediaMimeType( | 125 return media::IsSupportedKeySystemWithMediaMimeType( |
| 125 mime_type_ascii, codec_vector, base::UTF16ToASCII(key_system)); | 126 mime_type_ascii, codec_vector, base::UTF16ToASCII(key_system)); |
| 126 } | 127 } |
| 127 | 128 |
| 128 blink::WebMimeRegistry::SupportsType | 129 blink::WebMimeRegistry::SupportsType |
| 129 WebMimeRegistryImpl::supportsNonImageMIMEType( | 130 WebMimeRegistryImpl::supportsNonImageMIMEType( |
| 130 const blink::WebString& mime_type) { | 131 const blink::WebString& mime_type) { |
| 131 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? | 132 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? |
| 132 blink::WebMimeRegistry::IsSupported : | 133 blink::WebMimeRegistry::IsSupported : |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 return blink::WebString(); | 146 return blink::WebString(); |
| 146 } | 147 } |
| 147 | 148 |
| 148 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile( | 149 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile( |
| 149 const blink::WebString& file_path) { | 150 const blink::WebString& file_path) { |
| 150 NOTIMPLEMENTED(); | 151 NOTIMPLEMENTED(); |
| 151 return blink::WebString(); | 152 return blink::WebString(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 } // namespace html_viewer | 155 } // namespace html_viewer |
| OLD | NEW |