Chromium Code Reviews| Index: content/renderer/pepper/pepper_file_chooser_host.cc |
| diff --git a/content/renderer/pepper/pepper_file_chooser_host.cc b/content/renderer/pepper/pepper_file_chooser_host.cc |
| index 1229d17f610af7a1f69a3ff1e061e54c15e1cf7a..e73694ac33621d8d64fd692f0f60c3c0e1fc533e 100644 |
| --- a/content/renderer/pepper/pepper_file_chooser_host.cc |
| +++ b/content/renderer/pepper/pepper_file_chooser_host.cc |
| @@ -7,13 +7,12 @@ |
| #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/pepper/pepper_file_ref_renderer_host.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" |
| @@ -81,7 +80,8 @@ PepperFileChooserHost::PepperFileChooserHost( |
| PP_Resource resource) |
| : ResourceHost(host->GetPpapiHost(), instance, resource), |
| renderer_ppapi_host_(host), |
| - handler_(NULL) { |
| + handler_(NULL), |
| + weak_factory_(this) { |
| } |
| PepperFileChooserHost::~PepperFileChooserHost() { |
| @@ -98,29 +98,36 @@ int32_t PepperFileChooserHost::OnResourceMessageReceived( |
| void PepperFileChooserHost::StoreChosenFiles( |
| const std::vector<ChosenFileInfo>& files) { |
| - std::vector<ppapi::PPB_FileRef_CreateInfo> chosen_files; |
| + std::vector<IPC::Message> create_msgs; |
| + std::vector<base::FilePath> file_paths; |
| + std::vector<std::string> display_names; |
| 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 |
| - |
| - 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); |
| + file_paths.push_back(file_path); |
| + create_msgs.push_back(PpapiHostMsg_FileRef_CreateExternal(file_path)); |
| + display_names.push_back(files[i].display_name); |
| } |
| - 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. |
| + 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. |
| + } |
| } |
| int32_t PepperFileChooserHost::OnShow( |
| @@ -167,5 +174,34 @@ int32_t PepperFileChooserHost::OnShow( |
| 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>& browser_ids) { |
| + DCHECK(file_paths.size() == display_names.size()); |
| + DCHECK(file_paths.size() == browser_ids.size()); |
| + |
| + std::vector<ppapi::FileRefCreateInfo> chosen_files; |
| + for (size_t i = 0; i < browser_ids.size(); ++i) { |
| + PepperFileRefRendererHost* renderer_host = |
| + new PepperFileRefRendererHost(renderer_ppapi_host_, |
| + pp_instance(), |
| + 0, |
| + file_paths[i]); |
| + int renderer_id = |
| + renderer_ppapi_host_->GetPpapiHost()->AddPendingResourceHost( |
| + scoped_ptr<ppapi::host::ResourceHost>(renderer_host)); |
|
dmichael (off chromium)
2013/09/03 22:34:50
I don't think I have a better suggestion, but it f
teravest
2013/09/04 14:46:25
I don't think it's unfortunate. Now that URLLoader
dmichael (off chromium)
2013/09/04 17:23:54
I understand it has to be done. What I mean is it'
|
| + ppapi::FileRefCreateInfo info = ppapi::MakeExternalFileRefCreateInfo( |
| + file_paths[i], display_names[i], browser_ids[i], renderer_id); |
| + 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 |