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

Side by Side Diff: mojo/services/html_viewer/web_mime_registry_impl.cc

Issue 1099303002: Move html_viewer from mojo/services to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 months 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 "mojo/services/html_viewer/web_mime_registry_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 "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"
15
16 namespace html_viewer {
17 namespace {
18
19 std::string ToASCIIOrEmpty(const blink::WebString& string) {
20 return base::IsStringASCII(string) ? base::UTF16ToASCII(string)
21 : std::string();
22 }
23
24 } // namespace
25
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;
31 }
32
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;
38 }
39
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;
49 }
50
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;
57 }
58
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;
67
68 // Mojo does not currently support any key systems.
69 if (!key_system.isEmpty())
70 return IsNotSupported;
71
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));
79 }
80
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;
86
87 // Otherwise we have a perfect match.
88 return IsSupported;
89 }
90
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;
97
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);
102 }
103
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;
110 }
111
112 blink::WebString WebMimeRegistryImpl::mimeTypeForExtension(
113 const blink::WebString& file_extension) {
114 std::string mime_type;
115 net::GetMimeTypeFromExtension(
116 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
117 return blink::WebString::fromUTF8(mime_type);
118 }
119
120 blink::WebString WebMimeRegistryImpl::wellKnownMimeTypeForExtension(
121 const blink::WebString& file_extension) {
122 std::string mime_type;
123 net::GetWellKnownMimeTypeFromExtension(
124 base::FilePath::FromUTF16Unsafe(file_extension).value(), &mime_type);
125 return blink::WebString::fromUTF8(mime_type);
126 }
127
128 blink::WebString WebMimeRegistryImpl::mimeTypeFromFile(
129 const blink::WebString& file_path) {
130 std::string mime_type;
131 net::GetMimeTypeFromFile(base::FilePath::FromUTF16Unsafe(file_path),
132 &mime_type);
133 return blink::WebString::fromUTF8(mime_type);
134 }
135
136 } // namespace html_viewer
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/web_mime_registry_impl.h ('k') | mojo/services/html_viewer/web_notification_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698