- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / media / android / proxy_media_keys.cc
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(RendererMediaPlayerManager* manager,
17                                int media_keys_id,
18                                const media::KeyAddedCB& key_added_cb,
19                                const media::KeyErrorCB& key_error_cb,
20                                const media::KeyMessageCB& key_message_cb)
21     : manager_(manager),
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) {
26   DCHECK(manager_);
27 }
28
29 ProxyMediaKeys::~ProxyMediaKeys() {
30 }
31
32 void ProxyMediaKeys::InitializeCDM(const std::string& key_system,
33                                    const GURL& frame_url) {
34 #if defined(ENABLE_PEPPER_CDMS)
35   NOTIMPLEMENTED();
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);
40 #endif
41 }
42
43 bool ProxyMediaKeys::GenerateKeyRequest(const std::string& type,
44                                         const uint8* init_data,
45                                         int init_data_length) {
46   manager_->GenerateKeyRequest(
47       media_keys_id_,
48       type,
49       std::vector<uint8>(init_data, init_data + init_data_length));
50   return true;
51 }
52
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),
59                  session_id);
60 }
61
62 void ProxyMediaKeys::CancelKeyRequest(const std::string& session_id) {
63   manager_->CancelKeyRequest(media_keys_id_, session_id);
64 }
65
66 void ProxyMediaKeys::OnKeyAdded(const std::string& session_id) {
67   key_added_cb_.Run(session_id);
68 }
69
70 void ProxyMediaKeys::OnKeyError(const std::string& session_id,
71                                 media::MediaKeys::KeyError error_code,
72                                 int system_code) {
73   key_error_cb_.Run(session_id, error_code, system_code);
74 }
75
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);
80 }
81
82 }  // namespace content