OLD | NEW |
1 // Copyright (c) 2012 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 #include "ppapi/proxy/ppb_file_chooser_proxy.h" | 5 #include "ppapi/proxy/ppb_file_chooser_proxy.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "ppapi/c/dev/ppb_file_chooser_dev.h" | 10 #include "ppapi/c/dev/ppb_file_chooser_dev.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 public PPB_FileChooser_API { | 39 public PPB_FileChooser_API { |
40 public: | 40 public: |
41 FileChooser(const HostResource& resource); | 41 FileChooser(const HostResource& resource); |
42 virtual ~FileChooser(); | 42 virtual ~FileChooser(); |
43 | 43 |
44 // Resource overrides. | 44 // Resource overrides. |
45 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; | 45 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; |
46 | 46 |
47 // PPB_FileChooser_API implementation. | 47 // PPB_FileChooser_API implementation. |
48 virtual int32_t Show(const PP_ArrayOutput& output, | 48 virtual int32_t Show(const PP_ArrayOutput& output, |
49 const PP_CompletionCallback& callback) OVERRIDE; | 49 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
50 virtual int32_t ShowWithoutUserGesture( | 50 virtual int32_t ShowWithoutUserGesture( |
51 PP_Bool save_as, | 51 PP_Bool save_as, |
52 PP_Var suggested_file_name, | 52 PP_Var suggested_file_name, |
53 const PP_ArrayOutput& output, | 53 const PP_ArrayOutput& output, |
54 const PP_CompletionCallback& callback); | 54 scoped_refptr<TrackedCallback> callback); |
55 virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE; | 55 virtual int32_t Show0_5(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
56 virtual PP_Resource GetNextChosenFile() OVERRIDE; | 56 virtual PP_Resource GetNextChosenFile() OVERRIDE; |
57 virtual int32_t ShowWithoutUserGesture0_5( | 57 virtual int32_t ShowWithoutUserGesture0_5( |
58 PP_Bool save_as, | 58 PP_Bool save_as, |
59 PP_Var suggested_file_name, | 59 PP_Var suggested_file_name, |
60 const PP_CompletionCallback& callback) OVERRIDE; | 60 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
61 | 61 |
62 // Handles the choose complete notification from the host. | 62 // Handles the choose complete notification from the host. |
63 void ChooseComplete( | 63 void ChooseComplete( |
64 int32_t result_code, | 64 int32_t result_code, |
65 const std::vector<PPB_FileRef_CreateInfo>& chosen_files); | 65 const std::vector<PPB_FileRef_CreateInfo>& chosen_files); |
66 | 66 |
67 private: | 67 private: |
68 int32_t Show(bool require_user_gesture, | 68 int32_t Show(bool require_user_gesture, |
69 PP_Bool save_as, | 69 PP_Bool save_as, |
70 PP_Var suggested_file_name, | 70 PP_Var suggested_file_name, |
71 const PP_CompletionCallback& callback); | 71 scoped_refptr<TrackedCallback> callback); |
72 | 72 |
73 // When using v0.6 of the API, contains the array output info. | 73 // When using v0.6 of the API, contains the array output info. |
74 ArrayWriter output_; | 74 ArrayWriter output_; |
75 | 75 |
76 scoped_refptr<TrackedCallback> current_show_callback_; | 76 scoped_refptr<TrackedCallback> current_show_callback_; |
77 | 77 |
78 // When using v0.5 of the API, contains all files returned by the current | 78 // When using v0.5 of the API, contains all files returned by the current |
79 // show callback that haven't yet been given to the plugin. The plugin will | 79 // show callback that haven't yet been given to the plugin. The plugin will |
80 // repeatedly call us to get the next file, and we'll vend those out of this | 80 // repeatedly call us to get the next file, and we'll vend those out of this |
81 // queue, removing them when ownership has transferred to the plugin. | 81 // queue, removing them when ownership has transferred to the plugin. |
(...skipping 14 matching lines...) Expand all Loading... |
96 tracker->ReleaseResource(file_queue_.front()); | 96 tracker->ReleaseResource(file_queue_.front()); |
97 file_queue_.pop(); | 97 file_queue_.pop(); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { | 101 PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { |
102 return this; | 102 return this; |
103 } | 103 } |
104 | 104 |
105 int32_t FileChooser::Show(const PP_ArrayOutput& output, | 105 int32_t FileChooser::Show(const PP_ArrayOutput& output, |
106 const PP_CompletionCallback& callback) { | 106 scoped_refptr<TrackedCallback> callback) { |
107 int32_t result = Show(true, PP_FALSE, PP_MakeUndefined(), callback); | 107 int32_t result = Show(true, PP_FALSE, PP_MakeUndefined(), callback); |
108 if (result == PP_OK_COMPLETIONPENDING) | 108 if (result == PP_OK_COMPLETIONPENDING) |
109 output_.set_pp_array_output(output); | 109 output_.set_pp_array_output(output); |
110 return result; | 110 return result; |
111 } | 111 } |
112 | 112 |
113 int32_t FileChooser::ShowWithoutUserGesture( | 113 int32_t FileChooser::ShowWithoutUserGesture( |
114 PP_Bool save_as, | 114 PP_Bool save_as, |
115 PP_Var suggested_file_name, | 115 PP_Var suggested_file_name, |
116 const PP_ArrayOutput& output, | 116 const PP_ArrayOutput& output, |
117 const PP_CompletionCallback& callback) { | 117 scoped_refptr<TrackedCallback> callback) { |
118 int32_t result = Show(false, save_as, suggested_file_name, callback); | 118 int32_t result = Show(false, save_as, suggested_file_name, callback); |
119 if (result == PP_OK_COMPLETIONPENDING) | 119 if (result == PP_OK_COMPLETIONPENDING) |
120 output_.set_pp_array_output(output); | 120 output_.set_pp_array_output(output); |
121 return result; | 121 return result; |
122 } | 122 } |
123 | 123 |
124 int32_t FileChooser::Show0_5(const PP_CompletionCallback& callback) { | 124 int32_t FileChooser::Show0_5(scoped_refptr<TrackedCallback> callback) { |
125 return Show(true, PP_FALSE, PP_MakeUndefined(), callback); | 125 return Show(true, PP_FALSE, PP_MakeUndefined(), callback); |
126 } | 126 } |
127 | 127 |
128 int32_t FileChooser::ShowWithoutUserGesture0_5( | 128 int32_t FileChooser::ShowWithoutUserGesture0_5( |
129 PP_Bool save_as, | 129 PP_Bool save_as, |
130 PP_Var suggested_file_name, | 130 PP_Var suggested_file_name, |
131 const PP_CompletionCallback& callback) { | 131 scoped_refptr<TrackedCallback> callback) { |
132 return Show(false, save_as, suggested_file_name, callback); | 132 return Show(false, save_as, suggested_file_name, callback); |
133 } | 133 } |
134 | 134 |
135 int32_t FileChooser::Show(bool require_user_gesture, | 135 int32_t FileChooser::Show(bool require_user_gesture, |
136 PP_Bool save_as, | 136 PP_Bool save_as, |
137 PP_Var suggested_file_name, | 137 PP_Var suggested_file_name, |
138 const PP_CompletionCallback& callback) { | 138 scoped_refptr<TrackedCallback> callback) { |
139 if (!callback.func) | |
140 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
141 | |
142 if (TrackedCallback::IsPending(current_show_callback_)) | 139 if (TrackedCallback::IsPending(current_show_callback_)) |
143 return PP_ERROR_INPROGRESS; // Can't show more than once. | 140 return PP_ERROR_INPROGRESS; // Can't show more than once. |
144 | 141 |
145 current_show_callback_ = new TrackedCallback(this, callback); | 142 current_show_callback_ = callback; |
146 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); | 143 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
147 dispatcher->Send( | 144 dispatcher->Send( |
148 new PpapiHostMsg_PPBFileChooser_Show( | 145 new PpapiHostMsg_PPBFileChooser_Show( |
149 API_ID_PPB_FILE_CHOOSER, | 146 API_ID_PPB_FILE_CHOOSER, |
150 host_resource(), | 147 host_resource(), |
151 save_as, | 148 save_as, |
152 SerializedVarSendInput(dispatcher, suggested_file_name), | 149 SerializedVarSendInput(dispatcher, suggested_file_name), |
153 require_user_gesture)); | 150 require_user_gesture)); |
154 return PP_OK_COMPLETIONPENDING; | 151 return PP_OK_COMPLETIONPENDING; |
155 } | 152 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 files.push_back(cur_create_info); | 302 files.push_back(cur_create_info); |
306 } | 303 } |
307 } | 304 } |
308 | 305 |
309 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( | 306 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( |
310 API_ID_PPB_FILE_CHOOSER, chooser, result, files)); | 307 API_ID_PPB_FILE_CHOOSER, chooser, result, files)); |
311 } | 308 } |
312 | 309 |
313 } // namespace proxy | 310 } // namespace proxy |
314 } // namespace ppapi | 311 } // namespace ppapi |
OLD | NEW |