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 "content/child/simple_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 "net/base/mime_util.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
14 using blink::WebString
;
15 using blink::WebMimeRegistry
;
20 std::string
SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString
& string
) {
21 return IsStringASCII(string
) ? base::UTF16ToASCII(string
) : std::string();
24 WebMimeRegistry::SupportsType
SimpleWebMimeRegistryImpl::supportsMIMEType(
25 const WebString
& mime_type
) {
26 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type
)) ?
27 WebMimeRegistry::IsSupported
: WebMimeRegistry::IsNotSupported
;
30 WebMimeRegistry::SupportsType
SimpleWebMimeRegistryImpl::supportsImageMIMEType(
31 const WebString
& mime_type
) {
32 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type
)) ?
33 WebMimeRegistry::IsSupported
: WebMimeRegistry::IsNotSupported
;
36 WebMimeRegistry::SupportsType
37 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
38 const WebString
& mime_type
) {
39 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type
)) ?
40 WebMimeRegistry::IsSupported
: WebMimeRegistry::IsNotSupported
;
43 // When debugging layout tests failures in the test shell,
44 // see TestShellWebMimeRegistryImpl.
45 WebMimeRegistry::SupportsType
SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
46 const WebString
& mime_type
,
47 const WebString
& codecs
,
48 const WebString
& key_system
) {
49 // Media features are only supported at the content/renderer/ layer.
50 return IsNotSupported
;
53 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType(
54 const WebString
& mime_type
,
55 const WebString
& codecs
) {
56 // Media features are only supported at the content/renderer layer.
60 bool SimpleWebMimeRegistryImpl::supportsEncryptedMediaMIMEType(
61 const blink::WebString
& key_system
,
62 const blink::WebString
& mime_type
,
63 const blink::WebString
& codecs
) {
64 // Media features are only supported at the content/renderer layer.
68 WebMimeRegistry::SupportsType
69 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
70 const WebString
& mime_type
) {
71 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type
)) ?
72 WebMimeRegistry::IsSupported
: WebMimeRegistry::IsNotSupported
;
75 WebString
SimpleWebMimeRegistryImpl::mimeTypeForExtension(
76 const WebString
& file_extension
) {
77 std::string mime_type
;
78 net::GetMimeTypeFromExtension(
79 base::FilePath::FromUTF16Unsafe(file_extension
).value(), &mime_type
);
80 return WebString::fromUTF8(mime_type
);
83 WebString
SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension(
84 const WebString
& file_extension
) {
85 std::string mime_type
;
86 net::GetWellKnownMimeTypeFromExtension(
87 base::FilePath::FromUTF16Unsafe(file_extension
).value(), &mime_type
);
88 return WebString::fromUTF8(mime_type
);
91 WebString
SimpleWebMimeRegistryImpl::mimeTypeFromFile(
92 const WebString
& file_path
) {
93 std::string mime_type
;
94 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path
),
96 return WebString::fromUTF8(mime_type
);
99 } // namespace content