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 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_ 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "content/common/media/cdm_messages_enums.h" 14 #include "content/public/renderer/render_frame_observer.h" 15 #include "media/base/media_keys.h" 16 #include "url/gurl.h" 17 18 namespace blink { 19 class WebFrame; 20 } 21 22 namespace content { 23 24 class ProxyMediaKeys; 25 26 // Class for managing all the CDM objects in the same RenderFrame. 27 class RendererCdmManager : public RenderFrameObserver { 28 public: 29 static const int kInvalidCdmId = 0; 30 31 // Constructs a RendererCdmManager object for the |render_frame|. 32 explicit RendererCdmManager(RenderFrame* render_frame); 33 virtual ~RendererCdmManager(); 34 35 // RenderFrameObserver overrides. 36 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 37 38 // Encrypted media related methods. 39 void InitializeCdm(int cdm_id, 40 ProxyMediaKeys* media_keys, 41 const std::string& key_system, 42 const GURL& security_origin); 43 void CreateSession(int cdm_id, 44 uint32 session_id, 45 CdmHostMsg_CreateSession_ContentType conent_type, 46 const std::vector<uint8>& init_data); 47 void UpdateSession(int cdm_id, 48 uint32 session_id, 49 const std::vector<uint8>& response); 50 void ReleaseSession(int cdm_id, uint32 session_id); 51 void DestroyCdm(int cdm_id); 52 53 // Registers a ProxyMediaKeys object. Returns allocated CDM ID. 54 int RegisterMediaKeys(ProxyMediaKeys* media_keys); 55 56 // Unregisters a ProxyMediaKeys object identified by |cdm_id|. 57 void UnregisterMediaKeys(int cdm_id); 58 59 private: 60 // Gets the pointer to ProxyMediaKeys given the |cdm_id|. 61 ProxyMediaKeys* GetMediaKeys(int cdm_id); 62 63 // Message handlers. 64 void OnSessionCreated(int cdm_id, 65 uint32 session_id, 66 const std::string& web_session_id); 67 void OnSessionMessage(int cdm_id, 68 uint32 session_id, 69 const std::vector<uint8>& message, 70 const GURL& destination_url); 71 void OnSessionReady(int cdm_id, uint32 session_id); 72 void OnSessionClosed(int cdm_id, uint32 session_id); 73 void OnSessionError(int cdm_id, 74 uint32 session_id, 75 media::MediaKeys::KeyError error_code, 76 uint32 system_code); 77 78 // CDM ID should be unique per renderer frame. 79 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior. 80 int next_cdm_id_; 81 82 // CDM ID to ProxyMediaKeys mapping. 83 std::map<int, ProxyMediaKeys*> proxy_media_keys_map_; 84 85 DISALLOW_COPY_AND_ASSIGN(RendererCdmManager); 86 }; 87 88 } // namespace content 89 90 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_ 91