OLD | NEW |
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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // Resource overrides. | 32 // Resource overrides. |
33 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; | 33 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; |
34 | 34 |
35 // PPB_FileChooser_API implementation. | 35 // PPB_FileChooser_API implementation. |
36 virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE; | 36 virtual int32_t Show(const PP_CompletionCallback& callback) OVERRIDE; |
37 virtual PP_Resource GetNextChosenFile() OVERRIDE; | 37 virtual PP_Resource GetNextChosenFile() OVERRIDE; |
38 | 38 |
39 // Handles the choose complete notification from the host. | 39 // Handles the choose complete notification from the host. |
40 void ChooseComplete( | 40 void ChooseComplete( |
41 int32_t result_code, | 41 int32_t result_code, |
42 const std::vector<PPBFileRef_CreateInfo>& chosen_files); | 42 const std::vector<PPB_FileRef_CreateInfo>& chosen_files); |
43 | 43 |
44 private: | 44 private: |
45 PP_CompletionCallback current_show_callback_; | 45 PP_CompletionCallback current_show_callback_; |
46 | 46 |
47 // All files returned by the current show callback that haven't yet been | 47 // All files returned by the current show callback that haven't yet been |
48 // given to the plugin. The plugin will repeatedly call us to get the next | 48 // given to the plugin. The plugin will repeatedly call us to get the next |
49 // file, and we'll vend those out of this queue, removing them when ownership | 49 // file, and we'll vend those out of this queue, removing them when ownership |
50 // has transferred to the plugin. | 50 // has transferred to the plugin. |
51 std::queue<PP_Resource> file_queue_; | 51 std::queue<PP_Resource> file_queue_; |
52 | 52 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Return the next resource in the queue. These resource have already been | 99 // Return the next resource in the queue. These resource have already been |
100 // addrefed (they're currently owned by the FileChooser) and returning them | 100 // addrefed (they're currently owned by the FileChooser) and returning them |
101 // transfers ownership of that reference to the plugin. | 101 // transfers ownership of that reference to the plugin. |
102 PP_Resource next = file_queue_.front(); | 102 PP_Resource next = file_queue_.front(); |
103 file_queue_.pop(); | 103 file_queue_.pop(); |
104 return next; | 104 return next; |
105 } | 105 } |
106 | 106 |
107 void FileChooser::ChooseComplete( | 107 void FileChooser::ChooseComplete( |
108 int32_t result_code, | 108 int32_t result_code, |
109 const std::vector<PPBFileRef_CreateInfo>& chosen_files) { | 109 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { |
110 // Convert each of the passed in file infos to resources. These will be owned | 110 // Convert each of the passed in file infos to resources. These will be owned |
111 // by the FileChooser object until they're passed to the plugin. | 111 // by the FileChooser object until they're passed to the plugin. |
112 DCHECK(file_queue_.empty()); | 112 DCHECK(file_queue_.empty()); |
113 for (size_t i = 0; i < chosen_files.size(); i++) | 113 for (size_t i = 0; i < chosen_files.size(); i++) |
114 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); | 114 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); |
115 | 115 |
116 // Notify the plugin of the new data. | 116 // Notify the plugin of the new data. |
117 PP_RunAndClearCompletionCallback(¤t_show_callback_, result_code); | 117 PP_RunAndClearCompletionCallback(¤t_show_callback_, result_code); |
118 // DANGER: May delete |this|! | 118 // DANGER: May delete |this|! |
119 } | 119 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter( | 238 EnterHostFromHostResourceForceCallback<PPB_FileChooser_API> enter( |
239 chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback, | 239 chooser, callback_factory_, &PPB_FileChooser_Proxy::OnShowCallback, |
240 chooser); | 240 chooser); |
241 if (enter.succeeded()) | 241 if (enter.succeeded()) |
242 enter.SetResult(enter.object()->Show(enter.callback())); | 242 enter.SetResult(enter.object()->Show(enter.callback())); |
243 } | 243 } |
244 | 244 |
245 void PPB_FileChooser_Proxy::OnMsgChooseComplete( | 245 void PPB_FileChooser_Proxy::OnMsgChooseComplete( |
246 const HostResource& chooser, | 246 const HostResource& chooser, |
247 int32_t result_code, | 247 int32_t result_code, |
248 const std::vector<PPBFileRef_CreateInfo>& chosen_files) { | 248 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { |
249 EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser); | 249 EnterPluginFromHostResource<PPB_FileChooser_API> enter(chooser); |
250 if (enter.succeeded()) { | 250 if (enter.succeeded()) { |
251 static_cast<FileChooser*>(enter.object())->ChooseComplete( | 251 static_cast<FileChooser*>(enter.object())->ChooseComplete( |
252 result_code, chosen_files); | 252 result_code, chosen_files); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 void PPB_FileChooser_Proxy::OnShowCallback(int32_t result, | 256 void PPB_FileChooser_Proxy::OnShowCallback(int32_t result, |
257 const HostResource& chooser) { | 257 const HostResource& chooser) { |
258 std::vector<PPBFileRef_CreateInfo> files; | 258 std::vector<PPB_FileRef_CreateInfo> files; |
259 if (result == PP_OK) { | 259 if (result == PP_OK) { |
260 // Jump through some hoops to get the FileRef proxy. Since we know we're | 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. | 261 // in the host at this point, we can ask the host dispatcher for it. |
262 DCHECK(!dispatcher()->IsPlugin()); | 262 DCHECK(!dispatcher()->IsPlugin()); |
263 HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher()); | 263 HostDispatcher* host_disp = static_cast<HostDispatcher*>(dispatcher()); |
264 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( | 264 PPB_FileRef_Proxy* file_ref_proxy = static_cast<PPB_FileRef_Proxy*>( |
265 host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); | 265 host_disp->GetOrCreatePPBInterfaceProxy(INTERFACE_ID_PPB_FILE_REF)); |
266 | 266 |
267 // Convert the returned files to the serialized info. | 267 // Convert the returned files to the serialized info. |
268 while (PP_Resource cur_file_resource = | 268 while (PP_Resource cur_file_resource = |
269 ppb_file_chooser_target()->GetNextChosenFile( | 269 ppb_file_chooser_target()->GetNextChosenFile( |
270 chooser.host_resource())) { | 270 chooser.host_resource())) { |
271 PPBFileRef_CreateInfo cur_create_info; | 271 PPB_FileRef_CreateInfo cur_create_info; |
272 file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info); | 272 file_ref_proxy->SerializeFileRef(cur_file_resource, &cur_create_info); |
273 files.push_back(cur_create_info); | 273 files.push_back(cur_create_info); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( | 277 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( |
278 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files)); | 278 INTERFACE_ID_PPB_FILE_CHOOSER, chooser, result, files)); |
279 } | 279 } |
280 | 280 |
281 } // namespace proxy | 281 } // namespace proxy |
282 } // namespace ppapi | 282 } // namespace ppapi |
OLD | NEW |