Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / crypto / renderer_cdm_manager.h
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   // Constructs a RendererCdmManager object for the |render_frame|.
30   explicit RendererCdmManager(RenderFrame* render_frame);
31   virtual ~RendererCdmManager();
32
33   // RenderFrameObserver overrides.
34   virtual bool OnMessageReceived(const IPC::Message& msg) override;
35
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,
42                      uint32 session_id,
43                      CdmHostMsg_CreateSession_ContentType conent_type,
44                      const std::vector<uint8>& init_data);
45   void UpdateSession(int cdm_id,
46                      uint32 session_id,
47                      const std::vector<uint8>& response);
48   void ReleaseSession(int cdm_id, uint32 session_id);
49   void DestroyCdm(int cdm_id);
50
51   // Registers a ProxyMediaKeys object. Returns allocated CDM ID.
52   int RegisterMediaKeys(ProxyMediaKeys* media_keys);
53
54   // Unregisters a ProxyMediaKeys object identified by |cdm_id|.
55   void UnregisterMediaKeys(int cdm_id);
56
57  private:
58   // Gets the pointer to ProxyMediaKeys given the |cdm_id|.
59   ProxyMediaKeys* GetMediaKeys(int cdm_id);
60
61   // Message handlers.
62   void OnSessionCreated(int cdm_id,
63                         uint32 session_id,
64                         const std::string& web_session_id);
65   void OnSessionMessage(int cdm_id,
66                         uint32 session_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,
72                       uint32 session_id,
73                       media::MediaKeys::KeyError error_code,
74                       uint32 system_code);
75
76   // CDM ID should be unique per renderer frame.
77   // TODO(xhwang): Use uint32 to prevent undefined overflow behavior.
78   int next_cdm_id_;
79
80   // CDM ID to ProxyMediaKeys mapping.
81   std::map<int, ProxyMediaKeys*> proxy_media_keys_map_;
82
83   DISALLOW_COPY_AND_ASSIGN(RendererCdmManager);
84 };
85
86 }  // namespace content
87
88 #endif  // CONTENT_RENDERER_MEDIA_CRYPTO_RENDERER_CDM_MANAGER_H_