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 "webkit/plugins/ppapi/ppb_flash_menu_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "ppapi/c/pp_completion_callback.h" | 8 #include "ppapi/c/pp_completion_callback.h" |
9 #include "ui/gfx/point.h" | 9 #include "ui/gfx/point.h" |
10 #include "webkit/glue/webmenuitem.h" | 10 #include "webkit/glue/webmenuitem.h" |
11 #include "webkit/plugins/ppapi/common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
12 #include "webkit/plugins/ppapi/plugin_delegate.h" | 12 #include "webkit/plugins/ppapi/plugin_delegate.h" |
13 #include "webkit/plugins/ppapi/plugin_module.h" | 13 #include "webkit/plugins/ppapi/plugin_module.h" |
14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
15 #include "webkit/plugins/ppapi/resource_helper.h" | 15 #include "webkit/plugins/ppapi/resource_helper.h" |
16 | 16 |
| 17 using ppapi::ApiCallbackType; |
17 using ppapi::thunk::PPB_Flash_Menu_API; | 18 using ppapi::thunk::PPB_Flash_Menu_API; |
18 using ppapi::TrackedCallback; | 19 using ppapi::TrackedCallback; |
19 | 20 |
20 namespace webkit { | 21 namespace webkit { |
21 namespace ppapi { | 22 namespace ppapi { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are | 26 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are |
26 // allowed, but not sub-submenus). | 27 // allowed, but not sub-submenus). |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 124 |
124 return true; | 125 return true; |
125 } | 126 } |
126 | 127 |
127 PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() { | 128 PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() { |
128 return this; | 129 return this; |
129 } | 130 } |
130 | 131 |
131 int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, | 132 int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, |
132 int32_t* selected_id_out, | 133 int32_t* selected_id_out, |
133 PP_CompletionCallback callback) { | 134 ApiCallbackType callback) { |
134 // |location| is not (currently) optional. | 135 // |location| is not (currently) optional. |
135 // TODO(viettrungluu): Make it optional and default to the current mouse pos? | 136 // TODO(viettrungluu): Make it optional and default to the current mouse pos? |
136 if (!location) | 137 if (!location) |
137 return PP_ERROR_BADARGUMENT; | 138 return PP_ERROR_BADARGUMENT; |
138 | 139 |
139 if (!callback.func) | |
140 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
141 | |
142 if (TrackedCallback::IsPending(callback_)) | 140 if (TrackedCallback::IsPending(callback_)) |
143 return PP_ERROR_INPROGRESS; | 141 return PP_ERROR_INPROGRESS; |
144 | 142 |
145 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 143 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
146 if (!plugin_instance) | 144 if (!plugin_instance) |
147 return false; | 145 return false; |
148 | 146 |
149 int32_t rv = plugin_instance->delegate()->ShowContextMenu( | 147 int32_t rv = plugin_instance->delegate()->ShowContextMenu( |
150 plugin_instance, this, gfx::Point(location->x, location->y)); | 148 plugin_instance, this, gfx::Point(location->x, location->y)); |
151 if (rv == PP_OK_COMPLETIONPENDING) { | 149 if (rv == PP_OK_COMPLETIONPENDING) { |
152 // Record callback and output buffers. | 150 // Record callback and output buffers. |
153 callback_ = new TrackedCallback(this, callback); | 151 callback_ = callback; |
154 selected_id_out_ = selected_id_out; | 152 selected_id_out_ = selected_id_out; |
155 } else { | 153 } else { |
156 // This should never be completed synchronously successfully. | 154 // This should never be completed synchronously successfully. |
157 DCHECK_NE(rv, PP_OK); | 155 DCHECK_NE(rv, PP_OK); |
158 } | 156 } |
159 return rv; | 157 return rv; |
160 | |
161 NOTIMPLEMENTED(); | |
162 return PP_ERROR_FAILED; | |
163 } | 158 } |
164 | 159 |
165 void PPB_Flash_Menu_Impl::CompleteShow(int32_t result, | 160 void PPB_Flash_Menu_Impl::CompleteShow(int32_t result, |
166 unsigned action) { | 161 unsigned action) { |
167 int32_t rv = PP_ERROR_ABORTED; | 162 int32_t rv = PP_ERROR_ABORTED; |
168 if (!callback_->aborted()) { | 163 if (!callback_->aborted()) { |
169 CHECK(!callback_->completed()); | 164 CHECK(!callback_->completed()); |
170 rv = result; | 165 rv = result; |
171 | 166 |
172 // Write output data. | 167 // Write output data. |
173 if (selected_id_out_ && result == PP_OK) { | 168 if (selected_id_out_ && result == PP_OK) { |
174 // We reserved action 0 to be invalid. | 169 // We reserved action 0 to be invalid. |
175 if (action == 0 || action >= menu_id_map_.size()) { | 170 if (action == 0 || action >= menu_id_map_.size()) { |
176 NOTREACHED() << "Invalid action received."; | 171 NOTREACHED() << "Invalid action received."; |
177 rv = PP_ERROR_FAILED; | 172 rv = PP_ERROR_FAILED; |
178 } else { | 173 } else { |
179 *selected_id_out_ = menu_id_map_[action]; | 174 *selected_id_out_ = menu_id_map_[action]; |
180 } | 175 } |
181 } | 176 } |
182 } | 177 } |
183 | 178 |
184 selected_id_out_ = NULL; | 179 selected_id_out_ = NULL; |
185 TrackedCallback::ClearAndRun(&callback_, rv); | 180 TrackedCallback::ClearAndRun(&callback_, rv); |
186 } | 181 } |
187 | 182 |
188 } // namespace ppapi | 183 } // namespace ppapi |
189 } // namespace webkit | 184 } // namespace webkit |
OLD | NEW |