| 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 "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 10 matching lines...) Expand all Loading... |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 23 #include "webkit/glue/webkit_glue.h" | 23 #include "webkit/glue/webkit_glue.h" |
| 24 #include "webkit/plugins/ppapi/common.h" | 24 #include "webkit/plugins/ppapi/common.h" |
| 25 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 25 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
| 26 #include "webkit/plugins/ppapi/plugin_delegate.h" | 26 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 27 #include "webkit/plugins/ppapi/plugin_module.h" | 27 #include "webkit/plugins/ppapi/plugin_module.h" |
| 28 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 28 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 29 #include "webkit/plugins/ppapi/resource_helper.h" | 29 #include "webkit/plugins/ppapi/resource_helper.h" |
| 30 | 30 |
| 31 using ppapi::ApiCallbackType; |
| 31 using ppapi::StringVar; | 32 using ppapi::StringVar; |
| 32 using ppapi::thunk::PPB_FileChooser_API; | 33 using ppapi::thunk::PPB_FileChooser_API; |
| 33 using ppapi::TrackedCallback; | 34 using ppapi::TrackedCallback; |
| 34 using WebKit::WebCString; | 35 using WebKit::WebCString; |
| 35 using WebKit::WebFileChooserCompletion; | 36 using WebKit::WebFileChooserCompletion; |
| 36 using WebKit::WebFileChooserParams; | 37 using WebKit::WebFileChooserParams; |
| 37 using WebKit::WebString; | 38 using WebKit::WebString; |
| 38 using WebKit::WebVector; | 39 using WebKit::WebVector; |
| 39 | 40 |
| 40 namespace webkit { | 41 namespace webkit { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 142 } |
| 142 | 143 |
| 143 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL; | 144 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL; |
| 144 if (output_.is_valid()) | 145 if (output_.is_valid()) |
| 145 output_.StoreResourceVector(chosen_files); | 146 output_.StoreResourceVector(chosen_files); |
| 146 else // v0.5 API. | 147 else // v0.5 API. |
| 147 chosen_files_.swap(chosen_files); | 148 chosen_files_.swap(chosen_files); |
| 148 RunCallback(result_code); | 149 RunCallback(result_code); |
| 149 } | 150 } |
| 150 | 151 |
| 151 int32_t PPB_FileChooser_Impl::ValidateCallback( | 152 int32_t PPB_FileChooser_Impl::ValidateCallback(ApiCallbackType callback) { |
| 152 const PP_CompletionCallback& 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(ApiCallbackType callback) { |
| 164 const PP_CompletionCallback& callback) { | |
| 165 DCHECK(callback.func); | |
| 166 DCHECK(!TrackedCallback::IsPending(callback_)); | 160 DCHECK(!TrackedCallback::IsPending(callback_)); |
| 167 | 161 |
| 168 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 162 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 169 if (!plugin_module) | 163 if (!plugin_module) |
| 170 return; | 164 return; |
| 171 | 165 |
| 172 callback_ = new TrackedCallback(this, callback); | 166 callback_ = callback; |
| 173 } | 167 } |
| 174 | 168 |
| 175 void PPB_FileChooser_Impl::RunCallback(int32_t result) { | 169 void PPB_FileChooser_Impl::RunCallback(int32_t result) { |
| 176 TrackedCallback::ClearAndRun(&callback_, result); | 170 TrackedCallback::ClearAndRun(&callback_, result); |
| 177 } | 171 } |
| 178 | 172 |
| 179 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output, | 173 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output, |
| 180 const PP_CompletionCallback& callback) { | 174 ApiCallbackType callback) { |
| 181 int32_t result = Show0_5(callback); | 175 int32_t result = Show0_5(callback); |
| 182 if (result == PP_OK_COMPLETIONPENDING) | 176 if (result == PP_OK_COMPLETIONPENDING) |
| 183 output_.set_pp_array_output(output); | 177 output_.set_pp_array_output(output); |
| 184 return result; | 178 return result; |
| 185 } | 179 } |
| 186 | 180 |
| 187 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( | 181 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( |
| 188 PP_Bool save_as, | 182 PP_Bool save_as, |
| 189 PP_Var suggested_file_name, | 183 PP_Var suggested_file_name, |
| 190 const PP_ArrayOutput& output, | 184 const PP_ArrayOutput& output, |
| 191 const PP_CompletionCallback& callback) { | 185 ApiCallbackType callback) { |
| 192 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name, | 186 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name, |
| 193 callback); | 187 callback); |
| 194 if (result == PP_OK_COMPLETIONPENDING) | 188 if (result == PP_OK_COMPLETIONPENDING) |
| 195 output_.set_pp_array_output(output); | 189 output_.set_pp_array_output(output); |
| 196 return result; | 190 return result; |
| 197 } | 191 } |
| 198 | 192 |
| 199 int32_t PPB_FileChooser_Impl::Show0_5(const PP_CompletionCallback& callback) { | 193 int32_t PPB_FileChooser_Impl::Show0_5(ApiCallbackType callback) { |
| 200 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 194 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 201 if (!plugin_instance) | 195 if (!plugin_instance) |
| 202 return PP_ERROR_FAILED; | 196 return PP_ERROR_FAILED; |
| 203 if (!plugin_instance->IsProcessingUserGesture()) | 197 if (!plugin_instance->IsProcessingUserGesture()) |
| 204 return PP_ERROR_NO_USER_GESTURE; | 198 return PP_ERROR_NO_USER_GESTURE; |
| 205 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback); | 199 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback); |
| 206 } | 200 } |
| 207 | 201 |
| 208 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5( | 202 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5( |
| 209 PP_Bool save_as, | 203 PP_Bool save_as, |
| 210 PP_Var suggested_file_name, | 204 PP_Var suggested_file_name, |
| 211 const PP_CompletionCallback& callback) { | 205 ApiCallbackType callback) { |
| 212 int32_t rv = ValidateCallback(callback); | 206 int32_t rv = ValidateCallback(callback); |
| 213 if (rv != PP_OK) | 207 if (rv != PP_OK) |
| 214 return rv; | 208 return rv; |
| 215 | 209 |
| 216 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) || | 210 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) || |
| 217 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE)); | 211 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE)); |
| 218 | 212 |
| 219 WebFileChooserParams params; | 213 WebFileChooserParams params; |
| 220 if (save_as) { | 214 if (save_as) { |
| 221 params.saveAs = true; | 215 params.saveAs = true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 continue; | 258 continue; |
| 265 StringToLowerASCII(&mime_type); | 259 StringToLowerASCII(&mime_type); |
| 266 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), | 260 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), |
| 267 mime_type.size())); | 261 mime_type.size())); |
| 268 } | 262 } |
| 269 return normalized_mime_type_list; | 263 return normalized_mime_type_list; |
| 270 } | 264 } |
| 271 | 265 |
| 272 } // namespace ppapi | 266 } // namespace ppapi |
| 273 } // namespace webkit | 267 } // namespace webkit |
| OLD | NEW |