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

Side by Side Diff: webkit/glue/simple_webmimeregistry_impl.cc

Issue 17447011: Shuffle media-related WebMimeRegistry code from webkit/ to content/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forgot some diffs Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/simple_webmimeregistry_impl.h" 5 #include "webkit/glue/simple_webmimeregistry_impl.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "media/filters/stream_parser_factory.h"
11 #include "net/base/mime_util.h" 10 #include "net/base/mime_util.h"
12 #include "third_party/WebKit/public/platform/WebString.h" 11 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "webkit/base/file_path_string_conversions.h" 12 #include "webkit/base/file_path_string_conversions.h"
14 #include "webkit/renderer/media/crypto/key_systems.h"
15 13
16 using WebKit::WebString; 14 using WebKit::WebString;
17 using WebKit::WebMimeRegistry; 15 using WebKit::WebMimeRegistry;
18 16
19 namespace { 17 namespace webkit_glue {
20 18
21 // Convert a WebString to ASCII, falling back on an empty string in the case 19 //static
22 // of a non-ASCII string. 20 std::string SimpleWebMimeRegistryImpl::ToASCIIOrEmpty(const WebString& string) {
23 std::string ToASCIIOrEmpty(const WebString& string) {
24 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string(); 21 return IsStringASCII(string) ? UTF16ToASCII(string) : std::string();
25 } 22 }
26 23
27 } // namespace
28
29 namespace webkit_glue {
30
31 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType( 24 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMIMEType(
32 const WebString& mime_type) { 25 const WebString& mime_type) {
33 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ? 26 return net::IsSupportedMimeType(ToASCIIOrEmpty(mime_type)) ?
34 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 27 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
35 } 28 }
36 29
37 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType( 30 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsImageMIMEType(
38 const WebString& mime_type) { 31 const WebString& mime_type) {
39 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ? 32 return net::IsSupportedImageMimeType(ToASCIIOrEmpty(mime_type)) ?
40 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 33 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
41 } 34 }
42 35
43 WebMimeRegistry::SupportsType 36 WebMimeRegistry::SupportsType
44 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType( 37 SimpleWebMimeRegistryImpl::supportsJavaScriptMIMEType(
45 const WebString& mime_type) { 38 const WebString& mime_type) {
46 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ? 39 return net::IsSupportedJavascriptMimeType(ToASCIIOrEmpty(mime_type)) ?
47 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 40 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
48 } 41 }
49 42
50 // When debugging layout tests failures in the test shell, 43 // When debugging layout tests failures in the test shell,
51 // see TestShellWebMimeRegistryImpl. 44 // see TestShellWebMimeRegistryImpl.
52 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( 45 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
53 const WebString& mime_type, const WebString& codecs) { 46 const WebString& mime_type, const WebString& codecs) {
54 return supportsMediaMIMEType(mime_type, codecs, WebString()); 47 // Media features are only supported at the content/ layer.
48 return IsNotSupported;
55 } 49 }
56 50
57 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType( 51 WebMimeRegistry::SupportsType SimpleWebMimeRegistryImpl::supportsMediaMIMEType(
58 const WebString& mime_type, 52 const WebString& mime_type,
59 const WebString& codecs, 53 const WebString& codecs,
60 const WebString& key_system) { 54 const WebString& key_system) {
61 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); 55 // Media features are only supported at the content/ layer.
62 // Not supporting the container is a flat-out no. 56 return IsNotSupported;
63 if (!net::IsSupportedMediaMimeType(mime_type_ascii))
64 return IsNotSupported;
65
66 if (!key_system.isEmpty()) {
67 // Check whether the key system is supported with the mime_type and codecs.
68
69 // Not supporting the key system is a flat-out no.
70 if (!webkit_media::IsSupportedKeySystem(key_system))
71 return IsNotSupported;
72
73 std::vector<std::string> strict_codecs;
74 bool strip_suffix = !net::IsStrictMediaMimeType(mime_type_ascii);
75 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, strip_suffix);
76
77 if (!webkit_media::IsSupportedKeySystemWithMediaMimeType(
78 mime_type_ascii, strict_codecs, ToASCIIOrEmpty(key_system)))
79 return IsNotSupported;
80
81 // Continue processing the mime_type and codecs.
82 }
83
84 // Check list of strict codecs to see if it is supported.
85 if (net::IsStrictMediaMimeType(mime_type_ascii)) {
86 // We support the container, but no codecs were specified.
87 if (codecs.isNull())
88 return MayBeSupported;
89
90 // Check if the codecs are a perfect match.
91 std::vector<std::string> strict_codecs;
92 net::ParseCodecString(ToASCIIOrEmpty(codecs), &strict_codecs, false);
93 if (!net::IsSupportedStrictMediaMimeType(mime_type_ascii, strict_codecs))
94 return IsNotSupported;
95
96 // Good to go!
97 return IsSupported;
98 }
99
100 // If we don't recognize the codec, it's possible we support it.
101 std::vector<std::string> parsed_codecs;
102 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codecs, true);
103 if (!net::AreSupportedMediaCodecs(parsed_codecs))
104 return MayBeSupported;
105
106 // Otherwise we have a perfect match.
107 return IsSupported;
108 } 57 }
109 58
110 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType( 59 bool SimpleWebMimeRegistryImpl::supportsMediaSourceMIMEType(
111 const WebKit::WebString& mime_type, 60 const WebString& mime_type,
112 const WebString& codecs) { 61 const WebString& codecs) {
113 const std::string mime_type_ascii = ToASCIIOrEmpty(mime_type); 62 // Media features are only supported at the content/ layer.
114 std::vector<std::string> parsed_codec_ids; 63 return IsNotSupported;
115 net::ParseCodecString(ToASCIIOrEmpty(codecs), &parsed_codec_ids, false);
116 if (mime_type_ascii.empty() || parsed_codec_ids.size() == 0)
117 return false;
118 return media::StreamParserFactory::IsTypeSupported(
119 mime_type_ascii, parsed_codec_ids);
120 } 64 }
121 65
122 WebMimeRegistry::SupportsType 66 WebMimeRegistry::SupportsType
123 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType( 67 SimpleWebMimeRegistryImpl::supportsNonImageMIMEType(
124 const WebString& mime_type) { 68 const WebString& mime_type) {
125 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ? 69 return net::IsSupportedNonImageMimeType(ToASCIIOrEmpty(mime_type)) ?
126 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported; 70 WebMimeRegistry::IsSupported : WebMimeRegistry::IsNotSupported;
127 } 71 }
128 72
129 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension( 73 WebString SimpleWebMimeRegistryImpl::mimeTypeForExtension(
(...skipping 22 matching lines...) Expand all
152 96
153 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType( 97 WebString SimpleWebMimeRegistryImpl::preferredExtensionForMIMEType(
154 const WebString& mime_type) { 98 const WebString& mime_type) {
155 base::FilePath::StringType file_extension; 99 base::FilePath::StringType file_extension;
156 net::GetPreferredExtensionForMimeType(ToASCIIOrEmpty(mime_type), 100 net::GetPreferredExtensionForMimeType(ToASCIIOrEmpty(mime_type),
157 &file_extension); 101 &file_extension);
158 return webkit_base::FilePathStringToWebString(file_extension); 102 return webkit_base::FilePathStringToWebString(file_extension);
159 } 103 }
160 104
161 } // namespace webkit_glue 105 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/simple_webmimeregistry_impl.h ('k') | webkit/support/test_shell_webmimeregistry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698