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

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

Issue 225903006: PPAPI: Run clang_format.py on content/renderer/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 6 years, 8 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/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 blink::WebFileChooserCompletion { 25 : public blink::WebFileChooserCompletion {
26 public: 26 public:
27 explicit CompletionHandler(const base::WeakPtr<PepperFileChooserHost>& host) 27 explicit CompletionHandler(const base::WeakPtr<PepperFileChooserHost>& host)
28 : host_(host) { 28 : host_(host) {}
29 }
30 29
31 virtual ~CompletionHandler() {} 30 virtual ~CompletionHandler() {}
32 31
33 virtual void didChooseFile( 32 virtual void didChooseFile(
34 const blink::WebVector<blink::WebString>& file_names) { 33 const blink::WebVector<blink::WebString>& file_names) {
35 if (host_.get()) { 34 if (host_.get()) {
36 std::vector<PepperFileChooserHost::ChosenFileInfo> files; 35 std::vector<PepperFileChooserHost::ChosenFileInfo> files;
37 for (size_t i = 0; i < file_names.size(); i++) { 36 for (size_t i = 0; i < file_names.size(); i++) {
38 files.push_back(PepperFileChooserHost::ChosenFileInfo( 37 files.push_back(PepperFileChooserHost::ChosenFileInfo(
39 file_names[i].utf8(), std::string())); 38 file_names[i].utf8(), std::string()));
40 } 39 }
41 host_->StoreChosenFiles(files); 40 host_->StoreChosenFiles(files);
42 } 41 }
43 42
44 // It is the responsibility of this method to delete the instance. 43 // It is the responsibility of this method to delete the instance.
45 delete this; 44 delete this;
46 } 45 }
47 virtual void didChooseFile( 46 virtual void didChooseFile(
48 const blink::WebVector<SelectedFileInfo>& file_names) { 47 const blink::WebVector<SelectedFileInfo>& file_names) {
49 if (host_.get()) { 48 if (host_.get()) {
50 std::vector<PepperFileChooserHost::ChosenFileInfo> files; 49 std::vector<PepperFileChooserHost::ChosenFileInfo> files;
51 for (size_t i = 0; i < file_names.size(); i++) { 50 for (size_t i = 0; i < file_names.size(); i++) {
52 files.push_back(PepperFileChooserHost::ChosenFileInfo( 51 files.push_back(PepperFileChooserHost::ChosenFileInfo(
53 file_names[i].path.utf8(), 52 file_names[i].path.utf8(), file_names[i].displayName.utf8()));
54 file_names[i].displayName.utf8()));
55 } 53 }
56 host_->StoreChosenFiles(files); 54 host_->StoreChosenFiles(files);
57 } 55 }
58 56
59 // It is the responsibility of this method to delete the instance. 57 // It is the responsibility of this method to delete the instance.
60 delete this; 58 delete this;
61 } 59 }
62 60
63 private: 61 private:
64 base::WeakPtr<PepperFileChooserHost> host_; 62 base::WeakPtr<PepperFileChooserHost> host_;
65 63
66 DISALLOW_COPY_AND_ASSIGN(CompletionHandler); 64 DISALLOW_COPY_AND_ASSIGN(CompletionHandler);
67 }; 65 };
68 66
69 PepperFileChooserHost::ChosenFileInfo::ChosenFileInfo( 67 PepperFileChooserHost::ChosenFileInfo::ChosenFileInfo(
70 const std::string& path, 68 const std::string& path,
71 const std::string& display_name) 69 const std::string& display_name)
72 : path(path), 70 : path(path), display_name(display_name) {}
73 display_name(display_name) {
74 }
75 71
76 72 PepperFileChooserHost::PepperFileChooserHost(RendererPpapiHost* host,
77 PepperFileChooserHost::PepperFileChooserHost( 73 PP_Instance instance,
78 RendererPpapiHost* host, 74 PP_Resource resource)
79 PP_Instance instance,
80 PP_Resource resource)
81 : ResourceHost(host->GetPpapiHost(), instance, resource), 75 : ResourceHost(host->GetPpapiHost(), instance, resource),
82 renderer_ppapi_host_(host), 76 renderer_ppapi_host_(host),
83 handler_(NULL), 77 handler_(NULL),
84 weak_factory_(this) { 78 weak_factory_(this) {}
85 }
86 79
87 PepperFileChooserHost::~PepperFileChooserHost() { 80 PepperFileChooserHost::~PepperFileChooserHost() {}
88 }
89 81
90 int32_t PepperFileChooserHost::OnResourceMessageReceived( 82 int32_t PepperFileChooserHost::OnResourceMessageReceived(
91 const IPC::Message& msg, 83 const IPC::Message& msg,
92 ppapi::host::HostMessageContext* context) { 84 ppapi::host::HostMessageContext* context) {
93 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg) 85 IPC_BEGIN_MESSAGE_MAP(PepperFileChooserHost, msg)
94 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileChooser_Show, OnShow) 86 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileChooser_Show, OnShow)
95 IPC_END_MESSAGE_MAP() 87 IPC_END_MESSAGE_MAP()
96 return PP_ERROR_FAILED; 88 return PP_ERROR_FAILED;
97 } 89 }
98 90
99 void PepperFileChooserHost::StoreChosenFiles( 91 void PepperFileChooserHost::StoreChosenFiles(
100 const std::vector<ChosenFileInfo>& files) { 92 const std::vector<ChosenFileInfo>& files) {
101 std::vector<IPC::Message> create_msgs; 93 std::vector<IPC::Message> create_msgs;
102 std::vector<base::FilePath> file_paths; 94 std::vector<base::FilePath> file_paths;
103 std::vector<std::string> display_names; 95 std::vector<std::string> display_names;
104 for (size_t i = 0; i < files.size(); i++) { 96 for (size_t i = 0; i < files.size(); i++) {
(...skipping 29 matching lines...) Expand all
134 ppapi::host::HostMessageContext* context, 126 ppapi::host::HostMessageContext* context,
135 bool save_as, 127 bool save_as,
136 bool open_multiple, 128 bool open_multiple,
137 const std::string& suggested_file_name, 129 const std::string& suggested_file_name,
138 const std::vector<std::string>& accept_mime_types) { 130 const std::vector<std::string>& accept_mime_types) {
139 if (handler_) 131 if (handler_)
140 return PP_ERROR_INPROGRESS; // Already pending. 132 return PP_ERROR_INPROGRESS; // Already pending.
141 133
142 if (!host()->permissions().HasPermission( 134 if (!host()->permissions().HasPermission(
143 ppapi::PERMISSION_BYPASS_USER_GESTURE) && 135 ppapi::PERMISSION_BYPASS_USER_GESTURE) &&
144 !renderer_ppapi_host_->HasUserGesture(pp_instance())) { 136 !renderer_ppapi_host_->HasUserGesture(pp_instance())) {
145 return PP_ERROR_NO_USER_GESTURE; 137 return PP_ERROR_NO_USER_GESTURE;
146 } 138 }
147 139
148 blink::WebFileChooserParams params; 140 blink::WebFileChooserParams params;
149 if (save_as) { 141 if (save_as) {
150 params.saveAs = true; 142 params.saveAs = true;
151 params.initialValue = blink::WebString::fromUTF8( 143 params.initialValue = blink::WebString::fromUTF8(
152 suggested_file_name.data(), suggested_file_name.size()); 144 suggested_file_name.data(), suggested_file_name.size());
153 } else { 145 } else {
154 params.multiSelect = open_multiple; 146 params.multiSelect = open_multiple;
155 } 147 }
156 std::vector<blink::WebString> mine_types(accept_mime_types.size()); 148 std::vector<blink::WebString> mine_types(accept_mime_types.size());
157 for (size_t i = 0; i < accept_mime_types.size(); i++) { 149 for (size_t i = 0; i < accept_mime_types.size(); i++) {
158 mine_types[i] = blink::WebString::fromUTF8( 150 mine_types[i] = blink::WebString::fromUTF8(accept_mime_types[i].data(),
159 accept_mime_types[i].data(), accept_mime_types[i].size()); 151 accept_mime_types[i].size());
160 } 152 }
161 params.acceptTypes = mine_types; 153 params.acceptTypes = mine_types;
162 params.directory = false; 154 params.directory = false;
163 155
164 handler_ = new CompletionHandler(AsWeakPtr()); 156 handler_ = new CompletionHandler(AsWeakPtr());
165 RenderViewImpl* render_view = static_cast<RenderViewImpl*>( 157 RenderViewImpl* render_view = static_cast<RenderViewImpl*>(
166 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance())); 158 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()));
167 if (!render_view || !render_view->runFileChooser(params, handler_)) { 159 if (!render_view || !render_view->runFileChooser(params, handler_)) {
168 delete handler_; 160 delete handler_;
169 handler_ = NULL; 161 handler_ = NULL;
170 return PP_ERROR_NOACCESS; 162 return PP_ERROR_NOACCESS;
171 } 163 }
172 164
173 reply_context_ = context->MakeReplyMessageContext(); 165 reply_context_ = context->MakeReplyMessageContext();
174 return PP_OK_COMPLETIONPENDING; 166 return PP_OK_COMPLETIONPENDING;
175 } 167 }
176 168
177 void PepperFileChooserHost::DidCreateResourceHosts( 169 void PepperFileChooserHost::DidCreateResourceHosts(
178 const std::vector<base::FilePath>& file_paths, 170 const std::vector<base::FilePath>& file_paths,
179 const std::vector<std::string>& display_names, 171 const std::vector<std::string>& display_names,
180 const std::vector<int>& browser_ids) { 172 const std::vector<int>& browser_ids) {
181 DCHECK(file_paths.size() == display_names.size()); 173 DCHECK(file_paths.size() == display_names.size());
182 DCHECK(file_paths.size() == browser_ids.size()); 174 DCHECK(file_paths.size() == browser_ids.size());
183 175
184 std::vector<ppapi::FileRefCreateInfo> chosen_files; 176 std::vector<ppapi::FileRefCreateInfo> chosen_files;
185 for (size_t i = 0; i < browser_ids.size(); ++i) { 177 for (size_t i = 0; i < browser_ids.size(); ++i) {
186 PepperFileRefRendererHost* renderer_host = 178 PepperFileRefRendererHost* renderer_host = new PepperFileRefRendererHost(
187 new PepperFileRefRendererHost(renderer_ppapi_host_, 179 renderer_ppapi_host_, pp_instance(), 0, file_paths[i]);
188 pp_instance(),
189 0,
190 file_paths[i]);
191 int renderer_id = 180 int renderer_id =
192 renderer_ppapi_host_->GetPpapiHost()->AddPendingResourceHost( 181 renderer_ppapi_host_->GetPpapiHost()->AddPendingResourceHost(
193 scoped_ptr<ppapi::host::ResourceHost>(renderer_host)); 182 scoped_ptr<ppapi::host::ResourceHost>(renderer_host));
194 ppapi::FileRefCreateInfo info = ppapi::MakeExternalFileRefCreateInfo( 183 ppapi::FileRefCreateInfo info = ppapi::MakeExternalFileRefCreateInfo(
195 file_paths[i], display_names[i], browser_ids[i], renderer_id); 184 file_paths[i], display_names[i], browser_ids[i], renderer_id);
196 chosen_files.push_back(info); 185 chosen_files.push_back(info);
197 } 186 }
198 187
199 reply_context_.params.set_result(PP_OK); 188 reply_context_.params.set_result(PP_OK);
200 host()->SendReply(reply_context_, 189 host()->SendReply(reply_context_,
201 PpapiPluginMsg_FileChooser_ShowReply(chosen_files)); 190 PpapiPluginMsg_FileChooser_ShowReply(chosen_files));
202 reply_context_ = ppapi::host::ReplyMessageContext(); 191 reply_context_ = ppapi::host::ReplyMessageContext();
203 handler_ = NULL; // Handler deletes itself. 192 handler_ = NULL; // Handler deletes itself.
204 } 193 }
205 194
206 } // namespace content 195 } // namespace content
207
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698