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 | 16 |
16 using ::ppapi::thunk::PPB_Flash_Menu_API; | 17 using ::ppapi::thunk::PPB_Flash_Menu_API; |
17 | 18 |
18 namespace webkit { | 19 namespace webkit { |
19 namespace ppapi { | 20 namespace ppapi { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are | 24 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are |
24 // allowed, but not sub-submenus). | 25 // allowed, but not sub-submenus). |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 88 } |
88 | 89 |
89 out_menu->push_back(item); | 90 out_menu->push_back(item); |
90 } | 91 } |
91 | 92 |
92 return true; | 93 return true; |
93 } | 94 } |
94 | 95 |
95 } // namespace | 96 } // namespace |
96 | 97 |
97 PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PluginInstance* instance) | 98 PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PP_Instance instance) |
98 : Resource(instance) { | 99 : Resource(instance) { |
99 } | 100 } |
100 | 101 |
101 PPB_Flash_Menu_Impl::~PPB_Flash_Menu_Impl() { | 102 PPB_Flash_Menu_Impl::~PPB_Flash_Menu_Impl() { |
102 } | 103 } |
103 | 104 |
104 // static | 105 // static |
105 PP_Resource PPB_Flash_Menu_Impl::Create(PluginInstance* instance, | 106 PP_Resource PPB_Flash_Menu_Impl::Create(PP_Instance instance, |
106 const PP_Flash_Menu* menu_data) { | 107 const PP_Flash_Menu* menu_data) { |
107 scoped_refptr<PPB_Flash_Menu_Impl> menu(new PPB_Flash_Menu_Impl(instance)); | 108 scoped_refptr<PPB_Flash_Menu_Impl> menu(new PPB_Flash_Menu_Impl(instance)); |
108 if (!menu->Init(menu_data)) | 109 if (!menu->Init(menu_data)) |
109 return 0; | 110 return 0; |
110 return menu->GetReference(); | 111 return menu->GetReference(); |
111 } | 112 } |
112 | 113 |
113 bool PPB_Flash_Menu_Impl::Init(const PP_Flash_Menu* menu_data) { | 114 bool PPB_Flash_Menu_Impl::Init(const PP_Flash_Menu* menu_data) { |
114 menu_id_map_.clear(); | 115 menu_id_map_.clear(); |
115 menu_id_map_.push_back(0); // Reserve |menu_id_map_[0]|. | 116 menu_id_map_.push_back(0); // Reserve |menu_id_map_[0]|. |
(...skipping 18 matching lines...) Expand all Loading... |
134 return PP_ERROR_BADARGUMENT; | 135 return PP_ERROR_BADARGUMENT; |
135 | 136 |
136 if (!callback.func) { | 137 if (!callback.func) { |
137 NOTIMPLEMENTED(); | 138 NOTIMPLEMENTED(); |
138 return PP_ERROR_BADARGUMENT; | 139 return PP_ERROR_BADARGUMENT; |
139 } | 140 } |
140 | 141 |
141 if (callback_.get() && !callback_->completed()) | 142 if (callback_.get() && !callback_->completed()) |
142 return PP_ERROR_INPROGRESS; | 143 return PP_ERROR_INPROGRESS; |
143 | 144 |
144 int32_t rv = instance()->delegate()->ShowContextMenu( | 145 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
145 instance(), this, gfx::Point(location->x, location->y)); | 146 if (!plugin_instance) |
| 147 return false; |
| 148 |
| 149 int32_t rv = plugin_instance->delegate()->ShowContextMenu( |
| 150 plugin_instance, this, gfx::Point(location->x, location->y)); |
146 if (rv == PP_OK_COMPLETIONPENDING) { | 151 if (rv == PP_OK_COMPLETIONPENDING) { |
147 // Record callback and output buffers. | 152 // Record callback and output buffers. |
148 callback_ = new TrackedCompletionCallback( | 153 callback_ = new TrackedCompletionCallback( |
149 instance()->module()->GetCallbackTracker(), pp_resource(), callback); | 154 plugin_instance->module()->GetCallbackTracker(), |
| 155 pp_resource(), callback); |
150 selected_id_out_ = selected_id_out; | 156 selected_id_out_ = selected_id_out; |
151 } else { | 157 } else { |
152 // This should never be completed synchronously successfully. | 158 // This should never be completed synchronously successfully. |
153 DCHECK_NE(rv, PP_OK); | 159 DCHECK_NE(rv, PP_OK); |
154 } | 160 } |
155 return rv; | 161 return rv; |
156 | 162 |
157 NOTIMPLEMENTED(); | 163 NOTIMPLEMENTED(); |
158 return PP_ERROR_FAILED; | 164 return PP_ERROR_FAILED; |
159 } | 165 } |
(...skipping 19 matching lines...) Expand all Loading... |
179 | 185 |
180 scoped_refptr<TrackedCompletionCallback> callback; | 186 scoped_refptr<TrackedCompletionCallback> callback; |
181 callback.swap(callback_); | 187 callback.swap(callback_); |
182 selected_id_out_ = NULL; | 188 selected_id_out_ = NULL; |
183 | 189 |
184 callback->Run(rv); // Will complete abortively if necessary. | 190 callback->Run(rv); // Will complete abortively if necessary. |
185 } | 191 } |
186 | 192 |
187 } // namespace ppapi | 193 } // namespace ppapi |
188 } // namespace webkit | 194 } // namespace webkit |
OLD | NEW |