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..a5d1c5982245988f32875cd4374d44a92a0cc6b3 |
--- /dev/null |
+++ b/content/renderer/pepper/pepper_image_capture_host.cc |
@@ -0,0 +1,126 @@ |
+// 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() { |
+ DetachPlatformImageCapture(); |
+} |
+ |
+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( |
+ PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes, OnGetPreviewSizes) |
wuchengli
2015/02/03 14:34:45
naming should be consistent. s/OnGetPreviewSizes/O
Justin Chuang
2015/02/04 17:44:23
Done.
|
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, |
+ OnClose) |
+ PPAPI_END_MESSAGE_MAP() |
wuchengli
2015/02/03 14:34:45
wrong indent. Can git cl format fix this?
Justin Chuang
2015/02/04 17:44:23
Run git cl format again. Thanks.
|
+ 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::OnPreviewSizesEnumerated( |
+ 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( |
+ 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) { |
+ DetachPlatformImageCapture(); |
+ return PP_OK; |
+} |
+ |
+int32_t PepperImageCaptureHost::OnGetPreviewSizes( |
+ ppapi::host::HostMessageContext* context) { |
+ if (preview_sizes_reply_context_.is_valid()) |
+ return PP_ERROR_INPROGRESS; |
+ if (!platform_image_capture_) |
+ return PP_ERROR_FAILED; |
+ |
+ preview_sizes_reply_context_ = context->MakeReplyMessageContext(); |
+ platform_image_capture_->GetPreviewSizes(); |
wuchengli
2015/02/03 14:34:44
s/GetPreviewSizes/GetSupportedPreviewSizes/
Justin Chuang
2015/02/04 17:44:23
Done.
|
+ |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+void PepperImageCaptureHost::DetachPlatformImageCapture() { |
+ if (platform_image_capture_) { |
+ platform_image_capture_->DetachEventHandler(); |
+ platform_image_capture_.reset(); |
+ } |
+} |
+ |
+} // namespace content |