Index: trunk/src/content/renderer/pepper/pepper_file_chooser_host.cc |
=================================================================== |
--- trunk/src/content/renderer/pepper/pepper_file_chooser_host.cc (revision 220164) |
+++ trunk/src/content/renderer/pepper/pepper_file_chooser_host.cc (working copy) |
@@ -7,11 +7,13 @@ |
#include "base/files/file_path.h" |
#include "base/strings/utf_string_conversions.h" |
#include "content/public/renderer/renderer_ppapi_host.h" |
+#include "content/renderer/pepper/ppb_file_ref_impl.h" |
#include "content/renderer/render_view_impl.h" |
#include "ppapi/c/pp_errors.h" |
#include "ppapi/host/dispatch_host_message.h" |
#include "ppapi/host/ppapi_host.h" |
#include "ppapi/proxy/ppapi_messages.h" |
+#include "ppapi/proxy/ppb_file_ref_proxy.h" |
#include "third_party/WebKit/public/platform/WebCString.h" |
#include "third_party/WebKit/public/platform/WebString.h" |
#include "third_party/WebKit/public/platform/WebVector.h" |
@@ -79,8 +81,7 @@ |
PP_Resource resource) |
: ResourceHost(host->GetPpapiHost(), instance, resource), |
renderer_ppapi_host_(host), |
- handler_(NULL), |
- weak_factory_(this) { |
+ handler_(NULL) { |
} |
PepperFileChooserHost::~PepperFileChooserHost() { |
@@ -97,36 +98,29 @@ |
void PepperFileChooserHost::StoreChosenFiles( |
const std::vector<ChosenFileInfo>& files) { |
- std::vector<IPC::Message> create_msgs; |
- std::vector<base::FilePath> file_paths; |
- std::vector<std::string> display_names; |
+ std::vector<ppapi::PPB_FileRef_CreateInfo> chosen_files; |
for (size_t i = 0; i < files.size(); i++) { |
#if defined(OS_WIN) |
base::FilePath file_path(UTF8ToWide(files[i].path)); |
#else |
base::FilePath file_path(files[i].path); |
#endif |
- file_paths.push_back(file_path); |
- create_msgs.push_back(PpapiHostMsg_FileRef_CreateExternal(file_path)); |
- display_names.push_back(files[i].display_name); |
- } |
- if (!files.empty()) { |
- renderer_ppapi_host_->CreateBrowserResourceHosts( |
- pp_instance(), |
- create_msgs, |
- base::Bind(&PepperFileChooserHost::DidCreateResourceHosts, |
- weak_factory_.GetWeakPtr(), |
- file_paths, |
- display_names)); |
- } else { |
- reply_context_.params.set_result(PP_ERROR_USERCANCEL); |
- std::vector<ppapi::FileRefCreateInfo> chosen_files; |
- host()->SendReply(reply_context_, |
- PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
- reply_context_ = ppapi::host::ReplyMessageContext(); |
- handler_ = NULL; // Handler deletes itself. |
+ PPB_FileRef_Impl* ref = PPB_FileRef_Impl::CreateExternal( |
+ pp_instance(), file_path, files[i].display_name); |
+ ppapi::PPB_FileRef_CreateInfo create_info; |
+ ppapi::proxy::PPB_FileRef_Proxy::SerializeFileRef(ref->GetReference(), |
+ &create_info); |
+ chosen_files.push_back(create_info); |
} |
+ |
+ reply_context_.params.set_result( |
+ (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); |
+ host()->SendReply(reply_context_, |
+ PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
+ |
+ reply_context_ = ppapi::host::ReplyMessageContext(); |
+ handler_ = NULL; // Handler deletes itself. |
} |
int32_t PepperFileChooserHost::OnShow( |
@@ -173,26 +167,5 @@ |
return PP_OK_COMPLETIONPENDING; |
} |
-void PepperFileChooserHost::DidCreateResourceHosts( |
- const std::vector<base::FilePath>& file_paths, |
- const std::vector<std::string>& display_names, |
- const std::vector<int>& ids) { |
- DCHECK(file_paths.size() == display_names.size()); |
- DCHECK(file_paths.size() == ids.size()); |
- |
- std::vector<ppapi::FileRefCreateInfo> chosen_files; |
- for (size_t i = 0; i < ids.size(); ++i) { |
- ppapi::FileRefCreateInfo info = ppapi::MakeExternalFileRefCreateInfo( |
- file_paths[i], display_names[i], ids[i]); |
- chosen_files.push_back(info); |
- } |
- |
- reply_context_.params.set_result(PP_OK); |
- host()->SendReply(reply_context_, |
- PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
- reply_context_ = ppapi::host::ReplyMessageContext(); |
- handler_ = NULL; // Handler deletes itself. |
-} |
- |
} // namespace content |