Chromium Code Reviews| 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 #include "media/base/media_keys_session_promise.h" | |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 class Decryptor; | 19 class Decryptor; |
| 19 | 20 |
| 20 // Performs media key operations. | 21 // Performs media key operations. |
| 21 // | 22 // |
| 22 // All key operations are called on the renderer thread. Therefore, these calls | 23 // 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 // should be fast and nonblocking; key events should be fired asynchronously. |
| 24 class MEDIA_EXPORT MediaKeys { | 25 class MEDIA_EXPORT MediaKeys { |
| 25 public: | 26 public: |
| 26 // Reported to UMA, so never reuse a value! | 27 // Reported to UMA, so never reuse a value! |
| 27 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode | 28 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode |
| 28 // (enforced in webmediaplayer_impl.cc). | 29 // (enforced in webmediaplayer_impl.cc). |
| 29 enum KeyError { | 30 enum KeyError { |
| 30 kUnknownError = 1, | 31 kUnknownError = 1, |
| 31 kClientError, | 32 kClientError, |
| 32 // The commented v0.1b values below have never been used. | 33 // The commented v0.1b values below have never been used. |
| 33 // kServiceError, | 34 // kServiceError, |
| 34 kOutputError = 4, | 35 kOutputError = 4, |
| 35 // kHardwareChangeError, | 36 // kHardwareChangeError, |
| 36 // kDomainError, | 37 // kDomainError, |
| 37 kMaxKeyError // Must be last and greater than any legit value. | 38 kMaxKeyError // Must be last and greater than any legit value. |
| 38 }; | 39 }; |
| 39 | 40 |
| 41 // Type of license required when creating/loading a session. | |
| 42 // Must be kept in sync with | |
|
ddorwin
2014/05/05 18:35:42
incomplete
jrummell
2014/05/08 23:37:45
Done.
| |
| 43 enum SessionType { | |
| 44 kTemporary = 0, | |
| 45 kPersistent = 1 | |
|
xhwang
2014/05/05 20:46:42
We should use UPPER_CASE for enums. Sorry that Key
jrummell
2014/05/08 23:37:45
Done.
| |
| 46 }; | |
| 47 | |
| 40 const static uint32 kInvalidSessionId = 0; | 48 const static uint32 kInvalidSessionId = 0; |
| 41 | 49 |
| 42 MediaKeys(); | 50 MediaKeys(); |
| 43 virtual ~MediaKeys(); | 51 virtual ~MediaKeys(); |
| 44 | 52 |
| 45 // Creates a session with the |content_type| and |init_data| provided. | 53 // Creates a session with the |init_data_type|, |init_data| and |session_type| |
| 46 // Returns true if a session is successfully created, false otherwise. | 54 // provided. |
| 47 // Note: UpdateSession() and ReleaseSession() should only be called after | 55 // Note: UpdateSession() and ReleaseSession() should only be called after |
| 48 // SessionCreatedCB is fired. | 56 // |promise| is fired. |
|
ddorwin
2014/05/05 18:35:42
s/fired/resolved/. (It would not be okay to call a
jrummell
2014/05/08 23:37:45
Done.
| |
| 49 // TODO(jrummell): Remove return value when prefixed API is removed. | 57 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, | 58 const uint8* init_data, |
| 54 int init_data_length) = 0; | 59 int init_data_length, |
| 60 SessionType session_type, | |
| 61 scoped_ptr<MediaKeysSessionPromise> promise) = 0; | |
| 55 | 62 |
| 56 // Loads a session with the |web_session_id| provided. | 63 // Loads a session with the |web_session_id| provided. |
| 57 // Note: UpdateSession() and ReleaseSession() should only be called after | 64 // Note: UpdateSession() and ReleaseSession() should only be called after |
| 58 // SessionCreatedCB is fired. | 65 // |promise| is fired. |
|
ddorwin
2014/05/05 18:35:42
ditto
jrummell
2014/05/08 23:37:45
Done.
| |
| 59 virtual void LoadSession(uint32 session_id, | 66 virtual void LoadSession(const std::string& web_session_id, |
| 60 const std::string& web_session_id) = 0; | 67 scoped_ptr<MediaKeysSessionPromise> promise) = 0; |
| 61 | 68 |
| 62 // Updates a session specified by |session_id| with |response|. | 69 // Updates a session specified by |web_session_id| with |response|. |
| 63 virtual void UpdateSession(uint32 session_id, | 70 virtual void UpdateSession(const std::string& web_session_id, |
| 64 const uint8* response, | 71 const uint8* response, |
| 65 int response_length) = 0; | 72 int response_length, |
| 73 scoped_ptr<MediaKeysSessionPromise> promise) = 0; | |
| 66 | 74 |
| 67 // Releases the session specified by |session_id|. | 75 // Releases the session specified by |web_session_id|. |
| 68 virtual void ReleaseSession(uint32 session_id) = 0; | 76 virtual void ReleaseSession(const std::string& web_session_id, |
| 77 scoped_ptr<MediaKeysSessionPromise> promise) = 0; | |
| 69 | 78 |
| 70 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if | 79 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if |
| 71 // no Decryptor object is associated. The returned object is only guaranteed | 80 // no Decryptor object is associated. The returned object is only guaranteed |
| 72 // to be valid during the MediaKeys' lifetime. | 81 // to be valid during the MediaKeys' lifetime. |
| 73 virtual Decryptor* GetDecryptor(); | 82 virtual Decryptor* GetDecryptor(); |
| 74 | 83 |
| 75 private: | 84 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(MediaKeys); | 85 DISALLOW_COPY_AND_ASSIGN(MediaKeys); |
| 77 }; | 86 }; |
| 78 | 87 |
| 79 // Key event callbacks. See the spec for details: | 88 // 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 | 89 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted- media.html#event-summary |
| 81 typedef base::Callback< | 90 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, | 91 const std::vector<uint8>& message, |
| 87 const std::string& destination_url)> | 92 const std::string& destination_url)> |
| 88 SessionMessageCB; | 93 SessionMessageCB; |
| 89 | 94 |
| 90 typedef base::Callback<void(uint32 session_id)> SessionReadyCB; | 95 typedef base::Callback<void(const std::string& web_session_id)> SessionReadyCB; |
| 91 | 96 |
| 92 typedef base::Callback<void(uint32 session_id)> SessionClosedCB; | 97 typedef base::Callback<void(const std::string& web_session_id)> SessionClosedCB; |
| 93 | 98 |
| 94 typedef base::Callback<void(uint32 session_id, | 99 typedef base::Callback<void(const std::string& web_session_id, |
| 95 media::MediaKeys::KeyError error_code, | 100 const std::string& error_name, |
| 96 uint32 system_code)> SessionErrorCB; | 101 uint32 system_code, |
| 102 const std::string& error_message)> SessionErrorCB; | |
| 97 | 103 |
| 98 } // namespace media | 104 } // namespace media |
| 99 | 105 |
| 100 #endif // MEDIA_BASE_MEDIA_KEYS_H_ | 106 #endif // MEDIA_BASE_MEDIA_KEYS_H_ |
| OLD | NEW |