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

Side by Side Diff: ppapi/proxy/ppb_buffer_proxy.cc

Issue 4752008: Add proxies for some of the PDF & Flash functionality. There are still a few... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "ppapi/proxy/ppb_buffer_proxy.h"
6
7 #include <string.h> // For memcpy
viettrungluu 2010/11/11 20:27:51 Silly nit: Apparently, comments are supposed to be
8
9 #include <vector>
10
11 #include "base/logging.h"
12 #include "build/build_config.h"
13 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/c/dev/ppb_buffer_dev.h"
16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/plugin_resource.h"
18 #include "ppapi/proxy/ppapi_messages.h"
19
20 namespace pp {
21 namespace proxy {
22
23 class Buffer : public PluginResource {
24 public:
25 Buffer(uint64_t memory_handle, int32_t size);
26 virtual ~Buffer();
27
28 // Resource overrides.
29 virtual Buffer* AsBuffer() { return this; }
30
31 int32_t size() const { return size_; }
32
33 void* Map();
34 void Unmap();
35
36 private:
37 uint64_t memory_handle_;
38 int32_t size_;
39
40 void* mapped_data_;
41
42 DISALLOW_COPY_AND_ASSIGN(Buffer);
43 };
44
45 Buffer::Buffer(uint64_t memory_handle, int32_t size)
46 : memory_handle_(memory_handle),
47 size_(size),
48 mapped_data_(NULL) {
49 }
50
51 Buffer::~Buffer() {
52 Unmap();
53 }
54
55 void* Buffer::Map() {
56 // TODO(brettw) implement this.
57 return mapped_data_;
58 }
59
60 void Buffer::Unmap() {
61 // TODO(brettw) implement this.
62 }
63
64 namespace {
65
66 PP_Resource Create(PP_Module module_id, int32_t size) {
67 PP_Resource result = 0;
68 uint64_t shm_handle = -1;
69 PluginDispatcher::Get()->Send(
70 new PpapiHostMsg_PPBBuffer_Create(
71 INTERFACE_ID_PPB_BUFFER, module_id, size,
72 &result, &shm_handle));
73 if (!result)
74 return 0;
75
76 linked_ptr<Buffer> object(new Buffer(shm_handle, size));
77 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
78 result, object);
79 return result;
80 }
81
82 PP_Bool IsBuffer(PP_Resource resource) {
83 Buffer* object = PluginResource::GetAs<Buffer>(resource);
84 return BoolToPPBool(!!object);
85 }
86
87 PP_Bool Describe(PP_Resource resource, int32_t* size_in_bytes) {
88 Buffer* object = PluginResource::GetAs<Buffer>(resource);
89 if (!object) {
90 *size_in_bytes = 0;
91 return PP_FALSE;
92 }
93 *size_in_bytes = object->size();
94 return PP_TRUE;
95 }
96
97 void* Map(PP_Resource resource) {
98 Buffer* object = PluginResource::GetAs<Buffer>(resource);
99 if (!object)
100 return NULL;
101 return object->Map();
102 }
103
104 void Unmap(PP_Resource resource) {
105 Buffer* object = PluginResource::GetAs<Buffer>(resource);
106 if (object)
107 object->Unmap();
108 }
109
110 const PPB_Buffer_Dev ppb_buffer = {
111 &Create,
112 &IsBuffer,
113 &Describe,
114 &Map,
115 &Unmap,
116 };
117
118 } // namespace
119
120 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher,
121 const void* target_interface)
122 : InterfaceProxy(dispatcher, target_interface) {
123 }
124
125 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() {
126 }
127
128 const void* PPB_Buffer_Proxy::GetSourceInterface() const {
129 return &ppb_buffer;
130 }
131
132 InterfaceID PPB_Buffer_Proxy::GetInterfaceId() const {
133 return INTERFACE_ID_PPB_BUFFER;
134 }
135
136 void PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) {
137 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg)
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate)
139 IPC_END_MESSAGE_MAP()
140 // TODO(brettw) handle bad messages!
141 }
142
143 void PPB_Buffer_Proxy::OnMsgCreate(PP_Module module,
144 int32_t size,
145 PP_Resource* result_resource,
146 uint64_t* result_shm_handle) {
147 *result_resource = ppb_buffer_target()->Create(module, size);
148 // TODO(brettw) set the shm handle from a trusted interface.
149 *result_shm_handle = 0;
150 }
151
152 } // namespace proxy
153 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698