Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 5 #ifndef WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| 6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 13 #include "media/base/decryptor.h" | 13 #include "media/base/decryptor.h" |
| 14 #include "media/base/media_keys.h" | |
| 14 | 15 |
| 15 namespace WebKit { | 16 namespace WebKit { |
| 16 class WebFrame; | 17 class WebFrame; |
| 17 class WebMediaPlayerClient; | 18 class WebMediaPlayerClient; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace webkit_media { | 21 namespace webkit_media { |
| 21 | 22 |
| 23 class PpapiDecryptor; | |
| 24 | |
| 22 // A decryptor proxy that creates a real decryptor object on demand and | 25 // A decryptor proxy that creates a real decryptor object on demand and |
| 23 // forwards decryptor calls to it. | 26 // forwards decryptor calls to it. |
| 24 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 27 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
| 25 // objects. Fix this when needed. | 28 // objects. Fix this when needed. |
| 26 class ProxyDecryptor { | 29 class ProxyDecryptor : public media::MediaKeys { |
|
ddorwin
2013/05/24 20:39:12
We should probably rename this class in a future C
xhwang
2013/05/24 23:15:56
Any idea on the new name? How about MediaKeysManag
ddorwin
2013/05/28 19:44:33
I'm not sure. It still hides the separation of Dec
xhwang
2013/05/28 23:50:39
Added TODO.
| |
| 27 public: | 30 public: |
| 28 ProxyDecryptor(WebKit::WebMediaPlayerClient* web_media_player_client, | 31 ProxyDecryptor(WebKit::WebMediaPlayerClient* web_media_player_client, |
| 29 WebKit::WebFrame* web_frame, | 32 WebKit::WebFrame* web_frame, |
| 30 const media::KeyAddedCB& key_added_cb, | 33 const media::KeyAddedCB& key_added_cb, |
| 31 const media::KeyErrorCB& key_error_cb, | 34 const media::KeyErrorCB& key_error_cb, |
| 32 const media::KeyMessageCB& key_message_cb, | 35 const media::KeyMessageCB& key_message_cb, |
| 33 const media::NeedKeyCB& need_key_cb); | 36 const media::NeedKeyCB& need_key_cb); |
| 34 virtual ~ProxyDecryptor(); | 37 virtual ~ProxyDecryptor(); |
| 35 | 38 |
| 36 // Requests the ProxyDecryptor to notify the decryptor when it's ready through | 39 // Requests the ProxyDecryptor to notify the decryptor when it's ready through |
| 37 // the |decryptor_ready_cb| provided. | 40 // the |decryptor_ready_cb| provided. |
| 38 // If |decryptor_ready_cb| is null, the existing callback will be fired with | 41 // If |decryptor_ready_cb| is null, the existing callback will be fired with |
| 39 // NULL immediately and reset. | 42 // NULL immediately and reset. |
| 40 void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); | 43 void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); |
| 41 | 44 |
| 42 bool GenerateKeyRequest(const std::string& key_system, | 45 // MediaKeys implementation. |
| 43 const std::string& type, | 46 virtual bool GenerateKeyRequest(const std::string& key_system, |
| 44 const uint8* init_data, int init_data_length); | 47 const std::string& type, |
| 45 void AddKey(const std::string& key_system, | 48 const uint8* init_data, |
| 46 const uint8* key, int key_length, | 49 int init_data_length) OVERRIDE; |
| 47 const uint8* init_data, int init_data_length, | 50 virtual void AddKey(const std::string& key_system, |
| 48 const std::string& session_id); | 51 const uint8* key, int key_length, |
| 49 void CancelKeyRequest(const std::string& key_system, | 52 const uint8* init_data, int init_data_length, |
| 50 const std::string& session_id); | 53 const std::string& session_id) OVERRIDE; |
| 54 virtual void CancelKeyRequest(const std::string& key_system, | |
| 55 const std::string& session_id) OVERRIDE; | |
| 51 | 56 |
| 52 private: | 57 private: |
| 53 // Helper functions to create decryptors to handle the given |key_system|. | 58 // Helper functions to create decryptors to handle the given |key_system|. |
| 54 #if defined(ENABLE_PEPPER_CDMS) | 59 #if defined(ENABLE_PEPPER_CDMS) |
| 55 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( | 60 scoped_ptr<PpapiDecryptor> CreatePpapiDecryptor( |
| 56 const std::string& key_system); | 61 const std::string& key_system); |
| 57 #endif // defined(ENABLE_PEPPER_CDMS) | 62 #endif // defined(ENABLE_PEPPER_CDMS) |
| 58 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); | 63 bool CreateDecryptor(const std::string& key_system); |
| 59 | 64 |
| 60 // Callbacks for firing key events. | 65 // Callbacks for firing key events. |
| 61 void KeyAdded(const std::string& key_system, const std::string& session_id); | 66 void KeyAdded(const std::string& key_system, const std::string& session_id); |
| 62 void KeyError(const std::string& key_system, | 67 void KeyError(const std::string& key_system, |
| 63 const std::string& session_id, | 68 const std::string& session_id, |
| 64 media::Decryptor::KeyError error_code, | 69 media::MediaKeys::KeyError error_code, |
| 65 int system_code); | 70 int system_code); |
| 66 void KeyMessage(const std::string& key_system, | 71 void KeyMessage(const std::string& key_system, |
| 67 const std::string& session_id, | 72 const std::string& session_id, |
| 68 const std::string& message, | 73 const std::string& message, |
| 69 const std::string& default_url); | 74 const std::string& default_url); |
| 70 void NeedKey(const std::string& key_system, | 75 void NeedKey(const std::string& key_system, |
| 71 const std::string& session_id, | 76 const std::string& session_id, |
| 72 const std::string& type, | 77 const std::string& type, |
| 73 scoped_ptr<uint8[]> init_data, int init_data_size); | 78 scoped_ptr<uint8[]> init_data, int init_data_size); |
| 74 | 79 |
| 75 // Needed to create the PpapiDecryptor. | 80 // Needed to create the PpapiDecryptor. |
| 76 WebKit::WebMediaPlayerClient* web_media_player_client_; | 81 WebKit::WebMediaPlayerClient* web_media_player_client_; |
| 77 WebKit::WebFrame* web_frame_; | 82 WebKit::WebFrame* web_frame_; |
| 78 bool did_create_helper_plugin_; | 83 bool did_create_helper_plugin_; |
| 79 | 84 |
| 80 // Callbacks for firing key events. | 85 // Callbacks for firing key events. |
| 81 media::KeyAddedCB key_added_cb_; | 86 media::KeyAddedCB key_added_cb_; |
| 82 media::KeyErrorCB key_error_cb_; | 87 media::KeyErrorCB key_error_cb_; |
| 83 media::KeyMessageCB key_message_cb_; | 88 media::KeyMessageCB key_message_cb_; |
| 84 media::NeedKeyCB need_key_cb_; | 89 media::NeedKeyCB need_key_cb_; |
| 85 | 90 |
| 86 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread | 91 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread |
| 87 // safe as per the Decryptor interface. | 92 // safe as per the Decryptor interface. |
| 88 base::Lock lock_; | 93 base::Lock lock_; |
| 89 | 94 |
| 90 media::DecryptorReadyCB decryptor_ready_cb_; | 95 media::DecryptorReadyCB decryptor_ready_cb_; |
| 91 | 96 |
| 92 // The real decryptor that does decryption for the ProxyDecryptor. | 97 // The real MediaKeys and Decryptor objects that perform key operations and |
| 93 // This pointer is protected by the |lock_|. | 98 // decryption for the ProxyDecryptor. These two pointers refer to the same |
| 94 scoped_ptr<media::Decryptor> decryptor_; | 99 // object and |media_keys_| takes the ownership. They are protected by the |
| 100 // |lock_|. | |
| 101 scoped_ptr<media::MediaKeys> media_keys_; | |
| 102 media::Decryptor* decryptor_; | |
|
xhwang
2013/05/24 00:25:12
I like keeping MediaKeys and Decryptor separate. B
ddorwin
2013/05/24 20:39:12
The inheritance would be for convenience and not r
xhwang
2013/05/24 23:15:56
Done.
| |
| 95 | 103 |
| 96 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 104 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
| 97 | 105 |
| 98 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 106 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
| 99 }; | 107 }; |
| 100 | 108 |
| 101 } // namespace webkit_media | 109 } // namespace webkit_media |
| 102 | 110 |
| 103 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 111 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
| OLD | NEW |