diff options
author | tommycli <tommycli@chromium.org> | 2016-02-01 08:47:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-01 16:48:53 +0000 |
commit | f74fd9e11c465ff68c954cc30a1856300a9c54be (patch) | |
tree | 1138d267498648569a8796297ceb70288a21f438 | |
parent | b8f2530a0338d6d5590cd3a858107db08807855a (diff) | |
download | chromium_src-f74fd9e11c465ff68c954cc30a1856300a9c54be.zip chromium_src-f74fd9e11c465ff68c954cc30a1856300a9c54be.tar.gz chromium_src-f74fd9e11c465ff68c954cc30a1856300a9c54be.tar.bz2 |
Plugin Power Saver: Remove Size Recheck hack in plugin placeholders.
See https://code.google.com/p/chromium/issues/detail?id=343769.
The Blink faulty geometry is _almost_ fixed, and it seems fixed-enough
to remove the (awful) size recheck hack for plugin placeholders.
As a nice side effect, removing this size recheck hack will also make
essential plugins with posters no longer have an ugly delay.
BUG=497429,560590
Review URL: https://codereview.chromium.org/1491893004
Cr-Commit-Position: refs/heads/master@{#372674}
-rw-r--r-- | components/plugins/renderer/loadable_plugin_placeholder.cc | 115 | ||||
-rw-r--r-- | components/plugins/renderer/loadable_plugin_placeholder.h | 4 |
2 files changed, 38 insertions, 81 deletions
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.cc b/components/plugins/renderer/loadable_plugin_placeholder.cc index f28c196..b13ece5 100644 --- a/components/plugins/renderer/loadable_plugin_placeholder.cc +++ b/components/plugins/renderer/loadable_plugin_placeholder.cc @@ -4,7 +4,6 @@ #include "components/plugins/renderer/loadable_plugin_placeholder.h" -#include "base/auto_reset.h" #include "base/bind.h" #include "base/bind_helpers.h" #include "base/json/string_escape.h" @@ -35,11 +34,6 @@ using content::RenderThread; namespace plugins { -// TODO(tommycli): After a size update, re-check the size after this delay, as -// Blink can report incorrect sizes to plugins while the compositing state is -// dirty. Chosen because it seems to work. -const int kSizeChangeRecheckDelayMilliseconds = 100; - void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { DCHECK(!is_blocked_for_power_saver_poster_); is_blocked_for_power_saver_poster_ = true; @@ -71,7 +65,6 @@ LoadablePluginPlaceholder::LoadablePluginPlaceholder( premade_throttler_(nullptr), allow_loading_(false), finished_loading_(false), - in_size_recheck_(false), heuristic_run_before_(premade_throttler_ != nullptr), weak_factory_(this) {} @@ -190,25 +183,48 @@ v8::Local<v8::Object> LoadablePluginPlaceholder::GetV8ScriptableObject( void LoadablePluginPlaceholder::OnUnobscuredRectUpdate( const gfx::Rect& unobscured_rect) { DCHECK(content::RenderThread::Get()); - if (!power_saver_enabled_ || !finished_loading_) + if (!plugin() || !power_saver_enabled_ || !finished_loading_) return; - // Only update the unobscured rect during the recheck phase. Also early exit - // to prevent reentrancy issues. - if (in_size_recheck_) { - unobscured_rect_ = unobscured_rect; + if (unobscured_rect_ == unobscured_rect) return; - } - if (!size_update_timer_.IsRunning()) { - // TODO(tommycli): We have to post a delayed task to recheck the size, as - // Blink can report wrong sizes for partially obscured plugins while the - // compositing state is dirty. https://crbug.com/343769 - size_update_timer_.Start( - FROM_HERE, - base::TimeDelta::FromMilliseconds(kSizeChangeRecheckDelayMilliseconds), - base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle, - weak_factory_.GetWeakPtr())); + unobscured_rect_ = unobscured_rect; + + float zoom_factor = plugin()->container()->pageZoomFactor(); + int width = roundf(unobscured_rect_.width() / zoom_factor); + int height = roundf(unobscured_rect_.height() / zoom_factor); + + 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); + 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))); + + // On a size update check if we now qualify as a essential plugin. + url::Origin content_origin = url::Origin(GetPluginParams().url); + auto status = render_frame()->GetPeripheralContentStatus( + render_frame()->GetWebFrame()->top()->securityOrigin(), content_origin, + gfx::Size(width, height)); + if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) { + MarkPluginEssential( + heuristic_run_before_ + ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE + : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); + + if (!heuristic_run_before_ && + status == + content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) { + render_frame()->WhitelistContentOrigin(content_origin); + } + } + + heuristic_run_before_ = true; } } @@ -327,59 +343,4 @@ bool LoadablePluginPlaceholder::LoadingBlocked() const { is_blocked_for_prerendering_; } -void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() { - DCHECK(content::RenderThread::Get()); - DCHECK(!in_size_recheck_); - DCHECK(finished_loading_); - - base::AutoReset<bool> recheck_scope(&in_size_recheck_, true); - - if (!plugin()) - return; - - gfx::Rect old_rect = unobscured_rect_; - - // Re-check the size in case the reported size was incorrect. - plugin()->container()->reportGeometry(); - - if (old_rect == unobscured_rect_) - return; - - float zoom_factor = plugin()->container()->pageZoomFactor(); - int width = roundf(unobscured_rect_.width() / zoom_factor); - int height = roundf(unobscured_rect_.height() / zoom_factor); - - 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); - 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))); - - // On a size update check if we now qualify as a essential plugin. - url::Origin content_origin = url::Origin(GetPluginParams().url); - auto status = render_frame()->GetPeripheralContentStatus( - render_frame()->GetWebFrame()->top()->securityOrigin(), content_origin, - gfx::Size(width, height)); - if (status != content::RenderFrame::CONTENT_STATUS_PERIPHERAL) { - MarkPluginEssential( - heuristic_run_before_ - ? PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE - : PluginInstanceThrottler::UNTHROTTLE_METHOD_DO_NOT_RECORD); - - if (!heuristic_run_before_ && - status == - content::RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) { - render_frame()->WhitelistContentOrigin(content_origin); - } - } - - heuristic_run_before_ = true; - } -} - } // namespace plugins diff --git a/components/plugins/renderer/loadable_plugin_placeholder.h b/components/plugins/renderer/loadable_plugin_placeholder.h index bc5114e..5cddaed 100644 --- a/components/plugins/renderer/loadable_plugin_placeholder.h +++ b/components/plugins/renderer/loadable_plugin_placeholder.h @@ -88,7 +88,6 @@ class LoadablePluginPlaceholder : public PluginPlaceholderBase { void UpdateMessage(); bool LoadingBlocked() const; - void RecheckSizeAndMaybeUnthrottle(); // Plugin creation is embedder-specific. virtual blink::WebPlugin* CreatePlugin() = 0; @@ -120,10 +119,7 @@ class LoadablePluginPlaceholder : public PluginPlaceholderBase { bool finished_loading_; std::string identifier_; - // Used to prevent re-entrancy during the size recheck for throttled plugins. - bool in_size_recheck_; gfx::Rect unobscured_rect_; - base::OneShotTimer size_update_timer_; // True if the power saver heuristic has already been run on this content. bool heuristic_run_before_; |