| 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 "content/renderer/pepper/pepper_file_chooser_host.h" | 5 #include "content/renderer/pepper/pepper_file_chooser_host.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
| 10 #include "content/renderer/pepper/ppb_file_ref_impl.h" |
| 10 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
| 11 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/host/dispatch_host_message.h" | 13 #include "ppapi/host/dispatch_host_message.h" |
| 13 #include "ppapi/host/ppapi_host.h" | 14 #include "ppapi/host/ppapi_host.h" |
| 14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
| 15 #include "third_party/WebKit/public/platform/WebCString.h" | 17 #include "third_party/WebKit/public/platform/WebCString.h" |
| 16 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 17 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
| 18 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" | 20 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" |
| 19 #include "third_party/WebKit/public/web/WebFileChooserParams.h" | 21 #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
| 20 | 22 |
| 21 namespace content { | 23 namespace content { |
| 22 | 24 |
| 23 class PepperFileChooserHost::CompletionHandler | 25 class PepperFileChooserHost::CompletionHandler |
| 24 : public WebKit::WebFileChooserCompletion { | 26 : public WebKit::WebFileChooserCompletion { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 display_name(display_name) { | 74 display_name(display_name) { |
| 73 } | 75 } |
| 74 | 76 |
| 75 | 77 |
| 76 PepperFileChooserHost::PepperFileChooserHost( | 78 PepperFileChooserHost::PepperFileChooserHost( |
| 77 RendererPpapiHost* host, | 79 RendererPpapiHost* host, |
| 78 PP_Instance instance, | 80 PP_Instance instance, |
| 79 PP_Resource resource) | 81 PP_Resource resource) |
| 80 : ResourceHost(host->GetPpapiHost(), instance, resource), | 82 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 81 renderer_ppapi_host_(host), | 83 renderer_ppapi_host_(host), |
| 82 handler_(NULL), | 84 handler_(NULL) { |
| 83 weak_factory_(this) { | |
| 84 } | 85 } |
| 85 | 86 |
| 86 PepperFileChooserHost::~PepperFileChooserHost() { | 87 PepperFileChooserHost::~PepperFileChooserHost() { |
| 87 } | 88 } |
| 88 | 89 |
| 89 int32_t PepperFileChooserHost::OnResourceMessageReceived( | 90 int32_t PepperFileChooserHost::OnResourceMessageReceived( |
| 90 const IPC::Message& msg, | 91 const IPC::Message& msg, |
| 91 ppapi::host::HostMessageContext* context) { | 92 ppapi::host::HostMessageContext* context) { |
| 92 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) | 93 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) |
| 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileChooser_Show, OnShow) | 94 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileChooser_Show, OnShow) |
| 94 IPC_END_MESSAGE_MAP() | 95 IPC_END_MESSAGE_MAP() |
| 95 return PP_ERROR_FAILED; | 96 return PP_ERROR_FAILED; |
| 96 } | 97 } |
| 97 | 98 |
| 98 void PepperFileChooserHost::StoreChosenFiles( | 99 void PepperFileChooserHost::StoreChosenFiles( |
| 99 const std::vector<ChosenFileInfo>& files) { | 100 const std::vector<ChosenFileInfo>& files) { |
| 100 std::vector<IPC::Message> create_msgs; | 101 std::vector<ppapi::PPB_FileRef_CreateInfo> chosen_files; |
| 101 std::vector<base::FilePath> file_paths; | |
| 102 std::vector<std::string> display_names; | |
| 103 for (size_t i = 0; i < files.size(); i++) { | 102 for (size_t i = 0; i < files.size(); i++) { |
| 104 #if defined(OS_WIN) | 103 #if defined(OS_WIN) |
| 105 base::FilePath file_path(UTF8ToWide(files[i].path)); | 104 base::FilePath file_path(UTF8ToWide(files[i].path)); |
| 106 #else | 105 #else |
| 107 base::FilePath file_path(files[i].path); | 106 base::FilePath file_path(files[i].path); |
| 108 #endif | 107 #endif |
| 109 file_paths.push_back(file_path); | 108 |
| 110 create_msgs.push_back(PpapiHostMsg_FileRef_CreateExternal(file_path)); | 109 PPB_FileRef_Impl* ref = PPB_FileRef_Impl::CreateExternal( |
| 111 display_names.push_back(files[i].display_name); | 110 pp_instance(), file_path, files[i].display_name); |
| 111 ppapi::PPB_FileRef_CreateInfo create_info; |
| 112 ppapi::proxy::PPB_FileRef_Proxy::SerializeFileRef(ref->GetReference(), |
| 113 &create_info); |
| 114 chosen_files.push_back(create_info); |
| 112 } | 115 } |
| 113 | 116 |
| 114 if (!files.empty()) { | 117 reply_context_.params.set_result( |
| 115 renderer_ppapi_host_->CreateBrowserResourceHosts( | 118 (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); |
| 116 pp_instance(), | 119 host()->SendReply(reply_context_, |
| 117 create_msgs, | 120 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
| 118 base::Bind(&PepperFileChooserHost::DidCreateResourceHosts, | 121 |
| 119 weak_factory_.GetWeakPtr(), | 122 reply_context_ = ppapi::host::ReplyMessageContext(); |
| 120 file_paths, | 123 handler_ = NULL; // Handler deletes itself. |
| 121 display_names)); | |
| 122 } else { | |
| 123 reply_context_.params.set_result(PP_ERROR_USERCANCEL); | |
| 124 std::vector<ppapi::FileRefCreateInfo> chosen_files; | |
| 125 host()->SendReply(reply_context_, | |
| 126 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); | |
| 127 reply_context_ = ppapi::host::ReplyMessageContext(); | |
| 128 handler_ = NULL; // Handler deletes itself. | |
| 129 } | |
| 130 } | 124 } |
| 131 | 125 |
| 132 int32_t PepperFileChooserHost::OnShow( | 126 int32_t PepperFileChooserHost::OnShow( |
| 133 ppapi::host::HostMessageContext* context, | 127 ppapi::host::HostMessageContext* context, |
| 134 bool save_as, | 128 bool save_as, |
| 135 bool open_multiple, | 129 bool open_multiple, |
| 136 const std::string& suggested_file_name, | 130 const std::string& suggested_file_name, |
| 137 const std::vector<std::string>& accept_mime_types) { | 131 const std::vector<std::string>& accept_mime_types) { |
| 138 if (handler_) | 132 if (handler_) |
| 139 return PP_ERROR_INPROGRESS; // Already pending. | 133 return PP_ERROR_INPROGRESS; // Already pending. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 166 if (!render_view || !render_view->runFileChooser(params, handler_)) { | 160 if (!render_view || !render_view->runFileChooser(params, handler_)) { |
| 167 delete handler_; | 161 delete handler_; |
| 168 handler_ = NULL; | 162 handler_ = NULL; |
| 169 return PP_ERROR_NOACCESS; | 163 return PP_ERROR_NOACCESS; |
| 170 } | 164 } |
| 171 | 165 |
| 172 reply_context_ = context->MakeReplyMessageContext(); | 166 reply_context_ = context->MakeReplyMessageContext(); |
| 173 return PP_OK_COMPLETIONPENDING; | 167 return PP_OK_COMPLETIONPENDING; |
| 174 } | 168 } |
| 175 | 169 |
| 176 void PepperFileChooserHost::DidCreateResourceHosts( | |
| 177 const std::vector<base::FilePath>& file_paths, | |
| 178 const std::vector<std::string>& display_names, | |
| 179 const std::vector<int>& ids) { | |
| 180 DCHECK(file_paths.size() == display_names.size()); | |
| 181 DCHECK(file_paths.size() == ids.size()); | |
| 182 | |
| 183 std::vector<ppapi::FileRefCreateInfo> chosen_files; | |
| 184 for (size_t i = 0; i < ids.size(); ++i) { | |
| 185 ppapi::FileRefCreateInfo info = ppapi::MakeExternalFileRefCreateInfo( | |
| 186 file_paths[i], display_names[i], ids[i]); | |
| 187 chosen_files.push_back(info); | |
| 188 } | |
| 189 | |
| 190 reply_context_.params.set_result(PP_OK); | |
| 191 host()->SendReply(reply_context_, | |
| 192 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); | |
| 193 reply_context_ = ppapi::host::ReplyMessageContext(); | |
| 194 handler_ = NULL; // Handler deletes itself. | |
| 195 } | |
| 196 | |
| 197 } // namespace content | 170 } // namespace content |
| 198 | 171 |
| OLD | NEW |