OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 Close(); |
| 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(PpapiHostMsg_ImageCapture_Close, |
| 38 OnClose) |
| 39 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| 40 PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes, OnGetPreviewSizes) |
| 41 PPAPI_END_MESSAGE_MAP() |
| 42 return result; |
| 43 } |
| 44 |
| 45 void PepperImageCaptureHost::OnInitialized(bool succeeded) { |
| 46 if (!open_reply_context_.is_valid()) |
| 47 return; |
| 48 |
| 49 if (succeeded) { |
| 50 open_reply_context_.params.set_result(PP_OK); |
| 51 } else { |
| 52 DetachPlatformImageCapture(); |
| 53 open_reply_context_.params.set_result(PP_ERROR_FAILED); |
| 54 } |
| 55 |
| 56 host()->SendReply(open_reply_context_, |
| 57 PpapiPluginMsg_ImageCapture_OpenReply()); |
| 58 open_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 59 } |
| 60 |
| 61 void PepperImageCaptureHost::OnPlatformPreviewSizesEnumerated( |
| 62 const std::vector<PP_Size>& sizes) { |
| 63 if (!preview_sizes_reply_context_.is_valid()) |
| 64 return; |
| 65 |
| 66 if (sizes.size() > 0) |
| 67 preview_sizes_reply_context_.params.set_result(PP_OK); |
| 68 else |
| 69 preview_sizes_reply_context_.params.set_result(PP_ERROR_FAILED); |
| 70 host()->SendReply( |
| 71 preview_sizes_reply_context_, |
| 72 PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply(sizes)); |
| 73 preview_sizes_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 74 } |
| 75 |
| 76 int32_t PepperImageCaptureHost::OnOpen(ppapi::host::HostMessageContext* context, |
| 77 const std::string& device_id) { |
| 78 if (open_reply_context_.is_valid()) |
| 79 return PP_ERROR_INPROGRESS; |
| 80 |
| 81 if (platform_image_capture_.get()) |
| 82 return PP_ERROR_FAILED; |
| 83 |
| 84 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); |
| 85 if (!document_url.is_valid()) |
| 86 return PP_ERROR_FAILED; |
| 87 |
| 88 platform_image_capture_.reset(new PepperPlatformImageCapture( |
| 89 renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance()) |
| 90 ->GetRoutingID(), |
| 91 device_id, |
| 92 document_url, |
| 93 this)); |
| 94 |
| 95 open_reply_context_ = context->MakeReplyMessageContext(); |
| 96 |
| 97 return PP_OK_COMPLETIONPENDING; |
| 98 } |
| 99 |
| 100 int32_t PepperImageCaptureHost::OnClose( |
| 101 ppapi::host::HostMessageContext* context) { |
| 102 return Close(); |
| 103 } |
| 104 |
| 105 int32_t PepperImageCaptureHost::OnGetPreviewSizes( |
| 106 ppapi::host::HostMessageContext* context) { |
| 107 if (preview_sizes_reply_context_.is_valid()) |
| 108 return PP_ERROR_INPROGRESS; |
| 109 |
| 110 if (!platform_image_capture_.get()) |
| 111 return PP_ERROR_FAILED; |
| 112 |
| 113 preview_sizes_reply_context_ = context->MakeReplyMessageContext(); |
| 114 platform_image_capture_->GetPreviewSizes(); |
| 115 |
| 116 return PP_OK_COMPLETIONPENDING; |
| 117 } |
| 118 |
| 119 int32_t PepperImageCaptureHost::Close() { |
| 120 if (!platform_image_capture_.get()) |
| 121 return PP_OK; |
| 122 |
| 123 // TODO(jchuang): abort pending image capture. |
| 124 DetachPlatformImageCapture(); |
| 125 return PP_OK; |
| 126 } |
| 127 |
| 128 void PepperImageCaptureHost::DetachPlatformImageCapture() { |
| 129 if (platform_image_capture_) { |
| 130 platform_image_capture_->DetachEventHandler(); |
| 131 platform_image_capture_.reset(); |
| 132 } |
| 133 } |
| 134 |
| 135 } // namespace content |
OLD | NEW |