| Index: chrome/renderer/plugins/plugin_placeholder.cc
|
| diff --git a/chrome/renderer/plugins/plugin_placeholder.cc b/chrome/renderer/plugins/plugin_placeholder.cc
|
| index e46e9e463dd5bcf84ae69a8bd472d5952af924ee..1636774f2c7bd7e5dd89b4dc9e025dc89d100a5d 100644
|
| --- a/chrome/renderer/plugins/plugin_placeholder.cc
|
| +++ b/chrome/renderer/plugins/plugin_placeholder.cc
|
| @@ -17,6 +17,7 @@
|
| #include "chrome/renderer/chrome_content_renderer_client.h"
|
| #include "chrome/renderer/custom_menu_commands.h"
|
| #include "chrome/renderer/plugins/plugin_uma.h"
|
| +#include "content/public/common/context_menu_params.h"
|
| #include "content/public/renderer/render_thread.h"
|
| #include "content/public/renderer/render_view.h"
|
| #include "grit/generated_resources.h"
|
| @@ -228,7 +229,8 @@ PluginPlaceholder::PluginPlaceholder(content::RenderView* render_view,
|
| #endif
|
| hidden_(false),
|
| has_host_(false),
|
| - finished_loading_(false) {
|
| + finished_loading_(false),
|
| + context_menu_request_id_(0) {
|
| RenderThread::Get()->AddObserver(this);
|
| }
|
|
|
| @@ -452,23 +454,11 @@ void PluginPlaceholder::PluginListChanged() {
|
| ReplacePlugin(new_plugin);
|
| }
|
|
|
| -void PluginPlaceholder::SetMessage(const string16& message) {
|
| - message_ = message;
|
| - if (finished_loading_)
|
| - UpdateMessage();
|
| -}
|
| -
|
| -void PluginPlaceholder::UpdateMessage() {
|
| - std::string script = "window.setMessage(" +
|
| - base::GetDoubleQuotedJson(message_) + ")";
|
| - plugin_->web_view()->mainFrame()->executeScript(
|
| - WebScriptSource(ASCIIToUTF16(script)));
|
| -}
|
| -
|
| -void PluginPlaceholder::ContextMenuAction(unsigned id) {
|
| +void PluginPlaceholder::OnCustomContextMenuAction(int request_id,
|
| + unsigned action) {
|
| if (g_last_active_menu != this)
|
| return;
|
| - switch (id) {
|
| + switch (action) {
|
| case chrome::MENU_COMMAND_PLUGIN_RUN: {
|
| RenderThread::Get()->RecordUserMetrics("Plugin_Load_Menu");
|
| LoadPlugin();
|
| @@ -484,25 +474,40 @@ void PluginPlaceholder::ContextMenuAction(unsigned id) {
|
| }
|
| }
|
|
|
| -void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) {
|
| - WebContextMenuData menu_data;
|
| +void PluginPlaceholder::OnCustomContextMenuClosed(int request_id) {
|
| + DCHECK(request_id == context_menu_request_id_);
|
| + context_menu_request_id_ = 0;
|
| +}
|
|
|
| - size_t num_items = 3u;
|
| - if (!plugin_info_.path.value().empty())
|
| - num_items++;
|
| +void PluginPlaceholder::SetMessage(const string16& message) {
|
| + message_ = message;
|
| + if (finished_loading_)
|
| + UpdateMessage();
|
| +}
|
|
|
| - WebVector<WebMenuItemInfo> custom_items(num_items);
|
| +void PluginPlaceholder::UpdateMessage() {
|
| + std::string script = "window.setMessage(" +
|
| + base::GetDoubleQuotedJson(message_) + ")";
|
| + plugin_->web_view()->mainFrame()->executeScript(
|
| + WebScriptSource(ASCIIToUTF16(script)));
|
| +}
|
| +
|
| +void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) {
|
| + if (context_menu_request_id_)
|
| + return; // Don't allow nested context menu requests.
|
| +
|
| + content::ContextMenuParams params;
|
|
|
| size_t i = 0;
|
| WebMenuItemInfo name_item;
|
| name_item.label = title_;
|
| name_item.hasTextDirectionOverride = false;
|
| name_item.textDirection = WebKit::WebTextDirectionDefault;
|
| - custom_items[i++] = name_item;
|
| + params.custom_items.push_back(WebMenuItem(name_item));
|
|
|
| WebMenuItemInfo separator_item;
|
| separator_item.type = WebMenuItemInfo::Separator;
|
| - custom_items[i++] = separator_item;
|
| + params.custom_items.push_back(WebMenuItem(separator_item));
|
|
|
| if (!plugin_info_.path.value().empty()) {
|
| WebMenuItemInfo run_item;
|
| @@ -513,7 +518,7 @@ void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) {
|
| l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str());
|
| run_item.hasTextDirectionOverride = false;
|
| run_item.textDirection = WebKit::WebTextDirectionDefault;
|
| - custom_items[i++] = run_item;
|
| + params.custom_items.push_back(WebMenuItem(run_item));
|
| }
|
|
|
| WebMenuItemInfo hide_item;
|
| @@ -523,11 +528,12 @@ void PluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) {
|
| l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
|
| hide_item.hasTextDirectionOverride = false;
|
| hide_item.textDirection = WebKit::WebTextDirectionDefault;
|
| - custom_items[i++] = hide_item;
|
| + params.custom_items.push_back(WebMenuItem(hide_item));
|
| +
|
| + params.x = event.windowX;
|
| + params.y = event.windowY;
|
|
|
| - menu_data.customItems.swap(custom_items);
|
| - menu_data.mousePosition = WebPoint(event.windowX, event.windowY);
|
| - render_view()->ShowContextMenu(NULL, menu_data);
|
| + context_menu_request_id_ = render_view()->ShowContextMenu(this, params);
|
| g_last_active_menu = this;
|
| }
|
|
|
|
|