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 #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/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "ppapi/c/dev/ppb_file_chooser_dev.h" | 13 #include "ppapi/c/dev/ppb_file_chooser_dev.h" |
14 #include "ppapi/shared_impl/array_writer.h" | 14 #include "ppapi/shared_impl/array_writer.h" |
15 #include "ppapi/shared_impl/resource.h" | 15 #include "ppapi/shared_impl/resource.h" |
16 #include "ppapi/thunk/ppb_file_chooser_api.h" | 16 #include "ppapi/thunk/ppb_file_chooser_api.h" |
17 #include "webkit/plugins/webkit_plugins_export.h" | 17 #include "webkit/plugins/webkit_plugins_export.h" |
18 | 18 |
19 struct PP_CompletionCallback; | |
20 | |
21 namespace ppapi { | 19 namespace ppapi { |
22 class TrackedCallback; | 20 class TrackedCallback; |
23 } | 21 } |
24 | 22 |
25 namespace WebKit { | 23 namespace WebKit { |
26 class WebString; | 24 class WebString; |
27 } | 25 } |
28 | 26 |
29 namespace webkit { | 27 namespace webkit { |
30 namespace ppapi { | 28 namespace ppapi { |
(...skipping 25 matching lines...) Expand all Loading... |
56 | 54 |
57 // Resource overrides. | 55 // Resource overrides. |
58 virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; | 56 virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; |
59 | 57 |
60 // Stores the list of selected files. | 58 // Stores the list of selected files. |
61 void StoreChosenFiles(const std::vector<ChosenFileInfo>& files); | 59 void StoreChosenFiles(const std::vector<ChosenFileInfo>& files); |
62 | 60 |
63 // Check that |callback| is valid (only non-blocking operation is supported) | 61 // Check that |callback| is valid (only non-blocking operation is supported) |
64 // and that no callback is already pending. Returns |PP_OK| if okay, else | 62 // and that no callback is already pending. Returns |PP_OK| if okay, else |
65 // |PP_ERROR_...| to be returned to the plugin. | 63 // |PP_ERROR_...| to be returned to the plugin. |
66 int32_t ValidateCallback(const PP_CompletionCallback& callback); | 64 int32_t ValidateCallback(scoped_refptr< ::ppapi::TrackedCallback> callback); |
67 | 65 |
68 // Sets up |callback| as the pending callback. This should only be called once | 66 // Sets up |callback| as the pending callback. This should only be called once |
69 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. | 67 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. |
70 void RegisterCallback(const PP_CompletionCallback& callback); | 68 void RegisterCallback(scoped_refptr< ::ppapi::TrackedCallback> callback); |
71 | 69 |
72 void RunCallback(int32_t result); | 70 void RunCallback(int32_t result); |
73 | 71 |
74 // PPB_FileChooser_API implementation. | 72 // PPB_FileChooser_API implementation. |
75 virtual int32_t Show(const PP_ArrayOutput& output, | 73 virtual int32_t Show( |
76 const PP_CompletionCallback& callback) OVERRIDE; | 74 const PP_ArrayOutput& output, |
| 75 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; |
77 virtual int32_t ShowWithoutUserGesture( | 76 virtual int32_t ShowWithoutUserGesture( |
78 PP_Bool save_as, | 77 PP_Bool save_as, |
79 PP_Var suggested_file_name, | 78 PP_Var suggested_file_name, |
80 const PP_ArrayOutput& output, | 79 const PP_ArrayOutput& output, |
81 const PP_CompletionCallback& callback); | 80 scoped_refptr< ::ppapi::TrackedCallback> callback); |
82 virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE; | 81 virtual int32_t Show0_5( |
| 82 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; |
83 virtual PP_Resource GetNextChosenFile() OVERRIDE; | 83 virtual PP_Resource GetNextChosenFile() OVERRIDE; |
84 virtual int32_t ShowWithoutUserGesture0_5( | 84 virtual int32_t ShowWithoutUserGesture0_5( |
85 PP_Bool save_as, | 85 PP_Bool save_as, |
86 PP_Var suggested_file_name, | 86 PP_Var suggested_file_name, |
87 const PP_CompletionCallback& callback) OVERRIDE; | 87 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; |
88 | 88 |
89 // Splits a comma-separated MIME type/extension list |accept_types|, trims the | 89 // Splits a comma-separated MIME type/extension list |accept_types|, trims the |
90 // resultant split types, makes them lowercase, and returns them. | 90 // resultant split types, makes them lowercase, and returns them. |
91 // Though this should be private, this is public for testing. | 91 // Though this should be private, this is public for testing. |
92 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue( | 92 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue( |
93 const std::string& accept_types); | 93 const std::string& accept_types); |
94 | 94 |
95 private: | 95 private: |
96 PP_FileChooserMode_Dev mode_; | 96 PP_FileChooserMode_Dev mode_; |
97 std::string accept_types_; | 97 std::string accept_types_; |
98 scoped_refptr< ::ppapi::TrackedCallback> callback_; | 98 scoped_refptr< ::ppapi::TrackedCallback> callback_; |
99 | 99 |
100 // When using the v0.6 of the API, this will contain the output for the | 100 // When using the v0.6 of the API, this will contain the output for the |
101 // resources when the show command is complete. When using 0.5, this | 101 // resources when the show command is complete. When using 0.5, this |
102 // object will be is_null() and the chosen_files_ will be used instead. | 102 // object will be is_null() and the chosen_files_ will be used instead. |
103 ::ppapi::ArrayWriter output_; | 103 ::ppapi::ArrayWriter output_; |
104 | 104 |
105 // Used to store and iterate over the results when using 0.5 of the API. | 105 // Used to store and iterate over the results when using 0.5 of the API. |
106 // These are valid when we get a file result and output_ is not null. | 106 // These are valid when we get a file result and output_ is not null. |
107 std::vector< scoped_refptr<Resource> > chosen_files_; | 107 std::vector< scoped_refptr<Resource> > chosen_files_; |
108 size_t next_chosen_file_index_; | 108 size_t next_chosen_file_index_; |
109 }; | 109 }; |
110 | 110 |
111 } // namespace ppapi | 111 } // namespace ppapi |
112 } // namespace webkit | 112 } // namespace webkit |
113 | 113 |
114 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ | 114 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ |
OLD | NEW |