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

Unified Diff: content/renderer/pepper/pepper_io_stream_host.cc

Issue 119853003: [PPAPI] Implement an IOStreamResource for data transmission between plugin and renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 6 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/pepper_io_stream_host.cc
diff --git a/content/renderer/pepper/pepper_io_stream_host.cc b/content/renderer/pepper/pepper_io_stream_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..edd4e02e638a3b3b14192bd0fab07d786c399430
--- /dev/null
+++ b/content/renderer/pepper/pepper_io_stream_host.cc
@@ -0,0 +1,120 @@
+// 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/renderer/pepper/pepper_io_stream_host.h"
+
+#include "content/public/renderer/render_thread.h"
+#include "content/public/renderer/renderer_ppapi_host.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/host/dispatch_host_message.h"
+#include "ppapi/host/ppapi_host.h"
+#include "ppapi/proxy/host_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
yzshen1 2014/01/03 21:51:41 nit: extra empty line
+
+using ppapi::host::HostMessageContext;
+using ppapi::host::ReplyMessageContext;
+using ppapi::proxy::HostDispatcher;
+using ppapi::proxy::SerializedHandle;
+
+namespace content {
+
+namespace {
+
+base::PlatformFile ToPlatformFile(const base::SharedMemoryHandle& handle) {
yzshen1 2014/01/03 21:51:41 please consider putting it in shared_impl/platform
+#if defined(OS_WIN)
+ return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
+#elif defined(OS_POSIX)
+ return handle.fd;
+#else
+#error Not implemented.
+#endif
+}
+
+} // namespace
+
+PepperIOStreamHost::PepperIOStreamHost(
+ RendererPpapiHost* host,
+ PP_Instance instance,
+ PP_Resource resource,
+ bool is_input)
+ : ResourceHost(host->GetPpapiHost(), instance, resource),
+ ppapi::IOStreamShared(is_input) {
+}
+
+PepperIOStreamHost::~PepperIOStreamHost() {
+}
+
+void PepperIOStreamHost::MovePeerLimit(uint32_t offset) {
yzshen1 2014/01/03 21:51:41 please order the method definitions in the same or
+ DCHECK(offset);
+ host()->SendUnsolicitedReply(pp_resource(),
+ PpapiPluginMsg_IOStream_MoveLimit(offset));
+}
+
+bool PepperIOStreamHost::InitSharedBufferAndNotifyPlugin(uint32_t size) {
+ if (!InitSharedBuffer(size))
+ return false;
+
+ base::SharedMemoryHandle shm_handle = shared_memory()->handle();
+ base::PlatformFile platform_file = ToPlatformFile(shm_handle);
+ HostDispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance());
yzshen1 2014/01/03 21:51:41 Please use RendererPpapiHost::ShareHandleWithRemot
+ SerializedHandle handle(
+ dispatcher->ShareHandleWithRemote(platform_file, false),
+ size);
+ host()->SendUnsolicitedReplyWithHandle(pp_resource(),
+ PpapiPluginMsg_IOStream_Init(size), handle);
+ return true;
+}
+
+bool PepperIOStreamHost::InitSharedBuffer(uint32_t size) {
+ DCHECK(size);
+ content::RenderThread* render_thread = content::RenderThread::Get();
+ scoped_ptr<base::SharedMemory> shm(
+ render_thread->HostAllocateSharedMemoryBuffer(size).Pass());
+ if (!shm)
+ return false;
+
+ SetBuffer(shm.Pass(), size);
+ return true;
+}
+
+int32_t PepperIOStreamHost::OnResourceMessageReceived(
+ const IPC::Message& msg,
+ HostMessageContext* context) {
+ IPC_BEGIN_MESSAGE_MAP(PepperIOStreamHost, msg)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_IOStream_Init,
+ OnHostMsgInit)
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_IOStream_MoveLimit,
+ OnHostMsgMoveLimit)
+ IPC_END_MESSAGE_MAP()
+ return PP_ERROR_FAILED;
+}
+
+int32_t PepperIOStreamHost::OnHostMsgInit(HostMessageContext* context,
+ uint32_t size) {
+ if (!InitSharedBuffer(size))
+ return PP_ERROR_NOMEMORY;
+
+ base::SharedMemoryHandle shm_handle = shared_memory()->handle();
+ base::PlatformFile platform_file = ToPlatformFile(shm_handle);
+ ReplyMessageContext reply_context = context->MakeReplyMessageContext();
+ HostDispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance());
yzshen1 2014/01/03 21:51:41 ditto
+ SerializedHandle handle(
+ dispatcher->ShareHandleWithRemote(platform_file, false),
+ size);
+ reply_context.params.AppendHandle(handle);
+ reply_context.params.set_result(PP_OK);
+ SendReply(reply_context, PpapiPluginMsg_IOStream_InitReply());
+
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t PepperIOStreamHost::OnHostMsgMoveLimit(HostMessageContext* context,
+ uint32_t offset) {
+ DCHECK(offset);
+ MoveLimit(offset);
+ return PP_OK;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698