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
3 // found in the LICENSE file.
5 #ifndef WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
6 #define WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/synchronization/lock.h"
13 #include "media/base/decryptor.h"
17 class WebMediaPlayerClient
;
20 namespace webkit_media
{
22 // A decryptor proxy that creates a real decryptor object on demand and
23 // forwards decryptor calls to it.
24 // TODO(xhwang): Currently we don't support run-time switching among decryptor
25 // objects. Fix this when needed.
26 class ProxyDecryptor
{
28 ProxyDecryptor(WebKit::WebMediaPlayerClient
* web_media_player_client
,
29 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();
36 // Requests the ProxyDecryptor to notify the decryptor when it's ready through
37 // the |decryptor_ready_cb| provided.
38 // If |decryptor_ready_cb| is null, the existing callback will be fired with
39 // NULL immediately and reset.
40 void SetDecryptorReadyCB(const media::DecryptorReadyCB
& decryptor_ready_cb
);
42 bool GenerateKeyRequest(const std::string
& key_system
,
43 const std::string
& type
,
44 const uint8
* init_data
, int init_data_length
);
45 void AddKey(const std::string
& key_system
,
46 const uint8
* key
, int key_length
,
47 const uint8
* init_data
, int init_data_length
,
48 const std::string
& session_id
);
49 void CancelKeyRequest(const std::string
& key_system
,
50 const std::string
& session_id
);
53 // Helper functions to create decryptors to handle the given |key_system|.
54 scoped_ptr
<media::Decryptor
> CreatePpapiDecryptor(
55 const std::string
& key_system
);
56 scoped_ptr
<media::Decryptor
> CreateDecryptor(const std::string
& key_system
);
58 // Callbacks for firing key events.
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
,
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_ptr
<uint8
[]> init_data
, int init_data_size
);
73 // Needed to create the PpapiDecryptor.
74 WebKit::WebMediaPlayerClient
* web_media_player_client_
;
75 WebKit::WebFrame
* web_frame_
;
76 bool did_create_helper_plugin_
;
78 // Callbacks for firing key events.
79 media::KeyAddedCB key_added_cb_
;
80 media::KeyErrorCB key_error_cb_
;
81 media::KeyMessageCB key_message_cb_
;
82 media::NeedKeyCB need_key_cb_
;
84 // Protects the |decryptor_|. Note that |decryptor_| itself should be thread
85 // safe as per the Decryptor interface.
88 media::DecryptorReadyCB decryptor_ready_cb_
;
90 // The real decryptor that does decryption for the ProxyDecryptor.
91 // This pointer is protected by the |lock_|.
92 scoped_ptr
<media::Decryptor
> decryptor_
;
94 base::WeakPtrFactory
<ProxyDecryptor
> weak_ptr_factory_
;
96 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor
);
99 } // namespace webkit_media
101 #endif // WEBKIT_MEDIA_CRYPTO_PROXY_DECRYPTOR_H_