Chromium Code Reviews| 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_->PluginMenuEventListenerDestroyed(this); |
| +} |
| void BlockedPlugin::BindWebFrame(WebFrame* frame) { |
| BindToJavascript(frame, L"plugin"); |
| @@ -74,6 +88,51 @@ |
| delete this; |
| } |
| +void BlockedPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { |
| + WebContextMenuData menuData; |
|
brettw
2010/12/07 06:23:56
Local variables should be lower_case_with_undersco
Chris Evans
2010/12/07 15:36:14
Done.
|
| + WebVector<WebMenuItemInfo> customItems(static_cast<size_t>(4)); |
|
brettw
2010/12/07 06:23:56
I think you can just use custom_items(4) here? If
Chris Evans
2010/12/07 15:36:14
4u doesn't work either (on 64-bit); the constructo
brettw
2010/12/07 16:53:51
4u should be OK. size_t is equal to or larger than
|
| + { |
|
brettw
2010/12/07 06:23:56
Normally we wouldn't use {} here. Just separate th
Chris Evans
2010/12/07 15:36:14
Done.
|
| + WebMenuItemInfo nameItem; |
| + nameItem.label = name_; |
| + customItems[0] = nameItem; |
| + } |
| + { |
| + WebMenuItemInfo separatorItem; |
| + separatorItem.type = WebMenuItemInfo::Separator; |
| + customItems[1] = separatorItem; |
| + } |
| + { |
| + WebMenuItemInfo runItem; |
| + runItem.action = kMenuActionLoad; |
| + runItem.enabled = true; |
| + runItem.label = WebString::fromUTF8( |
| + l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str()); |
| + customItems[2] = runItem; |
| + } |
| + { |
| + WebMenuItemInfo hideItem; |
| + hideItem.action = kMenuActionRemove; |
| + hideItem.enabled = true; |
| + hideItem.label = WebString::fromUTF8( |
| + l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); |
| + customItems[3] = hideItem; |
| + } |
| + menuData.customItems.swap(customItems); |
| + menuData.mousePosition = WebPoint(event.windowX, event.windowY); |
| + render_view_->showContextMenu(NULL, menuData); |
| + render_view_->PluginMenuEventListenerInstall(this); |
| +} |
| + |
| +void BlockedPlugin::menuOptionSelected(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 +161,9 @@ |
| plugin_->destroy(); |
| } |
| } |
| + |
| +void BlockedPlugin::HidePlugin() { |
| + CHECK(plugin_); |
| + WebPluginContainer* container = plugin_->container(); |
| + container->element().setAttribute("style", "display: none;"); |
| +} |