| OLD | NEW |
| 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/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 #endif | 94 #endif |
| 95 } | 95 } |
| 96 | 96 |
| 97 #if defined(ENABLE_PLUGINS) | 97 #if defined(ENABLE_PLUGINS) |
| 98 void LoadablePluginPlaceholder::MarkPluginEssential( | 98 void LoadablePluginPlaceholder::MarkPluginEssential( |
| 99 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { | 99 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { |
| 100 if (plugin_marked_essential_) | 100 if (plugin_marked_essential_) |
| 101 return; | 101 return; |
| 102 | 102 |
| 103 plugin_marked_essential_ = true; | 103 plugin_marked_essential_ = true; |
| 104 power_saver_enabled_ = false; |
| 104 if (premade_throttler_) | 105 if (premade_throttler_) |
| 105 premade_throttler_->MarkPluginEssential(method); | 106 premade_throttler_->MarkPluginEssential(method); |
| 106 else | 107 else |
| 107 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); | 108 PluginInstanceThrottler::RecordUnthrottleMethodMetric(method); |
| 108 | 109 |
| 109 if (is_blocked_for_power_saver_poster_) { | 110 if (is_blocked_for_power_saver_poster_) { |
| 110 is_blocked_for_power_saver_poster_ = false; | 111 is_blocked_for_power_saver_poster_ = false; |
| 111 if (!LoadingBlocked()) | 112 if (!LoadingBlocked()) |
| 112 LoadPlugin(); | 113 LoadPlugin(); |
| 113 } | 114 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return; | 286 return; |
| 286 } | 287 } |
| 287 | 288 |
| 288 if (premade_throttler_) { | 289 if (premade_throttler_) { |
| 289 premade_throttler_->RemoveObserver(this); | 290 premade_throttler_->RemoveObserver(this); |
| 290 premade_throttler_->SetHiddenForPlaceholder(false /* hidden */); | 291 premade_throttler_->SetHiddenForPlaceholder(false /* hidden */); |
| 291 | 292 |
| 292 ReplacePlugin(premade_throttler_->GetWebPlugin()); | 293 ReplacePlugin(premade_throttler_->GetWebPlugin()); |
| 293 premade_throttler_ = nullptr; | 294 premade_throttler_ = nullptr; |
| 294 } else { | 295 } else { |
| 295 // TODO(mmenke): In the case of prerendering, feed into | 296 ReplacePlugin(CreatePlugin()); |
| 296 // ChromeContentRendererClient::CreatePlugin instead, to | |
| 297 // reduce the chance of future regressions. | |
| 298 scoped_ptr<PluginInstanceThrottler> throttler; | |
| 299 #if defined(ENABLE_PLUGINS) | |
| 300 // If the plugin has already been marked essential in its placeholder form, | |
| 301 // we shouldn't create a new throttler and start the process all over again. | |
| 302 if (!plugin_marked_essential_ && power_saver_enabled_) | |
| 303 throttler = PluginInstanceThrottler::Create(); | |
| 304 #endif | |
| 305 WebPlugin* plugin = render_frame()->CreatePlugin( | |
| 306 GetFrame(), plugin_info_, GetPluginParams(), throttler.Pass()); | |
| 307 | |
| 308 ReplacePlugin(plugin); | |
| 309 } | 297 } |
| 310 } | 298 } |
| 311 | 299 |
| 312 void LoadablePluginPlaceholder::LoadCallback() { | 300 void LoadablePluginPlaceholder::LoadCallback() { |
| 313 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); | 301 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); |
| 314 #if defined(ENABLE_PLUGINS) | 302 #if defined(ENABLE_PLUGINS) |
| 315 // If the user specifically clicks on the plugin content's placeholder, | 303 // If the user specifically clicks on the plugin content's placeholder, |
| 316 // disable power saver throttling for this instance. | 304 // disable power saver throttling for this instance. |
| 317 MarkPluginEssential(PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK); | 305 MarkPluginEssential(PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_CLICK); |
| 318 #endif | 306 #endif |
| (...skipping 22 matching lines...) Expand all Loading... |
| 341 } | 329 } |
| 342 | 330 |
| 343 const content::WebPluginInfo& LoadablePluginPlaceholder::GetPluginInfo() const { | 331 const content::WebPluginInfo& LoadablePluginPlaceholder::GetPluginInfo() const { |
| 344 return plugin_info_; | 332 return plugin_info_; |
| 345 } | 333 } |
| 346 | 334 |
| 347 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) { | 335 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) { |
| 348 identifier_ = identifier; | 336 identifier_ = identifier; |
| 349 } | 337 } |
| 350 | 338 |
| 339 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { |
| 340 return identifier_; |
| 341 } |
| 342 |
| 351 bool LoadablePluginPlaceholder::LoadingBlocked() const { | 343 bool LoadablePluginPlaceholder::LoadingBlocked() const { |
| 352 DCHECK(allow_loading_); | 344 DCHECK(allow_loading_); |
| 353 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 345 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
| 354 is_blocked_for_prerendering_; | 346 is_blocked_for_prerendering_; |
| 355 } | 347 } |
| 356 | 348 |
| 357 } // namespace plugins | 349 } // namespace plugins |
| OLD | NEW |