| OLD | NEW |
| 1 // Copyright (c) 2011 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 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(scoped_refptr< ::ppapi::TrackedCallback> 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(scoped_refptr< ::ppapi::TrackedCallback> 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( |
| 68 const PP_CompletionCallback& callback) OVERRIDE; | 66 const PP_ArrayOutput& output, |
| 67 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; |
| 69 virtual int32_t ShowWithoutUserGesture( | 68 virtual int32_t ShowWithoutUserGesture( |
| 70 PP_Bool save_as, | 69 PP_Bool save_as, |
| 71 PP_Var suggested_file_name, | 70 PP_Var suggested_file_name, |
| 72 const PP_ArrayOutput& output, | 71 const PP_ArrayOutput& output, |
| 73 const PP_CompletionCallback& callback); | 72 scoped_refptr< ::ppapi::TrackedCallback> callback); |
| 74 virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE; | 73 virtual int32_t Show0_5( |
| 74 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; |
| 75 virtual PP_Resource GetNextChosenFile() OVERRIDE; | 75 virtual PP_Resource GetNextChosenFile() OVERRIDE; |
| 76 virtual int32_t ShowWithoutUserGesture0_5( | 76 virtual int32_t ShowWithoutUserGesture0_5( |
| 77 PP_Bool save_as, | 77 PP_Bool save_as, |
| 78 PP_Var suggested_file_name, | 78 PP_Var suggested_file_name, |
| 79 const PP_CompletionCallback& callback) OVERRIDE; | 79 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; |
| 80 | 80 |
| 81 // Splits a comma-separated MIME type list |accept_mime_types|, trims the | 81 // Splits a comma-separated MIME type list |accept_mime_types|, trims the |
| 82 // resultant split types, makes them lowercase, and returns them. | 82 // resultant split types, makes them lowercase, and returns them. |
| 83 // Though this should be private, this is public for testing. | 83 // Though this should be private, this is public for testing. |
| 84 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue( | 84 WEBKIT_PLUGINS_EXPORT static std::vector<WebKit::WebString> ParseAcceptValue( |
| 85 const std::string& accept_mime_types); | 85 const std::string& accept_mime_types); |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 PP_FileChooserMode_Dev mode_; | 88 PP_FileChooserMode_Dev mode_; |
| 89 std::string accept_mime_types_; | 89 std::string accept_mime_types_; |
| 90 scoped_refptr< ::ppapi::TrackedCallback> callback_; | 90 scoped_refptr< ::ppapi::TrackedCallback> callback_; |
| 91 | 91 |
| 92 // When using the v0.6 of the API, this will contain the output for the | 92 // 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 | 93 // 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. | 94 // object will be is_null() and the chosen_files_ will be used instead. |
| 95 ::ppapi::ArrayWriter output_; | 95 ::ppapi::ArrayWriter output_; |
| 96 | 96 |
| 97 // Used to store and iterate over the results when using 0.5 of the API. | 97 // 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. | 98 // These are valid when we get a file result and output_ is not null. |
| 99 std::vector< scoped_refptr<Resource> > chosen_files_; | 99 std::vector< scoped_refptr<Resource> > chosen_files_; |
| 100 size_t next_chosen_file_index_; | 100 size_t next_chosen_file_index_; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 } // namespace ppapi | 103 } // namespace ppapi |
| 104 } // namespace webkit | 104 } // namespace webkit |
| 105 | 105 |
| 106 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ | 106 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_CHOOSER_IMPL_H_ |
| OLD | NEW |