| 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 "media/base/key_systems.h" | 12 #include "media/base/key_systems.h" |
| 12 #include "media/filters/stream_parser_factory.h" | 13 #include "media/filters/stream_parser_factory.h" |
| 13 #include "net/base/mime_util.h" | 14 #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 mime_util::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 mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) |
| 36 blink::WebMimeRegistry::IsSupported : | 37 ? blink::WebMimeRegistry::IsSupported |
| 37 blink::WebMimeRegistry::IsNotSupported; | 38 : blink::WebMimeRegistry::IsNotSupported; |
| 38 } | 39 } |
| 39 | 40 |
| 40 blink::WebMimeRegistry::SupportsType | 41 blink::WebMimeRegistry::SupportsType |
| 41 WebMimeRegistryImpl::supportsImagePrefixedMIMEType( | 42 WebMimeRegistryImpl::supportsImagePrefixedMIMEType( |
| 42 const blink::WebString& mime_type) { | 43 const blink::WebString& mime_type) { |
| 43 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type); | 44 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type); |
| 44 return (net::IsSupportedImageMimeType(ascii_mime_type) || | 45 return (mime_util::IsSupportedImageMimeType(ascii_mime_type) || |
| 45 (StartsWithASCII(ascii_mime_type, "image/", true) && | 46 (StartsWithASCII(ascii_mime_type, "image/", true) && |
| 46 net::IsSupportedNonImageMimeType(ascii_mime_type))) | 47 mime_util::IsSupportedNonImageMimeType(ascii_mime_type))) |
| 47 ? WebMimeRegistry::IsSupported | 48 ? WebMimeRegistry::IsSupported |
| 48 : WebMimeRegistry::IsNotSupported; | 49 : WebMimeRegistry::IsNotSupported; |
| 49 } | 50 } |
| 50 | 51 |
| 51 blink::WebMimeRegistry::SupportsType | 52 blink::WebMimeRegistry::SupportsType |
| 52 WebMimeRegistryImpl::supportsJavaScriptMIMEType( | 53 WebMimeRegistryImpl::supportsJavaScriptMIMEType( |
| 53 const blink::WebString& mime_type) { | 54 const blink::WebString& mime_type) { |
| 54 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? | 55 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) |
| 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 (!net::IsSupportedMediaMimeType(mime_type_ascii)) |
| 66 return IsNotSupported; | 67 return IsNotSupported; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 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 net::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 blink::WebMimeRegistry::SupportsType | 105 blink::WebMimeRegistry::SupportsType |
| 105 WebMimeRegistryImpl::supportsNonImageMIMEType( | 106 WebMimeRegistryImpl::supportsNonImageMIMEType( |
| 106 const blink::WebString& mime_type) { | 107 const blink::WebString& mime_type) { |
| 107 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? | 108 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) |
| 108 blink::WebMimeRegistry::IsSupported : | 109 ? blink::WebMimeRegistry::IsSupported |
| 109 blink::WebMimeRegistry::IsNotSupported; | 110 : blink::WebMimeRegistry::IsNotSupported; |
| 110 } | 111 } |
| 111 | 112 |
| 112 blink::WebString WebMimeRegistryImpl::mimeTypeForExtension( | 113 blink::WebString WebMimeRegistryImpl::mimeTypeForExtension( |
| 113 const blink::WebString& file_extension) { | 114 const blink::WebString& file_extension) { |
| 114 std::string mime_type; | 115 std::string mime_type; |
| 115 net::GetMimeTypeFromExtension( | 116 net::GetMimeTypeFromExtension( |
| 116 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); | 117 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); |
| 117 return blink::WebString::fromUTF8(mime_type); | 118 return blink::WebString::fromUTF8(mime_type); |
| 118 } | 119 } |
| 119 | 120 |
| 120 blink::WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension( | 121 blink::WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension( |
| 121 const blink::WebString& file_extension) { | 122 const blink::WebString& file_extension) { |
| 122 std::string mime_type; | 123 std::string mime_type; |
| 123 net::GetWellKnownMimeTypeFromExtension( | 124 net::GetWellKnownMimeTypeFromExtension( |
| 124 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); | 125 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); |
| 125 return blink::WebString::fromUTF8(mime_type); | 126 return blink::WebString::fromUTF8(mime_type); |
| 126 } | 127 } |
| 127 | 128 |
| 128 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile( | 129 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile( |
| 129 const blink::WebString& file_path) { | 130 const blink::WebString& file_path) { |
| 130 std::string mime_type; | 131 std::string mime_type; |
| 131 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), | 132 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path), |
| 132 &mime_type); | 133 &mime_type); |
| 133 return blink::WebString::fromUTF8(mime_type); | 134 return blink::WebString::fromUTF8(mime_type); |
| 134 } | 135 } |
| 135 | 136 |
| 136 } // namespace html_viewer | 137 } // namespace html_viewer |
| OLD | NEW |