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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_MEDIA_KEYS_H_
6 #define MEDIA_BASE_MEDIA_KEYS_H_
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "media/base/media_export.h"
20 // Performs media key operations.
22 // All key operations are called on the renderer thread. Therefore, these calls
23 // should be fast and nonblocking; key events should be fired asynchronously.
24 class MEDIA_EXPORT MediaKeys
{
26 // Reported to UMA, so never reuse a value!
27 // Must be kept in sync with WebKit::WebMediaPlayerClient::MediaKeyErrorCode
28 // (enforced in webmediaplayer_impl.cc).
32 // The following v0.1b values have never been used.
35 // kHardwareChangeError,
37 kMaxKeyError
// Must be last and greater than any legit value.
43 // Generates a key request with the |type| and |init_data| provided.
44 // Returns true if generating key request succeeded, false otherwise.
45 // Note: AddKey() and CancelKeyRequest() should only be called after
46 // GenerateKeyRequest() returns true.
47 virtual bool GenerateKeyRequest(const std::string
& type
,
48 const uint8
* init_data
,
49 int init_data_length
) = 0;
51 // Adds a |key| to the session. The |key| is not limited to a decryption
52 // key. It can be any data that the key system accepts, such as a license.
53 // If multiple calls of this function set different keys for the same
54 // key ID, the older key will be replaced by the newer key.
55 virtual void AddKey(const uint8
* key
, int key_length
,
56 const uint8
* init_data
, int init_data_length
,
57 const std::string
& session_id
) = 0;
59 // Cancels the key request specified by |session_id|.
60 virtual void CancelKeyRequest(const std::string
& session_id
) = 0;
62 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if
63 // no Decryptor object is associated. The returned object is only guaranteed
64 // to be valid during the MediaKeys' lifetime.
65 virtual Decryptor
* GetDecryptor();
68 DISALLOW_COPY_AND_ASSIGN(MediaKeys
);
71 // Key event callbacks. See the spec for details:
72 // http://dvcs.w3.org/hg/html-media/raw-file/eme-v0.1b/encrypted-media/encrypted-media.html#event-summary
73 typedef base::Callback
<void(const std::string
& session_id
)> KeyAddedCB
;
75 typedef base::Callback
<void(const std::string
& session_id
,
76 media::MediaKeys::KeyError error_code
,
77 int system_code
)> KeyErrorCB
;
79 typedef base::Callback
<void(const std::string
& session_id
,
80 const std::vector
<uint8
>& message
,
81 const std::string
& default_url
)> KeyMessageCB
;
83 typedef base::Callback
<void(const std::string
& session_id
,
84 const std::string
& type
,
85 const std::vector
<uint8
>& init_data
)> NeedKeyCB
;
89 #endif // MEDIA_BASE_MEDIA_KEYS_H_