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

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: Fix compile error on Linux build Created 5 years, 11 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..d6f04f9d4eff9d4f1a9cdf445555bc238bc4960d
--- /dev/null
+++ b/content/renderer/pepper/pepper_image_capture_host.cc
@@ -0,0 +1,134 @@
+// 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_media_device_manager.h"
wuchengli 2015/01/19 14:05:02 is this used?
Justin Chuang 2015/01/26 15:00:50 Done.
+#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"
wuchengli 2015/01/19 14:05:02 is this used?
Justin Chuang 2015/01/26 15:00:50 yes, must be kept
+#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)
wuchengli 2015/01/19 14:05:02 Most other pepper host use 2 space indentation.
Justin Chuang 2015/01/26 15:00:50 Done.
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, OnClose)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
+ PpapiPluginMsg_ImageCapture_GetPreviewSizes, OnGetPreviewSizes)
+ PPAPI_END_MESSAGE_MAP()
+ return result;
+}
+
+void PepperImageCaptureHost::OnPlatformInitialized(bool succeeded) {
wuchengli 2015/01/19 14:05:02 s/OnPlatformInitialized/OnInitialized/. I'd prefer
Justin Chuang 2015/01/26 15:00:50 Done.
+ 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;
+
wuchengli 2015/01/19 14:05:02 Do we need to check platform_image_capture_ != NUL
Justin Chuang 2015/01/26 15:00:50 No. Because the function is called directly in pla
+ if (sizes.size() > 0)
wuchengli 2015/01/19 14:05:02 GetDeviceSupportedFormats doesn't say about size =
Justin Chuang 2015/01/26 15:00:50 Yes, but you can see code in media stream treat it
wuchengli 2015/01/29 13:52:14 Agreed to have PP_ERROR here. This API won't work
+ 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_GetPreviewSizesReply(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/01/19 14:05:02 How about using PepperPlatformVideoCapture? We'll
Justin Chuang 2015/01/26 15:00:50 Good point. I prefer to put it in PepperPlatformIm
wuchengli 2015/01/29 13:52:14 Using PepperPlatformVideoCapture in this CL doesn'
+ 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/01/19 14:05:02 Close and DetachPlatformImageCapture are the same.
Justin Chuang 2015/01/26 15:00:50 When we support CaptureStillImage, then it will be
wuchengli 2015/01/29 13:52:14 This is the same problem like the previous comment
+ 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

Powered by Google App Engine
This is Rietveld 408576698