Chromium Code Reviews| Index: content/renderer/pepper/pepper_image_capture_host.cc |
| diff --git a/content/renderer/pepper/pepper_image_capture_host.cc b/content/renderer/pepper/pepper_image_capture_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f496f08f0b265bc3493e30508296f4a0150addae |
| --- /dev/null |
| +++ b/content/renderer/pepper/pepper_image_capture_host.cc |
| @@ -0,0 +1,135 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/renderer/pepper/pepper_image_capture_host.h" |
| + |
| +#include "content/renderer/pepper/pepper_platform_image_capture.h" |
| +#include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
| +#include "content/renderer/render_frame_impl.h" |
| +#include "ppapi/host/dispatch_host_message.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| + |
| +namespace content { |
| + |
| +PepperImageCaptureHost::PepperImageCaptureHost(RendererPpapiHostImpl* host, |
| + PP_Instance instance, |
| + PP_Resource resource) |
| + : ResourceHost(host->GetPpapiHost(), instance, resource), |
| + renderer_ppapi_host_(host) { |
| +} |
| + |
| +PepperImageCaptureHost::~PepperImageCaptureHost() { |
| + Close(); |
| +} |
| + |
| +bool PepperImageCaptureHost::Init() { |
| + return !!renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
| +} |
| + |
| +int32_t PepperImageCaptureHost::OnResourceMessageReceived( |
| + const IPC::Message& msg, |
| + ppapi::host::HostMessageContext* context) { |
| + int32_t result = PP_ERROR_FAILED; |
| + |
| + PPAPI_BEGIN_MESSAGE_MAP(PepperImageCaptureHost, msg) |
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_ImageCapture_Open, OnOpen) |
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, |
| + OnClose) |
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| + PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes, OnGetPreviewSizes) |
| + PPAPI_END_MESSAGE_MAP() |
| + return result; |
| +} |
| + |
| +void PepperImageCaptureHost::OnInitialized(bool succeeded) { |
| + if (!open_reply_context_.is_valid()) |
| + return; |
| + |
| + if (succeeded) { |
| + open_reply_context_.params.set_result(PP_OK); |
| + } else { |
| + DetachPlatformImageCapture(); |
| + open_reply_context_.params.set_result(PP_ERROR_FAILED); |
| + } |
| + |
| + host()->SendReply(open_reply_context_, |
| + PpapiPluginMsg_ImageCapture_OpenReply()); |
| + open_reply_context_ = ppapi::host::ReplyMessageContext(); |
| +} |
| + |
| +void PepperImageCaptureHost::OnPlatformPreviewSizesEnumerated( |
| + const std::vector<PP_Size>& sizes) { |
| + if (!preview_sizes_reply_context_.is_valid()) |
| + return; |
| + |
| + if (sizes.size() > 0) |
| + preview_sizes_reply_context_.params.set_result(PP_OK); |
| + else |
| + preview_sizes_reply_context_.params.set_result(PP_ERROR_FAILED); |
| + host()->SendReply( |
| + preview_sizes_reply_context_, |
| + PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply(sizes)); |
| + preview_sizes_reply_context_ = ppapi::host::ReplyMessageContext(); |
| +} |
| + |
| +int32_t PepperImageCaptureHost::OnOpen(ppapi::host::HostMessageContext* context, |
| + const std::string& device_id) { |
| + if (open_reply_context_.is_valid()) |
| + return PP_ERROR_INPROGRESS; |
| + |
| + if (platform_image_capture_.get()) |
| + return PP_ERROR_FAILED; |
| + |
| + GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); |
| + if (!document_url.is_valid()) |
| + return PP_ERROR_FAILED; |
| + |
| + platform_image_capture_.reset(new PepperPlatformImageCapture( |
|
wuchengli
2015/02/02 14:42:33
The comment in patchset 4 might have been missed.
Justin Chuang
2015/02/03 12:32:08
As discussed in draft refactoring in 883983005. We
|
| + renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance()) |
| + ->GetRoutingID(), |
| + device_id, |
| + document_url, |
| + this)); |
| + |
| + open_reply_context_ = context->MakeReplyMessageContext(); |
| + |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +int32_t PepperImageCaptureHost::OnClose( |
| + ppapi::host::HostMessageContext* context) { |
| + return Close(); |
| +} |
| + |
| +int32_t PepperImageCaptureHost::OnGetPreviewSizes( |
| + ppapi::host::HostMessageContext* context) { |
| + if (preview_sizes_reply_context_.is_valid()) |
| + return PP_ERROR_INPROGRESS; |
| + |
| + if (!platform_image_capture_.get()) |
| + return PP_ERROR_FAILED; |
| + |
| + preview_sizes_reply_context_ = context->MakeReplyMessageContext(); |
| + platform_image_capture_->GetPreviewSizes(); |
| + |
| + return PP_OK_COMPLETIONPENDING; |
| +} |
| + |
| +int32_t PepperImageCaptureHost::Close() { |
|
wuchengli
2015/02/02 14:42:32
The comments in patchset 4 might have been missed.
Justin Chuang
2015/02/03 12:32:07
Done.
|
| + if (!platform_image_capture_.get()) |
| + return PP_OK; |
| + |
| + // TODO(jchuang): abort pending image capture. |
| + DetachPlatformImageCapture(); |
| + return PP_OK; |
| +} |
| + |
| +void PepperImageCaptureHost::DetachPlatformImageCapture() { |
| + if (platform_image_capture_) { |
| + platform_image_capture_->DetachEventHandler(); |
| + platform_image_capture_.reset(); |
| + } |
| +} |
| + |
| +} // namespace content |