Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1131)

Unified Diff: content/renderer/pepper/pepper_image_capture_host.cc

Issue 848863002: PPAPI: implement GetSupportedPreviewSizes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update histogram.xml with pepper_hash_for_uma Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..39ba596af27b74cb173b4a7ff182df944c6017b6
--- /dev/null
+++ b/content/renderer/pepper/pepper_image_capture_host.cc
@@ -0,0 +1,124 @@
+// Copyright 2015 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)
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
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiHostMsg_ImageCapture_GetSupportedPreviewSizes,
+ OnGetSupportedPreviewSizes)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, OnClose)
+ 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::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::OnGetSupportedPreviewSizes(
+ 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();
+
+ return PP_OK_COMPLETIONPENDING;
+}
+
+void PepperImageCaptureHost::DetachPlatformImageCapture() {
+ if (platform_image_capture_) {
+ platform_image_capture_->DetachEventHandler();
+ platform_image_capture_.reset();
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698