blob: 05d01d3a79830f6a05d484a6bc342402838bed8b [file] [log] [blame]
[email protected]eccf80312012-07-14 15:43:421// 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
avie029c4132015-12-23 06:45:228#include <stdint.h>
9
[email protected]eccf80312012-07-14 15:43:4210#include <queue>
11#include <string>
12#include <vector>
13
avie029c4132015-12-23 06:45:2214#include "base/macros.h"
[email protected]eccf80312012-07-14 15:43:4215#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
21namespace ppapi {
22
[email protected]c6420f082013-09-18 22:42:4123struct FileRefCreateInfo;
[email protected]eccf80312012-07-14 15:43:4224
25namespace proxy {
26
27class PPAPI_PROXY_EXPORT FileChooserResource
28 : public PluginResource,
29 public NON_EXPORTED_BASE(thunk::PPB_FileChooser_API) {
30 public:
[email protected]93df81e2012-08-10 22:22:4631 FileChooserResource(Connection connection,
[email protected]eccf80312012-07-14 15:43:4232 PP_Instance instance,
33 PP_FileChooserMode_Dev mode,
34 const std::string& accept_types);
nicke4784432015-04-23 14:01:4835 ~FileChooserResource() override;
[email protected]eccf80312012-07-14 15:43:4236
37 // Resource overrides.
nicke4784432015-04-23 14:01:4838 thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() override;
[email protected]eccf80312012-07-14 15:43:4239
40 // PPB_FileChooser_API.
nicke4784432015-04-23 14:01:4841 int32_t Show(const PP_ArrayOutput& output,
42 scoped_refptr<TrackedCallback> callback) override;
43 int32_t ShowWithoutUserGesture(
[email protected]eccf80312012-07-14 15:43:4244 PP_Bool save_as,
45 PP_Var suggested_file_name,
46 const PP_ArrayOutput& output,
mostynb699af3c2014-10-06 18:03:3447 scoped_refptr<TrackedCallback> callback) override;
nicke4784432015-04-23 14:01:4848 int32_t Show0_5(scoped_refptr<TrackedCallback> callback) override;
49 PP_Resource GetNextChosenFile() override;
50 int32_t ShowWithoutUserGesture0_5(
[email protected]eccf80312012-07-14 15:43:4251 PP_Bool save_as,
52 PP_Var suggested_file_name,
mostynb699af3c2014-10-06 18:03:3453 scoped_refptr<TrackedCallback> callback) override;
[email protected]eccf80312012-07-14 15:43:4254
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]eccf80312012-07-14 15:43:4260 void OnPluginMsgShowReply(
[email protected]93df81e2012-08-10 22:22:4661 const ResourceMessageReplyParams& params,
[email protected]c6420f082013-09-18 22:42:4162 const std::vector<FileRefCreateInfo>& chosen_files);
[email protected]eccf80312012-07-14 15:43:4263
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_