| 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 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "ppapi/c/dev/ppb_file_chooser_dev.h" | 12 #include "ppapi/c/dev/ppb_file_chooser_dev.h" |
| 13 #include "ppapi/thunk/ppb_file_chooser_api.h" | |
| 14 #include "webkit/plugins/ppapi/resource.h" | 13 #include "webkit/plugins/ppapi/resource.h" |
| 15 | 14 |
| 16 struct PP_CompletionCallback; | 15 struct PP_CompletionCallback; |
| 17 | 16 |
| 18 namespace webkit { | 17 namespace webkit { |
| 19 namespace ppapi { | 18 namespace ppapi { |
| 20 | 19 |
| 21 class PluginInstance; | 20 class PluginInstance; |
| 22 class PPB_FileRef_Impl; | 21 class PPB_FileRef_Impl; |
| 23 class TrackedCompletionCallback; | 22 class TrackedCompletionCallback; |
| 24 | 23 |
| 25 class PPB_FileChooser_Impl : public Resource, | 24 class PPB_FileChooser_Impl : public Resource { |
| 26 public ::ppapi::thunk::PPB_FileChooser_API { | |
| 27 public: | 25 public: |
| 28 PPB_FileChooser_Impl(PluginInstance* instance, | 26 PPB_FileChooser_Impl(PluginInstance* instance, |
| 29 const PP_FileChooserOptions_Dev* options); | 27 const PP_FileChooserOptions_Dev* options); |
| 30 virtual ~PPB_FileChooser_Impl(); | 28 virtual ~PPB_FileChooser_Impl(); |
| 31 | 29 |
| 32 static PP_Resource Create(PP_Instance instance, | 30 // Returns a pointer to the interface implementing PPB_FileChooser that is |
| 33 const PP_FileChooserOptions_Dev* options); | 31 // exposed to the plugin. |
| 32 static const PPB_FileChooser_Dev* GetInterface(); |
| 34 | 33 |
| 35 // Resource overrides. | 34 // Resource overrides. |
| 36 virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl(); | 35 virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl(); |
| 37 | 36 |
| 38 // ResourceObjectBase overrides. | |
| 39 virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; | |
| 40 | |
| 41 // Stores the list of selected files. | 37 // Stores the list of selected files. |
| 42 void StoreChosenFiles(const std::vector<std::string>& files); | 38 void StoreChosenFiles(const std::vector<std::string>& files); |
| 43 | 39 |
| 44 // Check that |callback| is valid (only non-blocking operation is supported) | 40 // Check that |callback| is valid (only non-blocking operation is supported) |
| 45 // and that no callback is already pending. Returns |PP_OK| if okay, else | 41 // and that no callback is already pending. Returns |PP_OK| if okay, else |
| 46 // |PP_ERROR_...| to be returned to the plugin. | 42 // |PP_ERROR_...| to be returned to the plugin. |
| 47 int32_t ValidateCallback(const PP_CompletionCallback& callback); | 43 int32_t ValidateCallback(const PP_CompletionCallback& callback); |
| 48 | 44 |
| 49 // Sets up |callback| as the pending callback. This should only be called once | 45 // Sets up |callback| as the pending callback. This should only be called once |
| 50 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. | 46 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. |
| 51 void RegisterCallback(const PP_CompletionCallback& callback); | 47 void RegisterCallback(const PP_CompletionCallback& callback); |
| 52 | 48 |
| 53 void RunCallback(int32_t result); | 49 void RunCallback(int32_t result); |
| 54 | 50 |
| 55 // PPB_FileChooser_API implementation. | 51 // PPB_FileChooser implementation. |
| 56 virtual int32_t Show(PP_CompletionCallback callback) OVERRIDE; | 52 int32_t Show(const PP_CompletionCallback& callback); |
| 57 virtual PP_Resource GetNextChosenFile() OVERRIDE; | 53 scoped_refptr<PPB_FileRef_Impl> GetNextChosenFile(); |
| 58 | 54 |
| 59 private: | 55 private: |
| 60 PP_FileChooserMode_Dev mode_; | 56 PP_FileChooserMode_Dev mode_; |
| 61 std::string accept_mime_types_; | 57 std::string accept_mime_types_; |
| 62 scoped_refptr<TrackedCompletionCallback> callback_; | 58 scoped_refptr<TrackedCompletionCallback> callback_; |
| 63 std::vector< scoped_refptr<PPB_FileRef_Impl> > chosen_files_; | 59 std::vector< scoped_refptr<PPB_FileRef_Impl> > chosen_files_; |
| 64 size_t next_chosen_file_index_; | 60 size_t next_chosen_file_index_; |
| 65 }; | 61 }; |
| 66 | 62 |
| 67 } // namespace ppapi | 63 } // namespace ppapi |
| 68 } // namespace webkit | 64 } // namespace webkit |
| 69 | 65 |
| 70 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ | 66 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ |
| OLD | NEW |