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..3325c6d5cd95e0737fd784914566d1898db1ede3 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,17 @@ using content::RenderThread; |
| namespace plugins { |
| +namespace { |
|
Bernhard Bauer
2015/06/10 11:13:24
Nit: Anonymous namespace isn't necessary for const
tommycli
2015/06/10 18:55:52
Done.
|
| + |
| +#if defined(ENABLE_PLUGINS) |
| +// TODO(tommycli): After an unthrottling 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; |
| +#endif |
| + |
| +} // namespace |
| + |
| #if defined(ENABLE_PLUGINS) |
| void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { |
| DCHECK(!is_blocked_for_power_saver_poster_); |
| @@ -84,6 +96,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 +279,41 @@ v8::Local<v8::Object> LoadablePluginPlaceholder::GetV8ScriptableObject( |
| return v8::Local<v8::Object>(); |
| } |
| +#if defined(ENABLE_PLUGINS) |
| +void LoadablePluginPlaceholder::OnUnobscuredSizeUpdate( |
| + const gfx::Size& unobscured_size) { |
| + DCHECK( |
| + content::RenderThread::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| + if (!power_saver_enabled_ || !premade_throttler_ || !finished_loading_) |
| + return; |
| + |
| + unobscured_size_ = unobscured_size; |
| + |
| + // During a size recheck, we will get another notification into this method. |
| + // Use this flag to early exit to prevent reentrancy issues. |
| + if (in_size_recheck_) |
| + return; |
| + |
| + if (PluginInstanceThrottler::IsLargeContent(unobscured_size.width(), |
| + unobscured_size.height())) { |
| + if (!size_update_weak_factory_.HasWeakPtrs()) { |
|
Bernhard Bauer
2015/06/10 11:13:24
You could use a base::Timer for this instead of th
tommycli
2015/06/10 18:55:52
Done.
|
| + // 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 |
| + 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 +438,24 @@ bool LoadablePluginPlaceholder::LoadingBlocked() const { |
| is_blocked_for_prerendering_; |
| } |
| +#if defined(ENABLE_PLUGINS) |
| +void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() { |
| + DCHECK( |
| + content::RenderThread::Get()->GetTaskRunner()->BelongsToCurrentThread()); |
| + DCHECK(!in_size_recheck_); |
| + 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 |