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. 4 5 #ifndef MEDIA_BASE_MEDIA_KEYS_H_ 6 #define MEDIA_BASE_MEDIA_KEYS_H_ 7 8 #include <string> 9 #include <vector> 10 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" 16 17 namespace media { 18 19 class Decryptor; 20 21 template <typename T> 22 class CdmPromiseTemplate; 23 24 typedef CdmPromiseTemplate<std::string> NewSessionCdmPromise; 25 typedef CdmPromiseTemplate<void> SimpleCdmPromise; 26 27 // Performs media key operations. 28 // 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 { 32 public: 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? 38 enum KeyError { 39 kUnknownError = 1, 40 kClientError, 41 // The commented v0.1b values below have never been used. 42 // kServiceError, 43 kOutputError = 4, 44 // kHardwareChangeError, 45 // kDomainError, 46 kMaxKeyError // Must be last and greater than any legit value. 47 }; 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/encrypted-media.html#extensions 63 enum SessionType { 64 TEMPORARY_SESSION, 65 PERSISTENT_SESSION 66 }; 67 68 const static uint32 kInvalidSessionId = 0; 69 70 MediaKeys(); 71 virtual ~MediaKeys(); 72 73 // Creates a session with the |init_data_type|, |init_data| and |session_type| 74 // provided. 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, 79 int init_data_length, 80 SessionType session_type, 81 scoped_ptr<NewSessionCdmPromise> promise) = 0; 82 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; 88 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, 92 int response_length, 93 scoped_ptr<SimpleCdmPromise> promise) = 0; 94 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; 98 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(); 103 104 private: 105 DISALLOW_COPY_AND_ASSIGN(MediaKeys); 106 }; 107 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; 113 114 typedef base::Callback<void(const std::string& web_session_id)> SessionReadyCB; 115 116 typedef base::Callback<void(const std::string& web_session_id)> SessionClosedCB; 117 118 typedef base::Callback<void(const std::string& web_session_id, 119 MediaKeys::Exception exception_code, 120 uint32 system_code, 121 const std::string& error_message)> SessionErrorCB; 122 123 } // namespace media 124 125 #endif // MEDIA_BASE_MEDIA_KEYS_H_ 126