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/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 17 matching lines...) Expand all Loading... |
48 | 46 |
49 // Resource overrides. | 47 // Resource overrides. |
50 virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; | 48 virtual ::ppapi::thunk::PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; |
51 | 49 |
52 // Stores the list of selected files. | 50 // Stores the list of selected files. |
53 void StoreChosenFiles(const std::vector<std::string>& files); | 51 void StoreChosenFiles(const std::vector<std::string>& files); |
54 | 52 |
55 // Check that |callback| is valid (only non-blocking operation is supported) | 53 // Check that |callback| is valid (only non-blocking operation is supported) |
56 // and that no callback is already pending. Returns |PP_OK| if okay, else | 54 // and that no callback is already pending. Returns |PP_OK| if okay, else |
57 // |PP_ERROR_...| to be returned to the plugin. | 55 // |PP_ERROR_...| to be returned to the plugin. |
58 int32_t ValidateCallback(const PP_CompletionCallback& callback); | 56 int32_t ValidateCallback(::ppapi::ApiCallbackType callback); |
59 | 57 |
60 // Sets up |callback| as the pending callback. This should only be called once | 58 // Sets up |callback| as the pending callback. This should only be called once |
61 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. | 59 // it is certain that |PP_OK_COMPLETIONPENDING| will be returned. |
62 void RegisterCallback(const PP_CompletionCallback& callback); | 60 void RegisterCallback(::ppapi::ApiCallbackType callback); |
63 | 61 |
64 void RunCallback(int32_t result); | 62 void RunCallback(int32_t result); |
65 | 63 |
66 // PPB_FileChooser_API implementation. | 64 // PPB_FileChooser_API implementation. |
67 virtual int32_t Show(const PP_ArrayOutput& output, | 65 virtual int32_t Show(const PP_ArrayOutput& output, |
68 const PP_CompletionCallback& callback) OVERRIDE; | 66 ::ppapi::ApiCallbackType callback) OVERRIDE; |
69 virtual int32_t ShowWithoutUserGesture( | 67 virtual int32_t ShowWithoutUserGesture(PP_Bool save_as, |
70 PP_Bool save_as, | 68 PP_Var suggested_file_name, |
71 PP_Var suggested_file_name, | 69 const PP_ArrayOutput& output, |
72 const PP_ArrayOutput& output, | 70 ::ppapi::ApiCallbackType callback); |
73 const PP_CompletionCallback& callback); | 71 virtual int32_t Show0_5(::ppapi::ApiCallbackType callback) OVERRIDE; |
74 virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE; | |
75 virtual PP_Resource GetNextChosenFile() OVERRIDE; | 72 virtual PP_Resource GetNextChosenFile() OVERRIDE; |
76 virtual int32_t ShowWithoutUserGesture0_5( | 73 virtual int32_t ShowWithoutUserGesture0_5( |
77 PP_Bool save_as, | 74 PP_Bool save_as, |
78 PP_Var suggested_file_name, | 75 PP_Var suggested_file_name, |
79 const PP_CompletionCallback& callback) OVERRIDE; | 76 ::ppapi::ApiCallbackType callback) OVERRIDE; |
80 | 77 |
81 // Splits a comma-separated MIME type list |accept_mime_types|, trims the | 78 // Splits a comma-separated MIME type list |accept_mime_types|, trims the |
82 // resultant split types, makes them lowercase, and returns them. | 79 // resultant split types, makes them lowercase, and returns them. |
83 // Though this should be private, this is public for testing. | 80 // Though this should be private, this is public for testing. |
84 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue( | 81 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue( |
85 const std::string& accept_mime_types); | 82 const std::string& accept_mime_types); |
86 | 83 |
87 private: | 84 private: |
88 PP_FileChooserMode_Dev mode_; | 85 PP_FileChooserMode_Dev mode_; |
89 std::string accept_mime_types_; | 86 std::string accept_mime_types_; |
90 scoped_refptr< ::ppapi::TrackedCallback> callback_; | 87 scoped_refptr< ::ppapi::TrackedCallback> callback_; |
91 | 88 |
92 // When using the v0.6 of the API, this will contain the output for the | 89 // When using the v0.6 of the API, this will contain the output for the |
93 // resources when the show command is complete. When using 0.5, this | 90 // resources when the show command is complete. When using 0.5, this |
94 // object will be is_null() and the chosen_files_ will be used instead. | 91 // object will be is_null() and the chosen_files_ will be used instead. |
95 ::ppapi::ArrayWriter output_; | 92 ::ppapi::ArrayWriter output_; |
96 | 93 |
97 // Used to store and iterate over the results when using 0.5 of the API. | 94 // Used to store and iterate over the results when using 0.5 of the API. |
98 // These are valid when we get a file result and output_ is not null. | 95 // These are valid when we get a file result and output_ is not null. |
99 std::vector< scoped_refptr<Resource> > chosen_files_; | 96 std::vector< scoped_refptr<Resource> > chosen_files_; |
100 size_t next_chosen_file_index_; | 97 size_t next_chosen_file_index_; |
101 }; | 98 }; |
102 | 99 |
103 } // namespace ppapi | 100 } // namespace ppapi |
104 } // namespace webkit | 101 } // namespace webkit |
105 | 102 |
106 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ | 103 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ |
OLD | NEW |