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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 DCHECK(!media_keys_); | 76 DCHECK(!media_keys_); |
77 media_keys_ = CreateMediaKeys(key_system, frame_url); | 77 media_keys_ = CreateMediaKeys(key_system, frame_url); |
78 if (!media_keys_) | 78 if (!media_keys_) |
79 return false; | 79 return false; |
80 | 80 |
81 is_clear_key_ = | 81 is_clear_key_ = |
82 media::IsClearKey(key_system) || media::IsExternalClearKey(key_system); | 82 media::IsClearKey(key_system) || media::IsExternalClearKey(key_system); |
83 return true; | 83 return true; |
84 } | 84 } |
85 | 85 |
86 bool ProxyDecryptor::GenerateKeyRequest(const std::string& type, | 86 bool ProxyDecryptor::GenerateKeyRequest(const std::string& content_type, |
87 const uint8* init_data, | 87 const uint8* init_data, |
88 int init_data_length) { | 88 int init_data_length) { |
89 // Use a unique reference id for this request. | 89 // Use a unique reference id for this request. |
90 uint32 session_id = next_session_id_++; | 90 uint32 session_id = next_session_id_++; |
91 if (!media_keys_->CreateSession( | 91 |
92 session_id, type, init_data, init_data_length)) { | 92 const uint8 kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; |
93 return false; | 93 const int kPrefixedApiLoadSessionHeaderLength = |
| 94 sizeof(kPrefixedApiLoadSessionHeader) - 1; |
| 95 |
| 96 if (init_data_length > kPrefixedApiLoadSessionHeaderLength && |
| 97 std::equal(init_data, |
| 98 init_data + kPrefixedApiLoadSessionHeaderLength, |
| 99 kPrefixedApiLoadSessionHeader)) { |
| 100 // TODO(xhwang): Track loadable session to handle OnSessionClosed(). |
| 101 // See: http://crbug.com/340859. |
| 102 media_keys_->LoadSession( |
| 103 session_id, |
| 104 std::string(reinterpret_cast<const char*>( |
| 105 init_data + kPrefixedApiLoadSessionHeaderLength), |
| 106 init_data_length - kPrefixedApiLoadSessionHeaderLength)); |
| 107 return true; |
94 } | 108 } |
95 | 109 |
96 return true; | 110 return media_keys_->CreateSession( |
| 111 session_id, content_type, init_data, init_data_length); |
97 } | 112 } |
98 | 113 |
99 void ProxyDecryptor::AddKey(const uint8* key, | 114 void ProxyDecryptor::AddKey(const uint8* key, |
100 int key_length, | 115 int key_length, |
101 const uint8* init_data, | 116 const uint8* init_data, |
102 int init_data_length, | 117 int init_data_length, |
103 const std::string& web_session_id) { | 118 const std::string& web_session_id) { |
104 DVLOG(1) << "AddKey()"; | 119 DVLOG(1) << "AddKey()"; |
105 | 120 |
106 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. | 121 // WebMediaPlayerImpl ensures GenerateKeyRequest() has been called. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 246 |
232 const std::string& ProxyDecryptor::LookupWebSessionId(uint32 session_id) { | 247 const std::string& ProxyDecryptor::LookupWebSessionId(uint32 session_id) { |
233 DCHECK_NE(session_id, kInvalidSessionId); | 248 DCHECK_NE(session_id, kInvalidSessionId); |
234 | 249 |
235 // Session may not exist if error happens during GenerateKeyRequest(). | 250 // Session may not exist if error happens during GenerateKeyRequest(). |
236 SessionIdMap::iterator it = sessions_.find(session_id); | 251 SessionIdMap::iterator it = sessions_.find(session_id); |
237 return (it != sessions_.end()) ? it->second : base::EmptyString(); | 252 return (it != sessions_.end()) ? it->second : base::EmptyString(); |
238 } | 253 } |
239 | 254 |
240 } // namespace content | 255 } // namespace content |
OLD | NEW |