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

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

Issue 2143073002: Plugin Power Saver: Improve blocked tiny plugins behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename a variable again Created 4 years, 5 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
« no previous file with comments | « components/plugins/renderer/loadable_plugin_placeholder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 DCHECK(!premade_throttler_); 53 DCHECK(!premade_throttler_);
54 premade_throttler_ = throttler; 54 premade_throttler_ = throttler;
55 } 55 }
56 56
57 LoadablePluginPlaceholder::LoadablePluginPlaceholder( 57 LoadablePluginPlaceholder::LoadablePluginPlaceholder(
58 content::RenderFrame* render_frame, 58 content::RenderFrame* render_frame,
59 blink::WebLocalFrame* frame, 59 blink::WebLocalFrame* frame,
60 const blink::WebPluginParams& params, 60 const blink::WebPluginParams& params,
61 const std::string& html_data) 61 const std::string& html_data)
62 : PluginPlaceholderBase(render_frame, frame, params, html_data), 62 : PluginPlaceholderBase(render_frame, frame, params, html_data),
63 is_delayed_placeholder_(false), 63 is_blocked_for_tinyness_(false),
64 is_blocked_for_background_tab_(false), 64 is_blocked_for_background_tab_(false),
65 is_blocked_for_prerendering_(false), 65 is_blocked_for_prerendering_(false),
66 is_blocked_for_power_saver_poster_(false), 66 is_blocked_for_power_saver_poster_(false),
67 power_saver_enabled_(false), 67 power_saver_enabled_(false),
68 premade_throttler_(nullptr), 68 premade_throttler_(nullptr),
69 allow_loading_(false), 69 allow_loading_(false),
70 finished_loading_(false), 70 finished_loading_(false),
71 heuristic_run_before_(premade_throttler_ != nullptr), 71 heuristic_run_before_(premade_throttler_ != nullptr),
72 weak_factory_(this) {} 72 weak_factory_(this) {}
73 73
74 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { 74 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
75 } 75 }
76 76
77 void LoadablePluginPlaceholder::SetDelegate(
78 std::unique_ptr<Delegate> delegate) {
79 delegate_ = std::move(delegate);
80 }
81
82 void LoadablePluginPlaceholder::MarkPluginEssential( 77 void LoadablePluginPlaceholder::MarkPluginEssential(
83 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { 78 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
84 if (!power_saver_enabled_) 79 if (!power_saver_enabled_)
85 return; 80 return;
86 81
87 power_saver_enabled_ = false; 82 power_saver_enabled_ = false;
88 83
89 if (premade_throttler_) 84 if (premade_throttler_)
90 premade_throttler_->MarkPluginEssential(method); 85 premade_throttler_->MarkPluginEssential(method);
91 else if (method != PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD) 86 else if (method != PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD)
92 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); 87 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method);
93 88
94 if (is_blocked_for_power_saver_poster_) { 89 is_blocked_for_power_saver_poster_ = false;
95 is_blocked_for_power_saver_poster_ = false; 90 is_blocked_for_tinyness_ = false;
96 if (!LoadingBlocked()) 91 if (!LoadingBlocked())
97 LoadPlugin(); 92 LoadPlugin();
98 }
99 } 93 }
100 94
101 void LoadablePluginPlaceholder::ReplacePlugin(blink::WebPlugin* new_plugin) { 95 void LoadablePluginPlaceholder::ReplacePlugin(blink::WebPlugin* new_plugin) {
102 CHECK(plugin()); 96 CHECK(plugin());
103 if (!new_plugin) 97 if (!new_plugin)
104 return; 98 return;
105 blink::WebPluginContainer* container = plugin()->container(); 99 blink::WebPluginContainer* container = plugin()->container();
106 // This can occur if the container has been destroyed. 100 // This can occur if the container has been destroyed.
107 if (!container) { 101 if (!container) {
108 new_plugin->destroy(); 102 new_plugin->destroy();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (premade_throttler_ && premade_throttler_->GetWebPlugin()) { 179 if (premade_throttler_ && premade_throttler_->GetWebPlugin()) {
186 return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate); 180 return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate);
187 } 181 }
188 return v8::Local<v8::Object>(); 182 return v8::Local<v8::Object>();
189 } 183 }
190 184
191 void LoadablePluginPlaceholder::OnUnobscuredRectUpdate( 185 void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(
192 const gfx::Rect& unobscured_rect) { 186 const gfx::Rect& unobscured_rect) {
193 DCHECK(content::RenderThread::Get()); 187 DCHECK(content::RenderThread::Get());
194 188
195 // TODO(groby): Handle the case of power saver not being enabled.
196 if (!plugin() || !finished_loading_) 189 if (!plugin() || !finished_loading_)
197 return; 190 return;
198 191
192 if (!is_blocked_for_tinyness_ && !is_blocked_for_power_saver_poster_)
193 return;
194
199 if (unobscured_rect_ == unobscured_rect) 195 if (unobscured_rect_ == unobscured_rect)
200 return; 196 return;
201 197
202 unobscured_rect_ = unobscured_rect; 198 unobscured_rect_ = unobscured_rect;
203 199
204 float zoom_factor = plugin()->container()->pageZoomFactor(); 200 float zoom_factor = plugin()->container()->pageZoomFactor();
205 int width = roundf(unobscured_rect_.width() / zoom_factor); 201 int width = roundf(unobscured_rect_.width() / zoom_factor);
206 int height = roundf(unobscured_rect_.height() / zoom_factor); 202 int height = roundf(unobscured_rect_.height() / zoom_factor);
207 int x = roundf(unobscured_rect_.x() / zoom_factor); 203 int x = roundf(unobscured_rect_.x() / zoom_factor);
208 int y = roundf(unobscured_rect_.y() / zoom_factor); 204 int y = roundf(unobscured_rect_.y() / zoom_factor);
209 205
210 // On a size update check if we now qualify as a essential plugin. 206 // On a size update check if we now qualify as a essential plugin.
211 url::Origin content_origin = url::Origin(GetPluginParams().url); 207 url::Origin content_origin = url::Origin(GetPluginParams().url);
212 content::RenderFrame::PeripheralContentStatus status = 208 content::RenderFrame::PeripheralContentStatus status =
213 render_frame()->GetPeripheralContentStatus( 209 render_frame()->GetPeripheralContentStatus(
214 render_frame()->GetWebFrame()->top()->getSecurityOrigin(), 210 render_frame()->GetWebFrame()->top()->getSecurityOrigin(),
215 content_origin, gfx::Size(width, height)); 211 content_origin, gfx::Size(width, height));
216 // If this is a "delay" placeholder, delegate decisions. 212
217 if (is_delayed_placeholder_) { 213 bool plugin_is_tiny_and_blocked =
218 OnLoadedRectUpdate(gfx::Rect(x, y, width, height), status); 214 is_blocked_for_tinyness_ &&
219 is_delayed_placeholder_ = false; 215 status ==
216 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_TINY;
217
218 // Early exit for plugins that we've discovered to be essential.
219 if (!plugin_is_tiny_and_blocked &&
220 status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) {
221 MarkPluginEssential(
222 heuristic_run_before_
223 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE
224 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD);
225
226 if (!heuristic_run_before_ &&
227 status ==
228 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) {
229 render_frame()->WhitelistContentOrigin(content_origin);
230 }
231
220 return; 232 return;
221 } 233 }
234 heuristic_run_before_ = true;
235
236 if (is_blocked_for_tinyness_) {
237 if (plugin_is_tiny_and_blocked) {
238 OnBlockedTinyContent();
239 } else {
240 is_blocked_for_tinyness_ = false;
241 if (!LoadingBlocked()) {
242 LoadPlugin();
243 }
244 }
245 }
222 246
223 if (is_blocked_for_power_saver_poster_) { 247 if (is_blocked_for_power_saver_poster_) {
224 // Adjust poster container padding and dimensions to center play button for 248 // Adjust poster container padding and dimensions to center play button for
225 // plugins and plugin posters that have their top or left portions obscured. 249 // plugins and plugin posters that have their top or left portions obscured.
226 std::string script = base::StringPrintf( 250 std::string script = base::StringPrintf(
227 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, 251 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width,
228 height); 252 height);
229 plugin()->web_view()->mainFrame()->executeScript( 253 plugin()->web_view()->mainFrame()->executeScript(
230 blink::WebScriptSource(base::UTF8ToUTF16(script))); 254 blink::WebScriptSource(base::UTF8ToUTF16(script)));
231
232 if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) {
233 MarkPluginEssential(
234 heuristic_run_before_
235 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE
236 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD);
237
238 if (!heuristic_run_before_ &&
239 status ==
240 content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) {
241 render_frame()->WhitelistContentOrigin(content_origin);
242 }
243 }
244
245 heuristic_run_before_ = true;
246 } 255 }
247 } 256 }
248 257
249 void LoadablePluginPlaceholder::WasShown() { 258 void LoadablePluginPlaceholder::WasShown() {
250 if (is_blocked_for_background_tab_) { 259 if (is_blocked_for_background_tab_) {
251 is_blocked_for_background_tab_ = false; 260 is_blocked_for_background_tab_ = false;
252 if (!LoadingBlocked()) 261 if (!LoadingBlocked())
253 LoadPlugin(); 262 LoadPlugin();
254 } 263 }
255 } 264 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) { 360 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) {
352 identifier_ = identifier; 361 identifier_ = identifier;
353 } 362 }
354 363
355 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { 364 const std::string& LoadablePluginPlaceholder::GetIdentifier() const {
356 return identifier_; 365 return identifier_;
357 } 366 }
358 367
359 bool LoadablePluginPlaceholder::LoadingBlocked() const { 368 bool LoadablePluginPlaceholder::LoadingBlocked() const {
360 DCHECK(allow_loading_); 369 DCHECK(allow_loading_);
361 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || 370 return is_blocked_for_tinyness_ || is_blocked_for_background_tab_ ||
362 is_blocked_for_prerendering_; 371 is_blocked_for_power_saver_poster_ || is_blocked_for_prerendering_;
363 } 372 }
364 373
365 } // namespace plugins 374 } // namespace plugins
OLDNEW
« no previous file with comments | « components/plugins/renderer/loadable_plugin_placeholder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698