OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "webencryptedmediaclient_impl.h" | 5 #include "webencryptedmediaclient_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "media/base/key_systems.h" | 11 #include "media/base/key_systems.h" |
12 #include "media/base/media_permission.h" | 12 #include "media/base/media_permission.h" |
13 #include "net/base/mime_util.h" | 13 #include "net/base/mime_util.h" |
14 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" | 14 #include "third_party/WebKit/public/platform/WebEncryptedMediaRequest.h" |
15 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" | 15 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h" |
16 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
17 #include "third_party/WebKit/public/platform/WebVector.h" | 17 #include "third_party/WebKit/public/platform/WebVector.h" |
| 18 #include "webcontentdecryptionmodule_impl.h" |
18 #include "webcontentdecryptionmoduleaccess_impl.h" | 19 #include "webcontentdecryptionmoduleaccess_impl.h" |
19 | 20 |
20 namespace media { | 21 namespace media { |
21 | 22 |
22 // These names are used by UMA. | 23 // These names are used by UMA. |
23 const char kKeySystemSupportUMAPrefix[] = | 24 const char kKeySystemSupportUMAPrefix[] = |
24 "Media.EME.RequestMediaKeySystemAccess."; | 25 "Media.EME.RequestMediaKeySystemAccess."; |
25 | 26 |
26 static bool IsSupportedContentType( | 27 static bool IsSupportedContentType( |
27 const std::string& key_system, | 28 const std::string& key_system, |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 183 } |
183 | 184 |
184 const std::string uma_name_; | 185 const std::string uma_name_; |
185 bool is_request_reported_; | 186 bool is_request_reported_; |
186 bool is_support_reported_; | 187 bool is_support_reported_; |
187 }; | 188 }; |
188 | 189 |
189 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( | 190 WebEncryptedMediaClientImpl::WebEncryptedMediaClientImpl( |
190 scoped_ptr<CdmFactory> cdm_factory, | 191 scoped_ptr<CdmFactory> cdm_factory, |
191 MediaPermission* media_permission) | 192 MediaPermission* media_permission) |
192 : cdm_factory_(cdm_factory.Pass()) { | 193 : cdm_factory_(cdm_factory.Pass()), weak_factory_(this) { |
193 // TODO(sandersd): Use |media_permission| to check for media permissions in | 194 // TODO(sandersd): Use |media_permission| to check for media permissions in |
194 // this class. | 195 // this class. |
195 DCHECK(media_permission); | 196 DCHECK(media_permission); |
196 } | 197 } |
197 | 198 |
198 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { | 199 WebEncryptedMediaClientImpl::~WebEncryptedMediaClientImpl() { |
199 } | 200 } |
200 | 201 |
201 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( | 202 void WebEncryptedMediaClientImpl::requestMediaKeySystemAccess( |
202 blink::WebEncryptedMediaRequest request) { | 203 blink::WebEncryptedMediaRequest request) { |
(...skipping 27 matching lines...) Expand all Loading... |
230 // and abort these steps. | 231 // and abort these steps. |
231 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& | 232 const blink::WebVector<blink::WebMediaKeySystemConfiguration>& |
232 configurations = request.supportedConfigurations(); | 233 configurations = request.supportedConfigurations(); |
233 | 234 |
234 // TODO(sandersd): Remove once Blink requires the configurations parameter for | 235 // TODO(sandersd): Remove once Blink requires the configurations parameter for |
235 // requestMediaKeySystemAccess(). | 236 // requestMediaKeySystemAccess(). |
236 if (configurations.isEmpty()) { | 237 if (configurations.isEmpty()) { |
237 reporter->ReportSupported(); | 238 reporter->ReportSupported(); |
238 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | 239 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
239 request.keySystem(), blink::WebMediaKeySystemConfiguration(), | 240 request.keySystem(), blink::WebMediaKeySystemConfiguration(), |
240 request.securityOrigin(), cdm_factory_.get())); | 241 request.securityOrigin(), weak_factory_.GetWeakPtr())); |
241 return; | 242 return; |
242 } | 243 } |
243 | 244 |
244 for (size_t i = 0; i < configurations.size(); i++) { | 245 for (size_t i = 0; i < configurations.size(); i++) { |
245 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i]; | 246 const blink::WebMediaKeySystemConfiguration& candidate = configurations[i]; |
246 blink::WebMediaKeySystemConfiguration accumulated_configuration; | 247 blink::WebMediaKeySystemConfiguration accumulated_configuration; |
247 if (GetSupportedConfiguration(key_system, candidate, | 248 if (GetSupportedConfiguration(key_system, candidate, |
248 request.securityOrigin(), | 249 request.securityOrigin(), |
249 &accumulated_configuration)) { | 250 &accumulated_configuration)) { |
250 reporter->ReportSupported(); | 251 reporter->ReportSupported(); |
251 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( | 252 request.requestSucceeded(WebContentDecryptionModuleAccessImpl::Create( |
252 request.keySystem(), accumulated_configuration, | 253 request.keySystem(), accumulated_configuration, |
253 request.securityOrigin(), cdm_factory_.get())); | 254 request.securityOrigin(), weak_factory_.GetWeakPtr())); |
254 return; | 255 return; |
255 } | 256 } |
256 } | 257 } |
257 | 258 |
258 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError. | 259 // 7.4 Reject promise with a new DOMException whose name is NotSupportedError. |
259 request.requestNotSupported( | 260 request.requestNotSupported( |
260 "None of the requested configurations were supported."); | 261 "None of the requested configurations were supported."); |
261 } | 262 } |
262 | 263 |
| 264 void WebEncryptedMediaClientImpl::CreateCdm( |
| 265 blink::WebSecurityOrigin security_origin, |
| 266 blink::WebString key_system, |
| 267 blink::WebContentDecryptionModuleResult result) { |
| 268 WebContentDecryptionModuleImpl::Create(cdm_factory_.get(), security_origin, |
| 269 key_system, result); |
| 270 } |
| 271 |
263 // Lazily create Reporters. | 272 // Lazily create Reporters. |
264 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( | 273 WebEncryptedMediaClientImpl::Reporter* WebEncryptedMediaClientImpl::GetReporter( |
265 const std::string& key_system) { | 274 const std::string& key_system) { |
266 std::string uma_name = GetKeySystemNameForUMA(key_system); | 275 std::string uma_name = GetKeySystemNameForUMA(key_system); |
267 Reporter* reporter = reporters_.get(uma_name); | 276 Reporter* reporter = reporters_.get(uma_name); |
268 if (reporter != nullptr) | 277 if (reporter != nullptr) |
269 return reporter; | 278 return reporter; |
270 | 279 |
271 // Reporter not found, so create one. | 280 // Reporter not found, so create one. |
272 auto result = | 281 auto result = |
273 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); | 282 reporters_.add(uma_name, make_scoped_ptr(new Reporter(uma_name))); |
274 DCHECK(result.second); | 283 DCHECK(result.second); |
275 return result.first->second; | 284 return result.first->second; |
276 } | 285 } |
277 | 286 |
278 } // namespace media | 287 } // namespace media |
OLD | NEW |