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