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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/thread_task_runner_handle.h" | |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "content/public/child/v8_value_converter.h" | 16 #include "content/public/child/v8_value_converter.h" |
16 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
17 #include "content/public/renderer/render_frame.h" | 18 #include "content/public/renderer/render_frame.h" |
18 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
19 #include "gin/handle.h" | 20 #include "gin/handle.h" |
20 #include "gin/object_template_builder.h" | 21 #include "gin/object_template_builder.h" |
21 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" | 22 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" |
22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
23 #include "third_party/WebKit/public/web/WebElement.h" | 24 #include "third_party/WebKit/public/web/WebElement.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
38 using blink::WebPlugin; | 39 using blink::WebPlugin; |
39 using blink::WebPluginContainer; | 40 using blink::WebPluginContainer; |
40 using blink::WebPluginParams; | 41 using blink::WebPluginParams; |
41 using blink::WebScriptSource; | 42 using blink::WebScriptSource; |
42 using blink::WebURLRequest; | 43 using blink::WebURLRequest; |
43 using content::PluginInstanceThrottler; | 44 using content::PluginInstanceThrottler; |
44 using content::RenderThread; | 45 using content::RenderThread; |
45 | 46 |
46 namespace plugins { | 47 namespace plugins { |
47 | 48 |
49 namespace { | |
50 | |
51 // TODO(tommycli): After an unthrottling size update, re-check the size after | |
groby-ooo-7-16
2015/06/05 23:03:45
#if defined(ENABLE_PLUGINS)
tommycli
2015/06/06 01:23:22
Done.
| |
52 // this delay, as Blink can report incorrect sizes to plugins while the | |
53 // compositing state is dirty. Chosen because it seems to work. | |
groby-ooo-7-16
2015/06/05 23:03:45
Please add a bug to undo this. I don't trust TODO'
tommycli
2015/06/06 01:23:22
Done.
| |
54 const int kSizeChangeRecheckDelayMilliseconds = 100; | |
55 | |
56 } // namespace | |
57 | |
48 #if defined(ENABLE_PLUGINS) | 58 #if defined(ENABLE_PLUGINS) |
49 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { | 59 void LoadablePluginPlaceholder::BlockForPowerSaverPoster() { |
50 DCHECK(!is_blocked_for_power_saver_poster_); | 60 DCHECK(!is_blocked_for_power_saver_poster_); |
51 is_blocked_for_power_saver_poster_ = true; | 61 is_blocked_for_power_saver_poster_ = true; |
52 | 62 |
53 render_frame()->RegisterPeripheralPlugin( | 63 render_frame()->RegisterPeripheralPlugin( |
54 GURL(GetPluginParams().url).GetOrigin(), | 64 GURL(GetPluginParams().url).GetOrigin(), |
55 base::Bind(&LoadablePluginPlaceholder::MarkPluginEssential, | 65 base::Bind(&LoadablePluginPlaceholder::MarkPluginEssential, |
56 weak_factory_.GetWeakPtr(), | 66 weak_factory_.GetWeakPtr(), |
57 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST)); | 67 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_WHITELIST)); |
(...skipping 19 matching lines...) Expand all Loading... | |
77 html_data, | 87 html_data, |
78 placeholderDataUrl), | 88 placeholderDataUrl), |
79 is_blocked_for_background_tab_(false), | 89 is_blocked_for_background_tab_(false), |
80 is_blocked_for_prerendering_(false), | 90 is_blocked_for_prerendering_(false), |
81 is_blocked_for_power_saver_poster_(false), | 91 is_blocked_for_power_saver_poster_(false), |
82 power_saver_enabled_(false), | 92 power_saver_enabled_(false), |
83 premade_throttler_(nullptr), | 93 premade_throttler_(nullptr), |
84 allow_loading_(false), | 94 allow_loading_(false), |
85 hidden_(false), | 95 hidden_(false), |
86 finished_loading_(false), | 96 finished_loading_(false), |
97 in_size_recheck_(false), | |
98 size_update_weak_factory_(this), | |
87 weak_factory_(this) { | 99 weak_factory_(this) { |
88 } | 100 } |
89 | 101 |
90 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { | 102 LoadablePluginPlaceholder::~LoadablePluginPlaceholder() { |
91 } | 103 } |
92 | 104 |
93 #if defined(ENABLE_PLUGINS) | 105 #if defined(ENABLE_PLUGINS) |
94 void LoadablePluginPlaceholder::MarkPluginEssential( | 106 void LoadablePluginPlaceholder::MarkPluginEssential( |
95 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { | 107 PluginInstanceThrottler::PowerSaverUnthrottleMethod method) { |
96 if (!power_saver_enabled_) | 108 if (!power_saver_enabled_) |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 v8::Isolate* isolate) const { | 270 v8::Isolate* isolate) const { |
259 #if defined(ENABLE_PLUGINS) | 271 #if defined(ENABLE_PLUGINS) |
260 // Pass through JavaScript access to the underlying throttled plugin. | 272 // Pass through JavaScript access to the underlying throttled plugin. |
261 if (premade_throttler_ && premade_throttler_->GetWebPlugin()) { | 273 if (premade_throttler_ && premade_throttler_->GetWebPlugin()) { |
262 return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate); | 274 return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate); |
263 } | 275 } |
264 #endif | 276 #endif |
265 return v8::Local<v8::Object>(); | 277 return v8::Local<v8::Object>(); |
266 } | 278 } |
267 | 279 |
280 #if defined(ENABLE_PLUGINS) | |
281 void LoadablePluginPlaceholder::OnUnobscuredSizeUpdate( | |
282 const gfx::Size& unobscured_size) { | |
283 if (!power_saver_enabled_ || !premade_throttler_ || !finished_loading_) | |
284 return; | |
285 | |
286 unobscured_size_ = unobscured_size; | |
287 | |
288 if (in_size_recheck_) | |
groby-ooo-7-16
2015/06/05 23:03:45
Why do we have this test?
tommycli
2015/06/06 01:23:21
Done. Added comment above.
| |
289 return; | |
290 | |
291 if (PluginInstanceThrottler::IsLargeContent(unobscured_size.width(), | |
292 unobscured_size.height())) { | |
293 if (!size_update_weak_factory_.HasWeakPtrs()) { | |
294 // TODO(tommycli): We have to post a delayed task to recheck the size, as | |
295 // Blink can report wrong sizes for partially obscured plugins while the | |
296 // compositing state is dirty. https://crbug.com/343769 | |
groby-ooo-7-16
2015/06/05 23:03:45
Once that bug is gone, does this whole machinery v
tommycli
2015/06/06 01:23:22
Yes, if there was no bug, and the reported plugin
| |
297 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
298 FROM_HERE, | |
299 base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle, | |
300 size_update_weak_factory_.GetWeakPtr()), | |
301 base::TimeDelta::FromMilliseconds( | |
302 kSizeChangeRecheckDelayMilliseconds)); | |
303 } | |
304 } else { | |
305 // Cancel any pending unthrottle due to resize calls. | |
306 size_update_weak_factory_.InvalidateWeakPtrs(); | |
307 } | |
308 } | |
309 #endif // defined(ENABLE_PLUGINS) | |
310 | |
268 void LoadablePluginPlaceholder::WasShown() { | 311 void LoadablePluginPlaceholder::WasShown() { |
269 if (is_blocked_for_background_tab_) { | 312 if (is_blocked_for_background_tab_) { |
270 is_blocked_for_background_tab_ = false; | 313 is_blocked_for_background_tab_ = false; |
271 if (!LoadingBlocked()) | 314 if (!LoadingBlocked()) |
272 LoadPlugin(); | 315 LoadPlugin(); |
273 } | 316 } |
274 } | 317 } |
275 | 318 |
276 void LoadablePluginPlaceholder::OnLoadBlockedPlugins( | 319 void LoadablePluginPlaceholder::OnLoadBlockedPlugins( |
277 const std::string& identifier) { | 320 const std::string& identifier) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { | 425 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { |
383 return identifier_; | 426 return identifier_; |
384 } | 427 } |
385 | 428 |
386 bool LoadablePluginPlaceholder::LoadingBlocked() const { | 429 bool LoadablePluginPlaceholder::LoadingBlocked() const { |
387 DCHECK(allow_loading_); | 430 DCHECK(allow_loading_); |
388 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || | 431 return is_blocked_for_background_tab_ || is_blocked_for_power_saver_poster_ || |
389 is_blocked_for_prerendering_; | 432 is_blocked_for_prerendering_; |
390 } | 433 } |
391 | 434 |
435 #if defined(ENABLE_PLUGINS) | |
436 void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() { | |
437 DCHECK(!in_size_recheck_); | |
groby-ooo-7-16
2015/06/05 23:03:45
Do we need to protect against reentrancy?
tommycli
2015/06/06 01:23:21
Uh.... well I hope this never happens. If re-entra
| |
438 in_size_recheck_ = true; | |
439 | |
440 // Re-check the size in case the reported size was incorrect. | |
441 plugin()->container()->reportGeometry(); | |
442 | |
443 if (PluginInstanceThrottler::IsLargeContent(unobscured_size_.width(), | |
444 unobscured_size_.height())) { | |
445 MarkPluginEssential( | |
446 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE); | |
447 } | |
448 | |
449 in_size_recheck_ = false; | |
450 } | |
451 #endif // defined(ENABLE_PLUGINS) | |
452 | |
392 } // namespace plugins | 453 } // namespace plugins |
OLD | NEW |