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

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 7 years 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..bd463ab18054881aff6351962f1963e75421e204
--- /dev/null
+++ b/content/renderer/pepper/pepper_io_stream_host.cc
@@ -0,0 +1,122 @@
+// Copyright (c) 2013 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"
+
+
+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) {
+#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 input)
bbudge 2013/12/31 00:51:53 is_input
Peng 2013/12/31 23:33:54 Done.
+ : ResourceHost(host->GetPpapiHost(), instance, resource),
+ ppapi::IOStreamShared(input) {
+}
+
+PepperIOStreamHost::~PepperIOStreamHost() {
+}
+
+void PepperIOStreamHost::MovePeerLimit(uint32_t offset) {
+ CHECK(offset);
+ host()->SendUnsolicitedReply(pp_resource(),
+ PpapiPluginMsg_IOStream_MoveLimit(offset));
+}
+
+bool PepperIOStreamHost::InitSharedBufferAndInfoPlugin(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());
+ 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;
+ 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);
+ // We need send the SerializedHandle back, so we have to send reply by
+ // ourselves.
+ ReplyMessageContext reply_context = context->MakeReplyMessageContext();
+ HostDispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance());
+ SerializedHandle handle(
+ dispatcher->ShareHandleWithRemote(platform_file, false),
+ size);
+ reply_context.params.AppendHandle(handle);
+ reply_context.params.set_result(PP_OK);
+ SendReply(reply_context, IPC::Message());
+
+ 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