Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / crypto / ppapi_decryptor.cc
index cf7808c..d1fda56 100644 (file)
@@ -97,16 +97,15 @@ PpapiDecryptor::~PpapiDecryptor() {
 }
 
 bool PpapiDecryptor::CreateSession(uint32 session_id,
-                                   const std::string& type,
+                                   const std::string& content_type,
                                    const uint8* init_data,
                                    int init_data_length) {
   DVLOG(2) << __FUNCTION__;
   DCHECK(render_loop_proxy_->BelongsToCurrentThread());
-  DCHECK(plugin_cdm_delegate_);
 
   if (!plugin_cdm_delegate_ ||
       !plugin_cdm_delegate_->CreateSession(
-           session_id, type, init_data, init_data_length)) {
+           session_id, content_type, init_data, init_data_length)) {
     ReportFailureToCallPlugin(session_id);
     return false;
   }
@@ -114,6 +113,19 @@ bool PpapiDecryptor::CreateSession(uint32 session_id,
   return true;
 }
 
+void PpapiDecryptor::LoadSession(uint32 session_id,
+                                 const std::string& web_session_id) {
+  DVLOG(2) << __FUNCTION__;
+  DCHECK(render_loop_proxy_->BelongsToCurrentThread());
+
+  if (!plugin_cdm_delegate_) {
+    ReportFailureToCallPlugin(session_id);
+    return;
+  }
+
+  plugin_cdm_delegate_->LoadSession(session_id, web_session_id);
+}
+
 void PpapiDecryptor::UpdateSession(uint32 session_id,
                                    const uint8* response,
                                    int response_length) {
@@ -123,13 +135,8 @@ void PpapiDecryptor::UpdateSession(uint32 session_id,
   if (!plugin_cdm_delegate_ || !plugin_cdm_delegate_->UpdateSession(
                                     session_id, response, response_length)) {
     ReportFailureToCallPlugin(session_id);
+    return;
   }
-
-  if (!new_audio_key_cb_.is_null())
-    new_audio_key_cb_.Run();
-
-  if (!new_video_key_cb_.is_null())
-    new_video_key_cb_.Run();
 }
 
 void PpapiDecryptor::ReleaseSession(uint32 session_id) {
@@ -139,6 +146,7 @@ void PpapiDecryptor::ReleaseSession(uint32 session_id) {
   if (!plugin_cdm_delegate_ ||
       !plugin_cdm_delegate_->ReleaseSession(session_id)) {
     ReportFailureToCallPlugin(session_id);
+    return;
   }
 }
 
@@ -338,6 +346,19 @@ void PpapiDecryptor::OnSessionMessage(uint32 session_id,
 
 void PpapiDecryptor::OnSessionReady(uint32 session_id) {
   DCHECK(render_loop_proxy_->BelongsToCurrentThread());
+
+  // Based on the spec, we need to resume playback when update() completes
+  // successfully, or when a session is successfully loaded. In both cases,
+  // the CDM fires OnSessionReady() event. So we choose to call the NewKeyCBs
+  // here.
+  // TODO(xhwang): Rename OnSessionReady to indicate that the playback may
+  // resume successfully (e.g. a new key is available or available again).
+  if (!new_audio_key_cb_.is_null())
+    new_audio_key_cb_.Run();
+
+  if (!new_video_key_cb_.is_null())
+    new_video_key_cb_.Run();
+
   session_ready_cb_.Run(session_id);
 }