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 "ppapi/proxy/image_capture_resource.h" |
| 6 |
| 7 #include "ppapi/proxy/camera_capabilities_resource.h" |
| 8 #include "ppapi/proxy/plugin_globals.h" |
| 9 #include "ppapi/proxy/plugin_resource_tracker.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/proxy/ppb_buffer_proxy.h" |
| 12 #include "ppapi/shared_impl/proxy_lock.h" |
| 13 #include "ppapi/shared_impl/var.h" |
| 14 |
| 15 namespace ppapi { |
| 16 namespace proxy { |
| 17 |
| 18 ImageCaptureResource::ImageCaptureResource(Connection connection, |
| 19 PP_Instance instance) |
| 20 : PluginResource(connection, instance), |
| 21 open_state_(BEFORE_OPEN), |
| 22 get_capabilities_output_(NULL) { |
| 23 SendCreate(RENDERER, PpapiHostMsg_ImageCapture_Create()); |
| 24 } |
| 25 |
| 26 ImageCaptureResource::~ImageCaptureResource() { |
| 27 } |
| 28 |
| 29 int32_t ImageCaptureResource::Open(PP_Var camera_source_id, |
| 30 scoped_refptr<TrackedCallback> callback) { |
| 31 if (open_state_ != BEFORE_OPEN) |
| 32 return PP_ERROR_FAILED; |
| 33 |
| 34 if (TrackedCallback::IsPending(open_callback_)) |
| 35 return PP_ERROR_INPROGRESS; |
| 36 |
| 37 scoped_refptr<StringVar> source_string_var; |
| 38 source_string_var = StringVar::FromPPVar(camera_source_id); |
| 39 if (!source_string_var || source_string_var->value().empty()) |
| 40 return PP_ERROR_BADARGUMENT; |
| 41 |
| 42 open_callback_ = callback; |
| 43 |
| 44 Call<PpapiPluginMsg_ImageCapture_OpenReply>( |
| 45 RENDERER, |
| 46 PpapiHostMsg_ImageCapture_Open(source_string_var->value()), |
| 47 base::Bind(&ImageCaptureResource::OnPluginMsgOpenReply, |
| 48 base::Unretained(this))); |
| 49 return PP_OK_COMPLETIONPENDING; |
| 50 } |
| 51 |
| 52 void ImageCaptureResource::Close() { |
| 53 if (open_state_ == CLOSED) |
| 54 return; |
| 55 |
| 56 if (TrackedCallback::IsPending(open_callback_)) { |
| 57 open_callback_->PostAbort(); |
| 58 open_callback_ = NULL; |
| 59 } |
| 60 |
| 61 if (TrackedCallback::IsPending(get_capabilities_callback_)) { |
| 62 *get_capabilities_output_ = 0; |
| 63 get_capabilities_callback_->PostAbort(); |
| 64 get_capabilities_callback_ = NULL; |
| 65 get_capabilities_output_ = NULL; |
| 66 } |
| 67 |
| 68 Post(RENDERER, PpapiHostMsg_ImageCapture_Close()); |
| 69 |
| 70 open_state_ = CLOSED; |
| 71 } |
| 72 |
| 73 int32_t ImageCaptureResource::SetConfig( |
| 74 PP_Resource config, |
| 75 scoped_refptr<TrackedCallback> callback) { |
| 76 return PP_ERROR_NOTSUPPORTED; |
| 77 } |
| 78 |
| 79 int32_t ImageCaptureResource::GetConfig( |
| 80 PP_Resource* config, |
| 81 scoped_refptr<TrackedCallback> callback) { |
| 82 return PP_ERROR_NOTSUPPORTED; |
| 83 } |
| 84 |
| 85 int32_t ImageCaptureResource::GetCameraCapabilities( |
| 86 PP_Resource* capabilities, |
| 87 scoped_refptr<TrackedCallback> callback) { |
| 88 if (!IsOpened()) |
| 89 return PP_ERROR_FAILED; |
| 90 |
| 91 if (TrackedCallback::IsPending(get_capabilities_callback_)) |
| 92 return PP_ERROR_INPROGRESS; |
| 93 |
| 94 if (camera_capabilities_.get()) { |
| 95 *capabilities = camera_capabilities_->GetReference(); |
| 96 return PP_OK; |
| 97 } |
| 98 |
| 99 get_capabilities_output_ = capabilities; |
| 100 get_capabilities_callback_ = callback; |
| 101 Call<PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizesReply>( |
| 102 RENDERER, |
| 103 PpapiPluginMsg_ImageCapture_GetSupportedPreviewSizes(), |
| 104 base::Bind(&ImageCaptureResource::OnPluginMsgGetPreviewSizesReply, |
| 105 base::Unretained(this))); |
| 106 return PP_OK_COMPLETIONPENDING; |
| 107 } |
| 108 |
| 109 int32_t ImageCaptureResource::CaptureStillImage( |
| 110 PPB_ImageCapture_Private_ShutterCallback shutter_callback, |
| 111 PPB_ImageCapture_Private_PreviewCallback preview_callback, |
| 112 PPB_ImageCapture_Private_JpegCallback jpeg_callback, |
| 113 int64_t* sequence_id) { |
| 114 return PP_ERROR_NOTSUPPORTED; |
| 115 } |
| 116 |
| 117 void ImageCaptureResource::OnPluginMsgOpenReply( |
| 118 const ResourceMessageReplyParams& params) { |
| 119 if (open_state_ == BEFORE_OPEN && params.result() == PP_OK) |
| 120 open_state_ = OPENED; |
| 121 |
| 122 // The callback may have been aborted by Close(). |
| 123 if (TrackedCallback::IsPending(open_callback_)) |
| 124 open_callback_->Run(params.result()); |
| 125 } |
| 126 |
| 127 void ImageCaptureResource::OnPluginMsgGetPreviewSizesReply( |
| 128 const ResourceMessageReplyParams& params, |
| 129 const std::vector<PP_Size>& preview_sizes) { |
| 130 if (!TrackedCallback::IsPending(get_capabilities_callback_)) |
| 131 return; |
| 132 |
| 133 // Return camera capabilities. |
| 134 int32_t result = params.result(); |
| 135 scoped_refptr<TrackedCallback> callback; |
| 136 callback.swap(get_capabilities_callback_); |
| 137 if (result == PP_OK) { |
| 138 camera_capabilities_ = new CameraCapabilitiesResource( |
| 139 pp_instance(), preview_sizes); |
| 140 *get_capabilities_output_ = camera_capabilities_->GetReference(); |
| 141 } |
| 142 get_capabilities_output_ = NULL; |
| 143 callback->Run(result == PP_OK ? PP_OK : PP_ERROR_FAILED); |
| 144 } |
| 145 |
| 146 } // namespace proxy |
| 147 } // namespace ppapi |
OLD | NEW |