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/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
12 #include "media/base/decryptor.h" | 13 #include "media/base/decryptor.h" |
13 | 14 |
14 namespace media { | 15 namespace media { |
15 class DecryptorClient; | 16 class DecryptorClient; |
16 } | 17 } |
17 | 18 |
18 namespace WebKit { | 19 namespace WebKit { |
19 class WebFrame; | 20 class WebFrame; |
20 class WebMediaPlayerClient; | 21 class WebMediaPlayerClient; |
21 } | 22 } |
22 | 23 |
23 namespace webkit_media { | 24 namespace webkit_media { |
24 | 25 |
25 // A decryptor proxy that creates a real decryptor object on demand and | 26 // A decryptor proxy that creates a real decryptor object on demand and |
26 // forwards decryptor calls to it. | 27 // forwards decryptor calls to it. |
27 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 28 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
28 // objects. Fix this when needed. | 29 // objects. Fix this when needed. |
29 class ProxyDecryptor { | 30 class ProxyDecryptor { |
30 public: | 31 public: |
31 ProxyDecryptor(media::DecryptorClient* decryptor_client, | 32 ProxyDecryptor(WebKit::WebMediaPlayerClient* web_media_player_client, |
32 WebKit::WebMediaPlayerClient* web_media_player_client, | 33 WebKit::WebFrame* web_frame, |
33 WebKit::WebFrame* web_frame); | 34 const media::KeyAddedCB& key_added_cb, |
| 35 const media::KeyErrorCB& key_error_cb, |
| 36 const media::KeyMessageCB& key_message_cb, |
| 37 const media::NeedKeyCB& need_key_cb); |
34 virtual ~ProxyDecryptor(); | 38 virtual ~ProxyDecryptor(); |
35 | 39 |
36 // Requests the ProxyDecryptor to notify the decryptor when it's ready through | 40 // Requests the ProxyDecryptor to notify the decryptor when it's ready through |
37 // the |decryptor_ready_cb| provided. | 41 // the |decryptor_ready_cb| provided. |
38 // If |decryptor_ready_cb| is null, the existing callback will be fired with | 42 // If |decryptor_ready_cb| is null, the existing callback will be fired with |
39 // NULL immediately and reset. | 43 // NULL immediately and reset. |
40 void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); | 44 void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); |
41 | 45 |
42 bool GenerateKeyRequest(const std::string& key_system, | 46 bool GenerateKeyRequest(const std::string& key_system, |
43 const std::string& type, | 47 const std::string& type, |
44 const uint8* init_data, int init_data_length); | 48 const uint8* init_data, int init_data_length); |
45 void AddKey(const std::string& key_system, | 49 void AddKey(const std::string& key_system, |
46 const uint8* key, int key_length, | 50 const uint8* key, int key_length, |
47 const uint8* init_data, int init_data_length, | 51 const uint8* init_data, int init_data_length, |
48 const std::string& session_id); | 52 const std::string& session_id); |
49 void CancelKeyRequest(const std::string& key_system, | 53 void CancelKeyRequest(const std::string& key_system, |
50 const std::string& session_id); | 54 const std::string& session_id); |
51 | 55 |
52 private: | 56 private: |
53 // Helper functions to create decryptors to handle the given |key_system|. | 57 // Helper functions to create decryptors to handle the given |key_system|. |
54 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( | 58 scoped_ptr<media::Decryptor> CreatePpapiDecryptor( |
55 const std::string& key_system); | 59 const std::string& key_system); |
56 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); | 60 scoped_ptr<media::Decryptor> CreateDecryptor(const std::string& key_system); |
57 | 61 |
58 // DecryptorClient through which key events are fired. | 62 // Callbacks for firing key events. |
59 media::DecryptorClient* client_; | 63 void KeyAdded(const std::string& key_system, const std::string& session_id); |
| 64 void KeyError(const std::string& key_system, |
| 65 const std::string& session_id, |
| 66 media::Decryptor::KeyError error_code, |
| 67 int system_code); |
| 68 void KeyMessage(const std::string& key_system, |
| 69 const std::string& session_id, |
| 70 const std::string& message, |
| 71 const std::string& default_url); |
| 72 void NeedKey(const std::string& key_system, |
| 73 const std::string& session_id, |
| 74 const std::string& type, |
| 75 scoped_array<uint8> init_data, int init_data_size); |
60 | 76 |
61 // Needed to create the PpapiDecryptor. | 77 // Needed to create the PpapiDecryptor. |
62 WebKit::WebMediaPlayerClient* web_media_player_client_; | 78 WebKit::WebMediaPlayerClient* web_media_player_client_; |
63 WebKit::WebFrame* web_frame_; | 79 WebKit::WebFrame* web_frame_; |
64 | 80 |
| 81 // Callbacks for firing key events. |
| 82 media::KeyAddedCB key_added_cb_; |
| 83 media::KeyErrorCB key_error_cb_; |
| 84 media::KeyMessageCB key_message_cb_; |
| 85 media::NeedKeyCB need_key_cb_; |
| 86 |
65 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread | 87 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread |
66 // safe as per the Decryptor interface. | 88 // safe as per the Decryptor interface. |
67 base::Lock lock_; | 89 base::Lock lock_; |
68 | 90 |
69 media::DecryptorReadyCB decryptor_ready_cb_; | 91 media::DecryptorReadyCB decryptor_ready_cb_; |
70 | 92 |
71 // The real decryptor that does decryption for the ProxyDecryptor. | 93 // The real decryptor that does decryption for the ProxyDecryptor. |
72 // This pointer is protected by the |lock_|. | 94 // This pointer is protected by the |lock_|. |
73 scoped_ptr<media::Decryptor> decryptor_; | 95 scoped_ptr<media::Decryptor> decryptor_; |
74 | 96 |
| 97 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
| 98 |
75 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 99 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
76 }; | 100 }; |
77 | 101 |
78 } // namespace webkit_media | 102 } // namespace webkit_media |
79 | 103 |
80 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ | 104 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_ |
OLD | NEW |