| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "ppapi/c/pp_completion_callback.h" | 14 #include "ppapi/c/pp_completion_callback.h" |
| 15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/shared_impl/tracked_callback.h" |
| 16 #include "ppapi/shared_impl/var.h" | 17 #include "ppapi/shared_impl/var.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet
ion.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet
ion.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.
h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserParams.
h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 22 #include "webkit/glue/webkit_glue.h" | 23 #include "webkit/glue/webkit_glue.h" |
| 23 #include "webkit/plugins/ppapi/callbacks.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::StringVar; | 31 using ppapi::StringVar; |
| 32 using ppapi::thunk::PPB_FileChooser_API; | 32 using ppapi::thunk::PPB_FileChooser_API; |
| 33 using ppapi::TrackedCallback; |
| 33 using WebKit::WebCString; | 34 using WebKit::WebCString; |
| 34 using WebKit::WebFileChooserCompletion; | 35 using WebKit::WebFileChooserCompletion; |
| 35 using WebKit::WebFileChooserParams; | 36 using WebKit::WebFileChooserParams; |
| 36 using WebKit::WebString; | 37 using WebKit::WebString; |
| 37 using WebKit::WebVector; | 38 using WebKit::WebVector; |
| 38 | 39 |
| 39 namespace webkit { | 40 namespace webkit { |
| 40 namespace ppapi { | 41 namespace ppapi { |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 RunCallback((chosen_files_.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); | 118 RunCallback((chosen_files_.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL); |
| 118 } | 119 } |
| 119 | 120 |
| 120 int32_t PPB_FileChooser_Impl::ValidateCallback( | 121 int32_t PPB_FileChooser_Impl::ValidateCallback( |
| 121 const PP_CompletionCallback& callback) { | 122 const PP_CompletionCallback& callback) { |
| 122 // We only support non-blocking calls. | 123 // We only support non-blocking calls. |
| 123 if (!callback.func) | 124 if (!callback.func) |
| 124 return PP_ERROR_BLOCKS_MAIN_THREAD; | 125 return PP_ERROR_BLOCKS_MAIN_THREAD; |
| 125 | 126 |
| 126 if (callback_.get() && !callback_->completed()) | 127 if (TrackedCallback::IsPending(callback_)) |
| 127 return PP_ERROR_INPROGRESS; | 128 return PP_ERROR_INPROGRESS; |
| 128 | 129 |
| 129 return PP_OK; | 130 return PP_OK; |
| 130 } | 131 } |
| 131 | 132 |
| 132 void PPB_FileChooser_Impl::RegisterCallback( | 133 void PPB_FileChooser_Impl::RegisterCallback( |
| 133 const PP_CompletionCallback& callback) { | 134 const PP_CompletionCallback& callback) { |
| 134 DCHECK(callback.func); | 135 DCHECK(callback.func); |
| 135 DCHECK(!callback_.get() || callback_->completed()); | 136 DCHECK(!TrackedCallback::IsPending(callback_)); |
| 136 | 137 |
| 137 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 138 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 138 if (!plugin_module) | 139 if (!plugin_module) |
| 139 return; | 140 return; |
| 140 | 141 |
| 141 callback_ = new TrackedCompletionCallback(plugin_module->GetCallbackTracker(), | 142 callback_ = new TrackedCallback(this, callback); |
| 142 pp_resource(), callback); | |
| 143 } | 143 } |
| 144 | 144 |
| 145 void PPB_FileChooser_Impl::RunCallback(int32_t result) { | 145 void PPB_FileChooser_Impl::RunCallback(int32_t result) { |
| 146 scoped_refptr<TrackedCompletionCallback> callback; | 146 TrackedCallback::ClearAndRun(&callback_, result); |
| 147 callback.swap(callback_); | |
| 148 callback->Run(result); // Will complete abortively if necessary. | |
| 149 } | 147 } |
| 150 | 148 |
| 151 int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { | 149 int32_t PPB_FileChooser_Impl::Show(const PP_CompletionCallback& callback) { |
| 152 return ShowWithoutUserGesture(false, NULL, callback); | 150 return ShowWithoutUserGesture(false, NULL, callback); |
| 153 } | 151 } |
| 154 | 152 |
| 155 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( | 153 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( |
| 156 bool save_as, | 154 bool save_as, |
| 157 const char* suggested_file_name, | 155 const char* suggested_file_name, |
| 158 const PP_CompletionCallback& callback) { | 156 const PP_CompletionCallback& callback) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 continue; | 208 continue; |
| 211 StringToLowerASCII(&mime_type); | 209 StringToLowerASCII(&mime_type); |
| 212 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), | 210 normalized_mime_type_list.push_back(WebString::fromUTF8(mime_type.data(), |
| 213 mime_type.size())); | 211 mime_type.size())); |
| 214 } | 212 } |
| 215 return normalized_mime_type_list; | 213 return normalized_mime_type_list; |
| 216 } | 214 } |
| 217 | 215 |
| 218 } // namespace ppapi | 216 } // namespace ppapi |
| 219 } // namespace webkit | 217 } // namespace webkit |
| OLD | NEW |