| 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 #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::thunk::PPB_Flash_Menu_API; | 17 using ppapi::thunk::PPB_Flash_Menu_API; |
| 18 using ppapi::TrackedCallback; |
| 18 | 19 |
| 19 namespace webkit { | 20 namespace webkit { |
| 20 namespace ppapi { | 21 namespace ppapi { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are | 25 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are |
| 25 // allowed, but not sub-submenus). | 26 // allowed, but not sub-submenus). |
| 26 const size_t kMaxMenuDepth = 2; | 27 const size_t kMaxMenuDepth = 2; |
| 27 | 28 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return PP_ERROR_INPROGRESS; | 143 return PP_ERROR_INPROGRESS; |
| 143 | 144 |
| 144 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 145 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 145 if (!plugin_instance) | 146 if (!plugin_instance) |
| 146 return false; | 147 return false; |
| 147 | 148 |
| 148 int32_t rv = plugin_instance->delegate()->ShowContextMenu( | 149 int32_t rv = plugin_instance->delegate()->ShowContextMenu( |
| 149 plugin_instance, this, gfx::Point(location->x, location->y)); | 150 plugin_instance, this, gfx::Point(location->x, location->y)); |
| 150 if (rv == PP_OK_COMPLETIONPENDING) { | 151 if (rv == PP_OK_COMPLETIONPENDING) { |
| 151 // Record callback and output buffers. | 152 // Record callback and output buffers. |
| 152 callback_ = new TrackedCompletionCallback( | 153 callback_ = new TrackedCallback(this, callback); |
| 153 plugin_instance->module()->GetCallbackTracker(), | |
| 154 pp_resource(), callback); | |
| 155 selected_id_out_ = selected_id_out; | 154 selected_id_out_ = selected_id_out; |
| 156 } else { | 155 } else { |
| 157 // This should never be completed synchronously successfully. | 156 // This should never be completed synchronously successfully. |
| 158 DCHECK_NE(rv, PP_OK); | 157 DCHECK_NE(rv, PP_OK); |
| 159 } | 158 } |
| 160 return rv; | 159 return rv; |
| 161 | 160 |
| 162 NOTIMPLEMENTED(); | 161 NOTIMPLEMENTED(); |
| 163 return PP_ERROR_FAILED; | 162 return PP_ERROR_FAILED; |
| 164 } | 163 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 175 // We reserved action 0 to be invalid. | 174 // We reserved action 0 to be invalid. |
| 176 if (action == 0 || action >= menu_id_map_.size()) { | 175 if (action == 0 || action >= menu_id_map_.size()) { |
| 177 NOTREACHED() << "Invalid action received."; | 176 NOTREACHED() << "Invalid action received."; |
| 178 rv = PP_ERROR_FAILED; | 177 rv = PP_ERROR_FAILED; |
| 179 } else { | 178 } else { |
| 180 *selected_id_out_ = menu_id_map_[action]; | 179 *selected_id_out_ = menu_id_map_[action]; |
| 181 } | 180 } |
| 182 } | 181 } |
| 183 } | 182 } |
| 184 | 183 |
| 185 scoped_refptr<TrackedCompletionCallback> callback; | |
| 186 callback.swap(callback_); | |
| 187 selected_id_out_ = NULL; | 184 selected_id_out_ = NULL; |
| 188 | 185 TrackedCallback::ClearAndRun(&callback_, rv); |
| 189 callback->Run(rv); // Will complete abortively if necessary. | |
| 190 } | 186 } |
| 191 | 187 |
| 192 } // namespace ppapi | 188 } // namespace ppapi |
| 193 } // namespace webkit | 189 } // namespace webkit |
| OLD | NEW |