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

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

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: try again Created 8 years, 7 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 "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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL; 143 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL;
144 if (output_.is_valid()) 144 if (output_.is_valid())
145 output_.StoreResourceVector(chosen_files); 145 output_.StoreResourceVector(chosen_files);
146 else // v0.5 API. 146 else // v0.5 API.
147 chosen_files_.swap(chosen_files); 147 chosen_files_.swap(chosen_files);
148 RunCallback(result_code); 148 RunCallback(result_code);
149 } 149 }
150 150
151 int32_t PPB_FileChooser_Impl::ValidateCallback( 151 int32_t PPB_FileChooser_Impl::ValidateCallback(
152 const PP_CompletionCallback& callback) { 152 scoped_refptr<TrackedCallback> callback) {
153 // We only support non-blocking calls.
154 if (!callback.func)
155 return PP_ERROR_BLOCKS_MAIN_THREAD;
156
157 if (TrackedCallback::IsPending(callback_)) 153 if (TrackedCallback::IsPending(callback_))
158 return PP_ERROR_INPROGRESS; 154 return PP_ERROR_INPROGRESS;
159 155
160 return PP_OK; 156 return PP_OK;
161 } 157 }
162 158
163 void PPB_FileChooser_Impl::RegisterCallback( 159 void PPB_FileChooser_Impl::RegisterCallback(
164 const PP_CompletionCallback& callback) { 160 scoped_refptr<TrackedCallback> callback) {
165 DCHECK(callback.func);
166 DCHECK(!TrackedCallback::IsPending(callback_)); 161 DCHECK(!TrackedCallback::IsPending(callback_));
167 162
168 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); 163 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
169 if (!plugin_module) 164 if (!plugin_module)
170 return; 165 return;
171 166
172 callback_ = new TrackedCallback(this, callback); 167 callback_ = callback;
173 } 168 }
174 169
175 void PPB_FileChooser_Impl::RunCallback(int32_t result) { 170 void PPB_FileChooser_Impl::RunCallback(int32_t result) {
176 TrackedCallback::ClearAndRun(&callback_, result); 171 TrackedCallback::ClearAndRun(&callback_, result);
177 } 172 }
178 173
179 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output, 174 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output,
180 const PP_CompletionCallback& callback) { 175 scoped_refptr<TrackedCallback> callback) {
181 int32_t result = Show0_5(callback); 176 int32_t result = Show0_5(callback);
182 if (result == PP_OK_COMPLETIONPENDING) 177 if (result == PP_OK_COMPLETIONPENDING)
183 output_.set_pp_array_output(output); 178 output_.set_pp_array_output(output);
184 return result; 179 return result;
185 } 180 }
186 181
187 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( 182 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture(
188 PP_Bool save_as, 183 PP_Bool save_as,
189 PP_Var suggested_file_name, 184 PP_Var suggested_file_name,
190 const PP_ArrayOutput& output, 185 const PP_ArrayOutput& output,
191 const PP_CompletionCallback& callback) { 186 scoped_refptr<TrackedCallback> callback) {
192 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name, 187 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name,
193 callback); 188 callback);
194 if (result == PP_OK_COMPLETIONPENDING) 189 if (result == PP_OK_COMPLETIONPENDING)
195 output_.set_pp_array_output(output); 190 output_.set_pp_array_output(output);
196 return result; 191 return result;
197 } 192 }
198 193
199 int32_t PPB_FileChooser_Impl::Show0_5(const PP_CompletionCallback& callback) { 194 int32_t PPB_FileChooser_Impl::Show0_5(scoped_refptr<TrackedCallback> callback) {
200 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 195 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
201 if (!plugin_instance) 196 if (!plugin_instance)
202 return PP_ERROR_FAILED; 197 return PP_ERROR_FAILED;
203 if (!plugin_instance->IsProcessingUserGesture()) 198 if (!plugin_instance->IsProcessingUserGesture())
204 return PP_ERROR_NO_USER_GESTURE; 199 return PP_ERROR_NO_USER_GESTURE;
205 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback); 200 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback);
206 } 201 }
207 202
208 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5( 203 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5(
209 PP_Bool save_as, 204 PP_Bool save_as,
210 PP_Var suggested_file_name, 205 PP_Var suggested_file_name,
211 const PP_CompletionCallback& callback) { 206 scoped_refptr<TrackedCallback> callback) {
212 int32_t rv = ValidateCallback(callback); 207 int32_t rv = ValidateCallback(callback);
213 if (rv != PP_OK) 208 if (rv != PP_OK)
214 return rv; 209 return rv;
215 210
216 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) || 211 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) ||
217 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE)); 212 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE));
218 213
219 WebFileChooserParams params; 214 WebFileChooserParams params;
220 if (save_as) { 215 if (save_as) {
221 params.saveAs = true; 216 params.saveAs = true;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 continue; 259 continue;
265 StringToLowerASCII(&mime_type); 260 StringToLowerASCII(&mime_type);
266 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), 261 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(),
267 mime_type.size())); 262 mime_type.size()));
268 } 263 }
269 return normalized_mime_type_list; 264 return normalized_mime_type_list;
270 } 265 }
271 266
272 } // namespace ppapi 267 } // namespace ppapi
273 } // namespace webkit 268 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698