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.
5 #include "content/renderer/media/android/proxy_media_keys.h"
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"
16 ProxyMediaKeys::ProxyMediaKeys(RendererMediaPlayerManager* manager,
18 const media::KeyAddedCB& key_added_cb,
19 const media::KeyErrorCB& key_error_cb,
20 const media::KeyMessageCB& key_message_cb)
22 media_keys_id_(media_keys_id),
23 key_added_cb_(key_added_cb),
24 key_error_cb_(key_error_cb),
25 key_message_cb_(key_message_cb) {
29 ProxyMediaKeys::~ProxyMediaKeys() {
32 void ProxyMediaKeys::InitializeCDM(const std::string& key_system,
33 const GURL& frame_url) {
34 #if defined(ENABLE_PEPPER_CDMS)
36 #elif defined(OS_ANDROID)
37 std::vector<uint8> uuid = GetUUID(key_system);
38 DCHECK(!uuid.empty());
39 manager_->InitializeCDM(media_keys_id_, this, uuid, frame_url);
43 bool ProxyMediaKeys::GenerateKeyRequest(const std::string& type,
44 const uint8* init_data,
45 int init_data_length) {
46 manager_->GenerateKeyRequest(
49 std::vector<uint8>(init_data, init_data + init_data_length));
53 void ProxyMediaKeys::AddKey(const uint8* key, int key_length,
54 const uint8* init_data, int init_data_length,
55 const std::string& session_id) {
56 manager_->AddKey(media_keys_id_,
57 std::vector<uint8>(key, key + key_length),
58 std::vector<uint8>(init_data, init_data + init_data_length),
62 void ProxyMediaKeys::CancelKeyRequest(const std::string& session_id) {
63 manager_->CancelKeyRequest(media_keys_id_, session_id);
66 void ProxyMediaKeys::OnKeyAdded(const std::string& session_id) {
67 key_added_cb_.Run(session_id);
70 void ProxyMediaKeys::OnKeyError(const std::string& session_id,
71 media::MediaKeys::KeyError error_code,
73 key_error_cb_.Run(session_id, error_code, system_code);
76 void ProxyMediaKeys::OnKeyMessage(const std::string& session_id,
77 const std::vector<uint8>& message,
78 const std::string& destination_url) {
79 key_message_cb_.Run(session_id, message, destination_url);
82 } // namespace content