OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_MEDIA_KEYS_H_ | 5 #ifndef MEDIA_BASE_MEDIA_KEYS_H_ |
6 #define MEDIA_BASE_MEDIA_KEYS_H_ | 6 #define MEDIA_BASE_MEDIA_KEYS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "media/base/media_export.h" | 14 #include "media/base/media_export.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 class Decryptor; | 18 class Decryptor; |
19 | 19 |
| 20 template <typename T> |
| 21 class CdmPromise; |
| 22 |
20 // Performs media key operations. | 23 // Performs media key operations. |
21 // | 24 // |
22 // All key operations are called on the renderer thread. Therefore, these calls | 25 // All key operations are called on the renderer thread. Therefore, these calls |
23 // should be fast and nonblocking; key events should be fired asynchronously. | 26 // should be fast and nonblocking; key events should be fired asynchronously. |
24 class MEDIA_EXPORT MediaKeys { | 27 class MEDIA_EXPORT MediaKeys { |
25 public: | 28 public: |
26 // Reported to UMA, so never reuse a value! | 29 // Reported to UMA, so never reuse a value! |
27 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode | 30 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode |
28 // (enforced in webmediaplayer_impl.cc). | 31 // (enforced in webmediaplayer_impl.cc). |
29 enum KeyError { | 32 enum KeyError { |
30 kUnknownError = 1, | 33 kUnknownError = 1, |
31 kClientError, | 34 kClientError, |
32 // The commented v0.1b values below have never been used. | 35 // The commented v0.1b values below have never been used. |
33 // kServiceError, | 36 // kServiceError, |
34 kOutputError = 4, | 37 kOutputError = 4, |
35 // kHardwareChangeError, | 38 // kHardwareChangeError, |
36 // kDomainError, | 39 // kDomainError, |
37 kMaxKeyError // Must be last and greater than any legit value. | 40 kMaxKeyError // Must be last and greater than any legit value. |
38 }; | 41 }; |
39 | 42 |
| 43 // Must be kept in sync with cdm::MediaKeyException (enforced in |
| 44 // clear_key_cdm.cc). |
| 45 enum MediaKeysException { |
| 46 MEDIA_KEYS_EXCEPTION_INDEX_SIZE_ERROR = 1, |
| 47 // kDomstringSizeError = 2, |
| 48 MEDIA_KEYS_EXCEPTION_HIERARCHY_REQUEST_ERROR = 3, |
| 49 MEDIA_KEYS_EXCEPTION_WRONG_DOCUMENT_ERROR = 4, |
| 50 MEDIA_KEYS_EXCEPTION_INVALID_CHARACTER_ERROR = 5, |
| 51 // kNoDataAllowedError = 6, |
| 52 MEDIA_KEYS_EXCEPTION_NO_MODIFICATION_ALLOWED_ERROR = 7, |
| 53 MEDIA_KEYS_EXCEPTION_NOT_FOUND_ERROR = 8, |
| 54 MEDIA_KEYS_EXCEPTION_NOT_SUPPORTED_ERROR = 9, |
| 55 // kInuseAttributeError = 10, |
| 56 MEDIA_KEYS_EXCEPTION_INVALID_STATE_ERROR = 11, |
| 57 MEDIA_KEYS_EXCEPTION_SYNTAX_ERROR = 12, |
| 58 MEDIA_KEYS_EXCEPTION_INVALID_MODIFICATION_ERROR = 13, |
| 59 MEDIA_KEYS_EXCEPTION_NAMESPACE_ERROR = 14, |
| 60 MEDIA_KEYS_EXCEPTION_INVALID_ACCESS_ERROR = 15, |
| 61 // kValidationError = 16, |
| 62 // kTypeMismatchError = 17, |
| 63 MEDIA_KEYS_EXCEPTION_SECURITY_ERROR = 18, |
| 64 MEDIA_KEYS_EXCEPTION_NETWORK_ERROR = 19, |
| 65 MEDIA_KEYS_EXCEPTION_ABORT_ERROR = 20, |
| 66 MEDIA_KEYS_EXCEPTION_URL_MISMATCH_ERROR = 21, |
| 67 MEDIA_KEYS_EXCEPTION_QUOTA_EXCEEDED_ERROR = 22, |
| 68 MEDIA_KEYS_EXCEPTION_TIMEOUT_ERROR = 23, |
| 69 MEDIA_KEYS_EXCEPTION_INVALID_NODE_TYPE_ERROR = 24, |
| 70 MEDIA_KEYS_EXCEPTION_DATA_CLONE_ERROR = 25, |
| 71 |
| 72 // Additional values from the DOM4 spec that don't have assigned codes. |
| 73 MEDIA_KEYS_EXCEPTION_ENCODING_ERROR, |
| 74 MEDIA_KEYS_EXCEPTION_NOT_READABLE_ERROR, |
| 75 |
| 76 // Additional values. |
| 77 MEDIA_KEYS_EXCEPTION_DATA_ERROR, |
| 78 MEDIA_KEYS_EXCEPTION_OPERATION_ERROR, |
| 79 MEDIA_KEYS_EXCEPTION_VERSION_ERROR, |
| 80 |
| 81 // Additional values for backwards compatibility with previous versions. |
| 82 MEDIA_KEYS_EXCEPTION_UNKNOWN_ERROR = 100, |
| 83 MEDIA_KEYS_EXCEPTION_CLIENT_ERROR, |
| 84 MEDIA_KEYS_EXCEPTION_OUTPUT_ERROR |
| 85 }; |
| 86 |
| 87 // Type of license required when creating/loading a session. |
| 88 // Must be kept in sync with the values specified in the spec: |
| 89 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypte
d-media.html#extensions |
| 90 // Must be kept in sync with cdm::SessionType (enforced in clear_key_cdm.cc). |
| 91 enum SessionType { |
| 92 SESSION_TYPE_TEMPORARY = 0, |
| 93 SESSION_TYPE_PERSISTENT = 1 |
| 94 }; |
| 95 |
40 const static uint32 kInvalidSessionId = 0; | 96 const static uint32 kInvalidSessionId = 0; |
41 | 97 |
42 MediaKeys(); | 98 MediaKeys(); |
43 virtual ~MediaKeys(); | 99 virtual ~MediaKeys(); |
44 | 100 |
45 // Creates a session with the |content_type| and |init_data| provided. | 101 // Creates a session with the |init_data_type|, |init_data| and |session_type| |
46 // Returns true if a session is successfully created, false otherwise. | 102 // provided. |
47 // Note: UpdateSession() and ReleaseSession() should only be called after | 103 // Note: UpdateSession() and ReleaseSession() should only be called after |
48 // SessionCreatedCB is fired. | 104 // |promise| is resolved. |
49 // TODO(jrummell): Remove return value when prefixed API is removed. | 105 virtual void CreateSession(const std::string& init_data_type, |
50 // See http://crbug.com/342510 | |
51 virtual bool CreateSession(uint32 session_id, | |
52 const std::string& content_type, | |
53 const uint8* init_data, | 106 const uint8* init_data, |
54 int init_data_length) = 0; | 107 int init_data_length, |
| 108 SessionType session_type, |
| 109 scoped_ptr<CdmPromise<std::string> > promise) = 0; |
55 | 110 |
56 // Loads a session with the |web_session_id| provided. | 111 // Loads a session with the |web_session_id| provided. |
57 // Note: UpdateSession() and ReleaseSession() should only be called after | 112 // Note: UpdateSession() and ReleaseSession() should only be called after |
58 // SessionCreatedCB is fired. | 113 // |promise| is resolved. |
59 virtual void LoadSession(uint32 session_id, | 114 virtual void LoadSession(const std::string& web_session_id, |
60 const std::string& web_session_id) = 0; | 115 scoped_ptr<CdmPromise<std::string> > promise) = 0; |
61 | 116 |
62 // Updates a session specified by |session_id| with |response|. | 117 // Updates a session specified by |web_session_id| with |response|. |
63 virtual void UpdateSession(uint32 session_id, | 118 virtual void UpdateSession(const std::string& web_session_id, |
64 const uint8* response, | 119 const uint8* response, |
65 int response_length) = 0; | 120 int response_length, |
| 121 scoped_ptr<CdmPromise<void> > promise) = 0; |
66 | 122 |
67 // Releases the session specified by |session_id|. | 123 // Releases the session specified by |web_session_id|. |
68 virtual void ReleaseSession(uint32 session_id) = 0; | 124 virtual void ReleaseSession(const std::string& web_session_id, |
| 125 scoped_ptr<CdmPromise<void> > promise) = 0; |
69 | 126 |
70 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if | 127 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if |
71 // no Decryptor object is associated. The returned object is only guaranteed | 128 // no Decryptor object is associated. The returned object is only guaranteed |
72 // to be valid during the MediaKeys' lifetime. | 129 // to be valid during the MediaKeys' lifetime. |
73 virtual Decryptor* GetDecryptor(); | 130 virtual Decryptor* GetDecryptor(); |
74 | 131 |
75 private: | 132 private: |
76 DISALLOW_COPY_AND_ASSIGN(MediaKeys); | 133 DISALLOW_COPY_AND_ASSIGN(MediaKeys); |
77 }; | 134 }; |
78 | 135 |
79 // Key event callbacks. See the spec for details: | 136 // Key event callbacks. See the spec for details: |
80 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#event-summary | 137 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#event-summary |
81 typedef base::Callback< | 138 typedef base::Callback<void(const std::string& web_session_id, |
82 void(uint32 session_id, const std::string& web_session_id)> | |
83 SessionCreatedCB; | |
84 | |
85 typedef base::Callback<void(uint32 session_id, | |
86 const std::vector<uint8>& message, | 139 const std::vector<uint8>& message, |
87 const std::string& destination_url)> | 140 const std::string& destination_url)> |
88 SessionMessageCB; | 141 SessionMessageCB; |
89 | 142 |
90 typedef base::Callback<void(uint32 session_id)> SessionReadyCB; | 143 typedef base::Callback<void(const std::string& web_session_id)> SessionReadyCB; |
91 | 144 |
92 typedef base::Callback<void(uint32 session_id)> SessionClosedCB; | 145 typedef base::Callback<void(const std::string& web_session_id)> SessionClosedCB; |
93 | 146 |
94 typedef base::Callback<void(uint32 session_id, | 147 typedef base::Callback<void(const std::string& web_session_id, |
95 media::MediaKeys::KeyError error_code, | 148 MediaKeys::MediaKeysException exception_code, |
96 uint32 system_code)> SessionErrorCB; | 149 uint32 system_code, |
| 150 const std::string& error_message)> SessionErrorCB; |
97 | 151 |
98 } // namespace media | 152 } // namespace media |
99 | 153 |
100 #endif // MEDIA_BASE_MEDIA_KEYS_H_ | 154 #endif // MEDIA_BASE_MEDIA_KEYS_H_ |
OLD | NEW |