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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 // event propagation changes between "close" vs. "click-to-play". | 241 // event propagation changes between "close" vs. "click-to-play". |
241 if (hidden_) | 242 if (hidden_) |
242 return; | 243 return; |
243 if (!plugin_) | 244 if (!plugin_) |
244 return; | 245 return; |
245 if (!allow_loading_) { | 246 if (!allow_loading_) { |
246 NOTREACHED(); | 247 NOTREACHED(); |
247 return; | 248 return; |
248 } | 249 } |
249 | 250 |
251 #if defined(ENABLE_PLUGINS) | |
Lei Zhang
2015/01/16 01:09:58
Can you see if this works for platforms without EN
tommycli
2015/01/16 01:26:10
Done.
| |
252 WebPlugin* plugin = render_frame()->CreatePlugin( | |
253 frame_, plugin_info_, plugin_params_, | |
254 content::PluginInstanceThrottler::Get(render_frame(), plugin_params_.url, | |
255 power_saver_mode_)); | |
256 #else | |
257 WebPlugin* plugin = render_frame()->CreatePlugin(frame_, plugin_info_, | |
258 plugin_params_, nullptr); | |
259 #endif | |
250 // TODO(mmenke): In the case of prerendering, feed into | 260 // TODO(mmenke): In the case of prerendering, feed into |
Lei Zhang
2015/01/16 01:09:58
Is this referring to the CreatePlugin() calls, whi
tommycli
2015/01/16 01:26:10
Done.
| |
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( | |
254 frame_, plugin_info_, plugin_params_, power_saver_mode_); | |
255 ReplacePlugin(plugin); | 263 ReplacePlugin(plugin); |
256 } | 264 } |
257 | 265 |
258 void PluginPlaceholder::LoadCallback() { | 266 void PluginPlaceholder::LoadCallback() { |
259 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); | 267 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Load_Click")); |
260 // If the user specifically clicks on the plug-in content's placeholder, | 268 // If the user specifically clicks on the plug-in content's placeholder, |
261 // disable power saver throttling for this instance. | 269 // disable power saver throttling for this instance. |
262 #if defined(ENABLE_PLUGINS) | 270 #if defined(ENABLE_PLUGINS) |
263 DisablePowerSaverForInstance(); | 271 DisablePowerSaverForInstance(); |
264 #endif | 272 #endif |
(...skipping 30 matching lines...) Expand all Loading... | |
295 return plugin_params_; | 303 return plugin_params_; |
296 } | 304 } |
297 | 305 |
298 bool PluginPlaceholder::LoadingBlocked() const { | 306 bool PluginPlaceholder::LoadingBlocked() const { |
299 DCHECK(allow_loading_); | 307 DCHECK(allow_loading_); |
300 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 308 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
301 is_blocked_for_prerendering_; | 309 is_blocked_for_prerendering_; |
302 } | 310 } |
303 | 311 |
304 } // namespace plugins | 312 } // namespace plugins |
OLD | NEW |