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

Side by Side Diff: content/renderer/media/webcontentdecryptionmodule_impl.cc

Issue 557723003: Implement Chromium side of MediaKeys.isTypeSupported(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Requested changes. Created 6 years, 3 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/renderer/media/webcontentdecryptionmodule_impl.h" 5 #include "content/renderer/media/webcontentdecryptionmodule_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "content/renderer/media/cdm_session_adapter.h" 15 #include "content/renderer/media/cdm_session_adapter.h"
16 #include "content/renderer/media/crypto/key_systems.h" 16 #include "content/renderer/media/crypto/key_systems.h"
17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" 17 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
18 #include "media/base/media_keys.h" 18 #include "media/base/media_keys.h"
19 #include "net/base/mime_util.h"
19 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 21 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
21 #include "url/gurl.h" 22 #include "url/gurl.h"
22 23
23 #if defined(ENABLE_PEPPER_CDMS) 24 #if defined(ENABLE_PEPPER_CDMS)
24 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h" 25 #include "content/renderer/media/crypto/pepper_cdm_wrapper_impl.h"
25 #endif 26 #endif
26 27
27 namespace content { 28 namespace content {
28 29
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 manager, 70 manager,
70 #endif 71 #endif
71 key_system_ascii, 72 key_system_ascii,
72 security_origin_as_gurl)) { 73 security_origin_as_gurl)) {
73 return NULL; 74 return NULL;
74 } 75 }
75 76
76 return new WebContentDecryptionModuleImpl(adapter); 77 return new WebContentDecryptionModuleImpl(adapter);
77 } 78 }
78 79
80 // static
81 blink::WebContentDecryptionModule::KeySystemSupportedResult
82 WebContentDecryptionModuleImpl::IsKeySystemSupported(
83 const blink::WebString& key_system,
84 const blink::WebString& init_data_type,
85 const blink::WebString& container,
86 const blink::WebString& codecs,
87 const blink::WebString& capability) {
88 // Continuation (from Blink) of MediaKeys.isTypeSupported() algorithm.
89
90 // 1. If keySystem is an empty string or contains an unrecognized or
91 // unsupported Key System, return the empty string and abort these steps.
92 // String comparison is case-sensitive.
93 // 2. If the keySystem implementation is not available and usable, return the
94 // empty string and abort these steps.
95 // (Emptiness check is in Blink.)
96 // TODO(sandersd): Implement ASCII checks on Blink side.
97 const std::string key_system_ascii = key_system.utf8();
98 if (!IsSupportedKeySystem(key_system_ascii))
99 return blink::WebContentDecryptionModule::NotSupported;
100
101 // 3. Follow the steps for the first matching condition from the following
102 // list:
103 // - If keySystem is a value that may be successfully passed to create()
104 // Let probably result be "probably"
105 // - Otherwise (as may be the case for strings that are only used for
106 // discovery)
107 // Let probably result be "maybe".
108 blink::WebContentDecryptionModule::KeySystemSupportedResult probably_result =
109 (IsConcreteSupportedKeySystem(key_system_ascii) ?
ddorwin 2014/09/23 22:48:18 nit: () is not strictly necessary.
sandersd (OOO until July 31) 2014/09/24 22:22:34 Done.
110 blink::WebContentDecryptionModule::ProbablySupported :
ddorwin 2014/09/23 22:48:17 nit: I'm not sure what the style guide says or for
sandersd (OOO until July 31) 2014/09/24 22:22:34 Done.
111 blink::WebContentDecryptionModule::MaybeSupported);
112
113 // 4. If initDataType was not provided, follow the steps for the first
114 // matching condition from the following list and abort these steps:
115 // - If the user agent is not confident that the keySystem implementation
116 // is available and usable
117 // Return "maybe"
118 // - Otherwise
119 // Return probably result.
120 if (init_data_type.isEmpty())
121 return probably_result;
122
123 // 5. If initDataType is an empty string or contains an unrecognized or
124 // unsupported initialization data type, return the empty string and abort
125 // these steps. String comparison is case-sensitive.
126 // 6. If initDataType is not an initialization data type supported by the
127 // keySystem implementation, return the empty string and abort these steps.
128 // 7. If the keySystem implementation supporting initDataType is not available
129 // and usable, return the empty string and abort these steps.
130 // (Emptiness check is in Blink.)
131 const std::string init_data_type_ascii = init_data_type.utf8();
132 if (!IsSupportedKeySystemWithInitDataType(key_system_ascii,
133 init_data_type_ascii))
134 return blink::WebContentDecryptionModule::NotSupported;
135
136 // 8. If contentType was not provided, follow the steps for the first matching
137 // condition from the following list and abort these steps:
138 // - If the user agent is not confident that the keySystem implementation
139 // supporting initDataType is available and usable
140 // Return "maybe"
141 // - Otherwise
142 // Return probably result.
143 if (container.isEmpty())
144 return probably_result;
145
146 // 9. If contentType is an empty string or contains an invalid or
147 // unrecognized MIME type, return the empty string and abort these steps.
148 // 10. Let container be the container type specified by contentType.
149 // 11. Let parameters be the RFC 6381 parameters, if any, specified by
150 // contentType.
151 // 12. Let media types be the set of media types specified by parameters. It
152 // may be empty. The case-sensitivity of string comparisons is determined
153 // by the appropriate RFC or other specification.
154 // 13. If the user agent does not support container, return the empty string
155 // and abort these steps. The case-sensitivity of string comparisons is
156 // determined by the appropriate RFC.
157 // 14. If the user agent and keySystem implementation do not support playback
158 // of encrypted media data for all media types, return the empty string
159 // and abort these steps.
160 // (Emptiness check is in Blink.)
161 const std::string container_ascii = container.utf8();
162 if (!IsSaneInitDataTypeWithContainer(init_data_type_ascii, container_ascii))
163 return blink::WebContentDecryptionModule::NotSupported;
164
165 bool strip_codec_suffixes = !net::IsStrictMediaMimeType(container_ascii);
ddorwin 2014/09/23 22:48:17 http://crbug.com/374751 also affects this line, so
sandersd (OOO until July 31) 2014/09/24 22:22:34 Done.
166 std::vector<std::string> codec_vector;
167 net::ParseCodecString(codecs.utf8(), &codec_vector, strip_codec_suffixes);
168 if (!IsSupportedKeySystemWithMediaMimeType(
169 container_ascii, codec_vector, key_system_ascii))
170 return blink::WebContentDecryptionModule::NotSupported;
171
172 // 15-18. (Capabilities.)
173 // TODO(sandersd): Support capabilities.
174 if (!capability.isEmpty())
175 return blink::WebContentDecryptionModule::NotSupported;
176
177 // TODO(sandersd): If the codecs are all unambiguous and supported, return
178 // |probably_result|. http://crbug.com/374751
179 return blink::WebContentDecryptionModule::MaybeSupported;
180 }
181
79 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl( 182 WebContentDecryptionModuleImpl::WebContentDecryptionModuleImpl(
80 scoped_refptr<CdmSessionAdapter> adapter) 183 scoped_refptr<CdmSessionAdapter> adapter)
81 : adapter_(adapter) {} 184 : adapter_(adapter) {}
82 185
83 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() { 186 WebContentDecryptionModuleImpl::~WebContentDecryptionModuleImpl() {
84 } 187 }
85 188
86 // The caller owns the created session. 189 // The caller owns the created session.
87 blink::WebContentDecryptionModuleSession* 190 blink::WebContentDecryptionModuleSession*
88 WebContentDecryptionModuleImpl::createSession() { 191 WebContentDecryptionModuleImpl::createSession() {
(...skipping 12 matching lines...) Expand all
101 return adapter_->GetDecryptor(); 204 return adapter_->GetDecryptor();
102 } 205 }
103 206
104 #if defined(ENABLE_BROWSER_CDMS) 207 #if defined(ENABLE_BROWSER_CDMS)
105 int WebContentDecryptionModuleImpl::GetCdmId() const { 208 int WebContentDecryptionModuleImpl::GetCdmId() const {
106 return adapter_->GetCdmId(); 209 return adapter_->GetCdmId();
107 } 210 }
108 #endif // defined(ENABLE_BROWSER_CDMS) 211 #endif // defined(ENABLE_BROWSER_CDMS)
109 212
110 } // namespace content 213 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698