| Index: content/browser/renderer_host/pepper/pepper_mojo_host.cc
|
| diff --git a/content/browser/renderer_host/pepper/pepper_mojo_host.cc b/content/browser/renderer_host/pepper/pepper_mojo_host.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8d23fdaa32a5465bec55e4b06ab06dc20825815a
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/pepper/pepper_mojo_host.cc
|
| @@ -0,0 +1,122 @@
|
| +// Copyright (c) 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/browser/renderer_host/pepper/pepper_mojo_host.h"
|
| +
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "ipc/ipc_platform_file.h"
|
| +#include "mojo/embedder/platform_channel_pair.h"
|
| +#include "mojo/examples/echo/echo_service.mojom.h"
|
| +#include "mojo/public/cpp/system/message_pipe.h"
|
| +#include "ppapi/c/pp_errors.h"
|
| +#include "ppapi/c/ppb_file_io.h"
|
| +#include "ppapi/host/dispatch_host_message.h"
|
| +#include "ppapi/host/ppapi_host.h"
|
| +#include "ppapi/proxy/dispatch_reply_message.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +base::PlatformFile PlatformFileFromScopedPlatformHandle(
|
| + mojo::embedder::ScopedPlatformHandle handle) {
|
| +#if defined(OS_POSIX)
|
| + return handle.release().fd;
|
| +#elif defined(OS_WIN)
|
| + return handle.release().handle;
|
| +#endif
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +
|
| +PepperMojoHost::PepperMojoHost(BrowserPpapiHost* host,
|
| + PP_Instance instance,
|
| + PP_Resource resource)
|
| + : ResourceHost(host->GetPpapiHost(), instance, resource),
|
| + browser_ppapi_host_(host) {
|
| +}
|
| +
|
| +int32_t PepperMojoHost::OnResourceMessageReceived(
|
| + const IPC::Message& msg,
|
| + ppapi::host::HostMessageContext* context) {
|
| + PPAPI_BEGIN_MESSAGE_MAP(PepperMojoHost, msg)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Mojo_GetHandle,
|
| + OnGetHandle)
|
| + PPAPI_END_MESSAGE_MAP()
|
| + return PP_ERROR_FAILED;
|
| +}
|
| +
|
| +class EchoServiceImpl
|
| + : public mojo::InterfaceImpl<mojo::examples::EchoService> {
|
| + public:
|
| + virtual void OnConnectionEstablished() OVERRIDE {
|
| + LOG(INFO) << "EchoServiceImpl::OnConnectionEstablished()";
|
| + }
|
| +
|
| + virtual void OnConnectionError() OVERRIDE {
|
| + LOG(INFO) << "EchoServiceImpl::OnConnectionError()";
|
| + fprintf(stderr, "on connection error\n");
|
| + }
|
| +
|
| + virtual void EchoString(
|
| + const mojo::String& value,
|
| + const mojo::Callback<void(mojo::String)>& cb) OVERRIDE {
|
| + LOG(INFO) << "Browser EchoString(), value: " << value.get();
|
| + cb.Run(value);
|
| + }
|
| +};
|
| +
|
| +void CreateEchoService(
|
| + mojo::InterfaceRequest<mojo::examples::EchoService> request) {
|
| + mojo::WeakBindToRequest(new EchoServiceImpl(), &request);
|
| +}
|
| +
|
| +int32_t PepperMojoHost::OnGetHandle(ppapi::host::HostMessageContext* context) {
|
| + base::ProcessHandle plugin_process_handle =
|
| + browser_ppapi_host_->GetPluginProcessHandle();
|
| +
|
| + // No support for in-process.
|
| + if (base::GetProcId(plugin_process_handle) == base::kNullProcessId) {
|
| + return PP_ERROR_FAILED;
|
| + }
|
| +
|
| + // Note: This code is largely cloned from MojoApplicationHost.
|
| + mojo::embedder::PlatformChannelPair channel_pair;
|
| + mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init(
|
| + PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
|
| +
|
| + // TODO(teravest): Support more than one call to GetHandle(); this will
|
| + // incorrectly bind our service registry to multiple pipes and add services
|
| + // to it multiple times.
|
| + service_registry_.BindRemoteServiceProvider(message_pipe.Pass());
|
| +
|
| + // We use the base class here for calling AddService since
|
| + // ServiceRegistryImpl hides the base class' AddService() call.
|
| + ServiceRegistry* sr = &service_registry_;
|
| + sr->AddService<mojo::examples::EchoService>(base::Bind(&CreateEchoService));
|
| +
|
| + base::PlatformFile client_file =
|
| + PlatformFileFromScopedPlatformHandle(channel_pair.PassClientHandle());
|
| + ppapi::host::ReplyMessageContext reply_context =
|
| + context->MakeReplyMessageContext();
|
| +
|
| + ppapi::proxy::SerializedHandle file_handle;
|
| + int32_t open_flags = PP_FILEOPENFLAG_READ | PP_FILEOPENFLAG_WRITE;
|
| +
|
| + file_handle.set_file_handle(
|
| + IPC::GetFileHandleForProcess(client_file,
|
| + plugin_process_handle,
|
| + true),
|
| + open_flags,
|
| + 0);
|
| +
|
| + reply_context.params.AppendHandle(file_handle);
|
| + host()->SendReply(reply_context, PpapiPluginMsg_Mojo_GetHandleReply());
|
| +
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +} // namespace content
|
|
|