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 "content/child/simple_webmimeregistry_impl.h" | 5 #include "content/child/simple_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 "components/mime_util/mime_util.h" | 11 #include "components/mime_util/mime_util.h" |
12 #include "media/base/mime_util.h" | 12 #include "media/base/mime_util.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/FilePathConversion.h" | 15 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
15 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
16 | 17 |
17 using blink::WebString; | 18 using blink::WebString; |
18 using blink::WebMimeRegistry; | 19 using blink::WebMimeRegistry; |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 // static | 23 // static |
(...skipping 30 matching lines...) Expand all Loading... |
53 } | 54 } |
54 | 55 |
55 WebMimeRegistry::SupportsType | 56 WebMimeRegistry::SupportsType |
56 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( | 57 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( |
57 const WebString& mime_type) { | 58 const WebString& mime_type) { |
58 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) | 59 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) |
59 ? WebMimeRegistry::IsSupported | 60 ? WebMimeRegistry::IsSupported |
60 : WebMimeRegistry::IsNotSupported; | 61 : WebMimeRegistry::IsNotSupported; |
61 } | 62 } |
62 | 63 |
63 // When debugging layout tests failures in the test shell, | |
64 // see TestShellWebMimeRegistryImpl. | |
65 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( | 64 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( |
66 const WebString& mime_type, | 65 const WebString& mime_type, |
67 const WebString& codecs) { | 66 const WebString& codecs) { |
68 // Media features are only supported at the content/renderer/ layer. | 67 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); |
69 return IsNotSupported; | 68 std::vector<std::string> codec_vector; |
| 69 media::ParseCodecString(ToASCIIOrEmpty(codecs), &codec_vector, false); |
| 70 return static_cast<WebMimeRegistry::SupportsType>( |
| 71 media::IsSupportedMediaFormat(mime_type_ascii, codec_vector)); |
70 } | 72 } |
71 | 73 |
72 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( | 74 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( |
73 const WebString& mime_type, | 75 const WebString& mime_type, |
74 const WebString& codecs) { | 76 const WebString& codecs) { |
75 // Media features are only supported at the content/renderer layer. | |
76 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); | 77 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); |
77 return media::IsSupportedMediaMimeType(mime_type_ascii); | 78 if (mime_type_ascii.empty()) |
| 79 return false; |
| 80 std::vector<std::string> parsed_codec_ids; |
| 81 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false); |
| 82 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii, |
| 83 parsed_codec_ids); |
78 } | 84 } |
79 | 85 |
80 WebMimeRegistry::SupportsType | 86 WebMimeRegistry::SupportsType |
81 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( | 87 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( |
82 const WebString& mime_type) { | 88 const WebString& mime_type) { |
83 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) | 89 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) |
84 ? WebMimeRegistry::IsSupported | 90 ? WebMimeRegistry::IsSupported |
85 : WebMimeRegistry::IsNotSupported; | 91 : WebMimeRegistry::IsNotSupported; |
86 } | 92 } |
87 | 93 |
88 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( | 94 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( |
89 const WebString& file_extension) { | 95 const WebString& file_extension) { |
90 std::string mime_type; | 96 std::string mime_type; |
91 net::GetMimeTypeFromExtension( | 97 net::GetMimeTypeFromExtension( |
92 blink::WebStringToFilePath(file_extension).value(), &mime_type); | 98 blink::WebStringToFilePath(file_extension).value(), &mime_type); |
93 return WebString::fromUTF8(mime_type); | 99 return WebString::fromUTF8(mime_type); |
94 } | 100 } |
95 | 101 |
96 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension( | 102 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension( |
97 const WebString& file_extension) { | 103 const WebString& file_extension) { |
98 std::string mime_type; | 104 std::string mime_type; |
99 net::GetWellKnownMimeTypeFromExtension( | 105 net::GetWellKnownMimeTypeFromExtension( |
100 blink::WebStringToFilePath(file_extension).value(), &mime_type); | 106 blink::WebStringToFilePath(file_extension).value(), &mime_type); |
101 return WebString::fromUTF8(mime_type); | 107 return WebString::fromUTF8(mime_type); |
102 } | 108 } |
103 | 109 |
104 } // namespace content | 110 } // namespace content |
OLD | NEW |