Chromium Code Reviews| 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 90c3f9ba7183580e8f0c07d6736c85feda4421e8..ff4673b1794eb1d876b7cdcd56954407d5715b36 100644 |
| --- a/components/plugins/renderer/loadable_plugin_placeholder.cc |
| +++ b/components/plugins/renderer/loadable_plugin_placeholder.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/strings/string_piece.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/thread_task_runner_handle.h" |
| #include "base/values.h" |
| #include "content/public/child/v8_value_converter.h" |
| #include "content/public/common/content_switches.h" |
| @@ -45,6 +46,15 @@ using content::RenderThread; |
| namespace plugins { |
| +namespace { |
| + |
| +// TODO(tommycli): After an unthrottling size update, re-check the size after |
|
groby-ooo-7-16
2015/06/05 23:03:45
#if defined(ENABLE_PLUGINS)
tommycli
2015/06/06 01:23:22
Done.
|
| +// this delay, as Blink can report incorrect sizes to plugins while the |
| +// compositing state is dirty. Chosen because it seems to work. |
|
groby-ooo-7-16
2015/06/05 23:03:45
Please add a bug to undo this. I don't trust TODO'
tommycli
2015/06/06 01:23:22
Done.
|
| +const int kSizeChangeRecheckDelayMilliseconds = 100; |
| + |
| +} // namespace |
| + |
| #if defined(ENABLE_PLUGINS) |
| void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { |
| DCHECK(!is_blocked_for_power_saver_poster_); |
| @@ -84,6 +94,8 @@ LoadablePluginPlaceholder::LoadablePluginPlaceholder( |
| allow_loading_(false), |
| hidden_(false), |
| finished_loading_(false), |
| + in_size_recheck_(false), |
| + size_update_weak_factory_(this), |
| weak_factory_(this) { |
| } |
| @@ -265,6 +277,37 @@ v8::Local<v8::Object> LoadablePluginPlaceholder::GetV8ScriptableObject( |
| return v8::Local<v8::Object>(); |
| } |
| +#if defined(ENABLE_PLUGINS) |
| +void LoadablePluginPlaceholder::OnUnobscuredSizeUpdate( |
| + const gfx::Size& unobscured_size) { |
| + if (!power_saver_enabled_ || !premade_throttler_ || !finished_loading_) |
| + return; |
| + |
| + unobscured_size_ = unobscured_size; |
| + |
| + if (in_size_recheck_) |
|
groby-ooo-7-16
2015/06/05 23:03:45
Why do we have this test?
tommycli
2015/06/06 01:23:21
Done. Added comment above.
|
| + return; |
| + |
| + if (PluginInstanceThrottler::IsLargeContent(unobscured_size.width(), |
| + unobscured_size.height())) { |
| + if (!size_update_weak_factory_.HasWeakPtrs()) { |
| + // 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 |
|
groby-ooo-7-16
2015/06/05 23:03:45
Once that bug is gone, does this whole machinery v
tommycli
2015/06/06 01:23:22
Yes, if there was no bug, and the reported plugin
|
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle, |
| + size_update_weak_factory_.GetWeakPtr()), |
| + base::TimeDelta::FromMilliseconds( |
| + kSizeChangeRecheckDelayMilliseconds)); |
| + } |
| + } else { |
| + // Cancel any pending unthrottle due to resize calls. |
| + size_update_weak_factory_.InvalidateWeakPtrs(); |
| + } |
| +} |
| +#endif // defined(ENABLE_PLUGINS) |
| + |
| void LoadablePluginPlaceholder::WasShown() { |
| if (is_blocked_for_background_tab_) { |
| is_blocked_for_background_tab_ = false; |
| @@ -389,4 +432,22 @@ bool LoadablePluginPlaceholder::LoadingBlocked() const { |
| is_blocked_for_prerendering_; |
| } |
| +#if defined(ENABLE_PLUGINS) |
| +void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() { |
| + DCHECK(!in_size_recheck_); |
|
groby-ooo-7-16
2015/06/05 23:03:45
Do we need to protect against reentrancy?
tommycli
2015/06/06 01:23:21
Uh.... well I hope this never happens. If re-entra
|
| + in_size_recheck_ = true; |
| + |
| + // Re-check the size in case the reported size was incorrect. |
| + plugin()->container()->reportGeometry(); |
| + |
| + if (PluginInstanceThrottler::IsLargeContent(unobscured_size_.width(), |
| + unobscured_size_.height())) { |
| + MarkPluginEssential( |
| + PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE); |
| + } |
| + |
| + in_size_recheck_ = false; |
| +} |
| +#endif // defined(ENABLE_PLUGINS) |
| + |
| } // namespace plugins |