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