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

Side by Side Diff: webkit/media/crypto/proxy_decryptor.h

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

Powered by Google App Engine
This is Rietveld 408576698