| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/plugin_placeholder.h" | 5 #include "components/plugins/renderer/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 : content::RenderFrameObserver(render_frame), | 61 : content::RenderFrameObserver(render_frame), |
| 62 frame_(frame), | 62 frame_(frame), |
| 63 plugin_params_(params), | 63 plugin_params_(params), |
| 64 plugin_(WebViewPlugin::Create(this, | 64 plugin_(WebViewPlugin::Create(this, |
| 65 render_frame->GetWebkitPreferences(), | 65 render_frame->GetWebkitPreferences(), |
| 66 html_data, | 66 html_data, |
| 67 placeholderDataUrl)), | 67 placeholderDataUrl)), |
| 68 is_blocked_for_background_tab_(false), | 68 is_blocked_for_background_tab_(false), |
| 69 is_blocked_for_prerendering_(false), | 69 is_blocked_for_prerendering_(false), |
| 70 is_blocked_for_power_saver_poster_(false), | 70 is_blocked_for_power_saver_poster_(false), |
| 71 power_saver_mode_(content::RenderFrame::POWER_SAVER_MODE_ESSENTIAL), | 71 power_saver_mode_( |
| 72 content::PluginInstanceThrottler::POWER_SAVER_MODE_ESSENTIAL), |
| 72 allow_loading_(false), | 73 allow_loading_(false), |
| 73 hidden_(false), | 74 hidden_(false), |
| 74 finished_loading_(false), | 75 finished_loading_(false), |
| 75 weak_factory_(this) { | 76 weak_factory_(this) { |
| 76 } | 77 } |
| 77 | 78 |
| 78 PluginPlaceholder::~PluginPlaceholder() {} | 79 PluginPlaceholder::~PluginPlaceholder() {} |
| 79 | 80 |
| 80 #if defined(ENABLE_PLUGINS) | 81 #if defined(ENABLE_PLUGINS) |
| 81 void PluginPlaceholder::DisablePowerSaverForInstance() { | 82 void PluginPlaceholder::DisablePowerSaverForInstance() { |
| 82 power_saver_mode_ = content::RenderFrame::POWER_SAVER_MODE_ESSENTIAL; | 83 power_saver_mode_ = |
| 84 content::PluginInstanceThrottler::POWER_SAVER_MODE_ESSENTIAL; |
| 83 if (is_blocked_for_power_saver_poster_) { | 85 if (is_blocked_for_power_saver_poster_) { |
| 84 is_blocked_for_power_saver_poster_ = false; | 86 is_blocked_for_power_saver_poster_ = false; |
| 85 if (!LoadingBlocked()) | 87 if (!LoadingBlocked()) |
| 86 LoadPlugin(); | 88 LoadPlugin(); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 #endif | 91 #endif |
| 90 | 92 |
| 91 gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder( | 93 gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder( |
| 92 v8::Isolate* isolate) { | 94 v8::Isolate* isolate) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // event propagation changes between "close" vs. "click-to-play". | 242 // event propagation changes between "close" vs. "click-to-play". |
| 241 if (hidden_) | 243 if (hidden_) |
| 242 return; | 244 return; |
| 243 if (!plugin_) | 245 if (!plugin_) |
| 244 return; | 246 return; |
| 245 if (!allow_loading_) { | 247 if (!allow_loading_) { |
| 246 NOTREACHED(); | 248 NOTREACHED(); |
| 247 return; | 249 return; |
| 248 } | 250 } |
| 249 | 251 |
| 252 scoped_ptr<content::PluginInstanceThrottler> throttler; |
| 253 #if defined(ENABLE_PLUGINS) |
| 254 if (power_saver_mode_ != |
| 255 content::PluginInstanceThrottler::POWER_SAVER_MODE_ESSENTIAL) { |
| 256 throttler = content::PluginInstanceThrottler::Create( |
| 257 render_frame(), plugin_params_.url, power_saver_mode_); |
| 258 } |
| 259 #endif |
| 250 // TODO(mmenke): In the case of prerendering, feed into | 260 // TODO(mmenke): In the case of prerendering, feed into |
| 251 // ChromeContentRendererClient::CreatePlugin instead, to | 261 // ChromeContentRendererClient::CreatePlugin instead, to |
| 252 // reduce the chance of future regressions. | 262 // reduce the chance of future regressions. |
| 253 WebPlugin* plugin = render_frame()->CreatePlugin( | 263 WebPlugin* plugin = render_frame()->CreatePlugin( |
| 254 frame_, plugin_info_, plugin_params_, power_saver_mode_); | 264 frame_, plugin_info_, plugin_params_, throttler.Pass()); |
| 255 ReplacePlugin(plugin); | 265 ReplacePlugin(plugin); |
| 256 } | 266 } |
| 257 | 267 |
| 258 void PluginPlaceholder::LoadCallback() { | 268 void PluginPlaceholder::LoadCallback() { |
| 259 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); | 269 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); |
| 260 // If the user specifically clicks on the plug-in content's placeholder, | 270 // If the user specifically clicks on the plug-in content's placeholder, |
| 261 // disable power saver throttling for this instance. | 271 // disable power saver throttling for this instance. |
| 262 #if defined(ENABLE_PLUGINS) | 272 #if defined(ENABLE_PLUGINS) |
| 263 DisablePowerSaverForInstance(); | 273 DisablePowerSaverForInstance(); |
| 264 #endif | 274 #endif |
| (...skipping 30 matching lines...) Expand all Loading... |
| 295 return plugin_params_; | 305 return plugin_params_; |
| 296 } | 306 } |
| 297 | 307 |
| 298 bool PluginPlaceholder::LoadingBlocked() const { | 308 bool PluginPlaceholder::LoadingBlocked() const { |
| 299 DCHECK(allow_loading_); | 309 DCHECK(allow_loading_); |
| 300 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 310 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
| 301 is_blocked_for_prerendering_; | 311 is_blocked_for_prerendering_; |
| 302 } | 312 } |
| 303 | 313 |
| 304 } // namespace plugins | 314 } // namespace plugins |
| OLD | NEW |