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 3 // found in the LICENSE file. 4 5 #include "content/renderer/media/android/proxy_media_keys.h" 6 7 #include <vector> 8 9 #include "base/basictypes.h" 10 #include "base/logging.h" 11 #include "content/renderer/media/android/renderer_media_player_manager.h" 12 #include "content/renderer/media/crypto/key_systems.h" 13 14 namespace content { 15 16 ProxyMediaKeys::ProxyMediaKeys( 17 RendererMediaPlayerManager* manager, 18 int media_keys_id, 19 const media::SessionCreatedCB& session_created_cb, 20 const media::SessionMessageCB& session_message_cb, 21 const media::SessionReadyCB& session_ready_cb, 22 const media::SessionClosedCB& session_closed_cb, 23 const media::SessionErrorCB& session_error_cb) 24 : manager_(manager), 25 media_keys_id_(media_keys_id), 26 session_created_cb_(session_created_cb), 27 session_message_cb_(session_message_cb), 28 session_ready_cb_(session_ready_cb), 29 session_closed_cb_(session_closed_cb), 30 session_error_cb_(session_error_cb) { 31 DCHECK(manager_); 32 } 33 34 ProxyMediaKeys::~ProxyMediaKeys() { 35 } 36 37 void ProxyMediaKeys::InitializeCDM(const std::string& key_system, 38 const GURL& frame_url) { 39 #if defined(ENABLE_PEPPER_CDMS) 40 NOTIMPLEMENTED(); 41 #elif defined(OS_ANDROID) 42 std::vector<uint8> uuid = GetUUID(key_system); 43 DCHECK(!uuid.empty()); 44 manager_->InitializeCDM(media_keys_id_, this, uuid, frame_url); 45 #endif 46 } 47 48 bool ProxyMediaKeys::CreateSession(uint32 session_id, 49 const std::string& type, 50 const uint8* init_data, 51 int init_data_length) { 52 manager_->CreateSession( 53 media_keys_id_, 54 session_id, 55 type, 56 std::vector<uint8>(init_data, init_data + init_data_length)); 57 return true; 58 } 59 60 void ProxyMediaKeys::UpdateSession(uint32 session_id, 61 const uint8* response, 62 int response_length) { 63 manager_->UpdateSession( 64 media_keys_id_, 65 session_id, 66 std::vector<uint8>(response, response + response_length)); 67 } 68 69 void ProxyMediaKeys::ReleaseSession(uint32 session_id) { 70 manager_->ReleaseSession(media_keys_id_, session_id); 71 } 72 73 void ProxyMediaKeys::OnSessionCreated(uint32 session_id, 74 const std::string& web_session_id) { 75 session_created_cb_.Run(session_id, web_session_id); 76 } 77 78 void ProxyMediaKeys::OnSessionMessage(uint32 session_id, 79 const std::vector<uint8>& message, 80 const std::string& destination_url) { 81 session_message_cb_.Run(session_id, message, destination_url); 82 } 83 84 void ProxyMediaKeys::OnSessionReady(uint32 session_id) { 85 session_ready_cb_.Run(session_id); 86 } 87 88 void ProxyMediaKeys::OnSessionClosed(uint32 session_id) { 89 session_closed_cb_.Run(session_id); 90 } 91 92 void ProxyMediaKeys::OnSessionError(uint32 session_id, 93 media::MediaKeys::KeyError error_code, 94 int system_code) { 95 session_error_cb_.Run(session_id, error_code, system_code); 96 } 97 98 } // namespace content 99