Fix IsRenderFrameLive and use it in RenderFrameHostManager.
[chromium-blink-merge.git] / media / base / media_keys.h
blob063e54b1058d421a0ab89ba7dd1411cbc905619e
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_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "media/base/media_export.h"
15 #include "url/gurl.h"
17 namespace media {
19 class Decryptor;
21 template <typename T>
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 {
34 public:
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?
40 enum KeyError {
41 kUnknownError = 1,
42 kClientError,
43 // The commented v0.1b values below have never been used.
44 // kServiceError,
45 kOutputError = 4,
46 // kHardwareChangeError,
47 // kDomainError,
48 kMaxKeyError // Must be last and greater than any legit value.
51 // Must be a superset of cdm::MediaKeyException.
52 enum Exception {
53 NOT_SUPPORTED_ERROR,
54 INVALID_STATE_ERROR,
55 INVALID_ACCESS_ERROR,
56 QUOTA_EXCEEDED_ERROR,
57 UNKNOWN_ERROR,
58 CLIENT_ERROR,
59 OUTPUT_ERROR
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
65 enum SessionType {
66 TEMPORARY_SESSION,
67 PERSISTENT_SESSION
70 const static uint32 kInvalidSessionId = 0;
72 MediaKeys();
73 virtual ~MediaKeys();
75 // Creates a session with the |init_data_type|, |init_data| and |session_type|
76 // provided.
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,
81 int init_data_length,
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,
94 int response_length,
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();
106 private:
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,
122 uint32 system_code,
123 const std::string& error_message)> SessionErrorCB;
125 } // namespace media
127 #endif // MEDIA_BASE_MEDIA_KEYS_H_