| 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/string_split.h" | 7 #include "base/string_split.h" |
| 8 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/proxy/dispatch_reply_message.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
| 11 #include "ppapi/proxy/ppb_file_ref_proxy.h" | 12 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
| 12 #include "ppapi/shared_impl/var.h" | 13 #include "ppapi/shared_impl/var.h" |
| 13 | 14 |
| 14 namespace ppapi { | 15 namespace ppapi { |
| 15 namespace proxy { | 16 namespace proxy { |
| 16 | 17 |
| 17 FileChooserResource::FileChooserResource(IPC::Sender* sender, | 18 FileChooserResource::FileChooserResource(Connection connection, |
| 18 PP_Instance instance, | 19 PP_Instance instance, |
| 19 PP_FileChooserMode_Dev mode, | 20 PP_FileChooserMode_Dev mode, |
| 20 const std::string& accept_types) | 21 const std::string& accept_types) |
| 21 : PluginResource(sender, instance), | 22 : PluginResource(connection, instance), |
| 22 mode_(mode) { | 23 mode_(mode) { |
| 23 PopulateAcceptTypes(accept_types, &accept_types_); | 24 PopulateAcceptTypes(accept_types, &accept_types_); |
| 24 } | 25 } |
| 25 | 26 |
| 26 FileChooserResource::~FileChooserResource() { | 27 FileChooserResource::~FileChooserResource() { |
| 27 } | 28 } |
| 28 | 29 |
| 29 thunk::PPB_FileChooser_API* FileChooserResource::AsPPB_FileChooser_API() { | 30 thunk::PPB_FileChooser_API* FileChooserResource::AsPPB_FileChooser_API() { |
| 30 return this; | 31 return this; |
| 31 } | 32 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // type it would just be a "/". | 90 // type it would just be a "/". |
| 90 if (type.length() < 2) | 91 if (type.length() < 2) |
| 91 continue; | 92 continue; |
| 92 if (type.find_first_of('/') == std::string::npos && type[0] != '.') | 93 if (type.find_first_of('/') == std::string::npos && type[0] != '.') |
| 93 continue; | 94 continue; |
| 94 StringToLowerASCII(&type); | 95 StringToLowerASCII(&type); |
| 95 output->push_back(type); | 96 output->push_back(type); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 void FileChooserResource::OnReplyReceived(int /* sequence */, | 100 void FileChooserResource::OnReplyReceived( |
| 100 int32_t result, | 101 const ResourceMessageReplyParams& params, |
| 101 const IPC::Message& msg) { | 102 const IPC::Message& msg) { |
| 102 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param param; | 103 IPC_BEGIN_MESSAGE_MAP(FileChooserResource, msg) |
| 103 PpapiPluginMsg_FileChooser_ShowReply::Read(&msg, ¶m); | 104 PPAPI_DISPATCH_RESOURCE_REPLY(PpapiPluginMsg_FileChooser_ShowReply, |
| 104 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chosen_files = param.a; | 105 OnPluginMsgShowReply) |
| 106 IPC_END_MESSAGE_MAP() |
| 107 } |
| 105 | 108 |
| 109 void FileChooserResource::OnPluginMsgShowReply( |
| 110 const ResourceMessageReplyParams& params, |
| 111 const std::vector<PPB_FileRef_CreateInfo>& chosen_files) { |
| 106 if (output_.is_valid()) { | 112 if (output_.is_valid()) { |
| 107 // Using v0.6 of the API with the output array. | 113 // Using v0.6 of the API with the output array. |
| 108 std::vector<PP_Resource> files; | 114 std::vector<PP_Resource> files; |
| 109 for (size_t i = 0; i < chosen_files.size(); i++) | 115 for (size_t i = 0; i < chosen_files.size(); i++) |
| 110 files.push_back(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); | 116 files.push_back(PPB_FileRef_Proxy::DeserializeFileRef(chosen_files[i])); |
| 111 output_.StoreResourceVector(files); | 117 output_.StoreResourceVector(files); |
| 112 } else { | 118 } else { |
| 113 // Convert each of the passed in file infos to resources. These will be | 119 // Convert each of the passed in file infos to resources. These will be |
| 114 // owned by the FileChooser object until they're passed to the plugin. | 120 // owned by the FileChooser object until they're passed to the plugin. |
| 115 DCHECK(file_queue_.empty()); | 121 DCHECK(file_queue_.empty()); |
| 116 for (size_t i = 0; i < chosen_files.size(); i++) { | 122 for (size_t i = 0; i < chosen_files.size(); i++) { |
| 117 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef( | 123 file_queue_.push(PPB_FileRef_Proxy::DeserializeFileRef( |
| 118 chosen_files[i])); | 124 chosen_files[i])); |
| 119 } | 125 } |
| 120 } | 126 } |
| 121 | 127 |
| 122 // Notify the plugin of the new data. | 128 // Notify the plugin of the new data. |
| 123 TrackedCallback::ClearAndRun(&callback_, result); | 129 TrackedCallback::ClearAndRun(&callback_, params.result()); |
| 124 // DANGER: May delete |this|! | 130 // DANGER: May delete |this|! |
| 125 } | 131 } |
| 126 | 132 |
| 127 int32_t FileChooserResource::ShowInternal( | 133 int32_t FileChooserResource::ShowInternal( |
| 128 PP_Bool save_as, | 134 PP_Bool save_as, |
| 129 const PP_Var& suggested_file_name, | 135 const PP_Var& suggested_file_name, |
| 130 scoped_refptr<TrackedCallback> callback) { | 136 scoped_refptr<TrackedCallback> callback) { |
| 131 if (TrackedCallback::IsPending(callback_)) | 137 if (TrackedCallback::IsPending(callback_)) |
| 132 return PP_ERROR_INPROGRESS; | 138 return PP_ERROR_INPROGRESS; |
| 133 | 139 |
| 134 if (!sent_create_to_renderer()) | 140 if (!sent_create_to_renderer()) |
| 135 SendCreateToRenderer(PpapiHostMsg_FileChooser_Create()); | 141 SendCreateToRenderer(PpapiHostMsg_FileChooser_Create()); |
| 136 | 142 |
| 137 callback_ = callback; | 143 callback_ = callback; |
| 138 StringVar* sugg_str = StringVar::FromPPVar(suggested_file_name); | 144 StringVar* sugg_str = StringVar::FromPPVar(suggested_file_name); |
| 139 | 145 |
| 140 CallRenderer(PpapiHostMsg_FileChooser_Show( | 146 CallRenderer(PpapiHostMsg_FileChooser_Show( |
| 141 PP_ToBool(save_as), | 147 PP_ToBool(save_as), |
| 142 mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE, | 148 mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE, |
| 143 sugg_str ? sugg_str->value() : std::string(), | 149 sugg_str ? sugg_str->value() : std::string(), |
| 144 accept_types_)); | 150 accept_types_)); |
| 145 return PP_OK_COMPLETIONPENDING; | 151 return PP_OK_COMPLETIONPENDING; |
| 146 } | 152 } |
| 147 | 153 |
| 148 } // namespace proxy | 154 } // namespace proxy |
| 149 } // namespace ppapi | 155 } // namespace ppapi |
| OLD | NEW |