Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Side by Side Diff: webkit/plugins/ppapi/ppb_file_chooser_impl.h

Issue 10544089: Implement the file chooser as a new resource "host" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_
6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "ppapi/c/dev/ppb_file_chooser_dev.h"
14 #include "ppapi/shared_impl/array_writer.h"
15 #include "ppapi/shared_impl/resource.h"
16 #include "ppapi/thunk/ppb_file_chooser_api.h"
17 #include "webkit/plugins/webkit_plugins_export.h"
18
19 namespace ppapi {
20 class TrackedCallback;
21 }
22
23 namespace WebKit {
24 class WebString;
25 }
26
27 namespace webkit {
28 namespace ppapi {
29
30 class PPB_FileRef_Impl;
31
32 class PPB_FileChooser_Impl : public ::ppapi::Resource,
33 public ::ppapi::thunk::PPB_FileChooser_API {
34 public:
35 // Structure to store the information of chosen files.
36 struct ChosenFileInfo {
37 ChosenFileInfo(const std::string& path, const std::string& display_name);
38 std::string path;
39 // |display_name| may be empty.
40 std::string display_name;
41 };
42
43 PPB_FileChooser_Impl(PP_Instance instance,
44 PP_FileChooserMode_Dev mode,
45 const char* accept_types);
46 virtual ~PPB_FileChooser_Impl();
47
48 static PP_Resource Create(PP_Instance instance,
49 PP_FileChooserMode_Dev mode,
50 const char* accept_types);
51
52 // Resource overrides.
53 virtual PPB_FileChooser_Impl* AsPPB_FileChooser_Impl();
54
55 // Resource overrides.
56 virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE;
57
58 // Stores the list of selected files.
59 void StoreChosenFiles(const std::vector<ChosenFileInfo>& files);
60
61 // Check that |callback| is valid (only non-blocking operation is supported)
62 // and that no callback is already pending. Returns |PP_OK| if okay, else
63 // |PP_ERROR_...| to be returned to the plugin.
64 int32_t ValidateCallback(scoped_refptr< ::ppapi::TrackedCallback> callback);
65
66 // Sets up |callback| as the pending callback. This should only be called once
67 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned.
68 void RegisterCallback(scoped_refptr< ::ppapi::TrackedCallback> callback);
69
70 void RunCallback(int32_t result);
71
72 // PPB_FileChooser_API implementation.
73 virtual int32_t Show(
74 const PP_ArrayOutput& output,
75 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
76 virtual int32_t ShowWithoutUserGesture(
77 PP_Bool save_as,
78 PP_Var suggested_file_name,
79 const PP_ArrayOutput& output,
80 scoped_refptr< ::ppapi::TrackedCallback> callback);
81 virtual int32_t Show0_5(
82 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
83 virtual PP_Resource GetNextChosenFile() OVERRIDE;
84 virtual int32_t ShowWithoutUserGesture0_5(
85 PP_Bool save_as,
86 PP_Var suggested_file_name,
87 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE;
88
89 // Splits a comma-separated MIME type/extension list |accept_types|, trims the
90 // resultant split types, makes them lowercase, and returns them.
91 // Though this should be private, this is public for testing.
92 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue(
93 const std::string& accept_types);
94
95 private:
96 PP_FileChooserMode_Dev mode_;
97 std::string accept_types_;
98 scoped_refptr< ::ppapi::TrackedCallback> callback_;
99
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
102 // object will be is_null() and the chosen_files_ will be used instead.
103 ::ppapi::ArrayWriter output_;
104
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.
107 std::vector< scoped_refptr<Resource> > chosen_files_;
108 size_t next_chosen_file_index_;
109 };
110
111 } // namespace ppapi
112 } // namespace webkit
113
114 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698