cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / content / child / simple_webmimeregistry_impl.cc
blob98936816a9c2143fbd1b720fb4f3ae22fbf3c6e8
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 "components/mime_util/mime_util.h"
12 #include "net/base/mime_util.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
15 using blink::WebString;
16 using blink::WebMimeRegistry;
18 namespace content {
20 // static
21 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) {
22 return base::IsStringASCII(string)
23 ? base::UTF16ToASCII(base::StringPiece16(string))
24 : std::string();
27 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType(
28 const WebString& mime_type) {
29 return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mime_type))
30 ? WebMimeRegistry::IsSupported
31 : WebMimeRegistry::IsNotSupported;
34 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
35 const WebString& mime_type) {
36 return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type))
37 ? WebMimeRegistry::IsSupported
38 : WebMimeRegistry::IsNotSupported;
41 WebMimeRegistry::SupportsType
42 SimpleWebMimeRegistryImpl::supportsImagePrefixedMIMEType(
43 const WebString& mime_type) {
44 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type);
45 return (mime_util::IsSupportedImageMimeType(ascii_mime_type) ||
46 (base::StartsWith(ascii_mime_type, "image/",
47 base::CompareCase::SENSITIVE) &&
48 mime_util::IsSupportedNonImageMimeType(ascii_mime_type)))
49 ? WebMimeRegistry::IsSupported
50 : WebMimeRegistry::IsNotSupported;
53 WebMimeRegistry::SupportsType
54 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
55 const WebString& mime_type) {
56 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type))
57 ? WebMimeRegistry::IsSupported
58 : WebMimeRegistry::IsNotSupported;
61 // When debugging layout tests failures in the test shell,
62 // see TestShellWebMimeRegistryImpl.
63 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
64 const WebString& mime_type,
65 const WebString& codecs,
66 const WebString& key_system) {
67 // Media features are only supported at the content/renderer/ layer.
68 return IsNotSupported;
71 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType(
72 const WebString& mime_type,
73 const WebString& codecs) {
74 // Media features are only supported at the content/renderer layer.
75 return false;
78 WebMimeRegistry::SupportsType
79 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
80 const WebString& mime_type) {
81 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type))
82 ? WebMimeRegistry::IsSupported
83 : WebMimeRegistry::IsNotSupported;
86 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
87 const WebString& file_extension) {
88 std::string mime_type;
89 net::GetMimeTypeFromExtension(
90 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
91 return WebString::fromUTF8(mime_type);
94 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension(
95 const WebString& file_extension) {
96 std::string mime_type;
97 net::GetWellKnownMimeTypeFromExtension(
98 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
99 return WebString::fromUTF8(mime_type);
102 WebString SimpleWebMimeRegistryImpl::mimeTypeFromFile(
103 const WebString& file_path) {
104 std::string mime_type;
105 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path),
106 &mime_type);
107 return WebString::fromUTF8(mime_type);
110 } // namespace content