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

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

Issue 1161923004: Reland: Plugin Placeholders: Refactor for platforms that don't support plugins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove some enable_plugins that are no longer needed 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"
30 #include "ui/base/webui/jstemplate_builder.h" 29 #include "ui/base/webui/jstemplate_builder.h"
31 #include "ui/gfx/geometry/size.h" 30 #include "ui/gfx/geometry/size.h"
32 #include "url/url_util.h" 31 #include "url/url_util.h"
33 32
34 using base::UserMetricsAction; 33 using base::UserMetricsAction;
35 using blink::WebDocument; 34 using blink::WebDocument;
36 using blink::WebElement; 35 using blink::WebElement;
37 using blink::WebFrame; 36 using blink::WebFrame;
38 using blink::WebLocalFrame; 37 using blink::WebLocalFrame;
39 using blink::WebMouseEvent; 38 using blink::WebMouseEvent;
40 using blink::WebNode; 39 using blink::WebNode;
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 ChromePluginPlaceholder* 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 50 gin::WrapperInfo ChromePluginPlaceholder::kWrapperInfo = {
52 // have a chrome:// scheme that might let it be confused with a WebUI page. 51 gin::kEmbedderNativeGin};
53 const char ChromePluginPlaceholder::kPluginPlaceholderDataURL[] =
54 "data:text/html,pluginplaceholderdata";
55 52
56 ChromePluginPlaceholder::ChromePluginPlaceholder( 53 ChromePluginPlaceholder::ChromePluginPlaceholder(
57 content::RenderFrame* render_frame, 54 content::RenderFrame* render_frame,
58 blink::WebLocalFrame* frame, 55 blink::WebLocalFrame* frame,
59 const blink::WebPluginParams& params, 56 const blink::WebPluginParams& params,
60 const std::string& html_data, 57 const std::string& html_data,
61 const base::string16& title) 58 const base::string16& title)
62 : plugins::LoadablePluginPlaceholder(render_frame, 59 : plugins::LoadablePluginPlaceholder(render_frame,
63 frame, 60 frame,
64 params, 61 params,
65 html_data, 62 html_data),
66 GURL(kPluginPlaceholderDataURL)),
67 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed), 63 status_(ChromeViewHostMsg_GetPluginInfo_Status::kAllowed),
68 title_(title), 64 title_(title),
69 #if defined(ENABLE_PLUGIN_INSTALLATION) 65 #if defined(ENABLE_PLUGIN_INSTALLATION)
70 placeholder_routing_id_(MSG_ROUTING_NONE), 66 placeholder_routing_id_(MSG_ROUTING_NONE),
71 #endif 67 #endif
72 has_host_(false), 68 has_host_(false),
73 context_menu_request_id_(0) { 69 context_menu_request_id_(0) {
74 RenderThread::Get()->AddObserver(this); 70 RenderThread::Get()->AddObserver(this);
75 } 71 }
76 72
77 ChromePluginPlaceholder::~ChromePluginPlaceholder() { 73 ChromePluginPlaceholder::~ChromePluginPlaceholder() {
78 RenderThread::Get()->RemoveObserver(this); 74 RenderThread::Get()->RemoveObserver(this);
79 if (context_menu_request_id_ && render_frame()) 75 if (context_menu_request_id_ && render_frame())
80 render_frame()->CancelContextMenu(context_menu_request_id_); 76 render_frame()->CancelContextMenu(context_menu_request_id_);
81 77
82 #if defined(ENABLE_PLUGIN_INSTALLATION) 78 #if defined(ENABLE_PLUGIN_INSTALLATION)
83 if (placeholder_routing_id_ == MSG_ROUTING_NONE) 79 if (placeholder_routing_id_ == MSG_ROUTING_NONE)
84 return; 80 return;
85 RenderThread::Get()->RemoveRoute(placeholder_routing_id_); 81 RenderThread::Get()->RemoveRoute(placeholder_routing_id_);
86 if (has_host_) { 82 if (has_host_) {
87 RenderThread::Get()->Send(new ChromeViewHostMsg_RemovePluginPlaceholderHost( 83 RenderThread::Get()->Send(new ChromeViewHostMsg_RemovePluginPlaceholderHost(
88 routing_id(), placeholder_routing_id_)); 84 routing_id(), placeholder_routing_id_));
89 } 85 }
90 #endif 86 #endif
91 } 87 }
92 88
93 // static 89 // static
94 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateMissingPlugin( 90 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateLoadableMissingPlugin(
95 content::RenderFrame* render_frame, 91 content::RenderFrame* render_frame,
96 WebLocalFrame* frame, 92 WebLocalFrame* frame,
97 const WebPluginParams& params) { 93 const WebPluginParams& params) {
98 const base::StringPiece template_html( 94 const base::StringPiece template_html(
99 ResourceBundle::GetSharedInstance().GetRawDataResource( 95 ResourceBundle::GetSharedInstance().GetRawDataResource(
100 IDR_BLOCKED_PLUGIN_HTML)); 96 IDR_BLOCKED_PLUGIN_HTML));
101 97
102 base::DictionaryValue values; 98 base::DictionaryValue values;
103 values.SetString("message", 99 values.SetString("message",
104 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED)); 100 l10n_util::GetStringUTF8(IDS_PLUGIN_NOT_SUPPORTED));
105 101
106 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 102 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
107 103
108 // |missing_plugin| will destroy itself when its WebViewPlugin is going away. 104 // Will destroy itself when its WebViewPlugin is going away.
109 ChromePluginPlaceholder* missing_plugin = new ChromePluginPlaceholder( 105 return new ChromePluginPlaceholder(render_frame, frame, params, html_data,
110 render_frame, frame, params, html_data, params.mimeType); 106 params.mimeType);
111 missing_plugin->set_allow_loading(true);
112 return missing_plugin;
113 } 107 }
114 108
115 // static 109 // 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( 110 ChromePluginPlaceholder* ChromePluginPlaceholder::CreateBlockedPlugin(
140 content::RenderFrame* render_frame, 111 content::RenderFrame* render_frame,
141 WebLocalFrame* frame, 112 WebLocalFrame* frame,
142 const WebPluginParams& params, 113 const WebPluginParams& params,
143 const content::WebPluginInfo& info, 114 const content::WebPluginInfo& info,
144 const std::string& identifier, 115 const std::string& identifier,
145 const base::string16& name, 116 const base::string16& name,
146 int template_id, 117 int template_id,
147 const base::string16& message, 118 const base::string16& message,
148 const PlaceholderPosterInfo& poster_info) { 119 const PlaceholderPosterInfo& poster_info) {
(...skipping 20 matching lines...) Expand all
169 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id)); 140 ResourceBundle::GetSharedInstance().GetRawDataResource(template_id));
170 141
171 DCHECK(!template_html.empty()) << "unable to load template. ID: " 142 DCHECK(!template_html.empty()) << "unable to load template. ID: "
172 << template_id; 143 << template_id;
173 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values); 144 std::string html_data = webui::GetI18nTemplateHtml(template_html, &values);
174 145
175 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away. 146 // |blocked_plugin| will destroy itself when its WebViewPlugin is going away.
176 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder( 147 ChromePluginPlaceholder* blocked_plugin = new ChromePluginPlaceholder(
177 render_frame, frame, params, html_data, name); 148 render_frame, frame, params, html_data, name);
178 149
179 #if defined(ENABLE_PLUGINS)
180 if (!poster_info.poster_attribute.empty()) 150 if (!poster_info.poster_attribute.empty())
181 blocked_plugin->BlockForPowerSaverPoster(); 151 blocked_plugin->BlockForPowerSaverPoster();
182 #endif
183 blocked_plugin->SetPluginInfo(info); 152 blocked_plugin->SetPluginInfo(info);
184 blocked_plugin->SetIdentifier(identifier); 153 blocked_plugin->SetIdentifier(identifier);
185 return blocked_plugin; 154 return blocked_plugin;
186 } 155 }
187 156
188 void ChromePluginPlaceholder::SetStatus( 157 void ChromePluginPlaceholder::SetStatus(
189 ChromeViewHostMsg_GetPluginInfo_Status status) { 158 ChromeViewHostMsg_GetPluginInfo_Status status) {
190 status_ = status; 159 status_ = status;
191 } 160 }
192 161
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 267 }
299 } 268 }
300 269
301 void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) { 270 void ChromePluginPlaceholder::OnMenuAction(int request_id, unsigned action) {
302 DCHECK_EQ(context_menu_request_id_, request_id); 271 DCHECK_EQ(context_menu_request_id_, request_id);
303 if (g_last_active_menu != this) 272 if (g_last_active_menu != this)
304 return; 273 return;
305 switch (action) { 274 switch (action) {
306 case chrome::MENU_COMMAND_PLUGIN_RUN: { 275 case chrome::MENU_COMMAND_PLUGIN_RUN: {
307 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Menu")); 276 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Menu"));
308 #if defined(ENABLE_PLUGINS)
309 MarkPluginEssential( 277 MarkPluginEssential(
310 content::PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK); 278 content::PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK);
311 #endif
312 LoadPlugin(); 279 LoadPlugin();
313 break; 280 break;
314 } 281 }
315 case chrome::MENU_COMMAND_PLUGIN_HIDE: { 282 case chrome::MENU_COMMAND_PLUGIN_HIDE: {
316 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Menu")); 283 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Menu"));
317 HidePlugin(); 284 HidePlugin();
318 break; 285 break;
319 } 286 }
320 default: 287 default:
321 NOTREACHED(); 288 NOTREACHED();
322 } 289 }
323 } 290 }
324 291
325 void ChromePluginPlaceholder::OnMenuClosed(int request_id) { 292 void ChromePluginPlaceholder::OnMenuClosed(int request_id) {
326 DCHECK_EQ(context_menu_request_id_, request_id); 293 DCHECK_EQ(context_menu_request_id_, request_id);
327 context_menu_request_id_ = 0; 294 context_menu_request_id_ = 0;
328 } 295 }
329 296
297 v8::Local<v8::Value> ChromePluginPlaceholder::GetV8Handle(
298 v8::Isolate* isolate) {
299 return gin::CreateHandle(isolate, this).ToV8();
300 }
301
330 void ChromePluginPlaceholder::ShowContextMenu(const WebMouseEvent& event) { 302 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_) 303 if (context_menu_request_id_)
333 return; // Don't allow nested context menu requests. 304 return; // Don't allow nested context menu requests.
334 305
335 content::ContextMenuParams params; 306 content::ContextMenuParams params;
336 307
337 if (!title_.empty()) { 308 if (!title_.empty()) {
338 content::MenuItem name_item; 309 content::MenuItem name_item;
339 name_item.label = title_; 310 name_item.label = title_;
340 params.custom_items.push_back(name_item); 311 params.custom_items.push_back(name_item);
341 312
(...skipping 15 matching lines...) Expand all
357 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE; 328 hide_item.action = chrome::MENU_COMMAND_PLUGIN_HIDE;
358 hide_item.enabled = true; 329 hide_item.enabled = true;
359 hide_item.label = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLUGIN_HIDE); 330 hide_item.label = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLUGIN_HIDE);
360 params.custom_items.push_back(hide_item); 331 params.custom_items.push_back(hide_item);
361 332
362 params.x = event.windowX; 333 params.x = event.windowX;
363 params.y = event.windowY; 334 params.y = event.windowY;
364 335
365 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params); 336 context_menu_request_id_ = render_frame()->ShowContextMenu(this, params);
366 g_last_active_menu = this; 337 g_last_active_menu = this;
367 #endif // OS_ANDROID
368 } 338 }
369 339
370 blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() { 340 blink::WebPlugin* ChromePluginPlaceholder::CreatePlugin() {
371 scoped_ptr<content::PluginInstanceThrottler> throttler; 341 scoped_ptr<content::PluginInstanceThrottler> throttler;
372 #if defined(ENABLE_PLUGINS)
373 // If the plugin has already been marked essential in its placeholder form, 342 // 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. 343 // we shouldn't create a new throttler and start the process all over again.
375 if (power_saver_enabled()) { 344 if (power_saver_enabled()) {
376 throttler = content::PluginInstanceThrottler::Create(); 345 throttler = content::PluginInstanceThrottler::Create();
377 // PluginPreroller manages its own lifetime. 346 // PluginPreroller manages its own lifetime.
378 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(), 347 new PluginPreroller(render_frame(), GetFrame(), GetPluginParams(),
379 GetPluginInfo(), GetIdentifier(), title_, 348 GetPluginInfo(), GetIdentifier(), title_,
380 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_), 349 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, title_),
381 throttler.get()); 350 throttler.get());
382 } 351 }
383 #endif
384 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(), 352 return render_frame()->CreatePlugin(GetFrame(), GetPluginInfo(),
385 GetPluginParams(), throttler.Pass()); 353 GetPluginParams(), throttler.Pass());
386 } 354 }
387 355
388 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder( 356 gin::ObjectTemplateBuilder ChromePluginPlaceholder::GetObjectTemplateBuilder(
389 v8::Isolate* isolate) { 357 v8::Isolate* isolate) {
390 return LoadablePluginPlaceholder::GetObjectTemplateBuilder(isolate).SetMethod( 358 return gin::Wrappable<ChromePluginPlaceholder>::GetObjectTemplateBuilder(
391 "openAboutPlugins", &ChromePluginPlaceholder::OpenAboutPluginsCallback); 359 isolate)
360 .SetMethod<void (ChromePluginPlaceholder::*)()>(
361 "hide", &ChromePluginPlaceholder::HideCallback)
362 .SetMethod<void (ChromePluginPlaceholder::*)()>(
363 "load", &ChromePluginPlaceholder::LoadCallback)
364 .SetMethod<void (ChromePluginPlaceholder::*)()>(
365 "didFinishLoading",
366 &ChromePluginPlaceholder::DidFinishLoadingCallback)
367 .SetMethod("openAboutPlugins",
368 &ChromePluginPlaceholder::OpenAboutPluginsCallback);
392 } 369 }
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