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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/renderer/blocked_plugin.h" 5 #include "chrome/renderer/blocked_plugin.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/string_piece.h" 9 #include "base/string_piece.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/common/jstemplate_builder.h" 11 #include "chrome/common/jstemplate_builder.h"
12 #include "chrome/common/notification_service.h" 12 #include "chrome/common/notification_service.h"
13 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/renderer/render_view.h" 14 #include "chrome/renderer/render_view.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "grit/renderer_resources.h" 16 #include "grit/renderer_resources.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" 18 #include "third_party/WebKit/WebKit/chromium/public/WebData.h"
18 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
20 #include "third_party/WebKit/WebKit/chromium/public/WebMenuItemInfo.h"
19 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
22 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h"
23 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
20 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" 24 #include "third_party/WebKit/WebKit/chromium/public/WebView.h"
21 #include "webkit/glue/plugins/plugin_group.h" 25 #include "webkit/glue/plugins/plugin_group.h"
22 #include "webkit/glue/plugins/webview_plugin.h" 26 #include "webkit/glue/plugins/webview_plugin.h"
23 #include "webkit/glue/webpreferences.h" 27 #include "webkit/glue/webpreferences.h"
24 28
29 using WebKit::WebContextMenuData;
25 using WebKit::WebFrame; 30 using WebKit::WebFrame;
31 using WebKit::WebMenuItemInfo;
26 using WebKit::WebPlugin; 32 using WebKit::WebPlugin;
27 using WebKit::WebPluginContainer; 33 using WebKit::WebPluginContainer;
28 using WebKit::WebPluginParams; 34 using WebKit::WebPluginParams;
35 using WebKit::WebPoint;
36 using WebKit::WebString;
37 using WebKit::WebVector;
29 38
30 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/"; 39 static const char* const kBlockedPluginDataURL = "chrome://blockedplugindata/";
40 static const unsigned kMenuActionLoad = 1;
41 static const unsigned kMenuActionRemove = 2;
31 42
32 BlockedPlugin::BlockedPlugin(RenderView* render_view, 43 BlockedPlugin::BlockedPlugin(RenderView* render_view,
33 WebFrame* frame, 44 WebFrame* frame,
34 const PluginGroup& info, 45 const PluginGroup& info,
35 const WebPluginParams& params, 46 const WebPluginParams& params,
36 const WebPreferences& preferences, 47 const WebPreferences& preferences,
37 int template_id, 48 int template_id,
38 const string16& message) 49 const string16& message)
39 : render_view_(render_view), 50 : render_view_(render_view),
40 frame_(frame), 51 frame_(frame),
41 plugin_params_(params) { 52 plugin_params_(params) {
42 const base::StringPiece template_html( 53 const base::StringPiece template_html(
43 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 54 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
44 55
45 DCHECK(!template_html.empty()) << "unable to load template. ID: " 56 DCHECK(!template_html.empty()) << "unable to load template. ID: "
46 << template_id; 57 << template_id;
47 58
48 DictionaryValue values; 59 DictionaryValue values;
49 values.SetString("message", message); 60 values.SetString("message", message);
50 values.SetString("name", info.GetGroupName()); 61 name_ = info.GetGroupName();
62 values.SetString("name", name_);
51 63
52 // "t" is the id of the templates root node. 64 // "t" is the id of the templates root node.
53 std::string html_data = jstemplate_builder::GetTemplatesHtml( 65 std::string html_data = jstemplate_builder::GetTemplatesHtml(
54 template_html, &values, "t"); 66 template_html, &values, "t");
55 67
56 plugin_ = WebViewPlugin::Create(this, 68 plugin_ = WebViewPlugin::Create(this,
57 preferences, 69 preferences,
58 html_data, 70 html_data,
59 GURL(kBlockedPluginDataURL)); 71 GURL(kBlockedPluginDataURL));
60 72
61 registrar_.Add(this, 73 registrar_.Add(this,
62 NotificationType::SHOULD_LOAD_PLUGINS, 74 NotificationType::SHOULD_LOAD_PLUGINS,
63 NotificationService::AllSources()); 75 NotificationService::AllSources());
64 } 76 }
65 77
66 BlockedPlugin::~BlockedPlugin() {} 78 BlockedPlugin::~BlockedPlugin() {
79 render_view_->PluginMenuEventListenerDestroyed(this);
80 }
67 81
68 void BlockedPlugin::BindWebFrame(WebFrame* frame) { 82 void BlockedPlugin::BindWebFrame(WebFrame* frame) {
69 BindToJavascript(frame, L"plugin"); 83 BindToJavascript(frame, L"plugin");
70 BindMethod("load", &BlockedPlugin::Load); 84 BindMethod("load", &BlockedPlugin::Load);
71 } 85 }
72 86
73 void BlockedPlugin::WillDestroyPlugin() { 87 void BlockedPlugin::WillDestroyPlugin() {
74 delete this; 88 delete this;
75 } 89 }
76 90
91 void BlockedPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) {
92 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.
93 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
94 {
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.
95 WebMenuItemInfo nameItem;
96 nameItem.label = name_;
97 customItems[0] = nameItem;
98 }
99 {
100 WebMenuItemInfo separatorItem;
101 separatorItem.type = WebMenuItemInfo::Separator;
102 customItems[1] = separatorItem;
103 }
104 {
105 WebMenuItemInfo runItem;
106 runItem.action = kMenuActionLoad;
107 runItem.enabled = true;
108 runItem.label = WebString::fromUTF8(
109 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str());
110 customItems[2] = runItem;
111 }
112 {
113 WebMenuItemInfo hideItem;
114 hideItem.action = kMenuActionRemove;
115 hideItem.enabled = true;
116 hideItem.label = WebString::fromUTF8(
117 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
118 customItems[3] = hideItem;
119 }
120 menuData.customItems.swap(customItems);
121 menuData.mousePosition = WebPoint(event.windowX, event.windowY);
122 render_view_->showContextMenu(NULL, menuData);
123 render_view_->PluginMenuEventListenerInstall(this);
124 }
125
126 void BlockedPlugin::menuOptionSelected(unsigned id) {
127 if (id == kMenuActionLoad) {
128 LoadPlugin();
129 } else if (id == kMenuActionRemove) {
130 HidePlugin();
131 } else {
132 NOTREACHED();
133 }
134 }
135
77 void BlockedPlugin::Observe(NotificationType type, 136 void BlockedPlugin::Observe(NotificationType type,
78 const NotificationSource& source, 137 const NotificationSource& source,
79 const NotificationDetails& details) { 138 const NotificationDetails& details) {
80 if (type == NotificationType::SHOULD_LOAD_PLUGINS) { 139 if (type == NotificationType::SHOULD_LOAD_PLUGINS) {
81 LoadPlugin(); 140 LoadPlugin();
82 } else { 141 } else {
83 NOTREACHED(); 142 NOTREACHED();
84 } 143 }
85 } 144 }
86 145
87 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) { 146 void BlockedPlugin::Load(const CppArgumentList& args, CppVariant* result) {
88 LoadPlugin(); 147 LoadPlugin();
89 } 148 }
90 149
91 void BlockedPlugin::LoadPlugin() { 150 void BlockedPlugin::LoadPlugin() {
92 CHECK(plugin_); 151 CHECK(plugin_);
93 WebPluginContainer* container = plugin_->container(); 152 WebPluginContainer* container = plugin_->container();
94 WebPlugin* new_plugin = 153 WebPlugin* new_plugin =
95 render_view_->CreatePluginNoCheck(frame_, 154 render_view_->CreatePluginNoCheck(frame_,
96 plugin_params_); 155 plugin_params_);
97 if (new_plugin && new_plugin->initialize(container)) { 156 if (new_plugin && new_plugin->initialize(container)) {
98 container->setPlugin(new_plugin); 157 container->setPlugin(new_plugin);
99 container->invalidate(); 158 container->invalidate();
100 container->reportGeometry(); 159 container->reportGeometry();
101 plugin_->ReplayReceivedData(new_plugin); 160 plugin_->ReplayReceivedData(new_plugin);
102 plugin_->destroy(); 161 plugin_->destroy();
103 } 162 }
104 } 163 }
164
165 void BlockedPlugin::HidePlugin() {
166 CHECK(plugin_);
167 WebPluginContainer* container = plugin_->container();
168 container->element().setAttribute("style", "display: none;");
169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698