OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_CRYPTO_PROXY_DECRYPTOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
31 class RendererMediaPlayerManager; | 31 class RendererMediaPlayerManager; |
32 #endif // defined(OS_ANDROID) | 32 #endif // defined(OS_ANDROID) |
33 | 33 |
34 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. | 34 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. |
35 // A decryptor proxy that creates a real decryptor object on demand and | 35 // A decryptor proxy that creates a real decryptor object on demand and |
36 // forwards decryptor calls to it. | 36 // forwards decryptor calls to it. |
37 // | 37 // |
38 // Now that the Pepper API calls use reference ID to match responses with | 38 // Now that the Pepper API calls use session ID to match responses with |
39 // requests, this class maintains a mapping between reference ID and session ID. | 39 // requests, this class maintains a mapping between session ID and web session |
40 // Callers of this class expect session IDs in the responses. | 40 // ID. Callers of this class expect web session IDs in the responses. |
| 41 // Session IDs are internal unique references to the session. Web session IDs |
| 42 // are the CDM generated ID for the session, and are what are visible to users. |
41 // | 43 // |
42 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 44 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
43 // objects. Fix this when needed. | 45 // objects. Fix this when needed. |
44 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! | 46 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! |
45 class ProxyDecryptor { | 47 class ProxyDecryptor { |
46 public: | 48 public: |
47 // These are similar to the callbacks in media_keys.h, but pass back the | 49 // These are similar to the callbacks in media_keys.h, but pass back the |
48 // session ID rather than a reference ID. | 50 // web session ID rather than the internal session ID. |
49 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; | 51 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; |
50 typedef base::Callback<void(const std::string& session_id, | 52 typedef base::Callback<void(const std::string& session_id, |
51 media::MediaKeys::KeyError error_code, | 53 media::MediaKeys::KeyError error_code, |
52 int system_code)> KeyErrorCB; | 54 int system_code)> KeyErrorCB; |
53 typedef base::Callback<void(const std::string& session_id, | 55 typedef base::Callback<void(const std::string& session_id, |
54 const std::vector<uint8>& message, | 56 const std::vector<uint8>& message, |
55 const std::string& default_url)> KeyMessageCB; | 57 const std::string& default_url)> KeyMessageCB; |
56 | 58 |
57 ProxyDecryptor( | 59 ProxyDecryptor( |
58 #if defined(ENABLE_PEPPER_CDMS) | 60 #if defined(ENABLE_PEPPER_CDMS) |
(...skipping 20 matching lines...) Expand all Loading... |
79 // May only be called after InitializeCDM() succeeds. | 81 // May only be called after InitializeCDM() succeeds. |
80 bool GenerateKeyRequest(const std::string& type, | 82 bool GenerateKeyRequest(const std::string& type, |
81 const uint8* init_data, | 83 const uint8* init_data, |
82 int init_data_length); | 84 int init_data_length); |
83 void AddKey(const uint8* key, int key_length, | 85 void AddKey(const uint8* key, int key_length, |
84 const uint8* init_data, int init_data_length, | 86 const uint8* init_data, int init_data_length, |
85 const std::string& session_id); | 87 const std::string& session_id); |
86 void CancelKeyRequest(const std::string& session_id); | 88 void CancelKeyRequest(const std::string& session_id); |
87 | 89 |
88 private: | 90 private: |
89 // This is reference_id <-> session_id map. | 91 // Session_id <-> web_session_id map. |
90 typedef std::map<uint32, std::string> SessionIdMap; | 92 typedef std::map<uint32, std::string> SessionIdMap; |
91 | 93 |
92 // Helper function to create MediaKeys to handle the given |key_system|. | 94 // Helper function to create MediaKeys to handle the given |key_system|. |
93 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, | 95 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, |
94 const GURL& frame_url); | 96 const GURL& frame_url); |
95 | 97 |
96 // Callbacks for firing session events. | 98 // Callbacks for firing session events. |
97 void OnSessionCreated(uint32 reference_id, const std::string& session_id); | 99 void OnSessionCreated(uint32 session_id, const std::string& web_session_id); |
98 void OnSessionMessage(uint32 reference_id, | 100 void OnSessionMessage(uint32 session_id, |
99 const std::vector<uint8>& message, | 101 const std::vector<uint8>& message, |
100 const std::string& default_url); | 102 const std::string& default_url); |
101 void OnSessionReady(uint32 reference_id); | 103 void OnSessionReady(uint32 session_id); |
102 void OnSessionClosed(uint32 reference_id); | 104 void OnSessionClosed(uint32 session_id); |
103 void OnSessionError(uint32 reference_id, | 105 void OnSessionError(uint32 session_id, |
104 media::MediaKeys::KeyError error_code, | 106 media::MediaKeys::KeyError error_code, |
105 int system_code); | 107 int system_code); |
106 | 108 |
107 // Helper function to determine reference_id for the provided |session_id|. | 109 // Helper function to determine session_id for the provided |web_session_id|. |
108 uint32 LookupReferenceId(const std::string& session_id); | 110 uint32 LookupSessionId(const std::string& web_session_id); |
109 | 111 |
110 // Helper function to determine session_id for the provided |reference_id|. | 112 // Helper function to determine web_session_id for the provided |session_id|. |
111 // The returned session_id is only valid on the main thread, and should be | 113 // The returned web_session_id is only valid on the main thread, and should be |
112 // stored by copy. | 114 // stored by copy. |
113 const std::string& LookupSessionId(uint32 reference_id); | 115 const std::string& LookupWebSessionId(uint32 session_id); |
114 | 116 |
115 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 117 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
116 | 118 |
117 #if defined(ENABLE_PEPPER_CDMS) | 119 #if defined(ENABLE_PEPPER_CDMS) |
118 // Callback for cleaning up a Pepper-based CDM. | 120 // Callback for cleaning up a Pepper-based CDM. |
119 void DestroyHelperPlugin(); | 121 void DestroyHelperPlugin(); |
120 | 122 |
121 // Needed to create the PpapiDecryptor. | 123 // Needed to create the PpapiDecryptor. |
122 blink::WebMediaPlayerClient* web_media_player_client_; | 124 blink::WebMediaPlayerClient* web_media_player_client_; |
123 blink::WebFrame* web_frame_; | 125 blink::WebFrame* web_frame_; |
(...skipping 10 matching lines...) Expand all Loading... |
134 KeyAddedCB key_added_cb_; | 136 KeyAddedCB key_added_cb_; |
135 KeyErrorCB key_error_cb_; | 137 KeyErrorCB key_error_cb_; |
136 KeyMessageCB key_message_cb_; | 138 KeyMessageCB key_message_cb_; |
137 | 139 |
138 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread | 140 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread |
139 // safe as per the Decryptor interface. | 141 // safe as per the Decryptor interface. |
140 base::Lock lock_; | 142 base::Lock lock_; |
141 | 143 |
142 media::DecryptorReadyCB decryptor_ready_cb_; | 144 media::DecryptorReadyCB decryptor_ready_cb_; |
143 | 145 |
144 // Reference IDs are used to uniquely track sessions so that CDM callbacks | 146 // Session IDs are used to uniquely track sessions so that CDM callbacks |
145 // can get mapped to the correct session ID. Reference ID should be unique | 147 // can get mapped to the correct session ID. Session ID should be unique |
146 // per renderer process for debugging purposes. | 148 // per renderer process for debugging purposes. |
147 static uint32 next_reference_id_; | 149 static uint32 next_session_id_; |
148 | 150 |
149 SessionIdMap sessions_; | 151 SessionIdMap sessions_; |
150 | 152 |
151 bool is_clear_key_; | 153 bool is_clear_key_; |
152 | 154 |
153 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 155 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
154 }; | 156 }; |
155 | 157 |
156 } // namespace content | 158 } // namespace content |
157 | 159 |
158 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 160 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |