| 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 17 matching lines...) Expand all Loading... |
| 28 using base::UserMetricsAction; | 28 using base::UserMetricsAction; |
| 29 using blink::WebElement; | 29 using blink::WebElement; |
| 30 using blink::WebLocalFrame; | 30 using blink::WebLocalFrame; |
| 31 using blink::WebMouseEvent; | 31 using blink::WebMouseEvent; |
| 32 using blink::WebNode; | 32 using blink::WebNode; |
| 33 using blink::WebPlugin; | 33 using blink::WebPlugin; |
| 34 using blink::WebPluginContainer; | 34 using blink::WebPluginContainer; |
| 35 using blink::WebPluginParams; | 35 using blink::WebPluginParams; |
| 36 using blink::WebScriptSource; | 36 using blink::WebScriptSource; |
| 37 using blink::WebURLRequest; | 37 using blink::WebURLRequest; |
| 38 using content::PluginPowerSaverMode; |
| 38 using content::RenderThread; | 39 using content::RenderThread; |
| 39 | 40 |
| 40 namespace plugins { | 41 namespace plugins { |
| 41 | 42 |
| 42 gin::WrapperInfo PluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin}; | 43 gin::WrapperInfo PluginPlaceholder::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 43 | 44 |
| 44 #if defined(ENABLE_PLUGINS) | 45 #if defined(ENABLE_PLUGINS) |
| 45 void PluginPlaceholder::BlockForPowerSaverPoster() { | 46 void PluginPlaceholder::BlockForPowerSaverPoster() { |
| 46 DCHECK(!is_blocked_for_power_saver_poster_); | 47 DCHECK(!is_blocked_for_power_saver_poster_); |
| 47 is_blocked_for_power_saver_poster_ = true; | 48 is_blocked_for_power_saver_poster_ = true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 : content::RenderFrameObserver(render_frame), | 62 : content::RenderFrameObserver(render_frame), |
| 62 frame_(frame), | 63 frame_(frame), |
| 63 plugin_params_(params), | 64 plugin_params_(params), |
| 64 plugin_(WebViewPlugin::Create(this, | 65 plugin_(WebViewPlugin::Create(this, |
| 65 render_frame->GetWebkitPreferences(), | 66 render_frame->GetWebkitPreferences(), |
| 66 html_data, | 67 html_data, |
| 67 placeholderDataUrl)), | 68 placeholderDataUrl)), |
| 68 is_blocked_for_background_tab_(false), | 69 is_blocked_for_background_tab_(false), |
| 69 is_blocked_for_prerendering_(false), | 70 is_blocked_for_prerendering_(false), |
| 70 is_blocked_for_power_saver_poster_(false), | 71 is_blocked_for_power_saver_poster_(false), |
| 71 power_saver_mode_(content::RenderFrame::POWER_SAVER_MODE_ESSENTIAL), | 72 power_saver_mode_(PluginPowerSaverMode::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_ = PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL; |
| 83 if (is_blocked_for_power_saver_poster_) { | 84 if (is_blocked_for_power_saver_poster_) { |
| 84 is_blocked_for_power_saver_poster_ = false; | 85 is_blocked_for_power_saver_poster_ = false; |
| 85 if (!LoadingBlocked()) | 86 if (!LoadingBlocked()) |
| 86 LoadPlugin(); | 87 LoadPlugin(); |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 #endif | 90 #endif |
| 90 | 91 |
| 91 gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder( | 92 gin::ObjectTemplateBuilder PluginPlaceholder::GetObjectTemplateBuilder( |
| 92 v8::Isolate* isolate) { | 93 v8::Isolate* isolate) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return; | 245 return; |
| 245 if (!allow_loading_) { | 246 if (!allow_loading_) { |
| 246 NOTREACHED(); | 247 NOTREACHED(); |
| 247 return; | 248 return; |
| 248 } | 249 } |
| 249 | 250 |
| 250 // TODO(mmenke): In the case of prerendering, feed into | 251 // TODO(mmenke): In the case of prerendering, feed into |
| 251 // ChromeContentRendererClient::CreatePlugin instead, to | 252 // ChromeContentRendererClient::CreatePlugin instead, to |
| 252 // reduce the chance of future regressions. | 253 // reduce the chance of future regressions. |
| 253 WebPlugin* plugin = render_frame()->CreatePlugin( | 254 WebPlugin* plugin = render_frame()->CreatePlugin( |
| 254 frame_, plugin_info_, plugin_params_, power_saver_mode_); | 255 frame_, plugin_info_, plugin_params_, |
| 256 content::PluginInstanceThrottler::Get(render_frame(), plugin_params_.url, |
| 257 power_saver_mode_)); |
| 255 ReplacePlugin(plugin); | 258 ReplacePlugin(plugin); |
| 256 } | 259 } |
| 257 | 260 |
| 258 void PluginPlaceholder::LoadCallback() { | 261 void PluginPlaceholder::LoadCallback() { |
| 259 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); | 262 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); |
| 260 // If the user specifically clicks on the plug-in content's placeholder, | 263 // If the user specifically clicks on the plug-in content's placeholder, |
| 261 // disable power saver throttling for this instance. | 264 // disable power saver throttling for this instance. |
| 262 #if defined(ENABLE_PLUGINS) | 265 #if defined(ENABLE_PLUGINS) |
| 263 DisablePowerSaverForInstance(); | 266 DisablePowerSaverForInstance(); |
| 264 #endif | 267 #endif |
| (...skipping 30 matching lines...) Expand all Loading... |
| 295 return plugin_params_; | 298 return plugin_params_; |
| 296 } | 299 } |
| 297 | 300 |
| 298 bool PluginPlaceholder::LoadingBlocked() const { | 301 bool PluginPlaceholder::LoadingBlocked() const { |
| 299 DCHECK(allow_loading_); | 302 DCHECK(allow_loading_); |
| 300 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 303 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
| 301 is_blocked_for_prerendering_; | 304 is_blocked_for_prerendering_; |
| 302 } | 305 } |
| 303 | 306 |
| 304 } // namespace plugins | 307 } // namespace plugins |
| OLD | NEW |