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

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: fix unittest 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
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 = 110 uint8* init_data_vector_data =
ddorwin 2015/03/12 03:58:12 Move to 114
xhwang 2015/03/12 17:35:27 Done.
107 (init_data_vector.size() > 0) ? &init_data_vector[0] : nullptr; 111 (init_data_vector.size() > 0) ? &init_data_vector[0] : nullptr;
108 112
109 if (session_creation_type == LoadSession) { 113 if (session_creation_type == LoadSession) {
110 media_keys_->LoadSession( 114 media_keys_->LoadSession(
ddorwin 2015/03/12 03:58:12 In theory, a user could have allowed then denied a
xhwang 2015/03/12 17:35:27 Acknowledged.
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.
128 DCHECK(!key_system_.empty());
129 if (CanUseAesDecryptor(key_system_)) {
130 OnPermissionStatus(session_type, init_data_type, init_data_vector,
131 promise.Pass(), true /* granted */);
132 return true;
133 }
134
135 #if defined(OS_CHROMEOS)
136 media_permission_->RequestPermission(
ddorwin 2015/03/12 03:58:12 External Clear Key will now prompt. I guess that's
xhwang 2015/03/12 17:35:27 Actually External Clear Key browser tests fail now
137 MediaPermission::PROTECTED_MEDIA_IDENTIFIER, security_origin_,
138 base::Bind(&ProxyDecryptor::OnPermissionStatus,
139 weak_ptr_factory_.GetWeakPtr(), session_type, init_data_type,
140 init_data_vector, base::Passed(&promise)));
141 #else
142 // TODO(xhwang): Fix the Android path by requesting permission for key systems
143 // that don't use AesDecryptor.
ddorwin 2015/03/12 03:58:12 Bug? Deadline?
xhwang 2015/03/12 17:35:27 I'll do it right after this CL. Just don't want to
144 OnPermissionStatus(session_type, init_data_type, init_data_vector,
145 promise.Pass(), true /* granted */);
146 #endif
147
148 return true;
149 }
150
151 void ProxyDecryptor::OnPermissionStatus(
152 MediaKeys::SessionType session_type,
153 const std::string& init_data_type,
154 const std::vector<uint8>& init_data,
155 scoped_ptr<NewSessionCdmPromise> promise,
156 bool granted) {
157 DVLOG_IF(1, !granted) << "Permission request rejected.";
158
159 const uint8* init_data_vector_data =
160 (init_data.size() > 0) ? &init_data[0] : nullptr;
161
123 media_keys_->CreateSessionAndGenerateRequest( 162 media_keys_->CreateSessionAndGenerateRequest(
124 session_type, init_data_type, init_data_vector_data, 163 session_type, init_data_type, init_data_vector_data, init_data.size(),
125 init_data_vector.size(), promise.Pass()); 164 promise.Pass());
126 return true;
127 } 165 }
128 166
129 void ProxyDecryptor::AddKey(const uint8* key, 167 void ProxyDecryptor::AddKey(const uint8* key,
130 int key_length, 168 int key_length,
131 const uint8* init_data, 169 const uint8* init_data,
132 int init_data_length, 170 int init_data_length,
133 const std::string& session_id) { 171 const std::string& session_id) {
134 DVLOG(1) << "AddKey()"; 172 DVLOG(1) << "AddKey()";
135 173
136 // In the prefixed API, the session parameter provided to addKey() is 174 // 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 = 334 bool is_persistent =
297 session_type == PersistentSession || session_type == LoadSession; 335 session_type == PersistentSession || session_type == LoadSession;
298 active_sessions_.insert(std::make_pair(session_id, is_persistent)); 336 active_sessions_.insert(std::make_pair(session_id, is_persistent));
299 337
300 // For LoadSession(), generate the KeyAdded event. 338 // For LoadSession(), generate the KeyAdded event.
301 if (session_type == LoadSession) 339 if (session_type == LoadSession)
302 GenerateKeyAdded(session_id); 340 GenerateKeyAdded(session_id);
303 } 341 }
304 342
305 } // namespace media 343 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698