OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/crypto/renderer_cdm_manager.h" |
| 6 |
| 7 #include "base/stl_util.h" |
| 8 #include "content/common/media/cdm_messages.h" |
| 9 #include "content/renderer/media/crypto/proxy_media_keys.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 // Maximum sizes for various EME API parameters. These are checks to prevent |
| 14 // unnecessarily large messages from being passed around, and the sizes |
| 15 // are somewhat arbitrary as the EME spec doesn't specify any limits. |
| 16 const size_t kMaxWebSessionIdLength = 512; |
| 17 const size_t kMaxSessionMessageLength = 10240; // 10 KB |
| 18 |
| 19 RendererCdmManager::RendererCdmManager(RenderFrame* render_frame) |
| 20 : RenderFrameObserver(render_frame) { |
| 21 } |
| 22 |
| 23 RendererCdmManager::~RendererCdmManager() {} |
| 24 |
| 25 bool RendererCdmManager::OnMessageReceived(const IPC::Message& msg) { |
| 26 bool handled = true; |
| 27 IPC_BEGIN_MESSAGE_MAP(RendererCdmManager, msg) |
| 28 IPC_MESSAGE_HANDLER(CdmMsg_SessionCreated, OnSessionCreated) |
| 29 IPC_MESSAGE_HANDLER(CdmMsg_SessionMessage, OnSessionMessage) |
| 30 IPC_MESSAGE_HANDLER(CdmMsg_SessionReady, OnSessionReady) |
| 31 IPC_MESSAGE_HANDLER(CdmMsg_SessionClosed, OnSessionClosed) |
| 32 IPC_MESSAGE_HANDLER(CdmMsg_SessionError, OnSessionError) |
| 33 IPC_MESSAGE_UNHANDLED(handled = false) |
| 34 IPC_END_MESSAGE_MAP() |
| 35 return handled; |
| 36 } |
| 37 |
| 38 void RendererCdmManager::InitializeCdm(int cdm_id, |
| 39 ProxyMediaKeys* media_keys, |
| 40 const std::string& key_system, |
| 41 const GURL& security_origin) { |
| 42 DCHECK_NE(cdm_id, kInvalidCdmId); |
| 43 RegisterMediaKeys(cdm_id, media_keys); |
| 44 Send(new CdmHostMsg_InitializeCdm( |
| 45 routing_id(), cdm_id, key_system, security_origin)); |
| 46 } |
| 47 |
| 48 void RendererCdmManager::CreateSession( |
| 49 int cdm_id, |
| 50 uint32 session_id, |
| 51 CdmHostMsg_CreateSession_ContentType content_type, |
| 52 const std::vector<uint8>& init_data) { |
| 53 DCHECK(GetMediaKeys(cdm_id)) << "|cdm_id| not registered."; |
| 54 Send(new CdmHostMsg_CreateSession( |
| 55 routing_id(), cdm_id, session_id, content_type, init_data)); |
| 56 } |
| 57 |
| 58 void RendererCdmManager::UpdateSession(int cdm_id, |
| 59 uint32 session_id, |
| 60 const std::vector<uint8>& response) { |
| 61 DCHECK(GetMediaKeys(cdm_id)) << "|cdm_id| not registered."; |
| 62 Send( |
| 63 new CdmHostMsg_UpdateSession(routing_id(), cdm_id, session_id, response)); |
| 64 } |
| 65 |
| 66 void RendererCdmManager::ReleaseSession(int cdm_id, uint32 session_id) { |
| 67 DCHECK(GetMediaKeys(cdm_id)) << "|cdm_id| not registered."; |
| 68 Send(new CdmHostMsg_ReleaseSession(routing_id(), cdm_id, session_id)); |
| 69 } |
| 70 |
| 71 void RendererCdmManager::DestroyCdm(int cdm_id) { |
| 72 DCHECK(GetMediaKeys(cdm_id)) << "|cdm_id| not registered."; |
| 73 proxy_media_keys_map_.erase(cdm_id); |
| 74 Send(new CdmHostMsg_DestroyCdm(routing_id(), cdm_id)); |
| 75 } |
| 76 |
| 77 void RendererCdmManager::OnSessionCreated(int cdm_id, |
| 78 uint32 session_id, |
| 79 const std::string& web_session_id) { |
| 80 if (web_session_id.length() > kMaxWebSessionIdLength) { |
| 81 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 82 return; |
| 83 } |
| 84 |
| 85 ProxyMediaKeys* media_keys = GetMediaKeys(cdm_id); |
| 86 if (media_keys) |
| 87 media_keys->OnSessionCreated(session_id, web_session_id); |
| 88 } |
| 89 |
| 90 void RendererCdmManager::OnSessionMessage(int cdm_id, |
| 91 uint32 session_id, |
| 92 const std::vector<uint8>& message, |
| 93 const GURL& destination_url) { |
| 94 if (message.size() > kMaxSessionMessageLength) { |
| 95 OnSessionError(cdm_id, session_id, media::MediaKeys::kUnknownError, 0); |
| 96 return; |
| 97 } |
| 98 |
| 99 ProxyMediaKeys* media_keys = GetMediaKeys(cdm_id); |
| 100 if (media_keys) |
| 101 media_keys->OnSessionMessage(session_id, message, destination_url); |
| 102 } |
| 103 |
| 104 void RendererCdmManager::OnSessionReady(int cdm_id, uint32 session_id) { |
| 105 ProxyMediaKeys* media_keys = GetMediaKeys(cdm_id); |
| 106 if (media_keys) |
| 107 media_keys->OnSessionReady(session_id); |
| 108 } |
| 109 |
| 110 void RendererCdmManager::OnSessionClosed(int cdm_id, uint32 session_id) { |
| 111 ProxyMediaKeys* media_keys = GetMediaKeys(cdm_id); |
| 112 if (media_keys) |
| 113 media_keys->OnSessionClosed(session_id); |
| 114 } |
| 115 |
| 116 void RendererCdmManager::OnSessionError(int cdm_id, |
| 117 uint32 session_id, |
| 118 media::MediaKeys::KeyError error_code, |
| 119 uint32 system_code) { |
| 120 ProxyMediaKeys* media_keys = GetMediaKeys(cdm_id); |
| 121 if (media_keys) |
| 122 media_keys->OnSessionError(session_id, error_code, system_code); |
| 123 } |
| 124 |
| 125 void RendererCdmManager::RegisterMediaKeys(int cdm_id, |
| 126 ProxyMediaKeys* media_keys) { |
| 127 DCHECK(!ContainsKey(proxy_media_keys_map_, cdm_id)); |
| 128 proxy_media_keys_map_[cdm_id] = media_keys; |
| 129 } |
| 130 |
| 131 ProxyMediaKeys* RendererCdmManager::GetMediaKeys(int cdm_id) { |
| 132 std::map<int, ProxyMediaKeys*>::iterator iter = |
| 133 proxy_media_keys_map_.find(cdm_id); |
| 134 return (iter != proxy_media_keys_map_.end()) ? iter->second : NULL; |
| 135 } |
| 136 |
| 137 } // namespace content |
OLD | NEW |