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

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

Issue 7740038: Use macros to define pepper interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New patch Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_file_chooser_proxy.h ('k') | ppapi/proxy/ppb_file_ref_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/ppb_file_chooser_proxy.h" 5 #include "ppapi/proxy/ppb_file_chooser_proxy.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "ppapi/c/dev/ppb_file_chooser_dev.h" 9 #include "ppapi/c/dev/ppb_file_chooser_dev.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/private/ppb_proxy_private.h" 11 #include "ppapi/c/private/ppb_proxy_private.h"
12 #include "ppapi/proxy/enter_proxy.h" 12 #include "ppapi/proxy/enter_proxy.h"
13 #include "ppapi/proxy/host_dispatcher.h" 13 #include "ppapi/proxy/host_dispatcher.h"
14 #include "ppapi/proxy/plugin_dispatcher.h" 14 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.h"
16 #include "ppapi/proxy/ppb_file_ref_proxy.h" 16 #include "ppapi/proxy/ppb_file_ref_proxy.h"
17 #include "ppapi/proxy/serialized_var.h" 17 #include "ppapi/proxy/serialized_var.h"
18 #include "ppapi/shared_impl/var.h" 18 #include "ppapi/shared_impl/var.h"
19 #include "ppapi/thunk/resource_creation_api.h"
19 #include "ppapi/thunk/thunk.h" 20 #include "ppapi/thunk/thunk.h"
20 21
21 using ppapi::thunk::PPB_FileChooser_API; 22 using ppapi::thunk::PPB_FileChooser_API;
22 23
23 namespace ppapi { 24 namespace ppapi {
24 namespace proxy { 25 namespace proxy {
25 26
26 class FileChooser : public Resource, 27 class FileChooser : public Resource,
27 public PPB_FileChooser_API { 28 public PPB_FileChooser_API {
28 public: 29 public:
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // by the FileChooser object until they're passed to the plugin. 112 // by the FileChooser object until they're passed to the plugin.
112 DCHECK(file_queue_.empty()); 113 DCHECK(file_queue_.empty());
113 for (size_t i = 0; i < chosen_files.size(); i++) 114 for (size_t i = 0; i < chosen_files.size(); i++)
114 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); 115 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i]));
115 116
116 // Notify the plugin of the new data. 117 // Notify the plugin of the new data.
117 PP_RunAndClearCompletionCallback(&current_show_callback_, result_code); 118 PP_RunAndClearCompletionCallback(&current_show_callback_, result_code);
118 // DANGER: May delete |this|! 119 // DANGER: May delete |this|!
119 } 120 }
120 121
121 namespace { 122 PPB_FileChooser_Proxy::PPB_FileChooser_Proxy(Dispatcher* dispatcher)
122 123 : InterfaceProxy(dispatcher),
123 PP_Resource Create0_4(PP_Instance instance,
124 const PP_FileChooserOptions_0_4_Dev* options) {
125 PP_Var accept_var = PP_MakeUndefined();
126 if (options->accept_mime_types)
127 accept_var = StringVar::StringToPPVar(0, options->accept_mime_types);
128 PP_Resource result = thunk::GetPPB_FileChooser_Thunk()->Create(
129 instance, options->mode, accept_var);
130 if (accept_var.type == PP_VARTYPE_STRING)
131 PluginResourceTracker::GetInstance()->var_tracker().ReleaseVar(accept_var);
132 return result;
133 }
134
135 PP_Bool IsFileChooser0_4(PP_Resource resource) {
136 return thunk::GetPPB_FileChooser_Thunk()->IsFileChooser(resource);
137 }
138
139 int32_t Show0_4(PP_Resource chooser, PP_CompletionCallback callback) {
140 return thunk::GetPPB_FileChooser_Thunk()->Show(chooser, callback);
141 }
142
143 PP_Resource GetNextChosenFile0_4(PP_Resource chooser) {
144 return thunk::GetPPB_FileChooser_Thunk()->GetNextChosenFile(chooser);
145 }
146
147 PPB_FileChooser_0_4_Dev file_chooser_0_4_interface = {
148 &Create0_4,
149 &IsFileChooser0_4,
150 &Show0_4,
151 &GetNextChosenFile0_4
152 };
153
154 InterfaceProxy* CreateFileChooserProxy(Dispatcher* dispatcher,
155 const void* target_interface) {
156 return new PPB_FileChooser_Proxy(dispatcher, target_interface);
157 }
158
159 } // namespace
160
161 PPB_FileChooser_Proxy::PPB_FileChooser_Proxy(Dispatcher* dispatcher,
162 const void* target_interface)
163 : InterfaceProxy(dispatcher, target_interface),
164 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 124 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
165 } 125 }
166 126
167 PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() { 127 PPB_FileChooser_Proxy::~PPB_FileChooser_Proxy() {
168 } 128 }
169 129
170 const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo() {
171 static const Info info = {
172 thunk::GetPPB_FileChooser_Thunk(),
173 PPB_FILECHOOSER_DEV_INTERFACE,
174 INTERFACE_ID_PPB_FILE_CHOOSER,
175 false,
176 &CreateFileChooserProxy,
177 };
178 return &info;
179 }
180
181 const InterfaceProxy::Info* PPB_FileChooser_Proxy::GetInfo0_4() {
182 static const Info info = {
183 &file_chooser_0_4_interface,
184 PPB_FILECHOOSER_DEV_INTERFACE_0_4,
185 INTERFACE_ID_NONE,
186 false,
187 &CreateFileChooserProxy,
188 };
189 return &info;
190 }
191
192 // static 130 // static
193 PP_Resource PPB_FileChooser_Proxy::CreateProxyResource( 131 PP_Resource PPB_FileChooser_Proxy::CreateProxyResource(
194 PP_Instance instance, 132 PP_Instance instance,
195 PP_FileChooserMode_Dev mode, 133 PP_FileChooserMode_Dev mode,
196 const PP_Var& accept_mime_types) { 134 const PP_Var& accept_mime_types) {
197 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); 135 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
198 if (!dispatcher) 136 if (!dispatcher)
199 return 0; 137 return 0;
200 138
201 HostResource result; 139 HostResource result;
(...skipping 20 matching lines...) Expand all
222 IPC_MESSAGE_UNHANDLED(handled = false) 160 IPC_MESSAGE_UNHANDLED(handled = false)
223 IPC_END_MESSAGE_MAP() 161 IPC_END_MESSAGE_MAP()
224 return handled; 162 return handled;
225 } 163 }
226 164
227 void PPB_FileChooser_Proxy::OnMsgCreate( 165 void PPB_FileChooser_Proxy::OnMsgCreate(
228 PP_Instance instance, 166 PP_Instance instance,
229 int mode, 167 int mode,
230 SerializedVarReceiveInput accept_mime_types, 168 SerializedVarReceiveInput accept_mime_types,
231 HostResource* result) { 169 HostResource* result) {
232 result->SetHostResource(instance, ppb_file_chooser_target()->Create( 170 thunk::EnterResourceCreation enter(instance);
233 instance, static_cast<PP_FileChooserMode_Dev>(mode), 171 if (enter.succeeded()) {
234 accept_mime_types.Get(dispatcher()))); 172 result->SetHostResource(instance, enter.functions()->CreateFileChooser(
173 instance, static_cast<PP_FileChooserMode_Dev>(mode),
174 accept_mime_types.Get(dispatcher())));
175 }
235 } 176 }
236 177
237 void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) { 178 void PPB_FileChooser_Proxy::OnMsgShow(const HostResource& chooser) {
238 EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter( 179 EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter(
239 chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback, 180 chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback,
240 chooser); 181 chooser);
241 if (enter.succeeded()) 182 if (enter.succeeded())
242 enter.SetResult(enter.object()->Show(enter.callback())); 183 enter.SetResult(enter.object()->Show(enter.callback()));
243 } 184 }
244 185
245 void PPB_FileChooser_Proxy::OnMsgChooseComplete( 186 void PPB_FileChooser_Proxy::OnMsgChooseComplete(
246 const HostResource& chooser, 187 const HostResource& chooser,
247 int32_t result_code, 188 int32_t result_code,
248 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { 189 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) {
249 EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser); 190 EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser);
250 if (enter.succeeded()) { 191 if (enter.succeeded()) {
251 static_cast<FileChooser*>(enter.object())->ChooseComplete( 192 static_cast<FileChooser*>(enter.object())->ChooseComplete(
252 result_code, chosen_files); 193 result_code, chosen_files);
253 } 194 }
254 } 195 }
255 196
256 void PPB_FileChooser_Proxy::OnShowCallback(int32_t result, 197 void PPB_FileChooser_Proxy::OnShowCallback(int32_t result,
257 const HostResource& chooser) { 198 const HostResource& chooser) {
199 EnterHostFromHostResource<PPB_FileChooser_API> enter(chooser);
200
258 std::vector<PPB_FileRef_CreateInfo> files; 201 std::vector<PPB_FileRef_CreateInfo> files;
259 if (result == PP_OK) { 202 if (enter.succeeded() && result == PP_OK) {
260 // Jump through some hoops to get the FileRef proxy. Since we know we're
261 // in the host at this point, we can ask the host dispatcher for it.
262 DCHECK(!dispatcher()->IsPlugin());
263 HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher());
264 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( 203 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>(
265 host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); 204 dispatcher()->GetInterfaceProxy(INTERFACE_ID_PPB_FILE_REF));
266 205
267 // Convert the returned files to the serialized info. 206 // Convert the returned files to the serialized info.
268 while (PP_Resource cur_file_resource = 207 while (PP_Resource cur_file_resource =
269 ppb_file_chooser_target()->GetNextChosenFile( 208 enter.object()->GetNextChosenFile()) {
270 chooser.host_resource())) {
271 PPB_FileRef_CreateInfo cur_create_info; 209 PPB_FileRef_CreateInfo cur_create_info;
272 file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info); 210 file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info);
273 files.push_back(cur_create_info); 211 files.push_back(cur_create_info);
274 } 212 }
275 } 213 }
276 214
277 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( 215 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete(
278 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files)); 216 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files));
279 } 217 }
280 218
281 } // namespace proxy 219 } // namespace proxy
282 } // namespace ppapi 220 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_file_chooser_proxy.h ('k') | ppapi/proxy/ppb_file_ref_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698