[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PPAPI_PROXY_FILE_CHOOSER_RESOURCE_H_ |
| 6 | #define PPAPI_PROXY_FILE_CHOOSER_RESOURCE_H_ |
| 7 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 10 | #include <queue> |
| 11 | #include <string> |
| 12 | #include <vector> |
| 13 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 15 | #include "ppapi/proxy/plugin_resource.h" |
| 16 | #include "ppapi/proxy/ppapi_proxy_export.h" |
| 17 | #include "ppapi/shared_impl/array_writer.h" |
| 18 | #include "ppapi/shared_impl/tracked_callback.h" |
| 19 | #include "ppapi/thunk/ppb_file_chooser_api.h" |
| 20 | |
| 21 | namespace ppapi { |
| 22 | |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 23 | struct FileRefCreateInfo; |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 24 | |
| 25 | namespace proxy { |
| 26 | |
| 27 | class PPAPI_PROXY_EXPORT FileChooserResource |
| 28 | : public PluginResource, |
| 29 | public NON_EXPORTED_BASE(thunk::PPB_FileChooser_API) { |
| 30 | public: |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 31 | FileChooserResource(Connection connection, |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 32 | PP_Instance instance, |
| 33 | PP_FileChooserMode_Dev mode, |
| 34 | const std::string& accept_types); |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 35 | ~FileChooserResource() override; |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 36 | |
| 37 | // Resource overrides. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 38 | thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() override; |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 39 | |
| 40 | // PPB_FileChooser_API. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 41 | int32_t Show(const PP_ArrayOutput& output, |
| 42 | scoped_refptr<TrackedCallback> callback) override; |
| 43 | int32_t ShowWithoutUserGesture( |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 44 | PP_Bool save_as, |
| 45 | PP_Var suggested_file_name, |
| 46 | const PP_ArrayOutput& output, |
mostynb | 699af3c | 2014-10-06 18:03:34 | [diff] [blame] | 47 | scoped_refptr<TrackedCallback> callback) override; |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 48 | int32_t Show0_5(scoped_refptr<TrackedCallback> callback) override; |
| 49 | PP_Resource GetNextChosenFile() override; |
| 50 | int32_t ShowWithoutUserGesture0_5( |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 51 | PP_Bool save_as, |
| 52 | PP_Var suggested_file_name, |
mostynb | 699af3c | 2014-10-06 18:03:34 | [diff] [blame] | 53 | scoped_refptr<TrackedCallback> callback) override; |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 54 | |
| 55 | // Parses the accept string into the given vector. |
| 56 | static void PopulateAcceptTypes(const std::string& input, |
| 57 | std::vector<std::string>* output); |
| 58 | |
| 59 | private: |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 60 | void OnPluginMsgShowReply( |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 61 | const ResourceMessageReplyParams& params, |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 62 | const std::vector<FileRefCreateInfo>& chosen_files); |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 63 | |
| 64 | int32_t ShowInternal(PP_Bool save_as, |
| 65 | const PP_Var& suggested_file_name, |
| 66 | scoped_refptr<TrackedCallback> callback); |
| 67 | |
| 68 | PP_FileChooserMode_Dev mode_; |
| 69 | std::vector<std::string> accept_types_; |
| 70 | |
| 71 | // When using v0.6 of the API, contains the array output info. |
| 72 | ArrayWriter output_; |
| 73 | |
| 74 | // When using v0.5 of the API, contains all files returned by the current |
| 75 | // show callback that haven't yet been given to the plugin. The plugin will |
| 76 | // repeatedly call us to get the next file, and we'll vend those out of this |
| 77 | // queue, removing them when ownership has transferred to the plugin. |
| 78 | std::queue<PP_Resource> file_queue_; |
| 79 | |
| 80 | scoped_refptr<TrackedCallback> callback_; |
| 81 | |
| 82 | DISALLOW_COPY_AND_ASSIGN(FileChooserResource); |
| 83 | }; |
| 84 | |
| 85 | } // namespace proxy |
| 86 | } // namespace ppapi |
| 87 | |
| 88 | #endif // PPAPI_PROXY_FILE_CHOOSER_RESOURCE_H_ |