| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/public/common/file_chooser_params.h" |
| 12 #include "content/public/renderer/renderer_ppapi_host.h" | 13 #include "content/public/renderer/renderer_ppapi_host.h" |
| 13 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" | 14 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
| 14 #include "content/renderer/render_view_impl.h" | 15 #include "content/renderer/render_view_impl.h" |
| 15 #include "ppapi/c/pp_errors.h" | 16 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/host/dispatch_host_message.h" | 17 #include "ppapi/host/dispatch_host_message.h" |
| 17 #include "ppapi/host/ppapi_host.h" | 18 #include "ppapi/host/ppapi_host.h" |
| 18 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" | 22 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" |
| 22 #include "third_party/WebKit/public/web/WebFileChooserParams.h" | |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 | 25 |
| 26 class PepperFileChooserHost::CompletionHandler | 26 class PepperFileChooserHost::CompletionHandler |
| 27 : public blink::WebFileChooserCompletion { | 27 : public blink::WebFileChooserCompletion { |
| 28 public: | 28 public: |
| 29 explicit CompletionHandler(const base::WeakPtr<PepperFileChooserHost>& host) | 29 explicit CompletionHandler(const base::WeakPtr<PepperFileChooserHost>& host) |
| 30 : host_(host) {} | 30 : host_(host) {} |
| 31 | 31 |
| 32 ~CompletionHandler() override {} | 32 ~CompletionHandler() override {} |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 const std::vector<std::string>& accept_mime_types) { | 128 const std::vector<std::string>& accept_mime_types) { |
| 129 if (handler_) | 129 if (handler_) |
| 130 return PP_ERROR_INPROGRESS; // Already pending. | 130 return PP_ERROR_INPROGRESS; // Already pending. |
| 131 | 131 |
| 132 if (!host()->permissions().HasPermission( | 132 if (!host()->permissions().HasPermission( |
| 133 ppapi::PERMISSION_BYPASS_USER_GESTURE) && | 133 ppapi::PERMISSION_BYPASS_USER_GESTURE) && |
| 134 !renderer_ppapi_host_->HasUserGesture(pp_instance())) { | 134 !renderer_ppapi_host_->HasUserGesture(pp_instance())) { |
| 135 return PP_ERROR_NO_USER_GESTURE; | 135 return PP_ERROR_NO_USER_GESTURE; |
| 136 } | 136 } |
| 137 | 137 |
| 138 blink::WebFileChooserParams params; | 138 FileChooserParams params; |
| 139 if (save_as) { | 139 if (save_as) { |
| 140 params.saveAs = true; | 140 params.mode = FileChooserParams::Save; |
| 141 params.initialValue = blink::WebString::fromUTF8( | 141 params.default_file_name = |
| 142 suggested_file_name.data(), suggested_file_name.size()); | 142 base::FilePath::FromUTF8Unsafe(suggested_file_name).BaseName(); |
| 143 } else { | 143 } else { |
| 144 params.multiSelect = open_multiple; | 144 params.mode = open_multiple ? FileChooserParams::OpenMultiple |
| 145 : FileChooserParams::Open; |
| 145 } | 146 } |
| 146 std::vector<blink::WebString> mime_types(accept_mime_types.size()); | 147 params.accept_types.reserve(accept_mime_types.size()); |
| 147 for (size_t i = 0; i < accept_mime_types.size(); i++) { | 148 for (const auto& mime_type : accept_mime_types) |
| 148 mime_types[i] = blink::WebString::fromUTF8(accept_mime_types[i].data(), | 149 params.accept_types.push_back(base::UTF8ToUTF16(mime_type)); |
| 149 accept_mime_types[i].size()); | 150 params.need_local_path = true; |
| 150 } | 151 |
| 151 params.acceptTypes = mime_types; | |
| 152 params.directory = false; | |
| 153 params.needLocalPath = true; | |
| 154 params.requestor = renderer_ppapi_host_->GetDocumentURL(pp_instance()); | 152 params.requestor = renderer_ppapi_host_->GetDocumentURL(pp_instance()); |
| 155 | 153 |
| 156 handler_ = new CompletionHandler(AsWeakPtr()); | 154 handler_ = new CompletionHandler(AsWeakPtr()); |
| 157 RenderFrameImpl* render_frame = static_cast<RenderFrameImpl*>( | 155 RenderFrameImpl* render_frame = static_cast<RenderFrameImpl*>( |
| 158 renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance())); | 156 renderer_ppapi_host_->GetRenderFrameForInstance(pp_instance())); |
| 159 | 157 |
| 160 if (!render_frame || !render_frame->runFileChooser(params, handler_)) { | 158 if (!render_frame || !render_frame->ScheduleFileChooser(params, handler_)) { |
| 161 delete handler_; | 159 delete handler_; |
| 162 handler_ = NULL; | 160 handler_ = NULL; |
| 163 return PP_ERROR_NOACCESS; | 161 return PP_ERROR_NOACCESS; |
| 164 } | 162 } |
| 165 | 163 |
| 166 reply_context_ = context->MakeReplyMessageContext(); | 164 reply_context_ = context->MakeReplyMessageContext(); |
| 167 return PP_OK_COMPLETIONPENDING; | 165 return PP_OK_COMPLETIONPENDING; |
| 168 } | 166 } |
| 169 | 167 |
| 170 void PepperFileChooserHost::DidCreateResourceHosts( | 168 void PepperFileChooserHost::DidCreateResourceHosts( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 187 } | 185 } |
| 188 | 186 |
| 189 reply_context_.params.set_result(PP_OK); | 187 reply_context_.params.set_result(PP_OK); |
| 190 host()->SendReply(reply_context_, | 188 host()->SendReply(reply_context_, |
| 191 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); | 189 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
| 192 reply_context_ = ppapi::host::ReplyMessageContext(); | 190 reply_context_ = ppapi::host::ReplyMessageContext(); |
| 193 handler_ = NULL; // Handler deletes itself. | 191 handler_ = NULL; // Handler deletes itself. |
| 194 } | 192 } |
| 195 | 193 |
| 196 } // namespace content | 194 } // namespace content |
| OLD | NEW |