OLD | NEW |
---|---|
(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_media_device_manager.h" | |
wuchengli
2015/01/19 14:05:02
is this used?
Justin Chuang
2015/01/26 15:00:50
Done.
| |
8 #include "content/renderer/pepper/pepper_platform_image_capture.h" | |
9 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | |
10 #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
| |
11 #include "ppapi/host/dispatch_host_message.h" | |
12 #include "ppapi/proxy/ppapi_messages.h" | |
13 | |
14 namespace content { | |
15 | |
16 PepperImageCaptureHost::PepperImageCaptureHost(RendererPpapiHostImpl* host, | |
17 PP_Instance instance, | |
18 PP_Resource resource) | |
19 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
20 renderer_ppapi_host_(host) { | |
21 } | |
22 | |
23 PepperImageCaptureHost::~PepperImageCaptureHost() { | |
24 Close(); | |
25 } | |
26 | |
27 bool PepperImageCaptureHost::Init() { | |
28 return !!renderer_ppapi_host_->GetPluginInstance(pp_instance()); | |
29 } | |
30 | |
31 int32_t PepperImageCaptureHost::OnResourceMessageReceived( | |
32 const IPC::Message& msg, | |
33 ppapi::host::HostMessageContext* context) { | |
34 int32_t result = PP_ERROR_FAILED; | |
35 | |
36 PPAPI_BEGIN_MESSAGE_MAP(PepperImageCaptureHost, msg) | |
37 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.
| |
38 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_ImageCapture_Close, OnClose) | |
39 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | |
40 PpapiPluginMsg_ImageCapture_GetPreviewSizes, OnGetPreviewSizes) | |
41 PPAPI_END_MESSAGE_MAP() | |
42 return result; | |
43 } | |
44 | |
45 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.
| |
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::OnPlatformPreviewSizesEnumerated( | |
62 const std::vector<PP_Size>& sizes) { | |
63 if (!preview_sizes_reply_context_.is_valid()) | |
64 return; | |
65 | |
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
| |
66 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
| |
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(preview_sizes_reply_context_, | |
71 PpapiPluginMsg_ImageCapture_GetPreviewSizesReply(sizes)); | |
72 preview_sizes_reply_context_ = ppapi::host::ReplyMessageContext(); | |
73 } | |
74 | |
75 int32_t PepperImageCaptureHost::OnOpen(ppapi::host::HostMessageContext* context, | |
76 const std::string& device_id) { | |
77 if (open_reply_context_.is_valid()) | |
78 return PP_ERROR_INPROGRESS; | |
79 | |
80 if (platform_image_capture_.get()) | |
81 return PP_ERROR_FAILED; | |
82 | |
83 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); | |
84 if (!document_url.is_valid()) | |
85 return PP_ERROR_FAILED; | |
86 | |
87 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'
| |
88 renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance()) | |
89 ->GetRoutingID(), | |
90 device_id, | |
91 document_url, | |
92 this)); | |
93 | |
94 open_reply_context_ = context->MakeReplyMessageContext(); | |
95 | |
96 return PP_OK_COMPLETIONPENDING; | |
97 } | |
98 | |
99 int32_t PepperImageCaptureHost::OnClose( | |
100 ppapi::host::HostMessageContext* context) { | |
101 return Close(); | |
102 } | |
103 | |
104 int32_t PepperImageCaptureHost::OnGetPreviewSizes( | |
105 ppapi::host::HostMessageContext* context) { | |
106 if (preview_sizes_reply_context_.is_valid()) | |
107 return PP_ERROR_INPROGRESS; | |
108 | |
109 if (!platform_image_capture_.get()) | |
110 return PP_ERROR_FAILED; | |
111 | |
112 preview_sizes_reply_context_ = context->MakeReplyMessageContext(); | |
113 platform_image_capture_->GetPreviewSizes(); | |
114 | |
115 return PP_OK_COMPLETIONPENDING; | |
116 } | |
117 | |
118 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
| |
119 if (!platform_image_capture_.get()) | |
120 return PP_OK; | |
121 | |
122 // TODO(jchuang): abort pending image capture. | |
123 DetachPlatformImageCapture(); | |
124 return PP_OK; | |
125 } | |
126 | |
127 void PepperImageCaptureHost::DetachPlatformImageCapture() { | |
128 if (platform_image_capture_) { | |
129 platform_image_capture_->DetachEventHandler(); | |
130 platform_image_capture_.reset(); | |
131 } | |
132 } | |
133 | |
134 } // namespace content | |
OLD | NEW |