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 #include "content/renderer/media/crypto/proxy_decryptor.h" | 5 #include "content/renderer/media/crypto/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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 std::equal(data, data + header.size(), header.begin()); | 95 std::equal(data, data + header.size(), header.begin()); |
96 } | 96 } |
97 | 97 |
98 bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type, | 98 bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type, |
99 const uint8* init_data, | 99 const uint8* init_data, |
100 int init_data_length) { | 100 int init_data_length) { |
101 DVLOG(1) << "GenerateKeyRequest()"; | 101 DVLOG(1) << "GenerateKeyRequest()"; |
102 const char kPrefixedApiPersistentSessionHeader[] = "PERSISTENT|"; | 102 const char kPrefixedApiPersistentSessionHeader[] = "PERSISTENT|"; |
103 const char kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; | 103 const char kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; |
104 | 104 |
105 bool loadSession = | 105 bool is_load_session = |
106 HasHeader(init_data, init_data_length, kPrefixedApiLoadSessionHeader); | 106 HasHeader(init_data, init_data_length, kPrefixedApiLoadSessionHeader); |
107 bool persistent = HasHeader( | 107 bool is_create_persistent = HasHeader( |
108 init_data, init_data_length, kPrefixedApiPersistentSessionHeader); | 108 init_data, init_data_length, kPrefixedApiPersistentSessionHeader); |
109 | 109 |
110 scoped_ptr<media::NewSessionCdmPromise> promise( | 110 scoped_ptr<media::NewSessionCdmPromise> promise( |
111 new media::NewSessionCdmPromise( | 111 new media::NewSessionCdmPromise( |
112 base::Bind(&ProxyDecryptor::SetSessionId, | 112 base::Bind(&ProxyDecryptor::SetSessionId, |
113 weak_ptr_factory_.GetWeakPtr(), | 113 weak_ptr_factory_.GetWeakPtr(), |
114 persistent || loadSession), | 114 is_create_persistent, |
115 is_load_session), | |
115 base::Bind(&ProxyDecryptor::OnSessionError, | 116 base::Bind(&ProxyDecryptor::OnSessionError, |
116 weak_ptr_factory_.GetWeakPtr(), | 117 weak_ptr_factory_.GetWeakPtr(), |
117 std::string()))); // No session id until created. | 118 std::string()))); // No session id until created. |
118 | 119 |
119 if (loadSession) { | 120 if (is_load_session) { |
120 media_keys_->LoadSession( | 121 media_keys_->LoadSession( |
121 std::string(reinterpret_cast<const char*>( | 122 std::string(reinterpret_cast<const char*>( |
122 init_data + strlen(kPrefixedApiLoadSessionHeader)), | 123 init_data + strlen(kPrefixedApiLoadSessionHeader)), |
123 init_data_length - strlen(kPrefixedApiLoadSessionHeader)), | 124 init_data_length - strlen(kPrefixedApiLoadSessionHeader)), |
124 promise.Pass()); | 125 promise.Pass()); |
125 return true; | 126 return true; |
126 } | 127 } |
127 | 128 |
128 media::MediaKeys::SessionType session_type = | 129 media::MediaKeys::SessionType session_type = |
129 persistent ? media::MediaKeys::PERSISTENT_SESSION | 130 is_create_persistent ? media::MediaKeys::PERSISTENT_SESSION |
130 : media::MediaKeys::TEMPORARY_SESSION; | 131 : media::MediaKeys::TEMPORARY_SESSION; |
131 media_keys_->CreateSession( | 132 media_keys_->CreateSession( |
132 content_type, init_data, init_data_length, session_type, promise.Pass()); | 133 content_type, init_data, init_data_length, session_type, promise.Pass()); |
133 return true; | 134 return true; |
134 } | 135 } |
135 | 136 |
136 void ProxyDecryptor::AddKey(const uint8* key, | 137 void ProxyDecryptor::AddKey(const uint8* key, |
137 int key_length, | 138 int key_length, |
138 const uint8* init_data, | 139 const uint8* init_data, |
139 int init_data_length, | 140 int init_data_length, |
140 const std::string& web_session_id) { | 141 const std::string& web_session_id) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 break; | 280 break; |
280 default: | 281 default: |
281 // This will include all other CDM4 errors and any error generated | 282 // This will include all other CDM4 errors and any error generated |
282 // by CDM5 or later. | 283 // by CDM5 or later. |
283 error_code = media::MediaKeys::kUnknownError; | 284 error_code = media::MediaKeys::kUnknownError; |
284 break; | 285 break; |
285 } | 286 } |
286 key_error_cb_.Run(web_session_id, error_code, system_code); | 287 key_error_cb_.Run(web_session_id, error_code, system_code); |
287 } | 288 } |
288 | 289 |
289 void ProxyDecryptor::SetSessionId(bool persistent, | 290 void ProxyDecryptor::SetSessionId(bool is_new_persistent_session, |
291 bool is_loaded_session, | |
290 const std::string& web_session_id) { | 292 const std::string& web_session_id) { |
293 // Loaded sessions are considered persistent. | |
294 bool persistent = is_new_persistent_session || is_loaded_session; | |
ddorwin
2014/08/11 20:34:15
is_
jrummell
2014/08/13 21:18:06
Done.
| |
291 active_sessions_.insert(std::make_pair(web_session_id, persistent)); | 295 active_sessions_.insert(std::make_pair(web_session_id, persistent)); |
296 | |
297 // For LoadSession(), generate the SessionReady event. | |
298 if (is_loaded_session) | |
299 OnSessionReady(web_session_id); | |
292 } | 300 } |
293 | 301 |
294 } // namespace content | 302 } // namespace content |
OLD | NEW |