Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: content/child/simple_webmimeregistry_impl.cc

Issue 2444873002: Move WebMIMERegistry impl from //content to blink:platform/network/mime (Closed)
Patch Set: rebased Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "content/child/simple_webmimeregistry_impl.h"
6
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 "media/base/mime_util.h"
13 #include "media/filters/stream_parser_factory.h"
14 #include "net/base/mime_util.h"
15 #include "third_party/WebKit/public/platform/FilePathConversion.h"
16 #include "third_party/WebKit/public/platform/WebString.h"
17
18 using blink::WebString;
19 using blink::WebMimeRegistry;
20
21 namespace content {
22
23 // static
24 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) {
25 return string.containsOnlyASCII() ? string.ascii() : std::string();
26 }
27
28 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType(
29 const WebString& mime_type) {
30 return mime_util::IsSupportedMimeType(ToASCIIOrEmpty(mime_type))
31 ? WebMimeRegistry::IsSupported
32 : WebMimeRegistry::IsNotSupported;
33 }
34
35 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
36 const WebString& mime_type) {
37 return mime_util::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type))
38 ? WebMimeRegistry::IsSupported
39 : WebMimeRegistry::IsNotSupported;
40 }
41
42 WebMimeRegistry::SupportsType
43 SimpleWebMimeRegistryImpl::supportsImagePrefixedMIMEType(
44 const WebString& mime_type) {
45 std::string ascii_mime_type = ToASCIIOrEmpty(mime_type);
46 return (mime_util::IsSupportedImageMimeType(ascii_mime_type) ||
47 (base::StartsWith(ascii_mime_type, "image/",
48 base::CompareCase::SENSITIVE) &&
49 mime_util::IsSupportedNonImageMimeType(ascii_mime_type)))
50 ? WebMimeRegistry::IsSupported
51 : WebMimeRegistry::IsNotSupported;
52 }
53
54 WebMimeRegistry::SupportsType
55 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
56 const WebString& mime_type) {
57 return mime_util::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type))
58 ? WebMimeRegistry::IsSupported
59 : WebMimeRegistry::IsNotSupported;
60 }
61
62 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
63 const WebString& mime_type,
64 const WebString& codecs) {
65 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
66 std::vector<std::string> codec_vector;
67 media::ParseCodecString(ToASCIIOrEmpty(codecs), &codec_vector, false);
68 return static_cast<WebMimeRegistry::SupportsType>(
69 media::IsSupportedMediaFormat(mime_type_ascii, codec_vector));
70 }
71
72 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType(
73 const WebString& mime_type,
74 const WebString& codecs) {
75 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type);
76 if (mime_type_ascii.empty())
77 return false;
78 std::vector<std::string> parsed_codec_ids;
79 media::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
80 return media::StreamParserFactory::IsTypeSupported(mime_type_ascii,
81 parsed_codec_ids);
82 }
83
84 WebMimeRegistry::SupportsType
85 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
86 const WebString& mime_type) {
87 return mime_util::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type))
88 ? WebMimeRegistry::IsSupported
89 : WebMimeRegistry::IsNotSupported;
90 }
91
92 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
93 const WebString& file_extension) {
94 std::string mime_type;
95 net::GetMimeTypeFromExtension(
96 blink::WebStringToFilePath(file_extension).value(), &mime_type);
97 return WebString::fromUTF8(mime_type);
98 }
99
100 WebString SimpleWebMimeRegistryImpl::wellKnownMimeTypeForExtension(
101 const WebString& file_extension) {
102 std::string mime_type;
103 net::GetWellKnownMimeTypeFromExtension(
104 blink::WebStringToFilePath(file_extension).value(), &mime_type);
105 return WebString::fromUTF8(mime_type);
106 }
107
108 } // namespace content
OLDNEW
« no previous file with comments | « content/child/simple_webmimeregistry_impl.h ('k') | content/child/simple_webmimeregistry_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698