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

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

Issue 1421693002: Plugin Power Saver: Do not always throttle plugins with posters. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0025-pps-poster-pixel-tests
Patch Set: Created 5 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
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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const std::string& html_data) 68 const std::string& html_data)
69 : PluginPlaceholderBase(render_frame, frame, params, html_data), 69 : PluginPlaceholderBase(render_frame, frame, params, html_data),
70 is_blocked_for_background_tab_(false), 70 is_blocked_for_background_tab_(false),
71 is_blocked_for_prerendering_(false), 71 is_blocked_for_prerendering_(false),
72 is_blocked_for_power_saver_poster_(false), 72 is_blocked_for_power_saver_poster_(false),
73 power_saver_enabled_(false), 73 power_saver_enabled_(false),
74 premade_throttler_(nullptr), 74 premade_throttler_(nullptr),
75 allow_loading_(false), 75 allow_loading_(false),
76 finished_loading_(false), 76 finished_loading_(false),
77 in_size_recheck_(false), 77 in_size_recheck_(false),
78 weak_factory_(this) { 78 heuristic_run_before_(premade_throttler_ != nullptr),
79 } 79 weak_factory_(this) {}
80 80
81 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { 81 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
82 } 82 }
83 83
84 void LoadablePluginPlaceholder::MarkPluginEssential( 84 void LoadablePluginPlaceholder::MarkPluginEssential(
85 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { 85 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) {
86 if (!power_saver_enabled_) 86 if (!power_saver_enabled_)
87 return; 87 return;
88 88
89 power_saver_enabled_ = false; 89 power_saver_enabled_ = false;
90 90
91 if (premade_throttler_) 91 if (premade_throttler_)
92 premade_throttler_->MarkPluginEssential(method); 92 premade_throttler_->MarkPluginEssential(method);
93 else 93 else if (method != PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD)
94 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); 94 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method);
95 95
96 if (is_blocked_for_power_saver_poster_) { 96 if (is_blocked_for_power_saver_poster_) {
97 is_blocked_for_power_saver_poster_ = false; 97 is_blocked_for_power_saver_poster_ = false;
98 if (!LoadingBlocked()) 98 if (!LoadingBlocked())
99 LoadPlugin(); 99 LoadPlugin();
100 } 100 }
101 } 101 }
102 102
103 void LoadablePluginPlaceholder::ReplacePlugin(blink::WebPlugin* new_plugin) { 103 void LoadablePluginPlaceholder::ReplacePlugin(blink::WebPlugin* new_plugin) {
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 321
322 if (!plugin()) 322 if (!plugin())
323 return; 323 return;
324 324
325 in_size_recheck_ = true; 325 in_size_recheck_ = true;
326 326
327 // Re-check the size in case the reported size was incorrect. 327 // Re-check the size in case the reported size was incorrect.
328 plugin()->container()->reportGeometry(); 328 plugin()->container()->reportGeometry();
329 329
330 float zoom_factor = plugin()->container()->pageZoomFactor(); 330 float zoom_factor = plugin()->container()->pageZoomFactor();
331 int width = roundf(unobscured_rect_.width() / zoom_factor);
332 int height = roundf(unobscured_rect_.height() / zoom_factor);
331 333
332 // Adjust poster container padding and dimensions to center play button for
333 // plugins and plugin posters that have their top or left portions obscured.
334 if (is_blocked_for_power_saver_poster_) { 334 if (is_blocked_for_power_saver_poster_) {
335 // Adjust poster container padding and dimensions to center play button for
336 // plugins and plugin posters that have their top or left portions obscured.
335 int x = roundf(unobscured_rect_.x() / zoom_factor); 337 int x = roundf(unobscured_rect_.x() / zoom_factor);
336 int y = roundf(unobscured_rect_.y() / zoom_factor); 338 int y = roundf(unobscured_rect_.y() / zoom_factor);
337 int width = roundf(unobscured_rect_.width() / zoom_factor);
338 int height = roundf(unobscured_rect_.height() / zoom_factor);
339 std::string script = base::StringPrintf( 339 std::string script = base::StringPrintf(
340 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, 340 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width,
341 height); 341 height);
342 plugin()->web_view()->mainFrame()->executeScript( 342 plugin()->web_view()->mainFrame()->executeScript(
343 blink::WebScriptSource(base::UTF8ToUTF16(script))); 343 blink::WebScriptSource(base::UTF8ToUTF16(script)));
344 }
345 344
346 // Only unthrottle on size increase for plugins without poster. 345 // On a size update check if we now qualify as a essential plugin.
347 // TODO(tommycli): Address this unfairness to plugins that specify a poster. 346 url::Origin content_origin = url::Origin(GetPluginParams().url);
348 if (premade_throttler_ && 347 bool cross_origin_main_content = false;
349 PluginInstanceThrottler::IsLargeContent( 348 std::string plugin_module_name = base::UTF16ToUTF8(GetPluginInfo().name);
350 roundf(unobscured_rect_.width() / zoom_factor), 349 if (!render_frame()->ShouldThrottleContent(
351 roundf(unobscured_rect_.height() / zoom_factor))) { 350 render_frame()->GetWebFrame()->top()->securityOrigin(),
352 MarkPluginEssential( 351 content_origin, plugin_module_name, width, height,
353 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE); 352 &cross_origin_main_content)) {
353 MarkPluginEssential(
354 heuristic_run_before_
355 ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE
356 : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD);
357
358 if (cross_origin_main_content && !heuristic_run_before_)
359 render_frame()->WhitelistContentOrigin(content_origin);
360 }
361
362 heuristic_run_before_ = true;
354 } 363 }
355 364
356 in_size_recheck_ = false; 365 in_size_recheck_ = false;
357 } 366 }
358 367
359 } // namespace plugins 368 } // 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