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"
22 class CdmPromiseTemplate
;
24 typedef CdmPromiseTemplate
<std::string
> NewSessionCdmPromise
;
25 typedef CdmPromiseTemplate
<void> SimpleCdmPromise
;
26 typedef std::vector
<std::vector
<uint8
> > KeyIdsVector
;
27 typedef CdmPromiseTemplate
<KeyIdsVector
> KeyIdsPromise
;
29 // Performs media key operations.
31 // All key operations are called on the renderer thread. Therefore, these calls
32 // should be fast and nonblocking; key events should be fired asynchronously.
33 class MEDIA_EXPORT MediaKeys
{
35 // Reported to UMA, so never reuse a value!
36 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode
37 // (enforced in webmediaplayer_impl.cc).
38 // TODO(jrummell): Can this be moved to proxy_decryptor as it should only be
39 // used by the prefixed EME code?
43 // The commented v0.1b values below have never been used.
46 // kHardwareChangeError,
48 kMaxKeyError
// Must be last and greater than any legit value.
51 // Must be a superset of cdm::MediaKeyException.
62 // Type of license required when creating/loading a session.
63 // Must be consistent with the values specified in the spec:
64 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#extensions
70 const static uint32 kInvalidSessionId
= 0;
75 // Creates a session with the |init_data_type|, |init_data| and |session_type|
77 // Note: UpdateSession() and ReleaseSession() should only be called after
78 // |promise| is resolved.
79 virtual void CreateSession(const std::string
& init_data_type
,
80 const uint8
* init_data
,
82 SessionType session_type
,
83 scoped_ptr
<NewSessionCdmPromise
> promise
) = 0;
85 // Loads a session with the |web_session_id| provided.
86 // Note: UpdateSession() and ReleaseSession() should only be called after
87 // |promise| is resolved.
88 virtual void LoadSession(const std::string
& web_session_id
,
89 scoped_ptr
<NewSessionCdmPromise
> promise
) = 0;
91 // Updates a session specified by |web_session_id| with |response|.
92 virtual void UpdateSession(const std::string
& web_session_id
,
93 const uint8
* response
,
95 scoped_ptr
<SimpleCdmPromise
> promise
) = 0;
97 // Releases the session specified by |web_session_id|.
98 virtual void ReleaseSession(const std::string
& web_session_id
,
99 scoped_ptr
<SimpleCdmPromise
> promise
) = 0;
101 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if
102 // no Decryptor object is associated. The returned object is only guaranteed
103 // to be valid during the MediaKeys' lifetime.
104 virtual Decryptor
* GetDecryptor();
107 DISALLOW_COPY_AND_ASSIGN(MediaKeys
);
110 // Key event callbacks. See the spec for details:
111 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-media.html#event-summary
112 typedef base::Callback
<void(const std::string
& web_session_id
,
113 const std::vector
<uint8
>& message
,
114 const GURL
& destination_url
)> SessionMessageCB
;
116 typedef base::Callback
<void(const std::string
& web_session_id
)> SessionReadyCB
;
118 typedef base::Callback
<void(const std::string
& web_session_id
)> SessionClosedCB
;
120 typedef base::Callback
<void(const std::string
& web_session_id
,
121 MediaKeys::Exception exception_code
,
123 const std::string
& error_message
)> SessionErrorCB
;
127 #endif // MEDIA_BASE_MEDIA_KEYS_H_