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.
5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_
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"
26 // Class for managing all the CDM objects in the same RenderFrame.
27 class RendererCdmManager : public RenderFrameObserver {
29 // Constructs a RendererCdmManager object for the |render_frame|.
30 explicit RendererCdmManager(RenderFrame* render_frame);
31 virtual ~RendererCdmManager();
33 // RenderFrameObserver overrides.
34 virtual bool OnMessageReceived(const IPC::Message& msg) override;
36 // Encrypted media related methods.
37 void InitializeCdm(int cdm_id,
38 ProxyMediaKeys* media_keys,
39 const std::string& key_system,
40 const GURL& security_origin);
41 void CreateSession(int cdm_id,
43 CdmHostMsg_CreateSession_ContentType conent_type,
44 const std::vector<uint8>& init_data);
45 void UpdateSession(int cdm_id,
47 const std::vector<uint8>& response);
48 void ReleaseSession(int cdm_id, uint32 session_id);
49 void DestroyCdm(int cdm_id);
51 // Registers a ProxyMediaKeys object. Returns allocated CDM ID.
52 int RegisterMediaKeys(ProxyMediaKeys* media_keys);
54 // Unregisters a ProxyMediaKeys object identified by |cdm_id|.
55 void UnregisterMediaKeys(int cdm_id);
58 // Gets the pointer to ProxyMediaKeys given the |cdm_id|.
59 ProxyMediaKeys* GetMediaKeys(int cdm_id);
62 void OnSessionCreated(int cdm_id,
64 const std::string& web_session_id);
65 void OnSessionMessage(int cdm_id,
67 const std::vector<uint8>& message,
68 const GURL& destination_url);
69 void OnSessionReady(int cdm_id, uint32 session_id);
70 void OnSessionClosed(int cdm_id, uint32 session_id);
71 void OnSessionError(int cdm_id,
73 media::MediaKeys::KeyError error_code,
76 // CDM ID should be unique per renderer frame.
77 // TODO(xhwang): Use uint32 to prevent undefined overflow behavior.
80 // CDM ID to ProxyMediaKeys mapping.
81 std::map<int, ProxyMediaKeys*> proxy_media_keys_map_;
83 DISALLOW_COPY_AND_ASSIGN(RendererCdmManager);
86 } // namespace content
88 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_