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 "net/base/mime_util.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
17 std::string
ToASCIIOrEmpty(const blink::WebString
& string
) {
18 return base::IsStringASCII(string
) ? base::UTF16ToASCII(string
)
24 blink::WebMimeRegistry::SupportsType
WebMimeRegistryImpl::supportsMIMEType(
25 const blink::WebString
& mime_type
) {
26 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type
)) ?
27 blink::WebMimeRegistry::IsSupported
:
28 blink::WebMimeRegistry::IsNotSupported
;
31 blink::WebMimeRegistry::SupportsType
WebMimeRegistryImpl::supportsImageMIMEType(
32 const blink::WebString
& mime_type
) {
33 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type
)) ?
34 blink::WebMimeRegistry::IsSupported
:
35 blink::WebMimeRegistry::IsNotSupported
;
38 blink::WebMimeRegistry::SupportsType
39 WebMimeRegistryImpl::supportsImagePrefixedMIMEType(
40 const blink::WebString
& mime_type
) {
41 std::string ascii_mime_type
= ToASCIIOrEmpty(mime_type
);
42 return (net::IsSupportedImageMimeType(ascii_mime_type
) ||
43 (StartsWithASCII(ascii_mime_type
, "image/", true) &&
44 net::IsSupportedNonImageMimeType(ascii_mime_type
)))
45 ? WebMimeRegistry::IsSupported
46 : WebMimeRegistry::IsNotSupported
;
49 blink::WebMimeRegistry::SupportsType
50 WebMimeRegistryImpl::supportsJavaScriptMIMEType(
51 const blink::WebString
& mime_type
) {
52 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type
)) ?
53 blink::WebMimeRegistry::IsSupported
:
54 blink::WebMimeRegistry::IsNotSupported
;
57 blink::WebMimeRegistry::SupportsType
WebMimeRegistryImpl::supportsMediaMIMEType(
58 const blink::WebString
& mime_type
,
59 const blink::WebString
& codecs
,
60 const blink::WebString
& key_system
) {
62 return IsNotSupported
;
65 bool WebMimeRegistryImpl::supportsMediaSourceMIMEType(
66 const blink::WebString
& mime_type
,
67 const blink::WebString
& codecs
) {
72 bool WebMimeRegistryImpl::supportsEncryptedMediaMIMEType(
73 const blink::WebString
& key_system
,
74 const blink::WebString
& mime_type
,
75 const blink::WebString
& codecs
) {
80 blink::WebMimeRegistry::SupportsType
81 WebMimeRegistryImpl::supportsNonImageMIMEType(
82 const blink::WebString
& mime_type
) {
83 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type
)) ?
84 blink::WebMimeRegistry::IsSupported
:
85 blink::WebMimeRegistry::IsNotSupported
;
88 blink::WebString
WebMimeRegistryImpl::mimeTypeForExtension(
89 const blink::WebString
& file_extension
) {
91 return blink::WebString();
94 blink::WebString
WebMimeRegistryImpl::wellKnownMimeTypeForExtension(
95 const blink::WebString
& file_extension
) {
97 return blink::WebString();
100 blink::WebString
WebMimeRegistryImpl::mimeTypeFromFile(
101 const blink::WebString
& file_path
) {
103 return blink::WebString();