| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_chooser_resource.h" | 5 #include "ppapi/proxy/file_chooser_resource.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| 11 #include "ppapi/proxy/dispatch_reply_message.h" | 11 #include "ppapi/proxy/dispatch_reply_message.h" |
| 12 #include "ppapi/proxy/file_ref_resource.h" | |
| 13 #include "ppapi/proxy/ppapi_messages.h" | 12 #include "ppapi/proxy/ppapi_messages.h" |
| 13 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
| 14 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
| 15 | 15 |
| 16 namespace ppapi { | 16 namespace ppapi { |
| 17 namespace proxy { | 17 namespace proxy { |
| 18 | 18 |
| 19 FileChooserResource::FileChooserResource(Connection connection, | 19 FileChooserResource::FileChooserResource(Connection connection, |
| 20 PP_Instance instance, | 20 PP_Instance instance, |
| 21 PP_FileChooserMode_Dev mode, | 21 PP_FileChooserMode_Dev mode, |
| 22 const std::string& accept_types) | 22 const std::string& accept_types) |
| 23 : PluginResource(connection, instance), | 23 : PluginResource(connection, instance), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 continue; | 93 continue; |
| 94 if (type.find_first_of('/') == std::string::npos && type[0] != '.') | 94 if (type.find_first_of('/') == std::string::npos && type[0] != '.') |
| 95 continue; | 95 continue; |
| 96 StringToLowerASCII(&type); | 96 StringToLowerASCII(&type); |
| 97 output->push_back(type); | 97 output->push_back(type); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 | 100 |
| 101 void FileChooserResource::OnPluginMsgShowReply( | 101 void FileChooserResource::OnPluginMsgShowReply( |
| 102 const ResourceMessageReplyParams& params, | 102 const ResourceMessageReplyParams& params, |
| 103 const std::vector<FileRefCreateInfo>& chosen_files) { | 103 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { |
| 104 if (output_.is_valid()) { | 104 if (output_.is_valid()) { |
| 105 // Using v0.6 of the API with the output array. | 105 // Using v0.6 of the API with the output array. |
| 106 std::vector<PP_Resource> files; | 106 std::vector<PP_Resource> files; |
| 107 for (size_t i = 0; i < chosen_files.size(); i++) { | 107 for (size_t i = 0; i < chosen_files.size(); i++) |
| 108 files.push_back(FileRefResource::CreateFileRef( | 108 files.push_back(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); |
| 109 connection(), | |
| 110 pp_instance(), | |
| 111 chosen_files[i])); | |
| 112 } | |
| 113 output_.StoreResourceVector(files); | 109 output_.StoreResourceVector(files); |
| 114 } else { | 110 } else { |
| 115 // Convert each of the passed in file infos to resources. These will be | 111 // Convert each of the passed in file infos to resources. These will be |
| 116 // owned by the FileChooser object until they're passed to the plugin. | 112 // owned by the FileChooser object until they're passed to the plugin. |
| 117 DCHECK(file_queue_.empty()); | 113 DCHECK(file_queue_.empty()); |
| 118 for (size_t i = 0; i < chosen_files.size(); i++) { | 114 for (size_t i = 0; i < chosen_files.size(); i++) { |
| 119 file_queue_.push(FileRefResource::CreateFileRef( | 115 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef( |
| 120 connection(), | |
| 121 pp_instance(), | |
| 122 chosen_files[i])); | 116 chosen_files[i])); |
| 123 } | 117 } |
| 124 } | 118 } |
| 125 | 119 |
| 126 // Notify the plugin of the new data. | 120 // Notify the plugin of the new data. |
| 127 callback_->Run(params.result()); | 121 callback_->Run(params.result()); |
| 128 // DANGER: May delete |this|! | 122 // DANGER: May delete |this|! |
| 129 } | 123 } |
| 130 | 124 |
| 131 int32_t FileChooserResource::ShowInternal( | 125 int32_t FileChooserResource::ShowInternal( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 146 mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE, | 140 mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE, |
| 147 sugg_str ? sugg_str->value() : std::string(), | 141 sugg_str ? sugg_str->value() : std::string(), |
| 148 accept_types_); | 142 accept_types_); |
| 149 Call<PpapiPluginMsg_FileChooser_ShowReply>(RENDERER, msg, | 143 Call<PpapiPluginMsg_FileChooser_ShowReply>(RENDERER, msg, |
| 150 base::Bind(&FileChooserResource::OnPluginMsgShowReply, this)); | 144 base::Bind(&FileChooserResource::OnPluginMsgShowReply, this)); |
| 151 return PP_OK_COMPLETIONPENDING; | 145 return PP_OK_COMPLETIONPENDING; |
| 152 } | 146 } |
| 153 | 147 |
| 154 } // namespace proxy | 148 } // namespace proxy |
| 155 } // namespace ppapi | 149 } // namespace ppapi |
| OLD | NEW |