Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: media/cdm/proxy_decryptor.cc

Issue 1001723002: media: Refactor PlatformVerificationFlow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cdm/proxy_decryptor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "media/cdm/proxy_decryptor.h" 5 #include "media/cdm/proxy_decryptor.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 11 matching lines...) Expand all
22 22
23 // Special system code to signal a closed persistent session in a SessionError() 23 // Special system code to signal a closed persistent session in a SessionError()
24 // call. This is needed because there is no SessionClosed() call in the prefixed 24 // call. This is needed because there is no SessionClosed() call in the prefixed
25 // EME API. 25 // EME API.
26 const int kSessionClosedSystemCode = 29127; 26 const int kSessionClosedSystemCode = 29127;
27 27
28 ProxyDecryptor::ProxyDecryptor(MediaPermission* media_permission, 28 ProxyDecryptor::ProxyDecryptor(MediaPermission* media_permission,
29 const KeyAddedCB& key_added_cb, 29 const KeyAddedCB& key_added_cb,
30 const KeyErrorCB& key_error_cb, 30 const KeyErrorCB& key_error_cb,
31 const KeyMessageCB& key_message_cb) 31 const KeyMessageCB& key_message_cb)
32 : key_added_cb_(key_added_cb), 32 : media_permission_(media_permission),
33 key_added_cb_(key_added_cb),
33 key_error_cb_(key_error_cb), 34 key_error_cb_(key_error_cb),
34 key_message_cb_(key_message_cb), 35 key_message_cb_(key_message_cb),
35 is_clear_key_(false), 36 is_clear_key_(false),
36 weak_ptr_factory_(this) { 37 weak_ptr_factory_(this) {
37 DCHECK(media_permission); 38 DCHECK(media_permission);
38 DCHECK(!key_added_cb_.is_null()); 39 DCHECK(!key_added_cb_.is_null());
39 DCHECK(!key_error_cb_.is_null()); 40 DCHECK(!key_error_cb_.is_null());
40 DCHECK(!key_message_cb_.is_null()); 41 DCHECK(!key_message_cb_.is_null());
41 } 42 }
42 43
43 ProxyDecryptor::~ProxyDecryptor() { 44 ProxyDecryptor::~ProxyDecryptor() {
44 // Destroy the decryptor explicitly before destroying the plugin. 45 // Destroy the decryptor explicitly before destroying the plugin.
45 media_keys_.reset(); 46 media_keys_.reset();
46 } 47 }
47 48
48 CdmContext* ProxyDecryptor::GetCdmContext() { 49 CdmContext* ProxyDecryptor::GetCdmContext() {
49 return media_keys_ ? media_keys_->GetCdmContext() : nullptr; 50 return media_keys_ ? media_keys_->GetCdmContext() : nullptr;
50 } 51 }
51 52
52 bool ProxyDecryptor::InitializeCDM(CdmFactory* cdm_factory, 53 bool ProxyDecryptor::InitializeCDM(CdmFactory* cdm_factory,
53 const std::string& key_system, 54 const std::string& key_system,
54 const GURL& security_origin) { 55 const GURL& security_origin) {
55 DVLOG(1) << "InitializeCDM: key_system = " << key_system; 56 DVLOG(1) << "InitializeCDM: key_system = " << key_system;
56 57
57 DCHECK(!media_keys_); 58 DCHECK(!media_keys_);
58 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin); 59 media_keys_ = CreateMediaKeys(cdm_factory, key_system, security_origin);
59 if (!media_keys_) 60 if (!media_keys_)
60 return false; 61 return false;
61 62
63 key_system_ = key_system;
64 security_origin_ = security_origin;
65
62 is_clear_key_ = 66 is_clear_key_ =
63 IsClearKey(key_system) || IsExternalClearKey(key_system); 67 IsClearKey(key_system) || IsExternalClearKey(key_system);
64 return true; 68 return true;
65 } 69 }
66 70
67 // Returns true if |data| is prefixed with |header| and has data after the 71 // Returns true if |data| is prefixed with |header| and has data after the
68 // |header|. 72 // |header|.
69 bool HasHeader(const uint8* data, int data_length, const std::string& header) { 73 bool HasHeader(const uint8* data, int data_length, const std::string& header) {
70 return static_cast<size_t>(data_length) > header.size() && 74 return static_cast<size_t>(data_length) > header.size() &&
71 std::equal(data, data + header.size(), header.begin()); 75 std::equal(data, data + header.size(), header.begin());
(...skipping 24 matching lines...) Expand all
96 } 100 }
97 101
98 scoped_ptr<NewSessionCdmPromise> promise( 102 scoped_ptr<NewSessionCdmPromise> promise(
99 new CdmCallbackPromise<std::string>( 103 new CdmCallbackPromise<std::string>(
100 base::Bind(&ProxyDecryptor::SetSessionId, 104 base::Bind(&ProxyDecryptor::SetSessionId,
101 weak_ptr_factory_.GetWeakPtr(), 105 weak_ptr_factory_.GetWeakPtr(),
102 session_creation_type), 106 session_creation_type),
103 base::Bind(&ProxyDecryptor::OnSessionError, 107 base::Bind(&ProxyDecryptor::OnSessionError,
104 weak_ptr_factory_.GetWeakPtr(), 108 weak_ptr_factory_.GetWeakPtr(),
105 std::string()))); // No session id until created. 109 std::string()))); // No session id until created.
106 uint8* init_data_vector_data =
107 (init_data_vector.size() > 0) ? &init_data_vector[0] : nullptr;
108 110
109 if (session_creation_type == LoadSession) { 111 if (session_creation_type == LoadSession) {
112 uint8* init_data_vector_data =
113 (init_data_vector.size() > 0) ? &init_data_vector[0] : nullptr;
110 media_keys_->LoadSession( 114 media_keys_->LoadSession(
111 MediaKeys::PERSISTENT_LICENSE_SESSION, 115 MediaKeys::PERSISTENT_LICENSE_SESSION,
112 std::string(reinterpret_cast<const char*>(init_data_vector_data), 116 std::string(reinterpret_cast<const char*>(init_data_vector_data),
113 init_data_vector.size()), 117 init_data_vector.size()),
114 promise.Pass()); 118 promise.Pass());
115 return true; 119 return true;
116 } 120 }
117 121
118 MediaKeys::SessionType session_type = 122 MediaKeys::SessionType session_type =
119 session_creation_type == PersistentSession 123 session_creation_type == PersistentSession
120 ? MediaKeys::PERSISTENT_LICENSE_SESSION 124 ? MediaKeys::PERSISTENT_LICENSE_SESSION
121 : MediaKeys::TEMPORARY_SESSION; 125 : MediaKeys::TEMPORARY_SESSION;
122 126
127 // No permission required when AesDecryptor is used or when the key system is
128 // external clear key.
129 DCHECK(!key_system_.empty());
130 if (CanUseAesDecryptor(key_system_) || IsExternalClearKey(key_system_)) {
131 OnPermissionStatus(session_type, init_data_type, init_data_vector,
132 promise.Pass(), true /* granted */);
133 return true;
134 }
135
136 #if defined(OS_CHROMEOS)
137 media_permission_->RequestPermission(
138 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, security_origin_,
139 base::Bind(&ProxyDecryptor::OnPermissionStatus,
140 weak_ptr_factory_.GetWeakPtr(), session_type, init_data_type,
141 init_data_vector, base::Passed(&promise)));
142 #else
143 // TODO(xhwang): Fix the Android path by requesting permission for key systems
144 // that don't use AesDecryptor in M43.
145 OnPermissionStatus(session_type, init_data_type, init_data_vector,
146 promise.Pass(), true /* granted */);
147 #endif
148
149 return true;
150 }
151
152 void ProxyDecryptor::OnPermissionStatus(
153 MediaKeys::SessionType session_type,
154 const std::string& init_data_type,
155 const std::vector<uint8>& init_data,
156 scoped_ptr<NewSessionCdmPromise> promise,
157 bool granted) {
158 // ProxyDecryptor is only used by Prefixed EME, where RequestPermission() is
159 // only for triggering the permission UI. Later CheckPermission() will be
160 // called (e.g. in PlatformVerificationFlow) and the permission status will be
161 // evaluated there.
162 DVLOG_IF(1, !granted) << "Permission request rejected.";
163
164 const uint8* init_data_vector_data =
165 (init_data.size() > 0) ? &init_data[0] : nullptr;
166
123 media_keys_->CreateSessionAndGenerateRequest( 167 media_keys_->CreateSessionAndGenerateRequest(
124 session_type, init_data_type, init_data_vector_data, 168 session_type, init_data_type, init_data_vector_data, init_data.size(),
125 init_data_vector.size(), promise.Pass()); 169 promise.Pass());
126 return true;
127 } 170 }
128 171
129 void ProxyDecryptor::AddKey(const uint8* key, 172 void ProxyDecryptor::AddKey(const uint8* key,
130 int key_length, 173 int key_length,
131 const uint8* init_data, 174 const uint8* init_data,
132 int init_data_length, 175 int init_data_length,
133 const std::string& session_id) { 176 const std::string& session_id) {
134 DVLOG(1) << "AddKey()"; 177 DVLOG(1) << "AddKey()";
135 178
136 // In the prefixed API, the session parameter provided to addKey() is 179 // In the prefixed API, the session parameter provided to addKey() is
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 bool is_persistent = 339 bool is_persistent =
297 session_type == PersistentSession || session_type == LoadSession; 340 session_type == PersistentSession || session_type == LoadSession;
298 active_sessions_.insert(std::make_pair(session_id, is_persistent)); 341 active_sessions_.insert(std::make_pair(session_id, is_persistent));
299 342
300 // For LoadSession(), generate the KeyAdded event. 343 // For LoadSession(), generate the KeyAdded event.
301 if (session_type == LoadSession) 344 if (session_type == LoadSession)
302 GenerateKeyAdded(session_id); 345 GenerateKeyAdded(session_id);
303 } 346 }
304 347
305 } // namespace media 348 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/proxy_decryptor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698