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

Side by Side Diff: chrome/renderer/plugins/chrome_plugin_placeholder.cc

Issue 1126073003: Plugin Placeholders: Refactor for platforms that don't support plugins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: The version that was reverted. Created 5 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/plugins/chrome_plugin_placeholder.h" 5 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/common/prerender_messages.h" 10 #include "chrome/common/prerender_messages.h"
11 #include "chrome/common/render_messages.h" 11 #include "chrome/common/render_messages.h"
12 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
13 #include "chrome/grit/renderer_resources.h" 13 #include "chrome/grit/renderer_resources.h"
14 #include "chrome/renderer/chrome_content_renderer_client.h" 14 #include "chrome/renderer/chrome_content_renderer_client.h"
15 #include "chrome/renderer/custom_menu_commands.h" 15 #include "chrome/renderer/custom_menu_commands.h"
16 #include "chrome/renderer/plugins/plugin_preroller.h" 16 #include "chrome/renderer/plugins/plugin_preroller.h"
17 #include "chrome/renderer/plugins/plugin_uma.h" 17 #include "chrome/renderer/plugins/plugin_uma.h"
18 #include "components/content_settings/content/common/content_settings_messages.h " 18 #include "components/content_settings/content/common/content_settings_messages.h "
19 #include "content/app/strings/grit/content_strings.h"
20 #include "content/public/common/context_menu_params.h" 19 #include "content/public/common/context_menu_params.h"
21 #include "content/public/renderer/render_frame.h" 20 #include "content/public/renderer/render_frame.h"
22 #include "content/public/renderer/render_thread.h" 21 #include "content/public/renderer/render_thread.h"
23 #include "gin/object_template_builder.h" 22 #include "gin/object_template_builder.h"
24 #include "third_party/WebKit/public/web/WebDocument.h" 23 #include "third_party/WebKit/public/web/WebDocument.h"
25 #include "third_party/WebKit/public/web/WebInputEvent.h" 24 #include "third_party/WebKit/public/web/WebInputEvent.h"
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" 25 #include "third_party/WebKit/public/web/WebLocalFrame.h"
27 #include "third_party/WebKit/public/web/WebScriptSource.h" 26 #include "third_party/WebKit/public/web/WebScriptSource.h"
28 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
(...skipping 11 matching lines...) Expand all
41 using blink::WebPlugin; 40 using blink::WebPlugin;
42 using blink::WebPluginContainer; 41 using blink::WebPluginContainer;
43 using blink::WebPluginParams; 42 using blink::WebPluginParams;
44 using content::RenderThread; 43 using content::RenderThread;
45 using content::RenderView; 44 using content::RenderView;
46 45
47 namespace { 46 namespace {
48 const plugins::PluginPlaceholder* g_last_active_menu = NULL; 47 const plugins::PluginPlaceholder* g_last_active_menu = NULL;
49 } // namespace 48 } // namespace
50 49
51 // The placeholder is loaded in normal web renderer processes, so it should not
52 // have a chrome:// scheme that might let it be confused with a WebUI page.
53 const char ChromePluginPlaceholder::kPluginPlaceholderDataURL[] =
54 "data:text/html,pluginplaceholderdata";
55
56 ChromePluginPlaceholder::ChromePluginPlaceholder( 50 ChromePluginPlaceholder::ChromePluginPlaceholder(
57 content::RenderFrame* render_frame, 51 content::RenderFrame* render_frame,
58 blink::WebLocalFrame* frame, 52 blink::WebLocalFrame* frame,
59 const blink::WebPluginParams& params, 53 const blink::WebPluginParams& params,
60 const std::string& html_data, 54 const std::string& html_data,
61 const base::string16& title) 55 const base::string16& title)
62 : plugins::LoadablePluginPlaceholder(render_frame, 56 : plugins::LoadablePluginPlaceholder(render_frame,
63 frame, 57 frame,
64 params, 58 params,
65 html_data, 59 html_data),
66 GURL(kPluginPlaceholderDataURL)),
67 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed), 60 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed),
68 title_(title), 61 title_(title),
69 #if defined(ENABLE_PLUGIN_INSTALLATION) 62 #if defined(ENABLE_PLUGIN_INSTALLATION)
70 placeholder_routing_id_(MSG_ROUTING_NONE), 63 placeholder_routing_id_(MSG_ROUTING_NONE),
71 #endif 64 #endif
72 has_host_(false), 65 has_host_(false),
73 context_menu_request_id_(0) { 66 context_menu_request_id_(0) {
74 RenderThread::Get()->AddObserver(this); 67 RenderThread::Get()->AddObserver(this);
75 } 68 }
76 69
77 ChromePluginPlaceholder::~ChromePluginPlaceholder() { 70 ChromePluginPlaceholder::~ChromePluginPlaceholder() {
78 RenderThread::Get()->RemoveObserver(this); 71 RenderThread::Get()->RemoveObserver(this);
79 if (context_menu_request_id_ && render_frame()) 72 if (context_menu_request_id_ && render_frame())
80 render_frame()->CancelContextMenu(context_menu_request_id_); 73 render_frame()->CancelContextMenu(context_menu_request_id_);
81 74
82 #if defined(ENABLE_PLUGIN_INSTALLATION) 75 #if defined(ENABLE_PLUGIN_INSTALLATION)
83 if (placeholder_routing_id_ == MSG_ROUTING_NONE) 76 if (placeholder_routing_id_ == MSG_ROUTING_NONE)
84 return; 77 return;
85 RenderThread::Get()->RemoveRoute(placeholder_routing_id_); 78 RenderThread::Get()->RemoveRoute(placeholder_routing_id_);
86 if (has_host_) { 79 if (has_host_) {
87 RenderThread::Get()->Send(new ChromeViewHostMsg_RemovePluginPlaceholderHost( 80 RenderThread::Get()->Send(new ChromeViewHostMsg_RemovePluginPlaceholderHost(
88 routing_id(), placeholder_routing_id_)); 81 routing_id(), placeholder_routing_id_));
89 } 82 }
90 #endif 83 #endif
91 } 84 }
92 85
93 // static 86 // static
94 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateMissingPlugin( 87 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateLoadableMissingPlugin(
95 content::RenderFrame* render_frame, 88 content::RenderFrame* render_frame,
96 WebLocalFrame* frame, 89 WebLocalFrame* frame,
97 const WebPluginParams& params) { 90 const WebPluginParams& params) {
98 const base::StringPiece template_html( 91 const base::StringPiece template_html(
99 ResourceBundle::GetSharedInstance().GetRawDataResource( 92 ResourceBundle::GetSharedInstance().GetRawDataResource(
100 IDR_BLOCKED_PLUGIN_HTML)); 93 IDR_BLOCKED_PLUGIN_HTML));
101 94
102 base::DictionaryValue values; 95 base::DictionaryValue values;
103 values.SetString("message", 96 values.SetString("message",
104 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED)); 97 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED));
105 98
106 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 99 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
107 100
108 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. 101 // Will destroy itself when its WebViewPlugin is going away.
109 ChromePluginPlaceholder* missing_plugin = new ChromePluginPlaceholder( 102 return new ChromePluginPlaceholder(render_frame, frame, params, html_data,
110 render_frame, frame, params, html_data, params.mimeType); 103 params.mimeType);
111 missing_plugin->set_allow_loading(true);
112 return missing_plugin;
113 } 104 }
114 105
115 // static 106 // static
116 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateErrorPlugin(
117 content::RenderFrame* render_frame,
118 const base::FilePath& file_path) {
119 base::DictionaryValue values;
120 values.SetString("message",
121 l10n_util::GetStringUTF8(IDS_PLUGIN_INITIALIZATION_ERROR));
122
123 const base::StringPiece template_html(
124 ResourceBundle::GetSharedInstance().GetRawDataResource(
125 IDR_BLOCKED_PLUGIN_HTML));
126 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
127
128 WebPluginParams params;
129 // |missing_plugin| will destroy itself when its WebViewPlugin is going away.
130 ChromePluginPlaceholder* plugin = new ChromePluginPlaceholder(
131 render_frame, NULL, params, html_data, params.mimeType);
132
133 RenderThread::Get()->Send(new ChromeViewHostMsg_CouldNotLoadPlugin(
134 plugin->routing_id(), file_path));
135 return plugin;
136 }
137
138 // static
139 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin( 107 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin(
140 content::RenderFrame* render_frame, 108 content::RenderFrame* render_frame,
141 WebLocalFrame* frame, 109 WebLocalFrame* frame,
142 const WebPluginParams& params, 110 const WebPluginParams& params,
143 const content::WebPluginInfo& info, 111 const content::WebPluginInfo& info,
144 const std::string& identifier, 112 const std::string& identifier,
145 const base::string16& name, 113 const base::string16& name,
146 int template_id, 114 int template_id,
147 const base::string16& message, 115 const base::string16& message,
148 const PlaceholderPosterInfo& poster_info) { 116 const PlaceholderPosterInfo& poster_info) {
(...skipping 20 matching lines...) Expand all
169 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 137 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
170 138
171 DCHECK(!template_html.empty()) << "unable to load template. ID: " 139 DCHECK(!template_html.empty()) << "unable to load template. ID: "
172 << template_id; 140 << template_id;
173 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 141 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
174 142
175 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. 143 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away.
176 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( 144 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder(
177 render_frame, frame, params, html_data, name); 145 render_frame, frame, params, html_data, name);
178 146
179 #if defined(ENABLE_PLUGINS)
180 if (!poster_info.poster_attribute.empty()) 147 if (!poster_info.poster_attribute.empty())
181 blocked_plugin->BlockForPowerSaverPoster(); 148 blocked_plugin->BlockForPowerSaverPoster();
182 #endif
183 blocked_plugin->SetPluginInfo(info); 149 blocked_plugin->SetPluginInfo(info);
184 blocked_plugin->SetIdentifier(identifier); 150 blocked_plugin->SetIdentifier(identifier);
185 return blocked_plugin; 151 return blocked_plugin;
186 } 152 }
187 153
188 void ChromePluginPlaceholder::SetStatus( 154 void ChromePluginPlaceholder::SetStatus(
189 ChromeViewHostMsg_GetPluginInfo_Status status) { 155 ChromeViewHostMsg_GetPluginInfo_Status status) {
190 status_ = status; 156 status_ = status;
191 } 157 }
192 158
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 264 }
299 } 265 }
300 266
301 void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) { 267 void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) {
302 DCHECK_EQ(context_menu_request_id_, request_id); 268 DCHECK_EQ(context_menu_request_id_, request_id);
303 if (g_last_active_menu != this) 269 if (g_last_active_menu != this)
304 return; 270 return;
305 switch (action) { 271 switch (action) {
306 case chrome::MENU_COMMAND_PLUGIN_RUN: { 272 case chrome::MENU_COMMAND_PLUGIN_RUN: {
307 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Menu")); 273 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Menu"));
308 #if defined(ENABLE_PLUGINS)
309 MarkPluginEssential( 274 MarkPluginEssential(
310 content::PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK); 275 content::PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK);
311 #endif
312 LoadPlugin(); 276 LoadPlugin();
313 break; 277 break;
314 } 278 }
315 case chrome::MENU_COMMAND_PLUGIN_HIDE: { 279 case chrome::MENU_COMMAND_PLUGIN_HIDE: {
316 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Menu")); 280 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Menu"));
317 HidePlugin(); 281 HidePlugin();
318 break; 282 break;
319 } 283 }
320 default: 284 default:
321 NOTREACHED(); 285 NOTREACHED();
322 } 286 }
323 } 287 }
324 288
325 void ChromePluginPlaceholder::OnMenuClosed(int request_id) { 289 void ChromePluginPlaceholder::OnMenuClosed(int request_id) {
326 DCHECK_EQ(context_menu_request_id_, request_id); 290 DCHECK_EQ(context_menu_request_id_, request_id);
327 context_menu_request_id_ = 0; 291 context_menu_request_id_ = 0;
328 } 292 }
329 293
330 void ChromePluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { 294 void ChromePluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) {
331 #if !defined(OS_ANDROID) // The context menu is not applicable on Android.
332 if (context_menu_request_id_) 295 if (context_menu_request_id_)
333 return; // Don't allow nested context menu requests. 296 return; // Don't allow nested context menu requests.
334 297
335 content::ContextMenuParams params; 298 content::ContextMenuParams params;
336 299
337 if (!title_.empty()) { 300 if (!title_.empty()) {
338 content::MenuItem name_item; 301 content::MenuItem name_item;
339 name_item.label = title_; 302 name_item.label = title_;
340 params.custom_items.push_back(name_item); 303 params.custom_items.push_back(name_item);
341 304
(...skipping 15 matching lines...) Expand all
357 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; 320 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE;
358 hide_item.enabled = true; 321 hide_item.enabled = true;
359 hide_item.label = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLUGIN_HIDE); 322 hide_item.label = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLUGIN_HIDE);
360 params.custom_items.push_back(hide_item); 323 params.custom_items.push_back(hide_item);
361 324
362 params.x = event.windowX; 325 params.x = event.windowX;
363 params.y = event.windowY; 326 params.y = event.windowY;
364 327
365 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params); 328 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params);
366 g_last_active_menu = this; 329 g_last_active_menu = this;
367 #endif // OS_ANDROID
368 } 330 }
369 331
370 blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() { 332 blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() {
371 scoped_ptr<content::PluginInstanceThrottler> throttler; 333 scoped_ptr<content::PluginInstanceThrottler> throttler;
372 #if defined(ENABLE_PLUGINS)
373 // If the plugin has already been marked essential in its placeholder form, 334 // If the plugin has already been marked essential in its placeholder form,
374 // we shouldn't create a new throttler and start the process all over again. 335 // we shouldn't create a new throttler and start the process all over again.
375 if (power_saver_enabled()) { 336 if (power_saver_enabled()) {
376 throttler = content::PluginInstanceThrottler::Create(); 337 throttler = content::PluginInstanceThrottler::Create();
377 // PluginPreroller manages its own lifetime. 338 // PluginPreroller manages its own lifetime.
378 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(), 339 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(),
379 GetPluginInfo(), GetIdentifier(), title_, 340 GetPluginInfo(), GetIdentifier(), title_,
380 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_), 341 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_),
381 throttler.get()); 342 throttler.get());
382 } 343 }
383 #endif
384 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(), 344 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(),
385 GetPluginParams(), throttler.Pass()); 345 GetPluginParams(), throttler.Pass());
386 } 346 }
387 347
388 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( 348 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder(
389 v8::Isolate* isolate) { 349 v8::Isolate* isolate) {
390 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod( 350 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod(
391 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback); 351 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback);
392 } 352 }
OLDNEW
« no previous file with comments | « chrome/renderer/plugins/chrome_plugin_placeholder.h ('k') | chrome/renderer/plugins/non_loadable_plugin_placeholder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698