Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: content/renderer/pepper/pepper_file_chooser_host.cc

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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 "ppapi/proxy/ppb_file_ref_proxy.h"
17 #include "third_party/WebKit/public/platform/WebCString.h" 16 #include "third_party/WebKit/public/platform/WebCString.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 17 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebVector.h" 18 #include "third_party/WebKit/public/platform/WebVector.h"
20 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h" 19 #include "third_party/WebKit/public/web/WebFileChooserCompletion.h"
21 #include "third_party/WebKit/public/web/WebFileChooserParams.h" 20 #include "third_party/WebKit/public/web/WebFileChooserParams.h"
22 21
23 namespace content { 22 namespace content {
24 23
25 class PepperFileChooserHost::CompletionHandler 24 class PepperFileChooserHost::CompletionHandler
26 : public WebKit::WebFileChooserCompletion { 25 : public WebKit::WebFileChooserCompletion {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 display_name(display_name) { 73 display_name(display_name) {
75 } 74 }
76 75
77 76
78 PepperFileChooserHost::PepperFileChooserHost( 77 PepperFileChooserHost::PepperFileChooserHost(
79 RendererPpapiHost* host, 78 RendererPpapiHost* host,
80 PP_Instance instance, 79 PP_Instance instance,
81 PP_Resource resource) 80 PP_Resource resource)
82 : ResourceHost(host->GetPpapiHost(), instance, resource), 81 : ResourceHost(host->GetPpapiHost(), instance, resource),
83 renderer_ppapi_host_(host), 82 renderer_ppapi_host_(host),
84 handler_(NULL) { 83 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<ppapi::PPB_FileRef_CreateInfo> chosen_files; 101 std::vector<IPC::Message> create_msgs;
102 std::vector<base::FilePath> file_paths;
103 std::vector<std::string> display_names;
102 for (size_t i = 0; i < files.size(); i++) { 104 for (size_t i = 0; i < files.size(); i++) {
103 #if defined(OS_WIN) 105 #if defined(OS_WIN)
104 base::FilePath file_path(UTF8ToWide(files[i].path)); 106 base::FilePath file_path(UTF8ToWide(files[i].path));
105 #else 107 #else
106 base::FilePath file_path(files[i].path); 108 base::FilePath file_path(files[i].path);
107 #endif 109 #endif
108 110 file_paths.push_back(file_path);
109 PPB_FileRef_Impl* ref = PPB_FileRef_Impl::CreateExternal( 111 create_msgs.push_back(PpapiHostMsg_FileRef_CreateExternal(file_path));
110 pp_instance(), file_path, files[i].display_name); 112 display_names.push_back(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);
115 } 113 }
116 114
117 reply_context_.params.set_result( 115 if (!files.empty()) {
118 (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); 116 renderer_ppapi_host_->CreateBrowserResourceHosts(
119 host()->SendReply(reply_context_, 117 pp_instance(),
120 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); 118 create_msgs,
121 119 base::Bind(&PepperFileChooserHost::DidCreateResourceHosts,
122 reply_context_ = ppapi::host::ReplyMessageContext(); 120 weak_factory_.GetWeakPtr(),
123 handler_ = NULL; // Handler deletes itself. 121 file_paths,
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 }
124 } 131 }
125 132
126 int32_t PepperFileChooserHost::OnShow( 133 int32_t PepperFileChooserHost::OnShow(
127 ppapi::host::HostMessageContext* context, 134 ppapi::host::HostMessageContext* context,
128 bool save_as, 135 bool save_as,
129 bool open_multiple, 136 bool open_multiple,
130 const std::string& suggested_file_name, 137 const std::string& suggested_file_name,
131 const std::vector<std::string>& accept_mime_types) { 138 const std::vector<std::string>& accept_mime_types) {
132 if (handler_) 139 if (handler_)
133 return PP_ERROR_INPROGRESS; // Already pending. 140 return PP_ERROR_INPROGRESS; // Already pending.
(...skipping 26 matching lines...) Expand all
160 if (!render_view || !render_view->runFileChooser(params, handler_)) { 167 if (!render_view || !render_view->runFileChooser(params, handler_)) {
161 delete handler_; 168 delete handler_;
162 handler_ = NULL; 169 handler_ = NULL;
163 return PP_ERROR_NOACCESS; 170 return PP_ERROR_NOACCESS;
164 } 171 }
165 172
166 reply_context_ = context->MakeReplyMessageContext(); 173 reply_context_ = context->MakeReplyMessageContext();
167 return PP_OK_COMPLETIONPENDING; 174 return PP_OK_COMPLETIONPENDING;
168 } 175 }
169 176
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
170 } // namespace content 206 } // namespace content
171 207
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_file_chooser_host.h ('k') | content/renderer/pepper/pepper_file_chooser_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698