OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/html_viewer/web_mime_registry_impl.h" | |
6 | |
7 #include "base/files/file_path.h" | |
8 #include "base/strings/string_util.h" | |
9 #include "base/strings/sys_string_conversions.h" | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "components/mime_util/mime_util.h" | |
12 #include "media/base/key_systems.h" | |
13 #include "media/base/mime_util.h" | |
14 #include "media/filters/stream_parser_factory.h" | |
15 #include "net/base/mime_util.h" | |
16 #include "third_party/WebKit/public/platform/WebString.h" | |
17 | |
18 namespace html_viewer { | |
19 namespace { | |
20 | |
21 std::string ToASCIIOrEmpty(const blink::WebString& string) { | |
22 return base::IsStringASCII(string) | |
23 ? base::UTF16ToASCII(base::StringPiece16(string)) | |
24 : std::string(); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMIMEType( | |
30 const blink::WebString& mime_type) { | |
31 return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) | |
32 ? blink::WebMimeRegistry::IsSupported | |
33 : blink::WebMimeRegistry::IsNotSupported; | |
34 } | |
35 | |
36 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsImageMIMEType( | |
37 const blink::WebString& mime_type) { | |
38 return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) | |
39 ? blink::WebMimeRegistry::IsSupported | |
40 : blink::WebMimeRegistry::IsNotSupported; | |
41 } | |
42 | |
43 blink::WebMimeRegistry::SupportsType | |
44 WebMimeRegistryImpl::supportsImagePrefixedMIMEType( | |
45 const blink::WebString& mime_type) { | |
46 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type); | |
47 return (mime_util::IsSupportedImageMimeType(ascii_mime_type) || | |
48 (base::StartsWith(ascii_mime_type, "image/", | |
49 base::CompareCase::SENSITIVE) && | |
50 mime_util::IsSupportedNonImageMimeType(ascii_mime_type))) | |
51 ? WebMimeRegistry::IsSupported | |
52 : WebMimeRegistry::IsNotSupported; | |
53 } | |
54 | |
55 blink::WebMimeRegistry::SupportsType | |
56 WebMimeRegistryImpl::supportsJavaScriptMIMEType( | |
57 const blink::WebString& mime_type) { | |
58 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) | |
59 ? blink::WebMimeRegistry::IsSupported | |
60 : blink::WebMimeRegistry::IsNotSupported; | |
61 } | |
62 | |
63 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType( | |
64 const blink::WebString& mime_type, | |
65 const blink::WebString& codecs, | |
66 const blink::WebString& key_system) { | |
67 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | |
68 | |
69 // Mojo does not currently support any key systems. | |
70 if (!key_system.isEmpty()) | |
71 return IsNotSupported; | |
72 | |
73 std::vector<std::string> codec_vector; | |
74 media::ParseCodecString(ToASCIIOrEmpty(codecs), &codec_vector, false); | |
75 return static_cast<WebMimeRegistry::SupportsType>( | |
76 media::IsSupportedMediaFormat(mime_type_ascii, codec_vector)); | |
77 } | |
78 | |
79 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType( | |
80 const blink::WebString& mime_type, | |
81 const blink::WebString& codecs) { | |
82 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | |
83 if (mime_type_ascii.empty()) | |
84 return false; | |
85 | |
86 std::vector<std::string> parsed_codec_ids; | |
87 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); | |
88 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, | |
89 parsed_codec_ids); | |
90 } | |
91 | |
92 blink::WebMimeRegistry::SupportsType | |
93 WebMimeRegistryImpl::supportsNonImageMIMEType( | |
94 const blink::WebString& mime_type) { | |
95 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) | |
96 ? blink::WebMimeRegistry::IsSupported | |
97 : blink::WebMimeRegistry::IsNotSupported; | |
98 } | |
99 | |
100 blink::WebString WebMimeRegistryImpl::mimeTypeForExtension( | |
101 const blink::WebString& file_extension) { | |
102 std::string mime_type; | |
103 net::GetMimeTypeFromExtension( | |
104 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); | |
105 return blink::WebString::fromUTF8(mime_type); | |
106 } | |
107 | |
108 blink::WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension( | |
109 const blink::WebString& file_extension) { | |
110 std::string mime_type; | |
111 net::GetWellKnownMimeTypeFromExtension( | |
112 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type); | |
113 return blink::WebString::fromUTF8(mime_type); | |
114 } | |
115 | |
116 } // namespace html_viewer | |
OLD | NEW |