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

Side by Side 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, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "content/renderer/pepper/pepper_io_stream_host.h"
6
7 #include "content/public/renderer/render_thread.h"
8 #include "content/public/renderer/renderer_ppapi_host.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/host/dispatch_host_message.h"
11 #include "ppapi/host/ppapi_host.h"
12 #include "ppapi/proxy/host_dispatcher.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14
15
16 using ppapi::host::HostMessageContext;
17 using ppapi::host::ReplyMessageContext;
18 using ppapi::proxy::HostDispatcher;
19 using ppapi::proxy::SerializedHandle;
20
21 namespace content {
22
23 namespace {
24
25 base::PlatformFile ToPlatformFile(const base::SharedMemoryHandle& handle) {
26 #if defined(OS_WIN)
27 return reinterpret_cast<HANDLE>(static_cast<intptr_t>(handle));
28 #elif defined(OS_POSIX)
29 return handle.fd;
30 #else
31 #error Not implemented.
32 #endif
33 }
34
35 } // namespace
36
37 PepperIOStreamHost::PepperIOStreamHost(
38 RendererPpapiHost* host,
39 PP_Instance instance,
40 PP_Resource resource,
41 bool input)
bbudge 2013/12/31 00:51:53 is_input
Peng 2013/12/31 23:33:54 Done.
42 : ResourceHost(host->GetPpapiHost(), instance, resource),
43 ppapi::IOStreamShared(input) {
44 }
45
46 PepperIOStreamHost::~PepperIOStreamHost() {
47 }
48
49 void PepperIOStreamHost::MovePeerLimit(uint32_t offset) {
50 CHECK(offset);
51 host()->SendUnsolicitedReply(pp_resource(),
52 PpapiPluginMsg_IOStream_MoveLimit(offset));
53 }
54
55 bool PepperIOStreamHost::InitSharedBufferAndInfoPlugin(uint32_t size) {
56 if (!InitSharedBuffer(size))
57 return false;
58
59 base::SharedMemoryHandle shm_handle = shared_memory()->handle();
60 base::PlatformFile platform_file = ToPlatformFile(shm_handle);
61 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance());
62 SerializedHandle handle(
63 dispatcher->ShareHandleWithRemote(platform_file, false),
64 size);
65 host()->SendUnsolicitedReplyWithHandle(pp_resource(),
66 PpapiPluginMsg_IOStream_Init(size), handle);
67 return true;
68 }
69
70 bool PepperIOStreamHost::InitSharedBuffer(uint32_t size) {
71 DCHECK(size);
72 content::RenderThread* render_thread = content::RenderThread::Get();
73 scoped_ptr<base::SharedMemory> shm;
74 shm = render_thread->HostAllocateSharedMemoryBuffer(size).Pass();
75 if (!shm)
76 return false;
77
78 SetBuffer(shm.Pass(), size);
79 return true;
80 }
81
82 int32_t PepperIOStreamHost::OnResourceMessageReceived(
83 const IPC::Message& msg,
84 HostMessageContext* context) {
85 IPC_BEGIN_MESSAGE_MAP(PepperIOStreamHost, msg)
86 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_IOStream_Init,
87 OnHostMsgInit)
88 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_IOStream_MoveLimit,
89 OnHostMsgMoveLimit)
90 IPC_END_MESSAGE_MAP()
91 return PP_ERROR_FAILED;
92 }
93
94 int32_t PepperIOStreamHost::OnHostMsgInit(HostMessageContext* context,
95 uint32_t size) {
96 if (!InitSharedBuffer(size))
97 return PP_ERROR_NOMEMORY;
98
99 base::SharedMemoryHandle shm_handle = shared_memory()->handle();
100 base::PlatformFile platform_file = ToPlatformFile(shm_handle);
101 // We need send the SerializedHandle back, so we have to send reply by
102 // ourselves.
103 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
104 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(pp_instance());
105 SerializedHandle handle(
106 dispatcher->ShareHandleWithRemote(platform_file, false),
107 size);
108 reply_context.params.AppendHandle(handle);
109 reply_context.params.set_result(PP_OK);
110 SendReply(reply_context, IPC::Message());
111
112 return PP_OK_COMPLETIONPENDING;
113 }
114
115 int32_t PepperIOStreamHost::OnHostMsgMoveLimit(HostMessageContext* context,
116 uint32_t offset) {
117 DCHECK(offset);
118 MoveLimit(offset);
119 return PP_OK;
120 }
121
122 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698