Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4856)

Unified Diff: chrome/renderer/blocked_plugin.cc

Issue 5639004: Implement a useful context menu for the blocked plug-in frame:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/blocked_plugin.h ('k') | chrome/renderer/custom_menu_listener.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/blocked_plugin.cc
===================================================================
--- chrome/renderer/blocked_plugin.cc (revision 67601)
+++ chrome/renderer/blocked_plugin.cc (working copy)
@@ -14,20 +14,31 @@
#include "chrome/renderer/render_view.h"
#include "grit/generated_resources.h"
#include "grit/renderer_resources.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h"
#include "third_party/WebKit/WebKit/chromium/public/WebData.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
#include "webkit/glue/plugins/plugin_group.h"
#include "webkit/glue/plugins/webview_plugin.h"
#include "webkit/glue/webpreferences.h"
+using WebKit::WebContextMenuData;
using WebKit::WebFrame;
+using WebKit::WebMenuItemInfo;
using WebKit::WebPlugin;
using WebKit::WebPluginContainer;
using WebKit::WebPluginParams;
+using WebKit::WebPoint;
+using WebKit::WebString;
+using WebKit::WebVector;
static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/";
+static const unsigned kMenuActionLoad = 1;
+static const unsigned kMenuActionRemove = 2;
BlockedPlugin::BlockedPlugin(RenderView* render_view,
WebFrame* frame,
@@ -47,7 +58,8 @@
DictionaryValue values;
values.SetString("message", message);
- values.SetString("name", info.GetGroupName());
+ name_ = info.GetGroupName();
+ values.SetString("name", name_);
// "t" is the id of the templates root node.
std::string html_data = jstemplate_builder::GetTemplatesHtml(
@@ -63,7 +75,9 @@
NotificationService::AllSources());
}
-BlockedPlugin::~BlockedPlugin() {}
+BlockedPlugin::~BlockedPlugin() {
+ render_view_->CustomMenuListenerDestroyed(this);
+}
void BlockedPlugin::BindWebFrame(WebFrame* frame) {
BindToJavascript(frame, L"plugin");
@@ -74,6 +88,48 @@
delete this;
}
+void BlockedPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) {
+ WebContextMenuData menu_data;
+ WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(4));
+
+ WebMenuItemInfo name_item;
+ name_item.label = name_;
+ custom_items[0] = name_item;
+
+ WebMenuItemInfo separator_item;
+ separator_item.type = WebMenuItemInfo::Separator;
+ custom_items[1] = separator_item;
+
+ WebMenuItemInfo run_item;
+ run_item.action = kMenuActionLoad;
+ run_item.enabled = true;
+ run_item.label = WebString::fromUTF8(
+ l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str());
+ custom_items[2] = run_item;
+
+ WebMenuItemInfo hide_item;
+ hide_item.action = kMenuActionRemove;
+ hide_item.enabled = true;
+ hide_item.label = WebString::fromUTF8(
+ l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
+ custom_items[3] = hide_item;
+
+ menu_data.customItems.swap(custom_items);
+ menu_data.mousePosition = WebPoint(event.windowX, event.windowY);
+ render_view_->showContextMenu(NULL, menu_data);
+ render_view_->CustomMenuListenerInstall(this);
+}
+
+void BlockedPlugin::MenuItemSelected(unsigned id) {
+ if (id == kMenuActionLoad) {
+ LoadPlugin();
+ } else if (id == kMenuActionRemove) {
+ HidePlugin();
+ } else {
+ NOTREACHED();
+ }
+}
+
void BlockedPlugin::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -102,3 +158,10 @@
plugin_->destroy();
}
}
+
+void BlockedPlugin::HidePlugin() {
+ CHECK(plugin_);
+ WebPluginContainer* container = plugin_->container();
+ container->element().setAttribute("style", "display: none;");
+}
+
« no previous file with comments | « chrome/renderer/blocked_plugin.h ('k') | chrome/renderer/custom_menu_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698