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

Side by Side Diff: chrome/renderer/blocked_plugin.cc

Issue 7990005: Use a placeholder instead of the default plugin for missing plug-ins on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 2 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/string_piece.h" 7 #include "base/string_piece.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/jstemplate_builder.h" 10 #include "chrome/common/jstemplate_builder.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // TODO(cevans) - move these to a shared header file so that there are no 49 // TODO(cevans) - move these to a shared header file so that there are no
50 // collisions in the longer term. Currently, blocked_plugin.cc is the only 50 // collisions in the longer term. Currently, blocked_plugin.cc is the only
51 // user of custom menu commands (extension menu items have their own range). 51 // user of custom menu commands (extension menu items have their own range).
52 static const unsigned kMenuActionLoad = 1; 52 static const unsigned kMenuActionLoad = 1;
53 static const unsigned kMenuActionRemove = 2; 53 static const unsigned kMenuActionRemove = 2;
54 54
55 static const BlockedPlugin* g_last_active_menu; 55 static const BlockedPlugin* g_last_active_menu;
56 56
57 BlockedPlugin::BlockedPlugin(RenderView* render_view, 57 BlockedPlugin::BlockedPlugin(RenderView* render_view,
58 WebFrame* frame, 58 WebFrame* frame,
59 const webkit::npapi::PluginGroup& info,
60 const WebPluginParams& params, 59 const WebPluginParams& params,
61 const WebPreferences& preferences, 60 const WebPreferences& preferences,
62 int template_id, 61 int template_id,
62 const string16& name,
63 const string16& message, 63 const string16& message,
64 bool is_blocked_for_prerendering, 64 bool is_blocked_for_prerendering,
65 bool allow_loading) 65 bool allow_loading)
66 : RenderViewObserver(render_view), 66 : RenderViewObserver(render_view),
67 frame_(frame), 67 frame_(frame),
68 plugin_params_(params), 68 plugin_params_(params),
69 name_(name),
69 is_blocked_for_prerendering_(is_blocked_for_prerendering), 70 is_blocked_for_prerendering_(is_blocked_for_prerendering),
70 hidden_(false), 71 hidden_(false),
71 allow_loading_(allow_loading) { 72 allow_loading_(allow_loading) {
72 const base::StringPiece template_html( 73 const base::StringPiece template_html(
73 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 74 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
74 75
75 DCHECK(!template_html.empty()) << "unable to load template. ID: " 76 DCHECK(!template_html.empty()) << "unable to load template. ID: "
76 << template_id; 77 << template_id;
77 78
78 DictionaryValue values; 79 DictionaryValue values;
79 values.SetString("message", message); 80 values.SetString("message", message);
80 name_ = info.GetGroupName();
81 values.SetString("name", name_); 81 values.SetString("name", name_);
82 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE)); 82 values.SetString("hide", l10n_util::GetStringUTF8(IDS_PLUGIN_HIDE));
83 83
84 // "t" is the id of the templates root node. 84 // "t" is the id of the templates root node.
85 std::string html_data = jstemplate_builder::GetTemplatesHtml( 85 std::string html_data = jstemplate_builder::GetTemplatesHtml(
86 template_html, &values, "t"); 86 template_html, &values, "t");
87 87
88 plugin_ = webkit::npapi::WebViewPlugin::Create(this, 88 plugin_ = webkit::npapi::WebViewPlugin::Create(this,
89 preferences, 89 preferences,
90 html_data, 90 html_data,
91 GURL(kBlockedPluginDataURL)); 91 GURL(kBlockedPluginDataURL));
92 } 92 }
93 93
94 BlockedPlugin::~BlockedPlugin() { 94 BlockedPlugin::~BlockedPlugin() {
95 } 95 }
96 96
97 void BlockedPlugin::BindWebFrame(WebFrame* frame) { 97 void BlockedPlugin::BindWebFrame(WebFrame* frame) {
98 BindToJavascript(frame, "plugin"); 98 BindToJavascript(frame, "plugin");
99 BindMethod("load", &BlockedPlugin::Load); 99 BindMethod("load", &BlockedPlugin::Load);
100 BindMethod("hide", &BlockedPlugin::Hide); 100 BindMethod("hide", &BlockedPlugin::Hide);
101 } 101 }
102 102
103 void BlockedPlugin::WillDestroyPlugin() { 103 void BlockedPlugin::WillDestroyPlugin() {
104 delete this; 104 delete this;
105 } 105 }
106 106
107 void BlockedPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) { 107 void BlockedPlugin::ShowContextMenu(const WebKit::WebMouseEvent& event) {
108 WebContextMenuData menu_data; 108 WebContextMenuData menu_data;
109 WebVector<WebMenuItemInfo> custom_items(static_cast<size_t>(4));
110 109
111 WebMenuItemInfo name_item; 110 size_t num_items = name_.empty() ? 2u : 4u;
112 name_item.label = name_; 111 WebVector<WebMenuItemInfo> custom_items(num_items);
113 name_item.hasTextDirectionOverride = false;
114 name_item.textDirection = WebKit::WebTextDirectionDefault;
115 custom_items[0] = name_item;
116 112
117 WebMenuItemInfo separator_item; 113 size_t i = 0;
118 separator_item.type = WebMenuItemInfo::Separator; 114 if (!name_.empty()) {
119 custom_items[1] = separator_item; 115 WebMenuItemInfo name_item;
116 name_item.label = name_;
117 name_item.hasTextDirectionOverride = false;
118 name_item.textDirection = WebKit::WebTextDirectionDefault;
119 custom_items[i++] = name_item;
120
121 WebMenuItemInfo separator_item;
122 separator_item.type = WebMenuItemInfo::Separator;
123 custom_items[i++] = separator_item;
124 }
120 125
121 WebMenuItemInfo run_item; 126 WebMenuItemInfo run_item;
122 run_item.action = kMenuActionLoad; 127 run_item.action = kMenuActionLoad;
123 // Disable this menu item if the plugin is blocked by policy. 128 // Disable this menu item if the plugin is blocked by policy.
124 run_item.enabled = allow_loading_; 129 run_item.enabled = allow_loading_;
125 run_item.label = WebString::fromUTF8( 130 run_item.label = WebString::fromUTF8(
126 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str()); 131 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_RUN).c_str());
127 run_item.hasTextDirectionOverride = false; 132 run_item.hasTextDirectionOverride = false;
128 run_item.textDirection = WebKit::WebTextDirectionDefault; 133 run_item.textDirection = WebKit::WebTextDirectionDefault;
129 custom_items[2] = run_item; 134 custom_items[i++] = run_item;
130 135
131 WebMenuItemInfo hide_item; 136 WebMenuItemInfo hide_item;
132 hide_item.action = kMenuActionRemove; 137 hide_item.action = kMenuActionRemove;
133 hide_item.enabled = true; 138 hide_item.enabled = true;
134 hide_item.label = WebString::fromUTF8( 139 hide_item.label = WebString::fromUTF8(
135 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str()); 140 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_PLUGIN_HIDE).c_str());
136 hide_item.hasTextDirectionOverride = false; 141 hide_item.hasTextDirectionOverride = false;
137 hide_item.textDirection = WebKit::WebTextDirectionDefault; 142 hide_item.textDirection = WebKit::WebTextDirectionDefault;
138 custom_items[3] = hide_item; 143 custom_items[i++] = hide_item;
139 144
140 menu_data.customItems.swap(custom_items); 145 menu_data.customItems.swap(custom_items);
141 menu_data.mousePosition = WebPoint(event.windowX, event.windowY); 146 menu_data.mousePosition = WebPoint(event.windowX, event.windowY);
142 render_view()->showContextMenu(NULL, menu_data); 147 render_view()->showContextMenu(NULL, menu_data);
143 g_last_active_menu = this; 148 g_last_active_menu = this;
144 } 149 }
145 150
146 bool BlockedPlugin::OnMessageReceived(const IPC::Message& message) { 151 bool BlockedPlugin::OnMessageReceived(const IPC::Message& message) {
147 // We don't swallow ViewMsg_CustomContextMenuAction because we listen for all 152 // We don't swallow ViewMsg_CustomContextMenuAction because we listen for all
148 // custom menu IDs, and not just our own. We don't swallow 153 // custom menu IDs, and not just our own. We don't swallow
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 element = parent.toConst<WebElement>(); 264 element = parent.toConst<WebElement>();
260 if (element.hasAttribute("style")) { 265 if (element.hasAttribute("style")) {
261 WebString style_str = element.getAttribute("style"); 266 WebString style_str = element.getAttribute("style");
262 if (width_regex.match(style_str) >= 0 && 267 if (width_regex.match(style_str) >= 0 &&
263 height_regex.match(style_str) >= 0) 268 height_regex.match(style_str) >= 0)
264 element.setAttribute("style", "display: none;"); 269 element.setAttribute("style", "display: none;");
265 } 270 }
266 } 271 }
267 } 272 }
268 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698