0

Implement host side of sync EnumerateVideoCaptureDevices

This implements the host side of the sync ppapi function EnumerateVideoCaptureDevices. 


BUG=none
TEST=Wrote a sample that runs the sync and non-sync versions. Ran it and compared the outputs.

Review URL: https://chromiumcodereview.appspot.com/11016007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162048 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
raymes@chromium.org
2012-10-16 02:14:11 +00:00
parent c0131a39a5
commit d29171a549
9 changed files with 400 additions and 2 deletions

@ -168,6 +168,8 @@
'renderer/pepper/pepper_device_enumeration_event_handler.h',
'renderer/pepper/pepper_file_chooser_host.cc',
'renderer/pepper/pepper_file_chooser_host.h',
'renderer/pepper/pepper_flash_host.cc',
'renderer/pepper/pepper_flash_host.h',
'renderer/pepper/pepper_hung_plugin_filter.cc',
'renderer/pepper/pepper_hung_plugin_filter.h',
'renderer/pepper/pepper_in_process_resource_creation.cc',

@ -6,6 +6,7 @@
#include "base/logging.h"
#include "content/renderer/pepper/pepper_file_chooser_host.h"
#include "content/renderer/pepper/pepper_flash_host.h"
#include "content/renderer/pepper/pepper_websocket_host.h"
#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
#include "ppapi/host/resource_host.h"
@ -55,6 +56,16 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
host_, instance, params.pp_resource()));
}
}
// Resources for Flash interfaces.
if (GetPermissions().HasPermission(ppapi::PERMISSION_FLASH)) {
switch (message.type()) {
case PpapiHostMsg_Flash_Create::ID:
return scoped_ptr<ResourceHost>(new PepperFlashHost(
host_, instance, params.pp_resource()));
}
}
return scoped_ptr<ResourceHost>();
}

@ -0,0 +1,82 @@
// Copyright (c) 2012 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_flash_host.h"
#include <vector>
#include "content/public/renderer/renderer_ppapi_host.h"
#include "ipc/ipc_message_macros.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/host/dispatch_host_message.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/enter_proxy.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/resource_message_params.h"
#include "ppapi/thunk/ppb_video_capture_api.h"
using ppapi::proxy::EnterHostFromHostResource;
using ppapi::proxy::EnterHostFromHostResourceForceCallback;
using ppapi::thunk::PPB_VideoCapture_API;
namespace content {
PepperFlashHost::PepperFlashHost(
RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
PepperFlashHost::~PepperFlashHost() {
}
int32_t PepperFlashHost::OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) {
IPC_BEGIN_MESSAGE_MAP(PepperFlashHost, msg)
PPAPI_DISPATCH_HOST_RESOURCE_CALL(
PpapiHostMsg_Flash_EnumerateVideoCaptureDevices,
OnMsgEnumerateVideoCaptureDevices)
IPC_END_MESSAGE_MAP()
return PP_ERROR_FAILED;
}
int32_t PepperFlashHost::OnMsgEnumerateVideoCaptureDevices(
ppapi::host::HostMessageContext* host_context,
const ppapi::HostResource& host_resource) {
EnterHostFromHostResourceForceCallback<PPB_VideoCapture_API> enter(
host_resource, callback_factory_,
&PepperFlashHost::OnEnumerateVideoCaptureDevicesComplete,
host_context->MakeReplyMessageContext(),
host_resource);
if (enter.succeeded()) {
// We don't want the output to go into a PP_ResourceArray (which is
// deprecated), so just pass in NULL. We'll grab the DeviceRefData vector
// in the callback and convert it to a PP_ArrayOutput in the plugin.
enter.SetResult(enter.object()->EnumerateDevices(NULL, enter.callback()));
}
return PP_OK_COMPLETIONPENDING;
}
void PepperFlashHost::OnEnumerateVideoCaptureDevicesComplete(
int32_t result,
ppapi::host::ReplyMessageContext reply_message_context,
const ppapi::HostResource& host_resource) {
std::vector<ppapi::DeviceRefData> devices;
if (result == PP_OK) {
EnterHostFromHostResource<PPB_VideoCapture_API> enter(host_resource);
if (enter.succeeded())
devices = enter.object()->GetDeviceRefData();
else
result = PP_ERROR_FAILED;
}
reply_message_context.params.set_result(result);
host()->SendReply(reply_message_context,
PpapiPluginMsg_Flash_EnumerateVideoCaptureDevicesReply(devices));
}
} // namespace content

@ -0,0 +1,47 @@
// Copyright (c) 2012 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.
#ifndef CONTENT_RENDERER_PEPPER_PEPPER_FLASH_HOST_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_FLASH_HOST_H_
#include "base/basictypes.h"
#include "ipc/ipc_message.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/proxy_completion_callback_factory.h"
namespace content {
class RendererPpapiHost;
class PepperFlashHost
: public ppapi::host::ResourceHost {
public:
PepperFlashHost(RendererPpapiHost* host,
PP_Instance instance,
PP_Resource resource);
virtual ~PepperFlashHost();
virtual int32_t OnResourceMessageReceived(
const IPC::Message& msg,
ppapi::host::HostMessageContext* context) OVERRIDE;
int32_t OnMsgEnumerateVideoCaptureDevices(
ppapi::host::HostMessageContext* host_context,
const ppapi::HostResource& host_resource);
private:
void OnEnumerateVideoCaptureDevicesComplete(
int32_t result,
ppapi::host::ReplyMessageContext reply_message_context,
const ppapi::HostResource& host_resource);
ppapi::proxy::ProxyCompletionCallbackFactory<PepperFlashHost>
callback_factory_;
DISALLOW_COPY_AND_ASSIGN(PepperFlashHost);
};
} // namespace content
#endif // CONTENT_RENDERER_PEPPER_PEPPER_FLASH_HOST_H_