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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_chooser_impl.cc

Issue 9728001: Make the file chooser use PP_ArrayOutput (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_chooser_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/plugins/ppapi/ppb_file_chooser_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_chooser_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 virtual ~FileChooserCompletionImpl() {} 52 virtual ~FileChooserCompletionImpl() {}
53 53
54 virtual void didChooseFile(const WebVector<WebString>& file_names) { 54 virtual void didChooseFile(const WebVector<WebString>& file_names) {
55 std::vector<std::string> files; 55 std::vector<std::string> files;
56 for (size_t i = 0; i < file_names.size(); i++) 56 for (size_t i = 0; i < file_names.size(); i++)
57 files.push_back(file_names[i].utf8()); 57 files.push_back(file_names[i].utf8());
58 58
59 file_chooser_->StoreChosenFiles(files); 59 file_chooser_->StoreChosenFiles(files);
60 } 60 }
61 virtual void didChooseFile(const WebVector<SelectedFileInfo>& file_names) {
62 std::vector<std::string> files;
63 for (size_t i = 0; i < file_names.size(); i++)
64 files.push_back(file_names[i].path.utf8());
65
66 file_chooser_->StoreChosenFiles(files);
67 }
61 68
62 private: 69 private:
63 scoped_refptr<PPB_FileChooser_Impl> file_chooser_; 70 scoped_refptr<PPB_FileChooser_Impl> file_chooser_;
64 }; 71 };
65 72
66 } // namespace 73 } // namespace
67 74
68 PPB_FileChooser_Impl::PPB_FileChooser_Impl( 75 PPB_FileChooser_Impl::PPB_FileChooser_Impl(
69 PP_Instance instance, 76 PP_Instance instance,
70 PP_FileChooserMode_Dev mode, 77 PP_FileChooserMode_Dev mode,
(...skipping 23 matching lines...) Expand all
94 PPB_FileChooser_Impl* PPB_FileChooser_Impl::AsPPB_FileChooser_Impl() { 101 PPB_FileChooser_Impl* PPB_FileChooser_Impl::AsPPB_FileChooser_Impl() {
95 return this; 102 return this;
96 } 103 }
97 104
98 PPB_FileChooser_API* PPB_FileChooser_Impl::AsPPB_FileChooser_API() { 105 PPB_FileChooser_API* PPB_FileChooser_Impl::AsPPB_FileChooser_API() {
99 return this; 106 return this;
100 } 107 }
101 108
102 void PPB_FileChooser_Impl::StoreChosenFiles( 109 void PPB_FileChooser_Impl::StoreChosenFiles(
103 const std::vector<std::string>& files) { 110 const std::vector<std::string>& files) {
104 chosen_files_.clear();
105 next_chosen_file_index_ = 0; 111 next_chosen_file_index_ = 0;
112
113 std::vector< scoped_refptr<Resource> > chosen_files;
106 for (std::vector<std::string>::const_iterator it = files.begin(); 114 for (std::vector<std::string>::const_iterator it = files.begin();
107 it != files.end(); ++it) { 115 it != files.end(); ++it) {
108 #if defined(OS_WIN) 116 #if defined(OS_WIN)
109 FilePath file_path(base::SysUTF8ToWide(*it)); 117 FilePath file_path(base::SysUTF8ToWide(*it));
110 #else 118 #else
111 FilePath file_path(*it); 119 FilePath file_path(*it);
112 #endif 120 #endif
113 121
114 chosen_files_.push_back(make_scoped_refptr( 122 chosen_files.push_back(scoped_refptr<Resource>(
115 PPB_FileRef_Impl::CreateExternal(pp_instance(), file_path))); 123 PPB_FileRef_Impl::CreateExternal(pp_instance(), file_path)));
116 } 124 }
117 125
118 RunCallback((chosen_files_.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); 126 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL;
127 if (output_.is_valid())
128 output_.StoreResourceVector(chosen_files);
129 else // v0.5 API.
130 chosen_files_.swap(chosen_files);
131 RunCallback(result_code);
119 } 132 }
120 133
121 int32_t PPB_FileChooser_Impl::ValidateCallback( 134 int32_t PPB_FileChooser_Impl::ValidateCallback(
122 const PP_CompletionCallback& callback) { 135 const PP_CompletionCallback& callback) {
123 // We only support non-blocking calls. 136 // We only support non-blocking calls.
124 if (!callback.func) 137 if (!callback.func)
125 return PP_ERROR_BLOCKS_MAIN_THREAD; 138 return PP_ERROR_BLOCKS_MAIN_THREAD;
126 139
127 if (TrackedCallback::IsPending(callback_)) 140 if (TrackedCallback::IsPending(callback_))
128 return PP_ERROR_INPROGRESS; 141 return PP_ERROR_INPROGRESS;
(...skipping 10 matching lines...) Expand all
139 if (!plugin_module) 152 if (!plugin_module)
140 return; 153 return;
141 154
142 callback_ = new TrackedCallback(this, callback); 155 callback_ = new TrackedCallback(this, callback);
143 } 156 }
144 157
145 void PPB_FileChooser_Impl::RunCallback(int32_t result) { 158 void PPB_FileChooser_Impl::RunCallback(int32_t result) {
146 TrackedCallback::ClearAndRun(&callback_, result); 159 TrackedCallback::ClearAndRun(&callback_, result);
147 } 160 }
148 161
149 int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { 162 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output,
163 const PP_CompletionCallback& callback) {
164 int32_t result = Show0_5(callback);
165 if (result == PP_OK_COMPLETIONPENDING)
166 output_.set_pp_array_output(output);
167 return result;
168 }
169
170 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture(
171 PP_Bool save_as,
172 PP_Var suggested_file_name,
173 const PP_ArrayOutput& output,
174 const PP_CompletionCallback& callback) {
175 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name,
176 callback);
177 if (result == PP_OK_COMPLETIONPENDING)
178 output_.set_pp_array_output(output);
179 return result;
180 }
181
182 int32_t PPB_FileChooser_Impl::Show0_5(const PP_CompletionCallback& callback) {
150 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 183 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
151 if (!plugin_instance) 184 if (!plugin_instance)
152 return PP_ERROR_FAILED; 185 return PP_ERROR_FAILED;
153 if (!plugin_instance->IsProcessingUserGesture()) 186 if (!plugin_instance->IsProcessingUserGesture())
154 return PP_ERROR_NO_USER_GESTURE; 187 return PP_ERROR_NO_USER_GESTURE;
155 return ShowWithoutUserGesture(false, NULL, callback); 188 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback);
156 } 189 }
157 190
158 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( 191 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5(
159 bool save_as, 192 PP_Bool save_as,
160 const char* suggested_file_name, 193 PP_Var suggested_file_name,
161 const PP_CompletionCallback& callback) { 194 const PP_CompletionCallback& callback) {
162 int32_t rv = ValidateCallback(callback); 195 int32_t rv = ValidateCallback(callback);
163 if (rv != PP_OK) 196 if (rv != PP_OK)
164 return rv; 197 return rv;
165 198
166 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) || 199 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) ||
167 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE)); 200 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE));
168 201
169 WebFileChooserParams params; 202 WebFileChooserParams params;
170 if (save_as) { 203 if (save_as) {
171 params.saveAs = true; 204 params.saveAs = true;
172 if (suggested_file_name) 205 StringVar* str = StringVar::FromPPVar(suggested_file_name);
173 params.initialValue = WebString::fromUTF8(suggested_file_name); 206 if (str)
207 params.initialValue = WebString::fromUTF8(str->value().c_str());
174 } else { 208 } else {
175 params.multiSelect = (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE); 209 params.multiSelect = (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE);
176 } 210 }
177 params.acceptMIMETypes = ParseAcceptValue(accept_mime_types_); 211 params.acceptMIMETypes = ParseAcceptValue(accept_mime_types_);
178 params.directory = false; 212 params.directory = false;
179 213
180 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); 214 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
181 if (!plugin_delegate) 215 if (!plugin_delegate)
182 return PP_ERROR_FAILED; 216 return PP_ERROR_FAILED;
183 217
(...skipping 29 matching lines...) Expand all
213 continue; 247 continue;
214 StringToLowerASCII(&mime_type); 248 StringToLowerASCII(&mime_type);
215 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), 249 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(),
216 mime_type.size())); 250 mime_type.size()));
217 } 251 }
218 return normalized_mime_type_list; 252 return normalized_mime_type_list;
219 } 253 }
220 254
221 } // namespace ppapi 255 } // namespace ppapi
222 } // namespace webkit 256 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_chooser_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698