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