diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 20:41:32 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 20:41:32 +0000 |
commit | 97f581360ca8ef6a36d511609446d0406cf98c6c (patch) | |
tree | 9fea28464e808f3cf0fe4198878b8e35dd1c665b /webkit | |
parent | f2369e14406267f82b4a9577dc8c5c5ecff30193 (diff) | |
download | chromium_src-97f581360ca8ef6a36d511609446d0406cf98c6c.zip chromium_src-97f581360ca8ef6a36d511609446d0406cf98c6c.tar.gz chromium_src-97f581360ca8ef6a36d511609446d0406cf98c6c.tar.bz2 |
Implement the Flash menu as a new-style Pepper resource.
The code is now moved out of content and into Chrome. The functionality should be the same. Some of the ways that the host interacted with the PluginInstance (i.e. getting the fullscreen container) was tricky so I unfortunately had to add some functions to the RendererPpapiHost to expose this.
Review URL: https://codereview.chromium.org/11369176
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168016 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.cc | 7 | ||||
-rw-r--r-- | webkit/plugins/ppapi/mock_plugin_delegate.h | 5 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_delegate.h | 8 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 1 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_menu_impl.cc | 183 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_menu_impl.h | 72 | ||||
-rw-r--r-- | webkit/plugins/ppapi/resource_creation_impl.cc | 3 |
8 files changed, 1 insertions, 280 deletions
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index d4a12f3..215fe40 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -211,8 +211,6 @@ '../plugins/ppapi/ppb_file_system_impl.h', '../plugins/ppapi/ppb_flash_impl.cc', '../plugins/ppapi/ppb_flash_impl.h', - '../plugins/ppapi/ppb_flash_menu_impl.cc', - '../plugins/ppapi/ppb_flash_menu_impl.h', '../plugins/ppapi/ppb_flash_message_loop_impl.cc', '../plugins/ppapi/ppb_flash_message_loop_impl.h', '../plugins/ppapi/ppb_gpu_blacklist_private_impl.cc', diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 7de9f91..756770f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -376,13 +376,6 @@ bool MockPluginDelegate::X509CertificateParseDER( return false; } -int32_t MockPluginDelegate::ShowContextMenu( - PluginInstance* instance, - webkit::ppapi::PPB_Flash_Menu_Impl* menu, - const gfx::Point& position) { - return PP_ERROR_FAILED; -} - FullscreenContainer* MockPluginDelegate::CreateFullscreenContainer( PluginInstance* instance) { return NULL; diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index 39e072a..886823f 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -178,11 +178,6 @@ class MockPluginDelegate : public PluginDelegate { virtual bool X509CertificateParseDER( const std::vector<char>& der, ::ppapi::PPB_X509Certificate_Fields* fields); - - virtual int32_t ShowContextMenu( - PluginInstance* instance, - webkit::ppapi::PPB_Flash_Menu_Impl* menu, - const gfx::Point& position); virtual FullscreenContainer* CreateFullscreenContainer( PluginInstance* instance); virtual gfx::Size GetScreenSize(); diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index e721f72..5995feb 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -92,7 +92,6 @@ class FullscreenContainer; class PluginInstance; class PluginModule; class PPB_Broker_Impl; -class PPB_Flash_Menu_Impl; class PPB_TCPSocket_Private_Impl; class PPB_UDPSocket_Private_Impl; @@ -571,13 +570,6 @@ class PluginDelegate { const std::vector<char>& der, ::ppapi::PPB_X509Certificate_Fields* fields) = 0; - // Show the given context menu at the given position (in the plugin's - // coordinates). - virtual int32_t ShowContextMenu( - PluginInstance* instance, - webkit::ppapi::PPB_Flash_Menu_Impl* menu, - const gfx::Point& position) = 0; - // Create a fullscreen container for a plugin instance. This effectively // switches the plugin to fullscreen. virtual FullscreenContainer* CreateFullscreenContainer( diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index 79e833f..41248c8 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -110,7 +110,6 @@ #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" #include "webkit/plugins/ppapi/ppb_flash_impl.h" -#include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" #include "webkit/plugins/ppapi/ppb_gpu_blacklist_private_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_image_data_impl.h" diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc b/webkit/plugins/ppapi/ppb_flash_menu_impl.cc deleted file mode 100644 index 7452061..0000000 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.cc +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" - -#include "base/utf_string_conversions.h" -#include "ppapi/c/pp_completion_callback.h" -#include "ui/gfx/point.h" -#include "webkit/glue/webmenuitem.h" -#include "webkit/plugins/ppapi/common.h" -#include "webkit/plugins/ppapi/plugin_delegate.h" -#include "webkit/plugins/ppapi/plugin_module.h" -#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/resource_helper.h" - -using ppapi::thunk::PPB_Flash_Menu_API; -using ppapi::TrackedCallback; - -namespace webkit { -namespace ppapi { - -namespace { - -// Maximum depth of submenus allowed (e.g., 1 indicates that submenus are -// allowed, but not sub-submenus). -const size_t kMaxMenuDepth = 2; - -// Maximum number of entries in any single menu (including separators). -const size_t kMaxMenuEntries = 50; - -// Maximum total number of entries in the |menu_id_map| (see below). -// (Limit to 500 real entries; reserve the 0 action as an invalid entry.) -const size_t kMaxMenuIdMapEntries = 501; - -// Converts menu data from one form to another. -// - |depth| is the current nested depth (call it starting with 0). -// - |menu_id_map| is such that |menu_id_map[output_item.action] == -// input_item.id| (where |action| is what a |WebMenuItem| has, |id| is what a -// |PP_Flash_MenuItem| has). -bool ConvertMenuData(const PP_Flash_Menu* in_menu, - size_t depth, - PPB_Flash_Menu_Impl::MenuData* out_menu, - std::vector<int32_t>* menu_id_map) { - if (depth > kMaxMenuDepth || !in_menu) - return false; - - // Clear the output, just in case. - out_menu->clear(); - - if (!in_menu->count) - return true; // Nothing else to do. - - if (!in_menu->items || in_menu->count > kMaxMenuEntries) - return false; - for (uint32_t i = 0; i < in_menu->count; i++) { - WebMenuItem item; - - PP_Flash_MenuItem_Type type = in_menu->items[i].type; - switch (type) { - case PP_FLASH_MENUITEM_TYPE_NORMAL: - item.type = WebMenuItem::OPTION; - break; - case PP_FLASH_MENUITEM_TYPE_CHECKBOX: - item.type = WebMenuItem::CHECKABLE_OPTION; - break; - case PP_FLASH_MENUITEM_TYPE_SEPARATOR: - item.type = WebMenuItem::SEPARATOR; - break; - case PP_FLASH_MENUITEM_TYPE_SUBMENU: - item.type = WebMenuItem::SUBMENU; - break; - default: - return false; - } - if (in_menu->items[i].name) - item.label = UTF8ToUTF16(in_menu->items[i].name); - if (menu_id_map->size() >= kMaxMenuIdMapEntries) - return false; - item.action = static_cast<unsigned>(menu_id_map->size()); - // This sets |(*menu_id_map)[item.action] = in_menu->items[i].id|. - menu_id_map->push_back(in_menu->items[i].id); - item.enabled = PPBoolToBool(in_menu->items[i].enabled); - item.checked = PPBoolToBool(in_menu->items[i].checked); - if (type == PP_FLASH_MENUITEM_TYPE_SUBMENU) { - if (!ConvertMenuData(in_menu->items[i].submenu, depth + 1, &item.submenu, - menu_id_map)) - return false; - } - - out_menu->push_back(item); - } - - return true; -} - -} // namespace - -PPB_Flash_Menu_Impl::PPB_Flash_Menu_Impl(PP_Instance instance) - : Resource(::ppapi::OBJECT_IS_IMPL, instance), - selected_id_out_(NULL) { -} - -PPB_Flash_Menu_Impl::~PPB_Flash_Menu_Impl() { -} - -// static -PP_Resource PPB_Flash_Menu_Impl::Create(PP_Instance instance, - const PP_Flash_Menu* menu_data) { - scoped_refptr<PPB_Flash_Menu_Impl> menu(new PPB_Flash_Menu_Impl(instance)); - if (!menu->Init(menu_data)) - return 0; - return menu->GetReference(); -} - -bool PPB_Flash_Menu_Impl::Init(const PP_Flash_Menu* menu_data) { - menu_id_map_.clear(); - menu_id_map_.push_back(0); // Reserve |menu_id_map_[0]|. - if (!ConvertMenuData(menu_data, 0, &menu_data_, &menu_id_map_)) { - menu_id_map_.clear(); - return false; - } - - return true; -} - -PPB_Flash_Menu_API* PPB_Flash_Menu_Impl::AsPPB_Flash_Menu_API() { - return this; -} - -int32_t PPB_Flash_Menu_Impl::Show(const PP_Point* location, - int32_t* selected_id_out, - scoped_refptr<TrackedCallback> callback) { - // |location| is not (currently) optional. - // TODO(viettrungluu): Make it optional and default to the current mouse pos? - if (!location) - return PP_ERROR_BADARGUMENT; - - if (TrackedCallback::IsPending(callback_)) - return PP_ERROR_INPROGRESS; - - PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); - if (!plugin_instance) - return false; - - int32_t rv = plugin_instance->delegate()->ShowContextMenu( - plugin_instance, this, gfx::Point(location->x, location->y)); - if (rv == PP_OK_COMPLETIONPENDING) { - // Record callback and output buffers. - callback_ = callback; - selected_id_out_ = selected_id_out; - } else { - // This should never be completed synchronously successfully. - DCHECK_NE(rv, PP_OK); - } - return rv; -} - -void PPB_Flash_Menu_Impl::CompleteShow(int32_t result, - unsigned action) { - int32_t rv = PP_ERROR_ABORTED; - if (!callback_->aborted()) { - CHECK(!callback_->completed()); - rv = result; - - // Write output data. - if (selected_id_out_ && result == PP_OK) { - // We reserved action 0 to be invalid. - if (action == 0 || action >= menu_id_map_.size()) { - NOTREACHED() << "Invalid action received."; - rv = PP_ERROR_FAILED; - } else { - *selected_id_out_ = menu_id_map_[action]; - } - } - } - - selected_id_out_ = NULL; - callback_->Run(rv); -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_flash_menu_impl.h b/webkit/plugins/ppapi/ppb_flash_menu_impl.h deleted file mode 100644 index 33ce588..0000000 --- a/webkit/plugins/ppapi/ppb_flash_menu_impl.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef WEBKIT_PLUGINS_PPAPI_PPB_FLASH_MENU_IMPL_H_ -#define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_MENU_IMPL_H_ - -#include <vector> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "ppapi/c/pp_point.h" -#include "ppapi/c/private/ppb_flash_menu.h" -#include "ppapi/shared_impl/tracked_callback.h" -#include "ppapi/shared_impl/resource.h" -#include "ppapi/thunk/ppb_flash_menu_api.h" -#include "webkit/plugins/webkit_plugins_export.h" - -struct WebMenuItem; - -namespace webkit { -namespace ppapi { - -class PPB_Flash_Menu_Impl : public ::ppapi::Resource, - public ::ppapi::thunk::PPB_Flash_Menu_API { - public: - virtual ~PPB_Flash_Menu_Impl(); - - static PP_Resource Create(PP_Instance instance, - const PP_Flash_Menu* menu_data); - - // Resource. - virtual ::ppapi::thunk::PPB_Flash_Menu_API* AsPPB_Flash_Menu_API() OVERRIDE; - - // PPB_Flash_Menu implementation. - virtual int32_t Show( - const PP_Point* location, - int32_t* selected_id_out, - scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; - - // Called to complete |Show()|. - WEBKIT_PLUGINS_EXPORT void CompleteShow(int32_t result, unsigned action); - - typedef std::vector<WebMenuItem> MenuData; - const MenuData& menu_data() const { return menu_data_; } - - private: - explicit PPB_Flash_Menu_Impl(PP_Instance instance); - - bool Init(const PP_Flash_Menu* menu_data); - - MenuData menu_data_; - - // We send |WebMenuItem|s, which have an |unsigned| "action" field instead of - // an |int32_t| ID. (Chrome also limits the range of valid values for - // actions.) This maps actions to IDs. - std::vector<int32_t> menu_id_map_; - - // Any pending callback (for |Show()|). - scoped_refptr< ::ppapi::TrackedCallback> callback_; - - // Output buffers to be filled in when the callback is completed successfully. - int32_t* selected_id_out_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Menu_Impl); -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_PPB_FLASH_MENU_IMPL_H_ diff --git a/webkit/plugins/ppapi/resource_creation_impl.cc b/webkit/plugins/ppapi/resource_creation_impl.cc index 159e27f..0a85d9f 100644 --- a/webkit/plugins/ppapi/resource_creation_impl.cc +++ b/webkit/plugins/ppapi/resource_creation_impl.cc @@ -18,7 +18,6 @@ #include "webkit/plugins/ppapi/ppb_file_io_impl.h" #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" #include "webkit/plugins/ppapi/ppb_file_system_impl.h" -#include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" #include "webkit/plugins/ppapi/ppb_flash_message_loop_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" @@ -131,7 +130,7 @@ PP_Resource ResourceCreationImpl::CreateFlashFontFile( PP_Resource ResourceCreationImpl::CreateFlashMenu( PP_Instance instance, const PP_Flash_Menu* menu_data) { - return PPB_Flash_Menu_Impl::Create(instance, menu_data); + return 0; // Not supported in-process. } PP_Resource ResourceCreationImpl::CreateFlashMessageLoop(PP_Instance instance) { |