| 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" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() { | 127 PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() { |
| 128 return this; | 128 return this; |
| 129 } | 129 } |
| 130 | 130 |
| 131 int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, | 131 int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, |
| 132 int32_t* selected_id_out, | 132 int32_t* selected_id_out, |
| 133 PP_CompletionCallback callback) { | 133 scoped_refptr<TrackedCallback> callback) { |
| 134 // |location| is not (currently) optional. | 134 // |location| is not (currently) optional. |
| 135 // TODO(viettrungluu): Make it optional and default to the current mouse pos? | 135 // TODO(viettrungluu): Make it optional and default to the current mouse pos? |
| 136 if (!location) | 136 if (!location) |
| 137 return PP_ERROR_BADARGUMENT; | 137 return PP_ERROR_BADARGUMENT; |
| 138 | 138 |
| 139 if (!callback.func) | |
| 140 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
| 141 | |
| 142 if (TrackedCallback::IsPending(callback_)) | 139 if (TrackedCallback::IsPending(callback_)) |
| 143 return PP_ERROR_INPROGRESS; | 140 return PP_ERROR_INPROGRESS; |
| 144 | 141 |
| 145 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 142 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 146 if (!plugin_instance) | 143 if (!plugin_instance) |
| 147 return false; | 144 return false; |
| 148 | 145 |
| 149 int32_t rv = plugin_instance->delegate()->ShowContextMenu( | 146 int32_t rv = plugin_instance->delegate()->ShowContextMenu( |
| 150 plugin_instance, this, gfx::Point(location->x, location->y)); | 147 plugin_instance, this, gfx::Point(location->x, location->y)); |
| 151 if (rv == PP_OK_COMPLETIONPENDING) { | 148 if (rv == PP_OK_COMPLETIONPENDING) { |
| 152 // Record callback and output buffers. | 149 // Record callback and output buffers. |
| 153 callback_ = new TrackedCallback(this, callback); | 150 callback_ = callback; |
| 154 selected_id_out_ = selected_id_out; | 151 selected_id_out_ = selected_id_out; |
| 155 } else { | 152 } else { |
| 156 // This should never be completed synchronously successfully. | 153 // This should never be completed synchronously successfully. |
| 157 DCHECK_NE(rv, PP_OK); | 154 DCHECK_NE(rv, PP_OK); |
| 158 } | 155 } |
| 159 return rv; | 156 return rv; |
| 160 | |
| 161 NOTIMPLEMENTED(); | |
| 162 return PP_ERROR_FAILED; | |
| 163 } | 157 } |
| 164 | 158 |
| 165 void PPB_Flash_Menu_Impl::CompleteShow(int32_t result, | 159 void PPB_Flash_Menu_Impl::CompleteShow(int32_t result, |
| 166 unsigned action) { | 160 unsigned action) { |
| 167 int32_t rv = PP_ERROR_ABORTED; | 161 int32_t rv = PP_ERROR_ABORTED; |
| 168 if (!callback_->aborted()) { | 162 if (!callback_->aborted()) { |
| 169 CHECK(!callback_->completed()); | 163 CHECK(!callback_->completed()); |
| 170 rv = result; | 164 rv = result; |
| 171 | 165 |
| 172 // Write output data. | 166 // Write output data. |
| 173 if (selected_id_out_ && result == PP_OK) { | 167 if (selected_id_out_ && result == PP_OK) { |
| 174 // We reserved action 0 to be invalid. | 168 // We reserved action 0 to be invalid. |
| 175 if (action == 0 || action >= menu_id_map_.size()) { | 169 if (action == 0 || action >= menu_id_map_.size()) { |
| 176 NOTREACHED() << "Invalid action received."; | 170 NOTREACHED() << "Invalid action received."; |
| 177 rv = PP_ERROR_FAILED; | 171 rv = PP_ERROR_FAILED; |
| 178 } else { | 172 } else { |
| 179 *selected_id_out_ = menu_id_map_[action]; | 173 *selected_id_out_ = menu_id_map_[action]; |
| 180 } | 174 } |
| 181 } | 175 } |
| 182 } | 176 } |
| 183 | 177 |
| 184 selected_id_out_ = NULL; | 178 selected_id_out_ = NULL; |
| 185 TrackedCallback::ClearAndRun(&callback_, rv); | 179 TrackedCallback::ClearAndRun(&callback_, rv); |
| 186 } | 180 } |
| 187 | 181 |
| 188 } // namespace ppapi | 182 } // namespace ppapi |
| 189 } // namespace webkit | 183 } // namespace webkit |
| OLD | NEW |