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

Side by Side Diff: components/plugins/renderer/loadable_plugin_placeholder.cc

Issue 904913003: Plugin Power Saver: Fix implicitly sized and below the fold plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/plugins/renderer/loadable_plugin_placeholder.h" 5 #include "components/plugins/renderer/loadable_plugin_placeholder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 14 matching lines...) Expand all
25 using blink::WebElement; 25 using blink::WebElement;
26 using blink::WebLocalFrame; 26 using blink::WebLocalFrame;
27 using blink::WebMouseEvent; 27 using blink::WebMouseEvent;
28 using blink::WebNode; 28 using blink::WebNode;
29 using blink::WebPlugin; 29 using blink::WebPlugin;
30 using blink::WebPluginContainer; 30 using blink::WebPluginContainer;
31 using blink::WebPluginParams; 31 using blink::WebPluginParams;
32 using blink::WebScriptSource; 32 using blink::WebScriptSource;
33 using blink::WebURLRequest; 33 using blink::WebURLRequest;
34 using content::PluginInstanceThrottler; 34 using content::PluginInstanceThrottler;
35 using content::PluginPowerSaverMode;
36 using content::RenderThread; 35 using content::RenderThread;
37 36
38 namespace plugins { 37 namespace plugins {
39 38
40 #if defined(ENABLE_PLUGINS) 39 #if defined(ENABLE_PLUGINS)
41 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { 40 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() {
42 DCHECK(!is_blocked_for_power_saver_poster_); 41 DCHECK(!is_blocked_for_power_saver_poster_);
43 is_blocked_for_power_saver_poster_ = true; 42 is_blocked_for_power_saver_poster_ = true;
44 43
45 render_frame()->RegisterPeripheralPlugin( 44 render_frame()->RegisterPeripheralPlugin(
46 GURL(GetPluginParams().url).GetOrigin(), 45 GURL(GetPluginParams().url).GetOrigin(),
47 base::Bind(&LoadablePluginPlaceholder::DisablePowerSaverForInstance, 46 base::Bind(&LoadablePluginPlaceholder::MarkPluginEssential,
48 weak_factory_.GetWeakPtr(), 47 weak_factory_.GetWeakPtr(),
49 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST)); 48 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST));
50 } 49 }
51 #endif 50 #endif
52 51
53 void LoadablePluginPlaceholder::SetPremadePlugin( 52 void LoadablePluginPlaceholder::SetPremadePlugin(
54 blink::WebPlugin* plugin, 53 blink::WebPlugin* plugin,
55 content::PluginInstanceThrottler* throttler) { 54 content::PluginInstanceThrottler* throttler) {
56 DCHECK(plugin); 55 DCHECK(plugin);
57 DCHECK(throttler); 56 DCHECK(throttler);
(...skipping 12 matching lines...) Expand all
70 const std::string& html_data, 69 const std::string& html_data,
71 GURL placeholderDataUrl) 70 GURL placeholderDataUrl)
72 : PluginPlaceholder(render_frame, 71 : PluginPlaceholder(render_frame,
73 frame, 72 frame,
74 params, 73 params,
75 html_data, 74 html_data,
76 placeholderDataUrl), 75 placeholderDataUrl),
77 is_blocked_for_background_tab_(false), 76 is_blocked_for_background_tab_(false),
78 is_blocked_for_prerendering_(false), 77 is_blocked_for_prerendering_(false),
79 is_blocked_for_power_saver_poster_(false), 78 is_blocked_for_power_saver_poster_(false),
80 power_saver_mode_(PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL), 79 power_saver_enabled_(false),
80 plugin_marked_essential_(false),
81 premade_plugin_(nullptr), 81 premade_plugin_(nullptr),
82 premade_throttler_(nullptr), 82 premade_throttler_(nullptr),
83 allow_loading_(false), 83 allow_loading_(false),
84 placeholder_was_replaced_(false), 84 placeholder_was_replaced_(false),
85 hidden_(false), 85 hidden_(false),
86 finished_loading_(false), 86 finished_loading_(false),
87 weak_factory_(this) { 87 weak_factory_(this) {
88 } 88 }
89 89
90 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { 90 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
91 #if defined(ENABLE_PLUGINS) 91 #if defined(ENABLE_PLUGINS)
92 DCHECK(!premade_plugin_); 92 DCHECK(!premade_plugin_);
93 DCHECK(!premade_throttler_); 93 DCHECK(!premade_throttler_);
94 94
95 if (!placeholder_was_replaced_ && !is_blocked_for_prerendering_ && 95 if (!plugin_marked_essential_ && !placeholder_was_replaced_ &&
96 power_saver_mode_ != PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL) { 96 !is_blocked_for_prerendering_ && is_blocked_for_power_saver_poster_) {
97 PluginInstanceThrottler::RecordUnthrottleMethodMetric( 97 PluginInstanceThrottler::RecordUnthrottleMethodMetric(
98 PluginInstanceThrottler::UNTHROTTLE_METHOD_NEVER); 98 PluginInstanceThrottler::UNTHROTTLE_METHOD_NEVER);
99 } 99 }
100 #endif 100 #endif
101 } 101 }
102 102
103 #if defined(ENABLE_PLUGINS) 103 #if defined(ENABLE_PLUGINS)
104 void LoadablePluginPlaceholder::DisablePowerSaverForInstance( 104 void LoadablePluginPlaceholder::MarkPluginEssential(
105 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { 105 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
106 if (power_saver_mode_ == PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL) 106 if (plugin_marked_essential_)
107 return; 107 return;
108 108
109 power_saver_mode_ = PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL; 109 plugin_marked_essential_ = true;
110 if (premade_throttler_) { 110 if (premade_throttler_) {
111 premade_throttler_->MarkPluginEssential(method); 111 premade_throttler_->MarkPluginEssential(method);
112 } else {
113 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method);
114 } 112 }
115 113
116 if (is_blocked_for_power_saver_poster_) { 114 if (is_blocked_for_power_saver_poster_) {
117 is_blocked_for_power_saver_poster_ = false; 115 is_blocked_for_power_saver_poster_ = false;
116 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method);
118 if (!LoadingBlocked()) 117 if (!LoadingBlocked())
119 LoadPlugin(); 118 LoadPlugin();
120 } 119 }
121 } 120 }
122 #endif 121 #endif
123 122
124 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder( 123 gin::ObjectTemplateBuilder LoadablePluginPlaceholder::GetObjectTemplateBuilder(
125 v8::Isolate* isolate) { 124 v8::Isolate* isolate) {
126 return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate) 125 return gin::Wrappable<PluginPlaceholder>::GetObjectTemplateBuilder(isolate)
127 .SetMethod("load", &LoadablePluginPlaceholder::LoadCallback) 126 .SetMethod("load", &LoadablePluginPlaceholder::LoadCallback)
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 premade_throttler_ = nullptr; 299 premade_throttler_ = nullptr;
301 300
302 ReplacePlugin(premade_plugin_); 301 ReplacePlugin(premade_plugin_);
303 premade_plugin_ = nullptr; 302 premade_plugin_ = nullptr;
304 } else { 303 } else {
305 // TODO(mmenke): In the case of prerendering, feed into 304 // TODO(mmenke): In the case of prerendering, feed into
306 // ChromeContentRendererClient::CreatePlugin instead, to 305 // ChromeContentRendererClient::CreatePlugin instead, to
307 // reduce the chance of future regressions. 306 // reduce the chance of future regressions.
308 scoped_ptr<PluginInstanceThrottler> throttler; 307 scoped_ptr<PluginInstanceThrottler> throttler;
309 #if defined(ENABLE_PLUGINS) 308 #if defined(ENABLE_PLUGINS)
310 throttler = PluginInstanceThrottler::Get( 309 // If the plugin has already been marked essential in its placeholder form,
311 render_frame(), GetPluginParams().url, power_saver_mode_); 310 // we shouldn't create a new throttler and start the process all over again.
311 if (!plugin_marked_essential_)
312 throttler = PluginInstanceThrottler::Create(power_saver_enabled_);
312 #endif 313 #endif
313 WebPlugin* plugin = render_frame()->CreatePlugin( 314 WebPlugin* plugin = render_frame()->CreatePlugin(
314 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass()); 315 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass());
315 316
316 ReplacePlugin(plugin); 317 ReplacePlugin(plugin);
317 } 318 }
318 } 319 }
319 320
320 void LoadablePluginPlaceholder::LoadCallback() { 321 void LoadablePluginPlaceholder::LoadCallback() {
321 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); 322 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click"));
322 #if defined(ENABLE_PLUGINS) 323 #if defined(ENABLE_PLUGINS)
323 // If the user specifically clicks on the plug-in content's placeholder, 324 // If the user specifically clicks on the plug-in content's placeholder,
324 // disable power saver throttling for this instance. 325 // disable power saver throttling for this instance.
325 DisablePowerSaverForInstance( 326 MarkPluginEssential(PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK);
326 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK);
327 #endif 327 #endif
328 LoadPlugin(); 328 LoadPlugin();
329 } 329 }
330 330
331 void LoadablePluginPlaceholder::HideCallback() { 331 void LoadablePluginPlaceholder::HideCallback() {
332 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click")); 332 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Hide_Click"));
333 HidePlugin(); 333 HidePlugin();
334 } 334 }
335 335
336 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { 336 void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
(...skipping 20 matching lines...) Expand all
357 identifier_ = identifier; 357 identifier_ = identifier;
358 } 358 }
359 359
360 bool LoadablePluginPlaceholder::LoadingBlocked() const { 360 bool LoadablePluginPlaceholder::LoadingBlocked() const {
361 DCHECK(allow_loading_); 361 DCHECK(allow_loading_);
362 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || 362 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ ||
363 is_blocked_for_prerendering_; 363 is_blocked_for_prerendering_;
364 } 364 }
365 365
366 } // namespace plugins 366 } // namespace plugins
OLDNEW
« no previous file with comments | « components/plugins/renderer/loadable_plugin_placeholder.h ('k') | content/public/renderer/plugin_instance_throttler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698