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" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 // Pass through JavaScript access to the underlying throttled plugin. | 177 // Pass through JavaScript access to the underlying throttled plugin. |
178 if (premade_throttler_ && premade_throttler_->GetWebPlugin()) { | 178 if (premade_throttler_ && premade_throttler_->GetWebPlugin()) { |
179 return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate); | 179 return premade_throttler_->GetWebPlugin()->v8ScriptableObject(isolate); |
180 } | 180 } |
181 return v8::Local<v8::Object>(); | 181 return v8::Local<v8::Object>(); |
182 } | 182 } |
183 | 183 |
184 void LoadablePluginPlaceholder::OnUnobscuredRectUpdate( | 184 void LoadablePluginPlaceholder::OnUnobscuredRectUpdate( |
185 const gfx::Rect& unobscured_rect) { | 185 const gfx::Rect& unobscured_rect) { |
186 DCHECK(content::RenderThread::Get()); | 186 DCHECK(content::RenderThread::Get()); |
187 if (!power_saver_enabled_ || !premade_throttler_ || !finished_loading_) | 187 if (!power_saver_enabled_ || !finished_loading_) |
188 return; | 188 return; |
189 | 189 |
190 unobscured_rect_ = unobscured_rect; | 190 unobscured_rect_ = unobscured_rect; |
191 | 191 |
192 // During a size recheck, we will get another notification into this method. | 192 // During a size recheck, we will get another notification into this method. |
193 // Use this flag to early exit to prevent reentrancy issues. | 193 // Use this flag to early exit to prevent reentrancy issues. |
194 if (in_size_recheck_) | 194 if (in_size_recheck_) |
195 return; | 195 return; |
196 | 196 |
197 if (!size_update_timer_.IsRunning()) { | 197 if (!size_update_timer_.IsRunning()) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 if (!plugin()) | 321 if (!plugin()) |
322 return; | 322 return; |
323 | 323 |
324 in_size_recheck_ = true; | 324 in_size_recheck_ = true; |
325 | 325 |
326 // Re-check the size in case the reported size was incorrect. | 326 // Re-check the size in case the reported size was incorrect. |
327 plugin()->container()->reportGeometry(); | 327 plugin()->container()->reportGeometry(); |
328 | 328 |
329 float zoom_factor = plugin()->container()->pageZoomFactor(); | 329 float zoom_factor = plugin()->container()->pageZoomFactor(); |
330 | 330 |
331 // Adjust padding using clip coordinates to center play button for plugins | 331 // Adjust poster container padding and dimensions to center play button for |
332 // that have their top or left portions obscured. | 332 // plugins and plugin posters that have their top or left portions obscured. |
333 if (is_blocked_for_power_saver_poster_) { | 333 if (is_blocked_for_power_saver_poster_) { |
334 int x = roundf(unobscured_rect_.x() / zoom_factor); | 334 int x = roundf(unobscured_rect_.x() / zoom_factor); |
335 int y = roundf(unobscured_rect_.y() / zoom_factor); | 335 int y = roundf(unobscured_rect_.y() / zoom_factor); |
336 std::string script = | 336 int width = roundf(unobscured_rect_.width() / zoom_factor); |
337 base::StringPrintf("window.setPosterMargin('%dpx', '%dpx')", x, y); | 337 int height = roundf(unobscured_rect_.height() / zoom_factor); |
338 std::string script = base::StringPrintf( | |
339 "window.resizePoster('%dpx', '%dpx', '%dpx', '%dpx')", x, y, width, | |
340 height); | |
338 plugin()->web_view()->mainFrame()->executeScript( | 341 plugin()->web_view()->mainFrame()->executeScript( |
339 blink::WebScriptSource(base::UTF8ToUTF16(script))); | 342 blink::WebScriptSource(base::UTF8ToUTF16(script))); |
340 } | 343 } |
341 | 344 |
342 if (PluginInstanceThrottler::IsLargeContent( | 345 // Only unthrottle on size increase for plugins without poster. |
346 // TODO(tommycli): Address this unfairness to plugins that specify a poster. | |
347 if (premade_throttler_ && | |
tommycli
2015/10/15 21:54:50
Needed to compensate for change in line 187.
Lei Zhang
2015/10/15 23:05:31
Sorry, it's been a while. You'll have to remind me
tommycli
2015/10/16 17:16:25
Discussed in person.
| |
348 PluginInstanceThrottler::IsLargeContent( | |
343 roundf(unobscured_rect_.width() / zoom_factor), | 349 roundf(unobscured_rect_.width() / zoom_factor), |
344 roundf(unobscured_rect_.height() / zoom_factor))) { | 350 roundf(unobscured_rect_.height() / zoom_factor))) { |
345 MarkPluginEssential( | 351 MarkPluginEssential( |
346 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE); | 352 PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE); |
347 } | 353 } |
348 | 354 |
349 in_size_recheck_ = false; | 355 in_size_recheck_ = false; |
350 } | 356 } |
351 | 357 |
352 } // namespace plugins | 358 } // namespace plugins |
OLD | NEW |