Chromium Code Reviews| 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) | |
|
dcheng
2015/02/12 21:47:20
Mind indenting the lines between BEGIN_MESSAGE_MAP
Justin Chuang
2015/02/16 19:15:23
Done. Thanks
| |
| 37 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | |
| 38 PpapiHostMsg_ImageCapture_GetSupportedPreviewSizes, | |
| 39 OnGetSupportedPreviewSizes) | |
| 40 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, OnClose) | |
| 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::OnPreviewSizesEnumerated( | |
| 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, document_url, this)); | |
| 92 | |
| 93 open_reply_context_ = context->MakeReplyMessageContext(); | |
| 94 | |
| 95 return PP_OK_COMPLETIONPENDING; | |
| 96 } | |
| 97 | |
| 98 int32_t PepperImageCaptureHost::OnClose( | |
| 99 ppapi::host::HostMessageContext* context) { | |
| 100 DetachPlatformImageCapture(); | |
| 101 return PP_OK; | |
| 102 } | |
| 103 | |
| 104 int32_t PepperImageCaptureHost::OnGetSupportedPreviewSizes( | |
| 105 ppapi::host::HostMessageContext* context) { | |
| 106 if (preview_sizes_reply_context_.is_valid()) | |
| 107 return PP_ERROR_INPROGRESS; | |
| 108 if (!platform_image_capture_) | |
| 109 return PP_ERROR_FAILED; | |
| 110 | |
| 111 preview_sizes_reply_context_ = context->MakeReplyMessageContext(); | |
| 112 platform_image_capture_->GetPreviewSizes(); | |
| 113 | |
| 114 return PP_OK_COMPLETIONPENDING; | |
| 115 } | |
| 116 | |
| 117 void PepperImageCaptureHost::DetachPlatformImageCapture() { | |
| 118 if (platform_image_capture_) { | |
| 119 platform_image_capture_->DetachEventHandler(); | |
| 120 platform_image_capture_.reset(); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 } // namespace content | |
| OLD | NEW |