[Android] Mark testNotificationDeleteIntentClosesNotification instrumentation test...
[chromium-blink-merge.git] / mojo / services / html_viewer / webmimeregistry_impl.cc
blob0b7b689393fafa9eb356646caa8aa924eda1670b
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.
5 #include "mojo/services/html_viewer/webmimeregistry_impl.h"
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 "media/base/key_systems.h"
12 #include "media/filters/stream_parser_factory.h"
13 #include "net/base/mime_util.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
16 namespace html_viewer {
17 namespace {
19 std::string ToASCIIOrEmpty(const blink::WebString& string) {
20 return base::IsStringASCII(string) ? base::UTF16ToASCII(string)
21 : std::string();
24 } // namespace
26 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMIMEType(
27 const blink::WebString& mime_type) {
28 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ?
29 blink::WebMimeRegistry::IsSupported :
30 blink::WebMimeRegistry::IsNotSupported;
33 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsImageMIMEType(
34 const blink::WebString& mime_type) {
35 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ?
36 blink::WebMimeRegistry::IsSupported :
37 blink::WebMimeRegistry::IsNotSupported;
40 blink::WebMimeRegistry::SupportsType
41 WebMimeRegistryImpl::supportsImagePrefixedMIMEType(
42 const blink::WebString& mime_type) {
43 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type);
44 return (net::IsSupportedImageMimeType(ascii_mime_type) ||
45 (StartsWithASCII(ascii_mime_type, "image/", true) &&
46 net::IsSupportedNonImageMimeType(ascii_mime_type)))
47 ? WebMimeRegistry::IsSupported
48 : WebMimeRegistry::IsNotSupported;
51 blink::WebMimeRegistry::SupportsType
52 WebMimeRegistryImpl::supportsJavaScriptMIMEType(
53 const blink::WebString& mime_type) {
54 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ?
55 blink::WebMimeRegistry::IsSupported :
56 blink::WebMimeRegistry::IsNotSupported;
59 blink::WebMimeRegistry::SupportsType WebMimeRegistryImpl::supportsMediaMIMEType(
60 const blink::WebString& mime_type,
61 const blink::WebString& codecs,
62 const blink::WebString& key_system) {
63 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
64 // Not supporting the container is a flat-out no.
65 if (!net::IsSupportedMediaMimeType(mime_type_ascii))
66 return IsNotSupported;
68 // Mojo does not currently support any key systems.
69 if (!key_system.isEmpty())
70 return IsNotSupported;
72 // Check list of strict codecs to see if it is supported.
73 if (net::IsStrictMediaMimeType(mime_type_ascii)) {
74 // Check if the codecs are a perfect match.
75 std::vector<std::string> strict_codecs;
76 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false);
77 return static_cast<WebMimeRegistry::SupportsType>(
78 net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs));
81 // If we don't recognize the codec, it's possible we support it.
82 std::vector<std::string> parsed_codecs;
83 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
84 if (!net::AreSupportedMediaCodecs(parsed_codecs))
85 return MayBeSupported;
87 // Otherwise we have a perfect match.
88 return IsSupported;
91 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType(
92 const blink::WebString& mime_type,
93 const blink::WebString& codecs) {
94 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
95 if (mime_type_ascii.empty())
96 return false;
98 std::vector<std::string> parsed_codec_ids;
99 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
100 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii,
101 parsed_codec_ids);
104 blink::WebMimeRegistry::SupportsType
105 WebMimeRegistryImpl::supportsNonImageMIMEType(
106 const blink::WebString& mime_type) {
107 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ?
108 blink::WebMimeRegistry::IsSupported :
109 blink::WebMimeRegistry::IsNotSupported;
112 blink::WebString WebMimeRegistryImpl::mimeTypeForExtension(
113 const blink::WebString& file_extension) {
114 NOTIMPLEMENTED();
115 return blink::WebString();
118 blink::WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension(
119 const blink::WebString& file_extension) {
120 NOTIMPLEMENTED();
121 return blink::WebString();
124 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile(
125 const blink::WebString& file_path) {
126 NOTIMPLEMENTED();
127 return blink::WebString();
130 } // namespace html_viewer