| 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/pepper_file_ref_renderer_host.h" | 10 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
| 11 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
| 12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/host/dispatch_host_message.h" | 13 #include "ppapi/host/dispatch_host_message.h" |
| 14 #include "ppapi/host/ppapi_host.h" | 14 #include "ppapi/host/ppapi_host.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "third_party/WebKit/public/platform/WebCString.h" | 16 #include "third_party/WebKit/public/platform/WebCString.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebVector.h" | 18 #include "third_party/WebKit/public/platform/WebVector.h" |
| 19 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" | 19 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" |
| 20 #include "third_party/WebKit/public/web/WebFileChooserParams.h" | 20 #include "third_party/WebKit/public/web/WebFileChooserParams.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 class PepperFileChooserHost::CompletionHandler | 24 class PepperFileChooserHost::CompletionHandler |
| 25 : public WebKit::WebFileChooserCompletion { | 25 : public blink::WebFileChooserCompletion { |
| 26 public: | 26 public: |
| 27 CompletionHandler(const base::WeakPtr<PepperFileChooserHost>& host) | 27 CompletionHandler(const base::WeakPtr<PepperFileChooserHost>& host) |
| 28 : host_(host) { | 28 : host_(host) { |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual ~CompletionHandler() {} | 31 virtual ~CompletionHandler() {} |
| 32 | 32 |
| 33 virtual void didChooseFile( | 33 virtual void didChooseFile( |
| 34 const WebKit::WebVector<WebKit::WebString>& file_names) { | 34 const blink::WebVector<blink::WebString>& file_names) { |
| 35 if (host_.get()) { | 35 if (host_.get()) { |
| 36 std::vector<PepperFileChooserHost::ChosenFileInfo> files; | 36 std::vector<PepperFileChooserHost::ChosenFileInfo> files; |
| 37 for (size_t i = 0; i < file_names.size(); i++) { | 37 for (size_t i = 0; i < file_names.size(); i++) { |
| 38 files.push_back(PepperFileChooserHost::ChosenFileInfo( | 38 files.push_back(PepperFileChooserHost::ChosenFileInfo( |
| 39 file_names[i].utf8(), std::string())); | 39 file_names[i].utf8(), std::string())); |
| 40 } | 40 } |
| 41 host_->StoreChosenFiles(files); | 41 host_->StoreChosenFiles(files); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // It is the responsibility of this method to delete the instance. | 44 // It is the responsibility of this method to delete the instance. |
| 45 delete this; | 45 delete this; |
| 46 } | 46 } |
| 47 virtual void didChooseFile( | 47 virtual void didChooseFile( |
| 48 const WebKit::WebVector<SelectedFileInfo>& file_names) { | 48 const blink::WebVector<SelectedFileInfo>& file_names) { |
| 49 if (host_.get()) { | 49 if (host_.get()) { |
| 50 std::vector<PepperFileChooserHost::ChosenFileInfo> files; | 50 std::vector<PepperFileChooserHost::ChosenFileInfo> files; |
| 51 for (size_t i = 0; i < file_names.size(); i++) { | 51 for (size_t i = 0; i < file_names.size(); i++) { |
| 52 files.push_back(PepperFileChooserHost::ChosenFileInfo( | 52 files.push_back(PepperFileChooserHost::ChosenFileInfo( |
| 53 file_names[i].path.utf8(), | 53 file_names[i].path.utf8(), |
| 54 file_names[i].displayName.utf8())); | 54 file_names[i].displayName.utf8())); |
| 55 } | 55 } |
| 56 host_->StoreChosenFiles(files); | 56 host_->StoreChosenFiles(files); |
| 57 } | 57 } |
| 58 | 58 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 const std::vector<std::string>& accept_mime_types) { | 138 const std::vector<std::string>& accept_mime_types) { |
| 139 if (handler_) | 139 if (handler_) |
| 140 return PP_ERROR_INPROGRESS; // Already pending. | 140 return PP_ERROR_INPROGRESS; // Already pending. |
| 141 | 141 |
| 142 if (!host()->permissions().HasPermission( | 142 if (!host()->permissions().HasPermission( |
| 143 ppapi::PERMISSION_BYPASS_USER_GESTURE) && | 143 ppapi::PERMISSION_BYPASS_USER_GESTURE) && |
| 144 !renderer_ppapi_host_->HasUserGesture(pp_instance())) { | 144 !renderer_ppapi_host_->HasUserGesture(pp_instance())) { |
| 145 return PP_ERROR_NO_USER_GESTURE; | 145 return PP_ERROR_NO_USER_GESTURE; |
| 146 } | 146 } |
| 147 | 147 |
| 148 WebKit::WebFileChooserParams params; | 148 blink::WebFileChooserParams params; |
| 149 if (save_as) { | 149 if (save_as) { |
| 150 params.saveAs = true; | 150 params.saveAs = true; |
| 151 params.initialValue = WebKit::WebString::fromUTF8( | 151 params.initialValue = blink::WebString::fromUTF8( |
| 152 suggested_file_name.data(), suggested_file_name.size()); | 152 suggested_file_name.data(), suggested_file_name.size()); |
| 153 } else { | 153 } else { |
| 154 params.multiSelect = open_multiple; | 154 params.multiSelect = open_multiple; |
| 155 } | 155 } |
| 156 std::vector<WebKit::WebString> mine_types(accept_mime_types.size()); | 156 std::vector<blink::WebString> mine_types(accept_mime_types.size()); |
| 157 for (size_t i = 0; i < accept_mime_types.size(); i++) { | 157 for (size_t i = 0; i < accept_mime_types.size(); i++) { |
| 158 mine_types[i] = WebKit::WebString::fromUTF8( | 158 mine_types[i] = blink::WebString::fromUTF8( |
| 159 accept_mime_types[i].data(), accept_mime_types[i].size()); | 159 accept_mime_types[i].data(), accept_mime_types[i].size()); |
| 160 } | 160 } |
| 161 params.acceptTypes = mine_types; | 161 params.acceptTypes = mine_types; |
| 162 params.directory = false; | 162 params.directory = false; |
| 163 | 163 |
| 164 handler_ = new CompletionHandler(AsWeakPtr()); | 164 handler_ = new CompletionHandler(AsWeakPtr()); |
| 165 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( | 165 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( |
| 166 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); | 166 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); |
| 167 if (!render_view || !render_view->runFileChooser(params, handler_)) { | 167 if (!render_view || !render_view->runFileChooser(params, handler_)) { |
| 168 delete handler_; | 168 delete handler_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 198 | 198 |
| 199 reply_context_.params.set_result(PP_OK); | 199 reply_context_.params.set_result(PP_OK); |
| 200 host()->SendReply(reply_context_, | 200 host()->SendReply(reply_context_, |
| 201 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); | 201 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); |
| 202 reply_context_ = ppapi::host::ReplyMessageContext(); | 202 reply_context_ = ppapi::host::ReplyMessageContext(); |
| 203 handler_ = NULL; // Handler deletes itself. | 203 handler_ = NULL; // Handler deletes itself. |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace content | 206 } // namespace content |
| 207 | 207 |
| OLD | NEW |