OLD | NEW |
---|---|
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 "media/cdm/ppapi/cdm_adapter.h" | 5 #include "media/cdm/ppapi/cdm_adapter.h" |
6 | 6 |
7 #include "media/base/limits.h" | 7 #include "media/base/limits.h" |
8 #include "media/cdm/ppapi/cdm_file_io_impl.h" | 8 #include "media/cdm/ppapi/cdm_file_io_impl.h" |
9 #include "media/cdm/ppapi/cdm_helpers.h" | 9 #include "media/cdm/ppapi/cdm_helpers.h" |
10 #include "media/cdm/ppapi/cdm_logging.h" | 10 #include "media/cdm/ppapi/cdm_logging.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 output_protection_(this), | 295 output_protection_(this), |
296 platform_verification_(this), | 296 platform_verification_(this), |
297 output_link_mask_(0), | 297 output_link_mask_(0), |
298 output_protection_mask_(0), | 298 output_protection_mask_(0), |
299 query_output_protection_in_progress_(false), | 299 query_output_protection_in_progress_(false), |
300 uma_for_output_protection_query_reported_(false), | 300 uma_for_output_protection_query_reported_(false), |
301 uma_for_output_protection_positive_result_reported_(false), | 301 uma_for_output_protection_positive_result_reported_(false), |
302 #endif | 302 #endif |
303 allocator_(this), | 303 allocator_(this), |
304 cdm_(NULL), | 304 cdm_(NULL), |
305 allow_distinctive_identifier_(false), | |
306 allow_persistent_state_(false), | |
305 deferred_initialize_audio_decoder_(false), | 307 deferred_initialize_audio_decoder_(false), |
306 deferred_audio_decoder_config_id_(0), | 308 deferred_audio_decoder_config_id_(0), |
307 deferred_initialize_video_decoder_(false), | 309 deferred_initialize_video_decoder_(false), |
308 deferred_video_decoder_config_id_(0), | 310 deferred_video_decoder_config_id_(0), |
309 last_read_file_size_kb_(0), | 311 last_read_file_size_kb_(0), |
310 file_size_uma_reported_(false) { | 312 file_size_uma_reported_(false) { |
311 callback_factory_.Initialize(this); | 313 callback_factory_.Initialize(this); |
312 } | 314 } |
313 | 315 |
314 CdmAdapter::~CdmAdapter() {} | 316 CdmAdapter::~CdmAdapter() {} |
(...skipping 12 matching lines...) Expand all Loading... | |
327 return success; | 329 return success; |
328 } | 330 } |
329 | 331 |
330 // No errors should be reported in this function because the spec says: | 332 // No errors should be reported in this function because the spec says: |
331 // "Store this new error object internally with the MediaKeys instance being | 333 // "Store this new error object internally with the MediaKeys instance being |
332 // created. This will be used to fire an error against any session created for | 334 // created. This will be used to fire an error against any session created for |
333 // this instance." These errors will be reported during session creation | 335 // this instance." These errors will be reported during session creation |
334 // (CreateSession()) or session loading (LoadSession()). | 336 // (CreateSession()) or session loading (LoadSession()). |
335 // TODO(xhwang): If necessary, we need to store the error here if we want to | 337 // TODO(xhwang): If necessary, we need to store the error here if we want to |
336 // support more specific error reporting (other than "Unknown"). | 338 // support more specific error reporting (other than "Unknown"). |
337 void CdmAdapter::Initialize(const std::string& key_system) { | 339 void CdmAdapter::Initialize(const std::string& key_system, |
340 bool allow_distinctive_identifier, | |
341 bool allow_persistent_state) { | |
338 PP_DCHECK(!key_system.empty()); | 342 PP_DCHECK(!key_system.empty()); |
339 PP_DCHECK(key_system_.empty() || (key_system_ == key_system && cdm_)); | 343 PP_DCHECK(key_system_.empty() || (key_system_ == key_system && cdm_)); |
340 | 344 |
345 | |
jrummell
2015/03/06 21:40:47
nit: I don't think 2 blank lines are needed.
ddorwin
2015/03/06 21:42:54
remove
sandersd (OOO until July 31)
2015/03/06 22:36:58
Done.
| |
341 #if defined(CHECK_DOCUMENT_URL) | 346 #if defined(CHECK_DOCUMENT_URL) |
342 PP_URLComponents_Dev url_components = {}; | 347 PP_URLComponents_Dev url_components = {}; |
343 const pp::URLUtil_Dev* url_util = pp::URLUtil_Dev::Get(); | 348 const pp::URLUtil_Dev* url_util = pp::URLUtil_Dev::Get(); |
344 if (!url_util) | 349 if (!url_util) |
345 return; | 350 return; |
346 pp::Var href = url_util->GetDocumentURL(pp::InstanceHandle(pp_instance()), | 351 pp::Var href = url_util->GetDocumentURL(pp::InstanceHandle(pp_instance()), |
347 &url_components); | 352 &url_components); |
348 PP_DCHECK(href.is_string()); | 353 PP_DCHECK(href.is_string()); |
349 std::string url = href.AsString(); | 354 std::string url = href.AsString(); |
350 PP_DCHECK(!url.empty()); | 355 PP_DCHECK(!url.empty()); |
351 std::string url_scheme = | 356 std::string url_scheme = |
352 url.substr(url_components.scheme.begin, url_components.scheme.len); | 357 url.substr(url_components.scheme.begin, url_components.scheme.len); |
353 if (url_scheme != "file") { | 358 if (url_scheme != "file") { |
354 // Skip this check for file:// URLs as they don't have a host component. | 359 // Skip this check for file:// URLs as they don't have a host component. |
355 PP_DCHECK(url_components.host.begin); | 360 PP_DCHECK(url_components.host.begin); |
356 PP_DCHECK(0 < url_components.host.len); | 361 PP_DCHECK(0 < url_components.host.len); |
357 } | 362 } |
358 #endif // defined(CHECK_DOCUMENT_URL) | 363 #endif // defined(CHECK_DOCUMENT_URL) |
359 | 364 |
360 if (!cdm_ && !CreateCdmInstance(key_system)) | 365 if (!cdm_ && !CreateCdmInstance(key_system)) |
361 return; | 366 return; |
362 | 367 |
363 PP_DCHECK(cdm_); | 368 PP_DCHECK(cdm_); |
364 key_system_ = key_system; | 369 key_system_ = key_system; |
370 allow_distinctive_identifier_ = allow_distinctive_identifier; | |
371 allow_persistent_state_ = allow_persistent_state; | |
365 } | 372 } |
366 | 373 |
367 void CdmAdapter::SetServerCertificate(uint32_t promise_id, | 374 void CdmAdapter::SetServerCertificate(uint32_t promise_id, |
368 pp::VarArrayBuffer server_certificate) { | 375 pp::VarArrayBuffer server_certificate) { |
369 const uint8_t* server_certificate_ptr = | 376 const uint8_t* server_certificate_ptr = |
370 static_cast<const uint8_t*>(server_certificate.Map()); | 377 static_cast<const uint8_t*>(server_certificate.Map()); |
371 const uint32_t server_certificate_size = server_certificate.ByteLength(); | 378 const uint32_t server_certificate_size = server_certificate.ByteLength(); |
372 | 379 |
373 if (!server_certificate_ptr || | 380 if (!server_certificate_ptr || |
374 server_certificate_size < media::limits::kMinCertificateLength || | 381 server_certificate_size < media::limits::kMinCertificateLength || |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); | 1106 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
1100 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); | 1107 console->Log(pp_instance(), PP_LOGLEVEL_LOG, value.pp_var()); |
1101 } | 1108 } |
1102 #endif // !defined(NDEBUG) | 1109 #endif // !defined(NDEBUG) |
1103 | 1110 |
1104 void CdmAdapter::SendPlatformChallenge(const char* service_id, | 1111 void CdmAdapter::SendPlatformChallenge(const char* service_id, |
1105 uint32_t service_id_size, | 1112 uint32_t service_id_size, |
1106 const char* challenge, | 1113 const char* challenge, |
1107 uint32_t challenge_size) { | 1114 uint32_t challenge_size) { |
1108 #if defined(OS_CHROMEOS) | 1115 #if defined(OS_CHROMEOS) |
1109 pp::VarArrayBuffer challenge_var(challenge_size); | 1116 // If access to a distinctive identifier is not allowed, prevent platform |
1110 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | 1117 // verification so that no distinctive identifier will be available in the |
ddorwin
2015/03/06 21:42:54
... verification to prevent access to such an iden
sandersd (OOO until July 31)
2015/03/06 22:36:58
Done.
| |
1111 memcpy(var_data, challenge, challenge_size); | 1118 // first place. |
1119 if (allow_distinctive_identifier_) { | |
1120 pp::VarArrayBuffer challenge_var(challenge_size); | |
1121 uint8_t* var_data = static_cast<uint8_t*>(challenge_var.Map()); | |
1122 memcpy(var_data, challenge, challenge_size); | |
1112 | 1123 |
1113 std::string service_id_str(service_id, service_id_size); | 1124 std::string service_id_str(service_id, service_id_size); |
1114 | 1125 |
1115 linked_ptr<PepperPlatformChallengeResponse> response( | 1126 linked_ptr<PepperPlatformChallengeResponse> response( |
1116 new PepperPlatformChallengeResponse()); | 1127 new PepperPlatformChallengeResponse()); |
1117 | 1128 |
1118 int32_t result = platform_verification_.ChallengePlatform( | 1129 int32_t result = platform_verification_.ChallengePlatform( |
1119 pp::Var(service_id_str), | 1130 pp::Var(service_id_str), |
1120 challenge_var, | 1131 challenge_var, |
1121 &response->signed_data, | 1132 &response->signed_data, |
1122 &response->signed_data_signature, | 1133 &response->signed_data_signature, |
1123 &response->platform_key_certificate, | 1134 &response->platform_key_certificate, |
1124 callback_factory_.NewCallback(&CdmAdapter::SendPlatformChallengeDone, | 1135 callback_factory_.NewCallback(&CdmAdapter::SendPlatformChallengeDone, |
1125 response)); | 1136 response)); |
1126 challenge_var.Unmap(); | 1137 challenge_var.Unmap(); |
1127 if (result == PP_OK_COMPLETIONPENDING) | 1138 if (result == PP_OK_COMPLETIONPENDING) |
1128 return; | 1139 return; |
1129 | 1140 |
1130 // Fall through on error and issue an empty OnPlatformChallengeResponse(). | 1141 // Fall through on error and issue an empty OnPlatformChallengeResponse(). |
1131 PP_DCHECK(result != PP_OK); | 1142 PP_DCHECK(result != PP_OK); |
1143 } | |
1132 #endif | 1144 #endif |
1133 | 1145 |
1134 cdm::PlatformChallengeResponse platform_challenge_response = {}; | 1146 cdm::PlatformChallengeResponse platform_challenge_response = {}; |
1135 cdm_->OnPlatformChallengeResponse(platform_challenge_response); | 1147 cdm_->OnPlatformChallengeResponse(platform_challenge_response); |
1136 } | 1148 } |
1137 | 1149 |
1138 void CdmAdapter::EnableOutputProtection(uint32_t desired_protection_mask) { | 1150 void CdmAdapter::EnableOutputProtection(uint32_t desired_protection_mask) { |
1139 #if defined(OS_CHROMEOS) | 1151 #if defined(OS_CHROMEOS) |
1140 int32_t result = output_protection_.EnableProtection( | 1152 int32_t result = output_protection_.EnableProtection( |
1141 desired_protection_mask, callback_factory_.NewCallback( | 1153 desired_protection_mask, callback_factory_.NewCallback( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 deferred_video_decoder_config_id_, | 1205 deferred_video_decoder_config_id_, |
1194 decoder_status == cdm::kSuccess)); | 1206 decoder_status == cdm::kSuccess)); |
1195 deferred_initialize_video_decoder_ = false; | 1207 deferred_initialize_video_decoder_ = false; |
1196 deferred_video_decoder_config_id_ = 0; | 1208 deferred_video_decoder_config_id_ = 0; |
1197 break; | 1209 break; |
1198 } | 1210 } |
1199 } | 1211 } |
1200 | 1212 |
1201 // The CDM owns the returned object and must call FileIO::Close() to release it. | 1213 // The CDM owns the returned object and must call FileIO::Close() to release it. |
1202 cdm::FileIO* CdmAdapter::CreateFileIO(cdm::FileIOClient* client) { | 1214 cdm::FileIO* CdmAdapter::CreateFileIO(cdm::FileIOClient* client) { |
1203 return new CdmFileIOImpl( | 1215 if (allow_persistent_state_) { |
1204 client, | 1216 return new CdmFileIOImpl( |
1205 pp_instance(), | 1217 client, |
1206 callback_factory_.NewCallback(&CdmAdapter::OnFirstFileRead)); | 1218 pp_instance(), |
1219 callback_factory_.NewCallback(&CdmAdapter::OnFirstFileRead)); | |
1220 } | |
1221 | |
1222 return nullptr; | |
1207 } | 1223 } |
1208 | 1224 |
1209 #if defined(OS_CHROMEOS) | 1225 #if defined(OS_CHROMEOS) |
1210 void CdmAdapter::ReportOutputProtectionUMA(OutputProtectionStatus status) { | 1226 void CdmAdapter::ReportOutputProtectionUMA(OutputProtectionStatus status) { |
1211 pp::UMAPrivate uma_interface(this); | 1227 pp::UMAPrivate uma_interface(this); |
1212 uma_interface.HistogramEnumeration( | 1228 uma_interface.HistogramEnumeration( |
1213 "Media.EME.OutputProtection", status, OUTPUT_PROTECTION_MAX); | 1229 "Media.EME.OutputProtection", status, OUTPUT_PROTECTION_MAX); |
1214 } | 1230 } |
1215 | 1231 |
1216 void CdmAdapter::ReportOutputProtectionQuery() { | 1232 void CdmAdapter::ReportOutputProtectionQuery() { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1388 } // namespace media | 1404 } // namespace media |
1389 | 1405 |
1390 namespace pp { | 1406 namespace pp { |
1391 | 1407 |
1392 // Factory function for your specialization of the Module object. | 1408 // Factory function for your specialization of the Module object. |
1393 Module* CreateModule() { | 1409 Module* CreateModule() { |
1394 return new media::CdmAdapterModule(); | 1410 return new media::CdmAdapterModule(); |
1395 } | 1411 } |
1396 | 1412 |
1397 } // namespace pp | 1413 } // namespace pp |
OLD | NEW |