| 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 "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 class Decryptor; | 19 class Decryptor; |
| 20 | 20 |
| 21 template <typename T> |
| 22 class CdmPromiseTemplate; |
| 23 |
| 24 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; |
| 25 typedef CdmPromiseTemplate<void> SimpleCdmPromise; |
| 26 |
| 21 // Performs media key operations. | 27 // Performs media key operations. |
| 22 // | 28 // |
| 23 // All key operations are called on the renderer thread. Therefore, these calls | 29 // All key operations are called on the renderer thread. Therefore, these calls |
| 24 // should be fast and nonblocking; key events should be fired asynchronously. | 30 // should be fast and nonblocking; key events should be fired asynchronously. |
| 25 class MEDIA_EXPORT MediaKeys { | 31 class MEDIA_EXPORT MediaKeys { |
| 26 public: | 32 public: |
| 27 // Reported to UMA, so never reuse a value! | 33 // Reported to UMA, so never reuse a value! |
| 28 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode | 34 // Must be kept in sync with blink::WebMediaPlayerClient::MediaKeyErrorCode |
| 29 // (enforced in webmediaplayer_impl.cc). | 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? |
| 30 enum KeyError { | 38 enum KeyError { |
| 31 kUnknownError = 1, | 39 kUnknownError = 1, |
| 32 kClientError, | 40 kClientError, |
| 33 // The commented v0.1b values below have never been used. | 41 // The commented v0.1b values below have never been used. |
| 34 // kServiceError, | 42 // kServiceError, |
| 35 kOutputError = 4, | 43 kOutputError = 4, |
| 36 // kHardwareChangeError, | 44 // kHardwareChangeError, |
| 37 // kDomainError, | 45 // kDomainError, |
| 38 kMaxKeyError // Must be last and greater than any legit value. | 46 kMaxKeyError // Must be last and greater than any legit value. |
| 39 }; | 47 }; |
| 40 | 48 |
| 49 // Must be a superset of cdm::MediaKeyException. |
| 50 enum Exception { |
| 51 NOT_SUPPORTED_ERROR, |
| 52 INVALID_STATE_ERROR, |
| 53 INVALID_ACCESS_ERROR, |
| 54 QUOTA_EXCEEDED_ERROR, |
| 55 UNKNOWN_ERROR, |
| 56 CLIENT_ERROR, |
| 57 OUTPUT_ERROR |
| 58 }; |
| 59 |
| 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/encrypte
d-media.html#extensions |
| 63 enum SessionType { |
| 64 TEMPORARY_SESSION, |
| 65 PERSISTENT_SESSION |
| 66 }; |
| 67 |
| 41 const static uint32 kInvalidSessionId = 0; | 68 const static uint32 kInvalidSessionId = 0; |
| 42 | 69 |
| 43 MediaKeys(); | 70 MediaKeys(); |
| 44 virtual ~MediaKeys(); | 71 virtual ~MediaKeys(); |
| 45 | 72 |
| 46 // Creates a session with the |content_type| and |init_data| provided. | 73 // Creates a session with the |init_data_type|, |init_data| and |session_type| |
| 47 // Returns true if a session is successfully created, false otherwise. | 74 // provided. |
| 48 // Note: UpdateSession() and ReleaseSession() should only be called after | 75 // Note: UpdateSession() and ReleaseSession() should only be called after |
| 49 // SessionCreatedCB is fired. | 76 // |promise| is resolved. |
| 50 // TODO(jrummell): Remove return value when prefixed API is removed. | 77 virtual void CreateSession(const std::string& init_data_type, |
| 51 // See http://crbug.com/342510 | |
| 52 virtual bool CreateSession(uint32 session_id, | |
| 53 const std::string& content_type, | |
| 54 const uint8* init_data, | 78 const uint8* init_data, |
| 55 int init_data_length) = 0; | 79 int init_data_length, |
| 80 SessionType session_type, |
| 81 scoped_ptr<NewSessionCdmPromise> promise) = 0; |
| 56 | 82 |
| 57 // Loads a session with the |web_session_id| provided. | 83 // Loads a session with the |web_session_id| provided. |
| 58 // Note: UpdateSession() and ReleaseSession() should only be called after | 84 // Note: UpdateSession() and ReleaseSession() should only be called after |
| 59 // SessionCreatedCB is fired. | 85 // |promise| is resolved. |
| 60 virtual void LoadSession(uint32 session_id, | 86 virtual void LoadSession(const std::string& web_session_id, |
| 61 const std::string& web_session_id) = 0; | 87 scoped_ptr<NewSessionCdmPromise> promise) = 0; |
| 62 | 88 |
| 63 // Updates a session specified by |session_id| with |response|. | 89 // Updates a session specified by |web_session_id| with |response|. |
| 64 virtual void UpdateSession(uint32 session_id, | 90 virtual void UpdateSession(const std::string& web_session_id, |
| 65 const uint8* response, | 91 const uint8* response, |
| 66 int response_length) = 0; | 92 int response_length, |
| 93 scoped_ptr<SimpleCdmPromise> promise) = 0; |
| 67 | 94 |
| 68 // Releases the session specified by |session_id|. | 95 // Releases the session specified by |web_session_id|. |
| 69 virtual void ReleaseSession(uint32 session_id) = 0; | 96 virtual void ReleaseSession(const std::string& web_session_id, |
| 97 scoped_ptr<SimpleCdmPromise> promise) = 0; |
| 70 | 98 |
| 71 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if | 99 // Gets the Decryptor object associated with the MediaKeys. Returns NULL if |
| 72 // no Decryptor object is associated. The returned object is only guaranteed | 100 // no Decryptor object is associated. The returned object is only guaranteed |
| 73 // to be valid during the MediaKeys' lifetime. | 101 // to be valid during the MediaKeys' lifetime. |
| 74 virtual Decryptor* GetDecryptor(); | 102 virtual Decryptor* GetDecryptor(); |
| 75 | 103 |
| 76 private: | 104 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(MediaKeys); | 105 DISALLOW_COPY_AND_ASSIGN(MediaKeys); |
| 78 }; | 106 }; |
| 79 | 107 |
| 80 // Key event callbacks. See the spec for details: | 108 // Key event callbacks. See the spec for details: |
| 81 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#event-summary | 109 // https://dvcs.w3.org/hg/html-media/raw-file/default/encrypted-media/encrypted-
media.html#event-summary |
| 82 typedef base::Callback< | 110 typedef base::Callback<void(const std::string& web_session_id, |
| 83 void(uint32 session_id, const std::string& web_session_id)> | |
| 84 SessionCreatedCB; | |
| 85 | |
| 86 typedef base::Callback<void(uint32 session_id, | |
| 87 const std::vector<uint8>& message, | 111 const std::vector<uint8>& message, |
| 88 const GURL& destination_url)> SessionMessageCB; | 112 const GURL& destination_url)> SessionMessageCB; |
| 89 | 113 |
| 90 typedef base::Callback<void(uint32 session_id)> SessionReadyCB; | 114 typedef base::Callback<void(const std::string& web_session_id)> SessionReadyCB; |
| 91 | 115 |
| 92 typedef base::Callback<void(uint32 session_id)> SessionClosedCB; | 116 typedef base::Callback<void(const std::string& web_session_id)> SessionClosedCB; |
| 93 | 117 |
| 94 typedef base::Callback<void(uint32 session_id, | 118 typedef base::Callback<void(const std::string& web_session_id, |
| 95 media::MediaKeys::KeyError error_code, | 119 MediaKeys::Exception exception_code, |
| 96 uint32 system_code)> SessionErrorCB; | 120 uint32 system_code, |
| 121 const std::string& error_message)> SessionErrorCB; |
| 97 | 122 |
| 98 } // namespace media | 123 } // namespace media |
| 99 | 124 |
| 100 #endif // MEDIA_BASE_MEDIA_KEYS_H_ | 125 #endif // MEDIA_BASE_MEDIA_KEYS_H_ |
| OLD | NEW |