OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
6 #define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <string> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/containers/hash_tables.h" |
11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
13 #include "media/base/media_keys.h" | 15 #include "media/base/media_keys.h" |
14 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h
" | 16 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h
" |
15 | 17 |
16 #if defined(ENABLE_PEPPER_CDMS) | 18 #if defined(ENABLE_PEPPER_CDMS) |
17 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" | 19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h" |
18 #endif | 20 #endif |
19 | 21 |
20 class GURL; | 22 class GURL; |
21 | 23 |
22 namespace content { | 24 namespace content { |
23 | 25 |
24 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
25 class RendererCdmManager; | 27 class RendererCdmManager; |
26 #endif | 28 #endif |
27 class WebContentDecryptionModuleSessionImpl; | 29 class WebContentDecryptionModuleSessionImpl; |
28 | 30 |
29 // Owns the CDM instance and makes calls from session objects to the CDM. | 31 // Owns the CDM instance and makes calls from session objects to the CDM. |
30 // Forwards the session ID-based callbacks of the MediaKeys interface to the | 32 // Forwards the web session ID-based callbacks of the MediaKeys interface to the |
31 // appropriate session object. Callers should hold references to this class | 33 // appropriate session object. Callers should hold references to this class |
32 // as long as they need the CDM instance. | 34 // as long as they need the CDM instance. |
33 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { | 35 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { |
34 public: | 36 public: |
35 CdmSessionAdapter(); | 37 CdmSessionAdapter(); |
36 | 38 |
37 // Returns true on success. | 39 // Returns true on success. |
38 bool Initialize( | 40 bool Initialize( |
39 #if defined(ENABLE_PEPPER_CDMS) | 41 #if defined(ENABLE_PEPPER_CDMS) |
40 const CreatePepperCdmCB& create_pepper_cdm_cb, | 42 const CreatePepperCdmCB& create_pepper_cdm_cb, |
41 #elif defined(OS_ANDROID) | 43 #elif defined(OS_ANDROID) |
42 RendererCdmManager* manager, | 44 RendererCdmManager* manager, |
43 #endif | 45 #endif |
44 const std::string& key_system, | 46 const std::string& key_system, |
45 const GURL& security_origin); | 47 const GURL& security_origin); |
46 | 48 |
47 // Creates a new session and adds it to the internal map. The caller owns the | 49 // Creates a new session and adds it to the internal map. The caller owns the |
48 // created session. RemoveSession() must be called when destroying it. | 50 // created session. RemoveSession() must be called when destroying it, if |
| 51 // RegisterSession() was called. |
49 WebContentDecryptionModuleSessionImpl* CreateSession( | 52 WebContentDecryptionModuleSessionImpl* CreateSession( |
50 blink::WebContentDecryptionModuleSession::Client* client); | 53 blink::WebContentDecryptionModuleSession::Client* client); |
51 | 54 |
| 55 // Adds a session to the internal map. Called once the session is successfully |
| 56 // initialized. |
| 57 void RegisterSession( |
| 58 const std::string& web_session_id, |
| 59 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); |
| 60 |
52 // Removes a session from the internal map. | 61 // Removes a session from the internal map. |
53 void RemoveSession(uint32 session_id); | 62 void RemoveSession(const std::string& web_session_id); |
54 | 63 |
55 // Initializes the session specified by |session_id| with the |content_type| | 64 // Initializes a session with the |init_data_type|, |init_data| and |
56 // and |init_data| provided. | 65 // |session_type| provided. Takes ownership of |promise|. |
57 void InitializeNewSession(uint32 session_id, | 66 void InitializeNewSession(const std::string& init_data_type, |
58 const std::string& content_type, | |
59 const uint8* init_data, | 67 const uint8* init_data, |
60 int init_data_length); | 68 int init_data_length, |
| 69 media::MediaKeys::SessionType session_type, |
| 70 scoped_ptr<media::NewSessionCdmPromise> promise); |
61 | 71 |
62 // Updates the session specified by |session_id| with |response|. | 72 // Updates the session specified by |web_session_id| with |response|. |
63 void UpdateSession(uint32 session_id, | 73 // Takes ownership of |promise|. |
| 74 void UpdateSession(const std::string& web_session_id, |
64 const uint8* response, | 75 const uint8* response, |
65 int response_length); | 76 int response_length, |
| 77 scoped_ptr<media::SimpleCdmPromise> promise); |
66 | 78 |
67 // Releases the session specified by |session_id|. | 79 // Releases the session specified by |web_session_id|. |
68 void ReleaseSession(uint32 session_id); | 80 // Takes ownership of |promise|. |
| 81 void ReleaseSession(const std::string& web_session_id, |
| 82 scoped_ptr<media::SimpleCdmPromise> promise); |
69 | 83 |
70 // Returns the Decryptor associated with this CDM. May be NULL if no | 84 // Returns the Decryptor associated with this CDM. May be NULL if no |
71 // Decryptor is associated with the MediaKeys object. | 85 // Decryptor is associated with the MediaKeys object. |
72 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor | 86 // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor |
73 // after WebContentDecryptionModule is freed. http://crbug.com/330324 | 87 // after WebContentDecryptionModule is freed. http://crbug.com/330324 |
74 media::Decryptor* GetDecryptor(); | 88 media::Decryptor* GetDecryptor(); |
75 | 89 |
76 #if defined(OS_ANDROID) | 90 #if defined(OS_ANDROID) |
77 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId | 91 // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId |
78 // if no CDM ID is associated. | 92 // if no CDM ID is associated. |
79 int GetCdmId() const; | 93 int GetCdmId() const; |
80 #endif | 94 #endif |
81 | 95 |
82 private: | 96 private: |
83 friend class base::RefCounted<CdmSessionAdapter>; | 97 friend class base::RefCounted<CdmSessionAdapter>; |
84 typedef std::map<uint32, WebContentDecryptionModuleSessionImpl*> SessionMap; | 98 typedef base::hash_map<std::string, |
| 99 base::WeakPtr<WebContentDecryptionModuleSessionImpl> > |
| 100 SessionMap; |
85 | 101 |
86 ~CdmSessionAdapter(); | 102 ~CdmSessionAdapter(); |
87 | 103 |
88 // Callbacks for firing session events. | 104 // Callbacks for firing session events. |
89 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); | 105 void OnSessionMessage(const std::string& web_session_id, |
90 void OnSessionMessage(uint32 session_id, | |
91 const std::vector<uint8>& message, | 106 const std::vector<uint8>& message, |
92 const GURL& destination_url); | 107 const GURL& destination_url); |
93 void OnSessionReady(uint32 session_id); | 108 void OnSessionReady(const std::string& web_session_id); |
94 void OnSessionClosed(uint32 session_id); | 109 void OnSessionClosed(const std::string& web_session_id); |
95 void OnSessionError(uint32 session_id, | 110 void OnSessionError(const std::string& web_session_id, |
96 media::MediaKeys::KeyError error_code, | 111 media::MediaKeys::Exception exception_code, |
97 uint32 system_code); | 112 uint32 system_code, |
| 113 const std::string& error_message); |
98 | 114 |
99 // Helper function of the callbacks. | 115 // Helper function of the callbacks. |
100 WebContentDecryptionModuleSessionImpl* GetSession(uint32 session_id); | 116 WebContentDecryptionModuleSessionImpl* GetSession( |
101 | 117 const std::string& web_session_id); |
102 // Session ID should be unique per renderer process for debugging purposes. | |
103 static uint32 next_session_id_; | |
104 | 118 |
105 scoped_ptr<media::MediaKeys> media_keys_; | 119 scoped_ptr<media::MediaKeys> media_keys_; |
106 | 120 |
107 SessionMap sessions_; | 121 SessionMap sessions_; |
108 | 122 |
109 #if defined(OS_ANDROID) | 123 #if defined(OS_ANDROID) |
110 int cdm_id_; | 124 int cdm_id_; |
111 #endif | 125 #endif |
112 | 126 |
113 // NOTE: Weak pointers must be invalidated before all other member variables. | 127 // NOTE: Weak pointers must be invalidated before all other member variables. |
114 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; | 128 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; |
115 | 129 |
116 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); | 130 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); |
117 }; | 131 }; |
118 | 132 |
119 } // namespace content | 133 } // namespace content |
120 | 134 |
121 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ | 135 #endif // CONTENT_RENDERER_MEDIA_CDM_SESSION_ADAPTER_H_ |
OLD | NEW |