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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return true; | 88 return true; |
89 } | 89 } |
90 | 90 |
91 // Returns true if |data| is prefixed with |header| and has data after the | 91 // Returns true if |data| is prefixed with |header| and has data after the |
92 // |header|. | 92 // |header|. |
93 bool HasHeader(const uint8* data, int data_length, const std::string& header) { | 93 bool HasHeader(const uint8* data, int data_length, const std::string& header) { |
94 return static_cast<size_t>(data_length) > header.size() && | 94 return static_cast<size_t>(data_length) > header.size() && |
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& init_data_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 SessionCreationType session_creation_type = TemporarySession; | 105 SessionCreationType session_creation_type = TemporarySession; |
106 if (HasHeader(init_data, init_data_length, kPrefixedApiLoadSessionHeader)) { | 106 if (HasHeader(init_data, init_data_length, kPrefixedApiLoadSessionHeader)) { |
107 session_creation_type = LoadSession; | 107 session_creation_type = LoadSession; |
108 } else if (HasHeader(init_data, | 108 } else if (HasHeader(init_data, |
(...skipping 18 matching lines...) Expand all Loading... |
127 init_data_length - strlen(kPrefixedApiLoadSessionHeader)), | 127 init_data_length - strlen(kPrefixedApiLoadSessionHeader)), |
128 promise.Pass()); | 128 promise.Pass()); |
129 return true; | 129 return true; |
130 } | 130 } |
131 | 131 |
132 media::MediaKeys::SessionType session_type = | 132 media::MediaKeys::SessionType session_type = |
133 session_creation_type == PersistentSession | 133 session_creation_type == PersistentSession |
134 ? media::MediaKeys::PERSISTENT_SESSION | 134 ? media::MediaKeys::PERSISTENT_SESSION |
135 : media::MediaKeys::TEMPORARY_SESSION; | 135 : media::MediaKeys::TEMPORARY_SESSION; |
136 | 136 |
| 137 // Convert MIME types used in the prefixed implementation. |
| 138 std::string init_data_type; |
| 139 if (content_type == "audio/mp4" || content_type == "video/mp4") { |
| 140 init_data_type = "cenc"; |
| 141 } else if (content_type == "audio/webm" || content_type == "video/webm") { |
| 142 init_data_type = "webm"; |
| 143 } else { |
| 144 NOTREACHED(); |
| 145 init_data_type = content_type; |
| 146 } |
| 147 |
137 media_keys_->CreateSession(init_data_type, init_data, init_data_length, | 148 media_keys_->CreateSession(init_data_type, init_data, init_data_length, |
138 session_type, promise.Pass()); | 149 session_type, promise.Pass()); |
139 return true; | 150 return true; |
140 } | 151 } |
141 | 152 |
142 void ProxyDecryptor::AddKey(const uint8* key, | 153 void ProxyDecryptor::AddKey(const uint8* key, |
143 int key_length, | 154 int key_length, |
144 const uint8* init_data, | 155 const uint8* init_data, |
145 int init_data_length, | 156 int init_data_length, |
146 const std::string& web_session_id) { | 157 const std::string& web_session_id) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 bool is_persistent = | 335 bool is_persistent = |
325 session_type == PersistentSession || session_type == LoadSession; | 336 session_type == PersistentSession || session_type == LoadSession; |
326 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); | 337 active_sessions_.insert(std::make_pair(web_session_id, is_persistent)); |
327 | 338 |
328 // For LoadSession(), generate the SessionReady event. | 339 // For LoadSession(), generate the SessionReady event. |
329 if (session_type == LoadSession) | 340 if (session_type == LoadSession) |
330 OnSessionReady(web_session_id); | 341 OnSessionReady(web_session_id); |
331 } | 342 } |
332 | 343 |
333 } // namespace content | 344 } // namespace content |
OLD | NEW |