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

Side by Side 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: Address WuCheng's comments in Patch Set 9/10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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)
37 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
38 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.
39 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close,
40 OnClose)
41 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.
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,
92 document_url,
93 this));
94
95 open_reply_context_ = context->MakeReplyMessageContext();
96
97 return PP_OK_COMPLETIONPENDING;
98 }
99
100 int32_t PepperImageCaptureHost::OnClose(
101 ppapi::host::HostMessageContext* context) {
102 DetachPlatformImageCapture();
103 return PP_OK;
104 }
105
106 int32_t PepperImageCaptureHost::OnGetPreviewSizes(
107 ppapi::host::HostMessageContext* context) {
108 if (preview_sizes_reply_context_.is_valid())
109 return PP_ERROR_INPROGRESS;
110 if (!platform_image_capture_)
111 return PP_ERROR_FAILED;
112
113 preview_sizes_reply_context_ = context->MakeReplyMessageContext();
114 platform_image_capture_->GetPreviewSizes();
wuchengli 2015/02/03 14:34:44 s/GetPreviewSizes/GetSupportedPreviewSizes/
Justin Chuang 2015/02/04 17:44:23 Done.
115
116 return PP_OK_COMPLETIONPENDING;
117 }
118
119 void PepperImageCaptureHost::DetachPlatformImageCapture() {
120 if (platform_image_capture_) {
121 platform_image_capture_->DetachEventHandler();
122 platform_image_capture_.reset();
123 }
124 }
125
126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698