Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: components/plugins/renderer/loadable_plugin_placeholder.cc

Issue 1412963003: Plugin Power Saver: Implement pixel tests for plugin placeholders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
10 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
11 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
12 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
15 #include "base/values.h" 14 #include "base/values.h"
16 #include "content/public/child/v8_value_converter.h" 15 #include "content/public/child/v8_value_converter.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/renderer/render_frame.h" 16 #include "content/public/renderer/render_frame.h"
19 #include "content/public/renderer/render_thread.h" 17 #include "content/public/renderer/render_thread.h"
20 #include "gin/handle.h"
21 #include "gin/object_template_builder.h"
22 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h" 18 #include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
23 #include "third_party/WebKit/public/web/WebDocument.h" 19 #include "third_party/WebKit/public/web/WebDocument.h"
24 #include "third_party/WebKit/public/web/WebElement.h" 20 #include "third_party/WebKit/public/web/WebElement.h"
25 #include "third_party/WebKit/public/web/WebInputEvent.h" 21 #include "third_party/WebKit/public/web/WebInputEvent.h"
26 #include "third_party/WebKit/public/web/WebKit.h" 22 #include "third_party/WebKit/public/web/WebKit.h"
27 #include "third_party/WebKit/public/web/WebLocalFrame.h" 23 #include "third_party/WebKit/public/web/WebLocalFrame.h"
28 #include "third_party/WebKit/public/web/WebPluginContainer.h" 24 #include "third_party/WebKit/public/web/WebPluginContainer.h"
29 #include "third_party/WebKit/public/web/WebScriptSource.h" 25 #include "third_party/WebKit/public/web/WebScriptSource.h"
30 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 26 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
31 #include "third_party/WebKit/public/web/WebView.h" 27 #include "third_party/WebKit/public/web/WebView.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 177 }
182 return v8::Local<v8::Object>(); 178 return v8::Local<v8::Object>();
183 } 179 }
184 180
185 void LoadablePluginPlaceholder::OnUnobscuredRectUpdate( 181 void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(
186 const gfx::Rect& unobscured_rect) { 182 const gfx::Rect& unobscured_rect) {
187 DCHECK(content::RenderThread::Get()); 183 DCHECK(content::RenderThread::Get());
188 if (!power_saver_enabled_ || !finished_loading_) 184 if (!power_saver_enabled_ || !finished_loading_)
189 return; 185 return;
190 186
191 unobscured_rect_ = unobscured_rect; 187 // Only update the unobscured rect during the recheck phase. Also early exit
192 188 // to prevent reentrancy issues.
193 // During a size recheck, we will get another notification into this method. 189 if (in_size_recheck_) {
194 // Use this flag to early exit to prevent reentrancy issues. 190 unobscured_rect_ = unobscured_rect;
195 if (in_size_recheck_)
196 return; 191 return;
192 }
197 193
198 if (!size_update_timer_.IsRunning()) { 194 if (!size_update_timer_.IsRunning()) {
199 // TODO(tommycli): We have to post a delayed task to recheck the size, as 195 // TODO(tommycli): We have to post a delayed task to recheck the size, as
200 // Blink can report wrong sizes for partially obscured plugins while the 196 // Blink can report wrong sizes for partially obscured plugins while the
201 // compositing state is dirty. https://crbug.com/343769 197 // compositing state is dirty. https://crbug.com/343769
202 size_update_timer_.Start( 198 size_update_timer_.Start(
203 FROM_HERE, 199 FROM_HERE,
204 base::TimeDelta::FromMilliseconds(kSizeChangeRecheckDelayMilliseconds), 200 base::TimeDelta::FromMilliseconds(kSizeChangeRecheckDelayMilliseconds),
205 base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle, 201 base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle,
206 weak_factory_.GetWeakPtr())); 202 weak_factory_.GetWeakPtr()));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 262
267 void LoadablePluginPlaceholder::DidFinishLoadingCallback() { 263 void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
268 finished_loading_ = true; 264 finished_loading_ = true;
269 if (message_.length() > 0) 265 if (message_.length() > 0)
270 UpdateMessage(); 266 UpdateMessage();
271 267
272 // Wait for the placeholder to finish loading to hide the premade plugin. 268 // Wait for the placeholder to finish loading to hide the premade plugin.
273 // This is necessary to prevent a flicker. 269 // This is necessary to prevent a flicker.
274 if (premade_throttler_ && power_saver_enabled_) 270 if (premade_throttler_ && power_saver_enabled_)
275 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */); 271 premade_throttler_->SetHiddenForPlaceholder(true /* hidden */);
272 }
276 273
274 void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() {
277 // Set an attribute and post an event, so browser tests can wait for the 275 // Set an attribute and post an event, so browser tests can wait for the
278 // placeholder to be ready to receive simulated user input. 276 // placeholder to be ready to receive simulated user input.
279 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 277 blink::WebElement element = plugin()->container()->element();
280 switches::kEnablePluginPlaceholderTesting)) { 278 element.setAttribute("placeholderReady", "true");
281 blink::WebElement element = plugin()->container()->element();
282 element.setAttribute("placeholderLoaded", "true");
283 279
284 scoped_ptr<content::V8ValueConverter> converter( 280 scoped_ptr<content::V8ValueConverter> converter(
285 content::V8ValueConverter::create()); 281 content::V8ValueConverter::create());
286 base::StringValue value("placeholderLoaded"); 282 base::StringValue value("placeholderReady");
287 blink::WebSerializedScriptValue message_data = 283 blink::WebSerializedScriptValue message_data =
288 blink::WebSerializedScriptValue::serialize(converter->ToV8Value( 284 blink::WebSerializedScriptValue::serialize(converter->ToV8Value(
289 &value, element.document().frame()->mainWorldScriptContext())); 285 &value, element.document().frame()->mainWorldScriptContext()));
290 blink::WebDOMMessageEvent msg_event(message_data); 286 blink::WebDOMMessageEvent msg_event(message_data);
291 element.dispatchEvent(msg_event); 287
292 } 288 element.dispatchEvent(msg_event);
293 } 289 }
294 290
295 void LoadablePluginPlaceholder::SetPluginInfo( 291 void LoadablePluginPlaceholder::SetPluginInfo(
296 const content::WebPluginInfo& plugin_info) { 292 const content::WebPluginInfo& plugin_info) {
297 plugin_info_ = plugin_info; 293 plugin_info_ = plugin_info;
298 } 294 }
299 295
300 const content::WebPluginInfo& LoadablePluginPlaceholder::GetPluginInfo() const { 296 const content::WebPluginInfo& LoadablePluginPlaceholder::GetPluginInfo() const {
301 return plugin_info_; 297 return plugin_info_;
302 } 298 }
303 299
304 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) { 300 void LoadablePluginPlaceholder::SetIdentifier(const std::string& identifier) {
305 identifier_ = identifier; 301 identifier_ = identifier;
306 } 302 }
307 303
308 const std::string& LoadablePluginPlaceholder::GetIdentifier() const { 304 const std::string& LoadablePluginPlaceholder::GetIdentifier() const {
309 return identifier_; 305 return identifier_;
310 } 306 }
311 307
312 bool LoadablePluginPlaceholder::LoadingBlocked() const { 308 bool LoadablePluginPlaceholder::LoadingBlocked() const {
313 DCHECK(allow_loading_); 309 DCHECK(allow_loading_);
314 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_ ||
315 is_blocked_for_prerendering_; 311 is_blocked_for_prerendering_;
316 } 312 }
317 313
318 void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() { 314 void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() {
319 DCHECK(content::RenderThread::Get()); 315 DCHECK(content::RenderThread::Get());
320 DCHECK(!in_size_recheck_); 316 DCHECK(!in_size_recheck_);
317 DCHECK(finished_loading_);
321 318
322 if (!plugin()) 319 if (!plugin())
323 return; 320 return;
324 321
325 in_size_recheck_ = true; 322 in_size_recheck_ = true;
326 323
324 gfx::Rect old_rect = unobscured_rect_;
325
327 // Re-check the size in case the reported size was incorrect. 326 // Re-check the size in case the reported size was incorrect.
328 plugin()->container()->reportGeometry(); 327 plugin()->container()->reportGeometry();
329 328
329 if (old_rect == unobscured_rect_) {
330 in_size_recheck_ = false;
331 return;
332 }
333
330 float zoom_factor = plugin()->container()->pageZoomFactor(); 334 float zoom_factor = plugin()->container()->pageZoomFactor();
331 int width = roundf(unobscured_rect_.width() / zoom_factor); 335 int width = roundf(unobscured_rect_.width() / zoom_factor);
332 int height = roundf(unobscured_rect_.height() / zoom_factor); 336 int height = roundf(unobscured_rect_.height() / zoom_factor);
333 337
334 if (is_blocked_for_power_saver_poster_) { 338 if (is_blocked_for_power_saver_poster_) {
335 // Adjust poster container padding and dimensions to center play button for 339 // Adjust poster container padding and dimensions to center play button for
336 // plugins and plugin posters that have their top or left portions obscured. 340 // plugins and plugin posters that have their top or left portions obscured.
337 int x = roundf(unobscured_rect_.x() / zoom_factor); 341 int x = roundf(unobscured_rect_.x() / zoom_factor);
338 int y = roundf(unobscured_rect_.y() / zoom_factor); 342 int y = roundf(unobscured_rect_.y() / zoom_factor);
339 std::string script = base::StringPrintf( 343 std::string script = base::StringPrintf(
(...skipping 19 matching lines...) Expand all
359 render_frame()->WhitelistContentOrigin(content_origin); 363 render_frame()->WhitelistContentOrigin(content_origin);
360 } 364 }
361 365
362 heuristic_run_before_ = true; 366 heuristic_run_before_ = true;
363 } 367 }
364 368
365 in_size_recheck_ = false; 369 in_size_recheck_ = false;
366 } 370 }
367 371
368 } // namespace plugins 372 } // namespace plugins
OLDNEW
« no previous file with comments | « components/plugins/renderer/loadable_plugin_placeholder.h ('k') | ppapi/tests/power_saver_test_plugin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698