| 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 | 15 |
| 16 using ::ppapi::thunk::PPB_Flash_Menu_API; |
| 17 |
| 16 namespace webkit { | 18 namespace webkit { |
| 17 namespace ppapi { | 19 namespace ppapi { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 PP_Resource Create(PP_Instance instance_id, const PP_Flash_Menu* menu_data) { | |
| 22 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | |
| 23 if (!instance) | |
| 24 return 0; | |
| 25 | |
| 26 scoped_refptr<PPB_Flash_Menu_Impl> menu(new PPB_Flash_Menu_Impl(instance)); | |
| 27 if (!menu->Init(menu_data)) | |
| 28 return 0; | |
| 29 | |
| 30 return menu->GetReference(); | |
| 31 } | |
| 32 | |
| 33 PP_Bool IsFlashMenu(PP_Resource resource) { | |
| 34 return BoolToPPBool(!!Resource::GetAs<PPB_Flash_Menu_Impl>(resource)); | |
| 35 } | |
| 36 | |
| 37 int32_t Show(PP_Resource menu_id, | |
| 38 const PP_Point* location, | |
| 39 int32_t* selected_id, | |
| 40 PP_CompletionCallback callback) { | |
| 41 scoped_refptr<PPB_Flash_Menu_Impl> menu( | |
| 42 Resource::GetAs<PPB_Flash_Menu_Impl>(menu_id)); | |
| 43 if (!menu.get()) | |
| 44 return PP_ERROR_BADRESOURCE; | |
| 45 | |
| 46 return menu->Show(location, selected_id, callback); | |
| 47 } | |
| 48 | |
| 49 const PPB_Flash_Menu ppb_flash_menu = { | |
| 50 &Create, | |
| 51 &IsFlashMenu, | |
| 52 &Show, | |
| 53 }; | |
| 54 | |
| 55 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are | 23 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are |
| 56 // allowed, but not sub-submenus). | 24 // allowed, but not sub-submenus). |
| 57 const size_t kMaxMenuDepth = 2; | 25 const size_t kMaxMenuDepth = 2; |
| 58 | 26 |
| 59 // Maximum number of entries in any single menu (including separators). | 27 // Maximum number of entries in any single menu (including separators). |
| 60 const size_t kMaxMenuEntries = 50; | 28 const size_t kMaxMenuEntries = 50; |
| 61 | 29 |
| 62 // Maximum total number of entries in the |menu_id_map| (see below). | 30 // Maximum total number of entries in the |menu_id_map| (see below). |
| 63 // (Limit to 500 real entries; reserve the 0 action as an invalid entry.) | 31 // (Limit to 500 real entries; reserve the 0 action as an invalid entry.) |
| 64 const size_t kMaxMenuIdMapEntries = 501; | 32 const size_t kMaxMenuIdMapEntries = 501; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 91 |
| 124 return true; | 92 return true; |
| 125 } | 93 } |
| 126 | 94 |
| 127 } // namespace | 95 } // namespace |
| 128 | 96 |
| 129 PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PluginInstance* instance) | 97 PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PluginInstance* instance) |
| 130 : Resource(instance) { | 98 : Resource(instance) { |
| 131 } | 99 } |
| 132 | 100 |
| 101 PPB_Flash_Menu_Impl::~PPB_Flash_Menu_Impl() { |
| 102 } |
| 103 |
| 104 // static |
| 105 PP_Resource PPB_Flash_Menu_Impl::Create(PP_Instance pp_instance, |
| 106 const PP_Flash_Menu* menu_data) { |
| 107 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); |
| 108 if (!instance) |
| 109 return 0; |
| 110 |
| 111 scoped_refptr<PPB_Flash_Menu_Impl> menu(new PPB_Flash_Menu_Impl(instance)); |
| 112 if (!menu->Init(menu_data)) |
| 113 return 0; |
| 114 |
| 115 return menu->GetReference(); |
| 116 } |
| 117 |
| 133 bool PPB_Flash_Menu_Impl::Init(const PP_Flash_Menu* menu_data) { | 118 bool PPB_Flash_Menu_Impl::Init(const PP_Flash_Menu* menu_data) { |
| 134 menu_id_map_.clear(); | 119 menu_id_map_.clear(); |
| 135 menu_id_map_.push_back(0); // Reserve |menu_id_map_[0]|. | 120 menu_id_map_.push_back(0); // Reserve |menu_id_map_[0]|. |
| 136 if (!ConvertMenuData(menu_data, 0, &menu_data_, &menu_id_map_)) { | 121 if (!ConvertMenuData(menu_data, 0, &menu_data_, &menu_id_map_)) { |
| 137 menu_id_map_.clear(); | 122 menu_id_map_.clear(); |
| 138 return false; | 123 return false; |
| 139 } | 124 } |
| 140 | 125 |
| 141 return true; | 126 return true; |
| 142 } | 127 } |
| 143 | 128 |
| 144 PPB_Flash_Menu_Impl::~PPB_Flash_Menu_Impl() { | 129 PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() { |
| 145 } | |
| 146 | |
| 147 // static | |
| 148 const PPB_Flash_Menu* PPB_Flash_Menu_Impl::GetInterface() { | |
| 149 return &ppb_flash_menu; | |
| 150 } | |
| 151 | |
| 152 PPB_Flash_Menu_Impl* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_Impl() { | |
| 153 return this; | 130 return this; |
| 154 } | 131 } |
| 155 | 132 |
| 156 int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, | 133 int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, |
| 157 int32_t* selected_id_out, | 134 int32_t* selected_id_out, |
| 158 PP_CompletionCallback callback) { | 135 PP_CompletionCallback callback) { |
| 159 // |location| is not (currently) optional. | 136 // |location| is not (currently) optional. |
| 160 // TODO(viettrungluu): Make it optional and default to the current mouse pos? | 137 // TODO(viettrungluu): Make it optional and default to the current mouse pos? |
| 161 if (!location) | 138 if (!location) |
| 162 return PP_ERROR_BADARGUMENT; | 139 return PP_ERROR_BADARGUMENT; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 190 |
| 214 scoped_refptr<TrackedCompletionCallback> callback; | 191 scoped_refptr<TrackedCompletionCallback> callback; |
| 215 callback.swap(callback_); | 192 callback.swap(callback_); |
| 216 selected_id_out_ = NULL; | 193 selected_id_out_ = NULL; |
| 217 | 194 |
| 218 callback->Run(rv); // Will complete abortively if necessary. | 195 callback->Run(rv); // Will complete abortively if necessary. |
| 219 } | 196 } |
| 220 | 197 |
| 221 } // namespace ppapi | 198 } // namespace ppapi |
| 222 } // namespace webkit | 199 } // namespace webkit |
| OLD | NEW |