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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/plugins/renderer/loadable_plugin_placeholder.cc
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.cc b/components/plugins/renderer/loadable_plugin_placeholder.cc
index dc4b5b2797aacf78f1918d146b479e6e67053388..9091bb0a4a90d42907684a93ef5157952bbd5af3 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.cc
+++ b/components/plugins/renderer/loadable_plugin_placeholder.cc
@@ -6,7 +6,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/command_line.h"
#include "base/json/string_escape.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
@@ -14,11 +13,8 @@
#include "base/thread_task_runner_handle.h"
#include "base/values.h"
#include "content/public/child/v8_value_converter.h"
-#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
-#include "gin/handle.h"
-#include "gin/object_template_builder.h"
#include "third_party/WebKit/public/web/WebDOMMessageEvent.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
@@ -188,12 +184,12 @@ void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(
if (!power_saver_enabled_ || !finished_loading_)
return;
- unobscured_rect_ = unobscured_rect;
-
- // During a size recheck, we will get another notification into this method.
- // Use this flag to early exit to prevent reentrancy issues.
- if (in_size_recheck_)
+ // Only update the unobscured rect during the recheck phase. Also early exit
+ // to prevent reentrancy issues.
+ if (in_size_recheck_) {
+ unobscured_rect_ = unobscured_rect;
return;
+ }
if (!size_update_timer_.IsRunning()) {
// TODO(tommycli): We have to post a delayed task to recheck the size, as
@@ -273,23 +269,23 @@ void LoadablePluginPlaceholder::DidFinishLoadingCallback() {
// This is necessary to prevent a flicker.
if (premade_throttler_ && power_saver_enabled_)
premade_throttler_->SetHiddenForPlaceholder(true /* hidden */);
+}
+void LoadablePluginPlaceholder::DidFinishIconRepositionForTestingCallback() {
// Set an attribute and post an event, so browser tests can wait for the
// placeholder to be ready to receive simulated user input.
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnablePluginPlaceholderTesting)) {
- blink::WebElement element = plugin()->container()->element();
- element.setAttribute("placeholderLoaded", "true");
-
- scoped_ptr<content::V8ValueConverter> converter(
- content::V8ValueConverter::create());
- base::StringValue value("placeholderLoaded");
- blink::WebSerializedScriptValue message_data =
- blink::WebSerializedScriptValue::serialize(converter->ToV8Value(
- &value, element.document().frame()->mainWorldScriptContext()));
- blink::WebDOMMessageEvent msg_event(message_data);
- element.dispatchEvent(msg_event);
- }
+ blink::WebElement element = plugin()->container()->element();
+ element.setAttribute("placeholderReady", "true");
+
+ scoped_ptr<content::V8ValueConverter> converter(
+ content::V8ValueConverter::create());
+ base::StringValue value("placeholderReady");
+ blink::WebSerializedScriptValue message_data =
+ blink::WebSerializedScriptValue::serialize(converter->ToV8Value(
+ &value, element.document().frame()->mainWorldScriptContext()));
+ blink::WebDOMMessageEvent msg_event(message_data);
+
+ element.dispatchEvent(msg_event);
}
void LoadablePluginPlaceholder::SetPluginInfo(
@@ -318,15 +314,23 @@ bool LoadablePluginPlaceholder::LoadingBlocked() const {
void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() {
DCHECK(content::RenderThread::Get());
DCHECK(!in_size_recheck_);
+ DCHECK(finished_loading_);
if (!plugin())
return;
in_size_recheck_ = true;
+ gfx::Rect old_rect = unobscured_rect_;
+
// Re-check the size in case the reported size was incorrect.
plugin()->container()->reportGeometry();
+ if (old_rect == unobscured_rect_) {
+ in_size_recheck_ = false;
+ return;
+ }
+
float zoom_factor = plugin()->container()->pageZoomFactor();
int width = roundf(unobscured_rect_.width() / zoom_factor);
int height = roundf(unobscured_rect_.height() / zoom_factor);
« 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