OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/renderer/pepper/pepper_image_capture_host.h" |
| 6 |
| 7 #include "content/renderer/pepper/pepper_platform_image_capture.h" |
| 8 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| 9 #include "content/renderer/render_frame_impl.h" |
| 10 #include "ppapi/host/dispatch_host_message.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 PepperImageCaptureHost::PepperImageCaptureHost(RendererPpapiHostImpl* host, |
| 16 PP_Instance instance, |
| 17 PP_Resource resource) |
| 18 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 19 renderer_ppapi_host_(host) { |
| 20 } |
| 21 |
| 22 PepperImageCaptureHost::~PepperImageCaptureHost() { |
| 23 DetachPlatformImageCapture(); |
| 24 } |
| 25 |
| 26 bool PepperImageCaptureHost::Init() { |
| 27 return !!renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
| 28 } |
| 29 |
| 30 int32_t PepperImageCaptureHost::OnResourceMessageReceived( |
| 31 const IPC::Message& msg, |
| 32 ppapi::host::HostMessageContext* context) { |
| 33 int32_t result = PP_ERROR_FAILED; |
| 34 |
| 35 PPAPI_BEGIN_MESSAGE_MAP(PepperImageCaptureHost, msg) |
| 36 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_ImageCapture_Open, OnOpen) |
| 37 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| 38 PpapiHostMsg_ImageCapture_GetSupportedPreviewSizes, |
| 39 OnGetSupportedPreviewSizes) |
| 40 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, |
| 41 OnClose) |
| 42 PPAPI_END_MESSAGE_MAP() |
| 43 return result; |
| 44 } |
| 45 |
| 46 void PepperImageCaptureHost::OnInitialized(bool succeeded) { |
| 47 if (!open_reply_context_.is_valid()) |
| 48 return; |
| 49 |
| 50 if (succeeded) { |
| 51 open_reply_context_.params.set_result(PP_OK); |
| 52 } else { |
| 53 DetachPlatformImageCapture(); |
| 54 open_reply_context_.params.set_result(PP_ERROR_FAILED); |
| 55 } |
| 56 |
| 57 host()->SendReply(open_reply_context_, |
| 58 PpapiPluginMsg_ImageCapture_OpenReply()); |
| 59 open_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 60 } |
| 61 |
| 62 void PepperImageCaptureHost::OnPreviewSizesEnumerated( |
| 63 const std::vector<PP_Size>& sizes) { |
| 64 if (!preview_sizes_reply_context_.is_valid()) |
| 65 return; |
| 66 |
| 67 if (sizes.size() > 0) |
| 68 preview_sizes_reply_context_.params.set_result(PP_OK); |
| 69 else |
| 70 preview_sizes_reply_context_.params.set_result(PP_ERROR_FAILED); |
| 71 host()->SendReply( |
| 72 preview_sizes_reply_context_, |
| 73 PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply(sizes)); |
| 74 preview_sizes_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 75 } |
| 76 |
| 77 int32_t PepperImageCaptureHost::OnOpen(ppapi::host::HostMessageContext* context, |
| 78 const std::string& device_id) { |
| 79 if (open_reply_context_.is_valid()) |
| 80 return PP_ERROR_INPROGRESS; |
| 81 |
| 82 if (platform_image_capture_.get()) |
| 83 return PP_ERROR_FAILED; |
| 84 |
| 85 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); |
| 86 if (!document_url.is_valid()) |
| 87 return PP_ERROR_FAILED; |
| 88 |
| 89 platform_image_capture_.reset(new PepperPlatformImageCapture( |
| 90 renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance()) |
| 91 ->GetRoutingID(), |
| 92 device_id, document_url, this)); |
| 93 |
| 94 open_reply_context_ = context->MakeReplyMessageContext(); |
| 95 |
| 96 return PP_OK_COMPLETIONPENDING; |
| 97 } |
| 98 |
| 99 int32_t PepperImageCaptureHost::OnClose( |
| 100 ppapi::host::HostMessageContext* context) { |
| 101 DetachPlatformImageCapture(); |
| 102 return PP_OK; |
| 103 } |
| 104 |
| 105 int32_t PepperImageCaptureHost::OnGetSupportedPreviewSizes( |
| 106 ppapi::host::HostMessageContext* context) { |
| 107 if (preview_sizes_reply_context_.is_valid()) |
| 108 return PP_ERROR_INPROGRESS; |
| 109 if (!platform_image_capture_) |
| 110 return PP_ERROR_FAILED; |
| 111 |
| 112 preview_sizes_reply_context_ = context->MakeReplyMessageContext(); |
| 113 platform_image_capture_->GetPreviewSizes(); |
| 114 |
| 115 return PP_OK_COMPLETIONPENDING; |
| 116 } |
| 117 |
| 118 void PepperImageCaptureHost::DetachPlatformImageCapture() { |
| 119 if (platform_image_capture_) { |
| 120 platform_image_capture_->DetachEventHandler(); |
| 121 platform_image_capture_.reset(); |
| 122 } |
| 123 } |
| 124 |
| 125 } // namespace content |
OLD | NEW |