OLD | NEW |
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 "ppapi/proxy/ppb_image_data_proxy.h" | 5 #include "ppapi/proxy/ppb_image_data_proxy.h" |
6 | 6 |
7 #include <string.h> // For memcpy | 7 #include <string.h> // For memcpy |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 // We serialize the PP_ImageDataDesc just by copying to a string. | 485 // We serialize the PP_ImageDataDesc just by copying to a string. |
486 PP_ImageDataDesc desc; | 486 PP_ImageDataDesc desc; |
487 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); | 487 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); |
488 | 488 |
489 return (new ImageData(result, desc, image_handle))->GetReference(); | 489 return (new ImageData(result, desc, image_handle))->GetReference(); |
490 } | 490 } |
491 | 491 |
492 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { | 492 bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { |
493 bool handled = true; | 493 bool handled = true; |
494 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) | 494 IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) |
| 495 #if !defined(OS_NACL) |
495 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate) | 496 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate) |
496 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateNaCl, | 497 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateNaCl, |
497 OnHostMsgCreateNaCl) | 498 OnHostMsgCreateNaCl) |
498 | 499 #endif |
499 IPC_MESSAGE_HANDLER(PpapiMsg_PPBImageData_NotifyUnusedImageData, | 500 IPC_MESSAGE_HANDLER(PpapiMsg_PPBImageData_NotifyUnusedImageData, |
500 OnPluginMsgNotifyUnusedImageData) | 501 OnPluginMsgNotifyUnusedImageData) |
501 | 502 |
502 IPC_MESSAGE_UNHANDLED(handled = false) | 503 IPC_MESSAGE_UNHANDLED(handled = false) |
503 IPC_END_MESSAGE_MAP() | 504 IPC_END_MESSAGE_MAP() |
504 return handled; | 505 return handled; |
505 } | 506 } |
506 | 507 |
| 508 #if !defined(OS_NACL) |
507 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, | 509 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, |
508 int32_t format, | 510 int32_t format, |
509 const PP_Size& size, | 511 const PP_Size& size, |
510 PP_Bool init_to_zero, | 512 PP_Bool init_to_zero, |
511 HostResource* result, | 513 HostResource* result, |
512 std::string* image_data_desc, | 514 std::string* image_data_desc, |
513 ImageHandle* result_image_handle) { | 515 ImageHandle* result_image_handle) { |
514 #if defined(OS_NACL) | |
515 // This message should never be received in untrusted code. To minimize the | |
516 // size of the IRT, we just don't handle it. | |
517 return; | |
518 #else | |
519 *result_image_handle = ImageData::NullHandle(); | 516 *result_image_handle = ImageData::NullHandle(); |
520 | 517 |
521 thunk::EnterResourceCreation enter(instance); | 518 thunk::EnterResourceCreation enter(instance); |
522 if (enter.failed()) | 519 if (enter.failed()) |
523 return; | 520 return; |
524 | 521 |
525 PP_Resource resource = enter.functions()->CreateImageData( | 522 PP_Resource resource = enter.functions()->CreateImageData( |
526 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); | 523 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); |
527 if (!resource) | 524 if (!resource) |
528 return; | 525 return; |
(...skipping 11 matching lines...) Expand all Loading... |
540 uint32_t byte_count = 0; | 537 uint32_t byte_count = 0; |
541 int32_t handle = 0; | 538 int32_t handle = 0; |
542 if (enter_resource.object()->GetSharedMemory(&handle, &byte_count) == PP_OK) { | 539 if (enter_resource.object()->GetSharedMemory(&handle, &byte_count) == PP_OK) { |
543 #if defined(OS_WIN) | 540 #if defined(OS_WIN) |
544 ImageHandle ih = ImageData::HandleFromInt(handle); | 541 ImageHandle ih = ImageData::HandleFromInt(handle); |
545 *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false); | 542 *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false); |
546 #else | 543 #else |
547 *result_image_handle = ImageData::HandleFromInt(handle); | 544 *result_image_handle = ImageData::HandleFromInt(handle); |
548 #endif // defined(OS_WIN) | 545 #endif // defined(OS_WIN) |
549 } | 546 } |
550 #endif // defined(OS_NACL) | |
551 } | 547 } |
552 | 548 |
553 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( | 549 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( |
554 PP_Instance instance, | 550 PP_Instance instance, |
555 int32_t format, | 551 int32_t format, |
556 const PP_Size& size, | 552 const PP_Size& size, |
557 PP_Bool init_to_zero, | 553 PP_Bool init_to_zero, |
558 HostResource* result, | 554 HostResource* result, |
559 std::string* image_data_desc, | 555 std::string* image_data_desc, |
560 ppapi::proxy::SerializedHandle* result_image_handle) { | 556 ppapi::proxy::SerializedHandle* result_image_handle) { |
561 #if defined(OS_NACL) | |
562 // This message should never be received in untrusted code. To minimize the | |
563 // size of the IRT, we just don't handle it. | |
564 return; | |
565 #else | |
566 result_image_handle->set_null_shmem(); | 557 result_image_handle->set_null_shmem(); |
567 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 558 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
568 if (!dispatcher) | 559 if (!dispatcher) |
569 return; | 560 return; |
570 | 561 |
571 thunk::EnterResourceCreation enter(instance); | 562 thunk::EnterResourceCreation enter(instance); |
572 if (enter.failed()) | 563 if (enter.failed()) |
573 return; | 564 return; |
574 | 565 |
575 PP_Resource resource = enter.functions()->CreateImageDataNaCl( | 566 PP_Resource resource = enter.functions()->CreateImageDataNaCl( |
(...skipping 21 matching lines...) Expand all Loading... |
597 #if defined(OS_WIN) | 588 #if defined(OS_WIN) |
598 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); | 589 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); |
599 #elif defined(OS_POSIX) | 590 #elif defined(OS_POSIX) |
600 local_fd; | 591 local_fd; |
601 #else | 592 #else |
602 #error Not implemented. | 593 #error Not implemented. |
603 #endif // defined(OS_WIN) | 594 #endif // defined(OS_WIN) |
604 result_image_handle->set_shmem( | 595 result_image_handle->set_shmem( |
605 dispatcher->ShareHandleWithRemote(platform_file, false), | 596 dispatcher->ShareHandleWithRemote(platform_file, false), |
606 byte_count); | 597 byte_count); |
607 #endif // defined(OS_NACL) | |
608 } | 598 } |
| 599 #endif // !defined(OS_NACL) |
609 | 600 |
610 void PPB_ImageData_Proxy::OnPluginMsgNotifyUnusedImageData( | 601 void PPB_ImageData_Proxy::OnPluginMsgNotifyUnusedImageData( |
611 const HostResource& old_image_data) { | 602 const HostResource& old_image_data) { |
612 PluginGlobals* plugin_globals = PluginGlobals::Get(); | 603 PluginGlobals* plugin_globals = PluginGlobals::Get(); |
613 if (!plugin_globals) | 604 if (!plugin_globals) |
614 return; // This may happen if the plugin is maliciously sending this | 605 return; // This may happen if the plugin is maliciously sending this |
615 // message to the renderer. | 606 // message to the renderer. |
616 | 607 |
617 EnterPluginFromHostResource<PPB_ImageData_API> enter(old_image_data); | 608 EnterPluginFromHostResource<PPB_ImageData_API> enter(old_image_data); |
618 if (enter.succeeded()) { | 609 if (enter.succeeded()) { |
619 ImageData* image_data = static_cast<ImageData*>(enter.object()); | 610 ImageData* image_data = static_cast<ImageData*>(enter.object()); |
620 ImageDataCache::GetInstance()->ImageDataUsable(image_data); | 611 ImageDataCache::GetInstance()->ImageDataUsable(image_data); |
621 } | 612 } |
622 | 613 |
623 // The renderer sent us a reference with the message. If the image data was | 614 // The renderer sent us a reference with the message. If the image data was |
624 // still cached in our process, the proxy still holds a reference so we can | 615 // still cached in our process, the proxy still holds a reference so we can |
625 // remove the one the renderer just sent is. If the proxy no longer holds a | 616 // remove the one the renderer just sent is. If the proxy no longer holds a |
626 // reference, we released everything and we should also release the one the | 617 // reference, we released everything and we should also release the one the |
627 // renderer just sent us. | 618 // renderer just sent us. |
628 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 619 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
629 API_ID_PPB_CORE, old_image_data)); | 620 API_ID_PPB_CORE, old_image_data)); |
630 } | 621 } |
631 | 622 |
632 } // namespace proxy | 623 } // namespace proxy |
633 } // namespace ppapi | 624 } // namespace ppapi |
OLD | NEW |