Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: content/renderer/media/crypto/proxy_decryptor.h

Issue 660673002: Introduce CdmFactory interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_result_promise
Patch Set: rebase only Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "media/base/decryptor.h" 15 #include "media/base/decryptor.h"
16 #include "media/base/media_keys.h" 16 #include "media/base/media_keys.h"
17 17
18 #if defined(ENABLE_PEPPER_CDMS) 18 class GURL;
19 #include "content/renderer/media/crypto/pepper_cdm_wrapper.h"
20 #endif
21 19
22 class GURL; 20 namespace media {
21 class CdmFactory;
22 }
23 23
24 namespace content { 24 namespace content {
25 25
26 #if defined(ENABLE_BROWSER_CDMS) 26 #if defined(ENABLE_BROWSER_CDMS)
27 class RendererCdmManager; 27 class RendererCdmManager;
28 #endif // defined(ENABLE_BROWSER_CDMS) 28 #endif // defined(ENABLE_BROWSER_CDMS)
29 29
30 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. 30 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API.
31 // A decryptor proxy that creates a real decryptor object on demand and 31 // A decryptor proxy that creates a real decryptor object on demand and
32 // forwards decryptor calls to it. 32 // forwards decryptor calls to it.
33 // 33 //
34 // TODO(xhwang): Currently we don't support run-time switching among decryptor 34 // TODO(xhwang): Currently we don't support run-time switching among decryptor
35 // objects. Fix this when needed. 35 // objects. Fix this when needed.
36 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! 36 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name!
37 class ProxyDecryptor { 37 class ProxyDecryptor {
38 public: 38 public:
39 // These are similar to the callbacks in media_keys.h, but pass back the 39 // These are similar to the callbacks in media_keys.h, but pass back the
40 // web session ID rather than the internal session ID. 40 // web session ID rather than the internal session ID.
41 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; 41 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB;
42 typedef base::Callback<void(const std::string& session_id, 42 typedef base::Callback<void(const std::string& session_id,
43 media::MediaKeys::KeyError error_code, 43 media::MediaKeys::KeyError error_code,
44 uint32 system_code)> KeyErrorCB; 44 uint32 system_code)> KeyErrorCB;
45 typedef base::Callback<void(const std::string& session_id, 45 typedef base::Callback<void(const std::string& session_id,
46 const std::vector<uint8>& message, 46 const std::vector<uint8>& message,
47 const GURL& destination_url)> KeyMessageCB; 47 const GURL& destination_url)> KeyMessageCB;
48 48
49 ProxyDecryptor( 49 ProxyDecryptor(const KeyAddedCB& key_added_cb,
50 #if defined(ENABLE_PEPPER_CDMS) 50 const KeyErrorCB& key_error_cb,
51 const CreatePepperCdmCB& create_pepper_cdm_cb, 51 const KeyMessageCB& key_message_cb);
52 #elif defined(ENABLE_BROWSER_CDMS)
53 RendererCdmManager* manager,
54 #endif // defined(ENABLE_PEPPER_CDMS)
55 const KeyAddedCB& key_added_cb,
56 const KeyErrorCB& key_error_cb,
57 const KeyMessageCB& key_message_cb);
58 virtual ~ProxyDecryptor(); 52 virtual ~ProxyDecryptor();
59 53
60 // Returns the Decryptor associated with this object. May be NULL if no 54 // Returns the Decryptor associated with this object. May be NULL if no
61 // Decryptor is associated. 55 // Decryptor is associated.
62 media::Decryptor* GetDecryptor(); 56 media::Decryptor* GetDecryptor();
63 57
64 #if defined(ENABLE_BROWSER_CDMS) 58 #if defined(ENABLE_BROWSER_CDMS)
65 // Returns the CDM ID associated with this object. May be kInvalidCdmId if no 59 // Returns the CDM ID associated with this object. May be kInvalidCdmId if no
66 // CDM ID is associated, such as when Clear Key is used. 60 // CDM ID is associated, such as when Clear Key is used.
67 int GetCdmId(); 61 int GetCdmId();
68 #endif 62 #endif
69 63
70 // Only call this once. 64 // Only call this once.
71 bool InitializeCDM(const std::string& key_system, 65 bool InitializeCDM(const media::CdmFactory& cdm_factory,
66 const std::string& key_system,
72 const GURL& security_origin); 67 const GURL& security_origin);
73 68
74 // May only be called after InitializeCDM() succeeds. 69 // May only be called after InitializeCDM() succeeds.
75 bool GenerateKeyRequest(const std::string& init_data_type, 70 bool GenerateKeyRequest(const std::string& init_data_type,
76 const uint8* init_data, 71 const uint8* init_data,
77 int init_data_length); 72 int init_data_length);
78 void AddKey(const uint8* key, int key_length, 73 void AddKey(const uint8* key, int key_length,
79 const uint8* init_data, int init_data_length, 74 const uint8* init_data, int init_data_length,
80 const std::string& session_id); 75 const std::string& session_id);
81 void CancelKeyRequest(const std::string& session_id); 76 void CancelKeyRequest(const std::string& session_id);
82 77
83 private: 78 private:
84 // Helper function to create MediaKeys to handle the given |key_system|. 79 // Helper function to create MediaKeys to handle the given |key_system|.
85 scoped_ptr<media::MediaKeys> CreateMediaKeys(const std::string& key_system, 80 scoped_ptr<media::MediaKeys> CreateMediaKeys(
86 const GURL& security_origin); 81 const media::CdmFactory& cdm_factory,
82 const std::string& key_system,
83 const GURL& security_origin);
87 84
88 // Callbacks for firing session events. 85 // Callbacks for firing session events.
89 void OnSessionMessage(const std::string& web_session_id, 86 void OnSessionMessage(const std::string& web_session_id,
90 const std::vector<uint8>& message, 87 const std::vector<uint8>& message,
91 const GURL& default_url); 88 const GURL& default_url);
92 void OnSessionKeysChange(const std::string& web_session_id, 89 void OnSessionKeysChange(const std::string& web_session_id,
93 bool has_additional_usable_key); 90 bool has_additional_usable_key);
94 void OnSessionExpirationUpdate(const std::string& web_session_id, 91 void OnSessionExpirationUpdate(const std::string& web_session_id,
95 const base::Time& new_expiry_time); 92 const base::Time& new_expiry_time);
96 void OnSessionReady(const std::string& web_session_id); 93 void OnSessionReady(const std::string& web_session_id);
97 void OnSessionClosed(const std::string& web_session_id); 94 void OnSessionClosed(const std::string& web_session_id);
98 void OnSessionError(const std::string& web_session_id, 95 void OnSessionError(const std::string& web_session_id,
99 media::MediaKeys::Exception exception_code, 96 media::MediaKeys::Exception exception_code,
100 uint32 system_code, 97 uint32 system_code,
101 const std::string& error_message); 98 const std::string& error_message);
102 99
103 enum SessionCreationType { 100 enum SessionCreationType {
104 TemporarySession, 101 TemporarySession,
105 PersistentSession, 102 PersistentSession,
106 LoadSession 103 LoadSession
107 }; 104 };
108 105
109 // Called when a session is actually created or loaded. 106 // Called when a session is actually created or loaded.
110 void SetSessionId(SessionCreationType session_type, 107 void SetSessionId(SessionCreationType session_type,
111 const std::string& web_session_id); 108 const std::string& web_session_id);
112 109
113 #if defined(ENABLE_PEPPER_CDMS)
114 // Callback to create the Pepper plugin.
115 CreatePepperCdmCB create_pepper_cdm_cb_;
116 #elif defined(ENABLE_BROWSER_CDMS)
117 RendererCdmManager* manager_;
118 int cdm_id_;
119 #endif // defined(ENABLE_PEPPER_CDMS)
120
121 // The real MediaKeys that manages key operations for the ProxyDecryptor. 110 // The real MediaKeys that manages key operations for the ProxyDecryptor.
122 scoped_ptr<media::MediaKeys> media_keys_; 111 scoped_ptr<media::MediaKeys> media_keys_;
123 112
124 // Callbacks for firing key events. 113 // Callbacks for firing key events.
125 KeyAddedCB key_added_cb_; 114 KeyAddedCB key_added_cb_;
126 KeyErrorCB key_error_cb_; 115 KeyErrorCB key_error_cb_;
127 KeyMessageCB key_message_cb_; 116 KeyMessageCB key_message_cb_;
128 117
129 // Keep track of both persistent and non-persistent sessions. 118 // Keep track of both persistent and non-persistent sessions.
130 base::hash_map<std::string, bool> active_sessions_; 119 base::hash_map<std::string, bool> active_sessions_;
131 120
132 bool is_clear_key_; 121 bool is_clear_key_;
133 122
123 #if defined(ENABLE_BROWSER_CDMS)
124 int cdm_id_;
125 #endif
126
134 // NOTE: Weak pointers must be invalidated before all other member variables. 127 // NOTE: Weak pointers must be invalidated before all other member variables.
135 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; 128 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_;
136 129
137 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); 130 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor);
138 }; 131 };
139 132
140 } // namespace content 133 } // namespace content
141 134
142 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ 135 #endif // CONTENT_RENDERER_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698