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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: components/plugins/renderer/loadable_plugin_placeholder.cc
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.cc b/components/plugins/renderer/loadable_plugin_placeholder.cc
index 376db7bd3226e64a63dcee666419b37c884c020b..dc4b5b2797aacf78f1918d146b479e6e67053388 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.cc
+++ b/components/plugins/renderer/loadable_plugin_placeholder.cc
@@ -75,8 +75,8 @@ LoadablePluginPlaceholder::LoadablePluginPlaceholder(
allow_loading_(false),
finished_loading_(false),
in_size_recheck_(false),
- weak_factory_(this) {
-}
+ heuristic_run_before_(premade_throttler_ != nullptr),
+ weak_factory_(this) {}
LoadablePluginPlaceholder::~LoadablePluginPlaceholder() {
}
@@ -90,7 +90,7 @@ void LoadablePluginPlaceholder::MarkPluginEssential(
if (premade_throttler_)
premade_throttler_->MarkPluginEssential(method);
- else
+ else if (method != PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD)
PluginInstanceThrottler::RecordUnthrottleMethodMetric(method);
if (is_blocked_for_power_saver_poster_) {
@@ -328,29 +328,38 @@ void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() {
plugin()->container()->reportGeometry();
float zoom_factor = plugin()->container()->pageZoomFactor();
+ int width = roundf(unobscured_rect_.width() / zoom_factor);
+ int height = roundf(unobscured_rect_.height() / zoom_factor);
- // Adjust poster container padding and dimensions to center play button for
- // plugins and plugin posters that have their top or left portions obscured.
if (is_blocked_for_power_saver_poster_) {
+ // Adjust poster container padding and dimensions to center play button for
+ // plugins and plugin posters that have their top or left portions obscured.
int x = roundf(unobscured_rect_.x() / zoom_factor);
int y = roundf(unobscured_rect_.y() / zoom_factor);
- int width = roundf(unobscured_rect_.width() / zoom_factor);
- int height = roundf(unobscured_rect_.height() / zoom_factor);
std::string script = base::StringPrintf(
"window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width,
height);
plugin()->web_view()->mainFrame()->executeScript(
blink::WebScriptSource(base::UTF8ToUTF16(script)));
- }
- // Only unthrottle on size increase for plugins without poster.
- // TODO(tommycli): Address this unfairness to plugins that specify a poster.
- if (premade_throttler_ &&
- PluginInstanceThrottler::IsLargeContent(
- roundf(unobscured_rect_.width() / zoom_factor),
- roundf(unobscured_rect_.height() / zoom_factor))) {
- MarkPluginEssential(
- PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE);
+ // On a size update check if we now qualify as a essential plugin.
+ url::Origin content_origin = url::Origin(GetPluginParams().url);
+ bool cross_origin_main_content = false;
+ std::string plugin_module_name = base::UTF16ToUTF8(GetPluginInfo().name);
+ if (!render_frame()->ShouldThrottleContent(
+ render_frame()->GetWebFrame()->top()->securityOrigin(),
+ content_origin, plugin_module_name, width, height,
+ &cross_origin_main_content)) {
+ MarkPluginEssential(
+ heuristic_run_before_
+ ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE
+ : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD);
+
+ if (cross_origin_main_content && !heuristic_run_before_)
+ render_frame()->WhitelistContentOrigin(content_origin);
+ }
+
+ heuristic_run_before_ = true;
}
in_size_recheck_ = false;
« 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