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

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
« no previous file with comments | « ppapi/proxy/ppb_buffer_proxy.h ('k') | ppapi/proxy/ppb_flash_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector>
8
9 #include "base/logging.h"
10 #include "build/build_config.h"
11 #include "ppapi/c/pp_completion_callback.h"
12 #include "ppapi/c/pp_resource.h"
13 #include "ppapi/c/dev/ppb_buffer_dev.h"
14 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/plugin_resource.h"
16 #include "ppapi/proxy/ppapi_messages.h"
17
18 namespace pp {
19 namespace proxy {
20
21 class Buffer : public PluginResource {
22 public:
23 Buffer(uint64_t memory_handle, int32_t size);
24 virtual ~Buffer();
25
26 // Resource overrides.
27 virtual Buffer* AsBuffer() { return this; }
28
29 int32_t size() const { return size_; }
30
31 void* Map();
32 void Unmap();
33
34 private:
35 uint64_t memory_handle_;
36 int32_t size_;
37
38 void* mapped_data_;
39
40 DISALLOW_COPY_AND_ASSIGN(Buffer);
41 };
42
43 Buffer::Buffer(uint64_t memory_handle, int32_t size)
44 : memory_handle_(memory_handle),
45 size_(size),
46 mapped_data_(NULL) {
47 }
48
49 Buffer::~Buffer() {
50 Unmap();
51 }
52
53 void* Buffer::Map() {
54 // TODO(brettw) implement this.
55 return mapped_data_;
56 }
57
58 void Buffer::Unmap() {
59 // TODO(brettw) implement this.
60 }
61
62 namespace {
63
64 PP_Resource Create(PP_Module module_id, int32_t size) {
65 PP_Resource result = 0;
66 uint64_t shm_handle = -1;
67 PluginDispatcher::Get()->Send(
68 new PpapiHostMsg_PPBBuffer_Create(
69 INTERFACE_ID_PPB_BUFFER, module_id, size,
70 &result, &shm_handle));
71 if (!result)
72 return 0;
73
74 linked_ptr<Buffer> object(new Buffer(shm_handle, size));
75 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
76 result, object);
77 return result;
78 }
79
80 PP_Bool IsBuffer(PP_Resource resource) {
81 Buffer* object = PluginResource::GetAs<Buffer>(resource);
82 return BoolToPPBool(!!object);
83 }
84
85 PP_Bool Describe(PP_Resource resource, int32_t* size_in_bytes) {
86 Buffer* object = PluginResource::GetAs<Buffer>(resource);
87 if (!object) {
88 *size_in_bytes = 0;
89 return PP_FALSE;
90 }
91 *size_in_bytes = object->size();
92 return PP_TRUE;
93 }
94
95 void* Map(PP_Resource resource) {
96 Buffer* object = PluginResource::GetAs<Buffer>(resource);
97 if (!object)
98 return NULL;
99 return object->Map();
100 }
101
102 void Unmap(PP_Resource resource) {
103 Buffer* object = PluginResource::GetAs<Buffer>(resource);
104 if (object)
105 object->Unmap();
106 }
107
108 const PPB_Buffer_Dev ppb_buffer = {
109 &Create,
110 &IsBuffer,
111 &Describe,
112 &Map,
113 &Unmap,
114 };
115
116 } // namespace
117
118 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher,
119 const void* target_interface)
120 : InterfaceProxy(dispatcher, target_interface) {
121 }
122
123 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() {
124 }
125
126 const void* PPB_Buffer_Proxy::GetSourceInterface() const {
127 return &ppb_buffer;
128 }
129
130 InterfaceID PPB_Buffer_Proxy::GetInterfaceId() const {
131 return INTERFACE_ID_PPB_BUFFER;
132 }
133
134 void PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) {
135 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg)
136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate)
137 IPC_END_MESSAGE_MAP()
138 // TODO(brettw) handle bad messages!
139 }
140
141 void PPB_Buffer_Proxy::OnMsgCreate(PP_Module module,
142 int32_t size,
143 PP_Resource* result_resource,
144 uint64_t* result_shm_handle) {
145 *result_resource = ppb_buffer_target()->Create(module, size);
146 // TODO(brettw) set the shm handle from a trusted interface.
147 *result_shm_handle = 0;
148 }
149
150 } // namespace proxy
151 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_buffer_proxy.h ('k') | ppapi/proxy/ppb_flash_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698