Add integration browser tests for settings hardening.
[chromium-blink-merge.git] / media / base / media_keys.h
blobd581ae4e8bd9cfb7d1bfcd1fc77fb4578393d179
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;
27 // Performs media key operations.
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.
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
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
68 const static uint32 kInvalidSessionId = 0;
70 MediaKeys();
71 virtual ~MediaKeys();
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;
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;
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;
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;
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();
104 private:
105 DISALLOW_COPY_AND_ASSIGN(MediaKeys);
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;
114 typedef base::Callback<void(const std::string& web_session_id)> SessionReadyCB;
116 typedef base::Callback<void(const std::string& web_session_id)> SessionClosedCB;
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;
123 } // namespace media
125 #endif // MEDIA_BASE_MEDIA_KEYS_H_