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

Side by Side Diff: webkit/media/crypto/ppapi/cdm_wrapper.cc

Issue 10909068: Fix resource leaks in CDM implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Same patchset as number 8, hopefully this one is viewable... Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cstring> // For memcpy. 5 #include <cstring> // For memcpy.
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/compiler_specific.h" // For OVERRIDE. 8 #include "base/compiler_specific.h" // For OVERRIDE.
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/pp_stdint.h" 10 #include "ppapi/c/pp_stdint.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; 83 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
84 virtual bool DecryptAndDecode( 84 virtual bool DecryptAndDecode(
85 pp::Buffer_Dev encrypted_buffer, 85 pp::Buffer_Dev encrypted_buffer,
86 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; 86 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE;
87 87
88 private: 88 private:
89 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the 89 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the
90 // buffer resource, and returns it. Returns a an invalid PP_Resource with an 90 // buffer resource, and returns it. Returns a an invalid PP_Resource with an
91 // ID of 0 on failure. Upon success, the returned Buffer resource has a 91 // ID of 0 on failure. Upon success, the returned Buffer resource has a
92 // reference count of 1. 92 // reference count of 1.
93 PP_Resource MakeBufferResource(const uint8_t* data, uint32_t data_size); 93 pp::Resource MakeBufferResource(const uint8_t* data, uint32_t data_size);
94 94
95 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to 95 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to
96 // <code>callback_factory_</code> to ensure that calls into 96 // <code>callback_factory_</code> to ensure that calls into
97 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. 97 // <code>PPP_ContentDecryptor_Private</code> are asynchronous.
98 void KeyAdded(int32_t result, const std::string& session_id); 98 void KeyAdded(int32_t result, const std::string& session_id);
99 void KeyMessage(int32_t result, cdm::KeyMessage& key_message); 99 void KeyMessage(int32_t result, cdm::KeyMessage& key_message);
100 void KeyError(int32_t result, const std::string& session_id); 100 void KeyError(int32_t result, const std::string& session_id);
101 void DeliverBlock(int32_t result, 101 void DeliverBlock(int32_t result,
102 const cdm::Status& status, 102 const cdm::Status& status,
103 cdm::OutputBuffer& output_buffer, 103 cdm::OutputBuffer& output_buffer,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp; 226 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp;
227 227
228 cdm::OutputBuffer output_buffer; 228 cdm::OutputBuffer output_buffer;
229 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer); 229 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer);
230 230
231 CallOnMain(callback_factory_.NewCallback( 231 CallOnMain(callback_factory_.NewCallback(
232 &CdmWrapper::DeliverBlock, 232 &CdmWrapper::DeliverBlock,
233 status, 233 status,
234 output_buffer, 234 output_buffer,
235 encrypted_block_info.tracking_info)); 235 encrypted_block_info.tracking_info));
236
237 return true; 236 return true;
238 } 237 }
239 238
240 bool CdmWrapper::DecryptAndDecode( 239 bool CdmWrapper::DecryptAndDecode(
241 pp::Buffer_Dev encrypted_buffer, 240 pp::Buffer_Dev encrypted_buffer,
242 const PP_EncryptedBlockInfo& encrypted_block_info) { 241 const PP_EncryptedBlockInfo& encrypted_block_info) {
243 return false; 242 return false;
244 } 243 }
245 244
246 PP_Resource CdmWrapper::MakeBufferResource(const uint8_t* data, 245 pp::Resource CdmWrapper::MakeBufferResource(const uint8_t* data,
247 uint32_t data_size) { 246 uint32_t data_size) {
248 if (!data || !data_size) 247 if (!data || !data_size)
249 return 0; 248 return pp::Resource();
250 249
251 pp::Buffer_Dev buffer(this, data_size); 250 pp::Buffer_Dev buffer(this, data_size);
252 if (!buffer.data()) 251 if (!buffer.data())
253 return 0; 252 return pp::Resource();
254 253
255 memcpy(buffer.data(), data, data_size); 254 memcpy(buffer.data(), data, data_size);
256 255 return buffer;
257 return buffer.detach();
258 } 256 }
259 257
260 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) { 258 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) {
261 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id); 259 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id);
262 } 260 }
263 261
264 void CdmWrapper::KeyMessage(int32_t result, 262 void CdmWrapper::KeyMessage(int32_t result,
265 cdm::KeyMessage& key_message) { 263 cdm::KeyMessage& key_message) {
266 pp::Buffer_Dev message_buffer(MakeBufferResource(key_message.message, 264 pp::Buffer_Dev message_buffer(
267 key_message.message_size)); 265 MakeBufferResource(key_message.message,
266 key_message.message_size).pp_resource());
dmichael (off chromium) 2012/09/06 02:46:52 Don't call pp_resource; just use the copy construc
Tom Finegan 2012/09/06 04:01:02 Done.
268 pp::ContentDecryptor_Private::KeyMessage( 267 pp::ContentDecryptor_Private::KeyMessage(
269 key_system_, 268 key_system_,
270 std::string(key_message.session_id, key_message.session_id_size), 269 std::string(key_message.session_id, key_message.session_id_size),
271 message_buffer, 270 message_buffer,
272 std::string(key_message.default_url, key_message.default_url_size)); 271 std::string(key_message.default_url, key_message.default_url_size));
273 272
274 // TODO(xhwang): Fix this. This is not always safe as the memory is allocated 273 // TODO(xhwang): Fix this. This is not always safe as the memory is allocated
275 // in another shared object. 274 // in another shared object.
276 delete [] key_message.session_id; 275 delete [] key_message.session_id;
277 key_message.session_id = NULL; 276 key_message.session_id = NULL;
278 delete [] key_message.message; 277 delete [] key_message.message;
279 key_message.message = NULL; 278 key_message.message = NULL;
280 delete [] key_message.default_url; 279 delete [] key_message.default_url;
281 key_message.default_url = NULL; 280 key_message.default_url = NULL;
282 } 281 }
283 282
284 // TODO(xhwang): Support MediaKeyError (see spec: http://goo.gl/rbdnR) in CDM 283 // TODO(xhwang): Support MediaKeyError (see spec: http://goo.gl/rbdnR) in CDM
285 // interface and in this function. 284 // interface and in this function.
286 void CdmWrapper::KeyError(int32_t result, const std::string& session_id) { 285 void CdmWrapper::KeyError(int32_t result, const std::string& session_id) {
287 pp::ContentDecryptor_Private::KeyError(key_system_, 286 pp::ContentDecryptor_Private::KeyError(key_system_,
288 session_id, 287 session_id,
289 kUnknownError, 288 kUnknownError,
290 0); 289 0);
291 } 290 }
292 291
293 void CdmWrapper::DeliverBlock(int32_t result, 292 void CdmWrapper::DeliverBlock(int32_t result,
294 const cdm::Status& status, 293 const cdm::Status& status,
295 cdm::OutputBuffer& output_buffer, 294 cdm::OutputBuffer& output_buffer,
296 const PP_DecryptTrackingInfo& tracking_info) { 295 const PP_DecryptTrackingInfo& tracking_info) {
297 pp::Buffer_Dev decrypted_buffer(MakeBufferResource(output_buffer.data, 296 pp::Buffer_Dev decrypted_buffer(
298 output_buffer.data_size)); 297 MakeBufferResource(output_buffer.data,
298 output_buffer.data_size).pp_resource());
dmichael (off chromium) 2012/09/06 02:46:52 ditto
Tom Finegan 2012/09/06 04:01:02 Done.
299 299
300 PP_DecryptedBlockInfo decrypted_block_info; 300 PP_DecryptedBlockInfo decrypted_block_info;
301 decrypted_block_info.tracking_info.request_id = tracking_info.request_id; 301 decrypted_block_info.tracking_info.request_id = tracking_info.request_id;
302 decrypted_block_info.tracking_info.timestamp = output_buffer.timestamp; 302 decrypted_block_info.tracking_info.timestamp = output_buffer.timestamp;
303 303
304 switch (status) { 304 switch (status) {
305 case cdm::kSuccess: 305 case cdm::kSuccess:
306 decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS; 306 decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS;
307 break; 307 break;
308 case cdm::kErrorNoKey: 308 case cdm::kErrorNoKey:
(...skipping 27 matching lines...) Expand all
336 } // namespace webkit_media 336 } // namespace webkit_media
337 337
338 namespace pp { 338 namespace pp {
339 339
340 // Factory function for your specialization of the Module object. 340 // Factory function for your specialization of the Module object.
341 Module* CreateModule() { 341 Module* CreateModule() {
342 return new webkit_media::MyModule(); 342 return new webkit_media::MyModule();
343 } 343 }
344 344
345 } // namespace pp 345 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_content_decryptor_private_proxy.cc ('k') | webkit/plugins/ppapi/ppapi_plugin_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698