summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authortommycli <tommycli@chromium.org>2015-07-14 11:25:46 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-14 18:26:41 +0000
commit5ffce36e4eb2986a39172dd26f8f9a8cef8308a3 (patch)
treeaa88981663a3beb5fa9d475b4791340876c9c2ea /components
parentf9ce01dccdb33e0646ef6fc2e71bf14d1f97cf96 (diff)
downloadchromium_src-5ffce36e4eb2986a39172dd26f8f9a8cef8308a3.zip
chromium_src-5ffce36e4eb2986a39172dd26f8f9a8cef8308a3.tar.gz
chromium_src-5ffce36e4eb2986a39172dd26f8f9a8cef8308a3.tar.bz2
Plugin Power Saver: Center 'Play' icon for all partially obscured plugins.
This centers the 'Play' icon correctly even if the plugin's left side or top side is obscured. BUG=503771 Review URL: https://codereview.chromium.org/1234103002 Cr-Commit-Position: refs/heads/master@{#338717}
Diffstat (limited to 'components')
-rw-r--r--components/plugins/renderer/loadable_plugin_placeholder.cc51
-rw-r--r--components/plugins/renderer/loadable_plugin_placeholder.h4
-rw-r--r--components/plugins/renderer/webview_plugin.cc2
-rw-r--r--components/plugins/renderer/webview_plugin.h4
4 files changed, 33 insertions, 28 deletions
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.cc b/components/plugins/renderer/loadable_plugin_placeholder.cc
index eb884da..f9e2f59 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.cc
+++ b/components/plugins/renderer/loadable_plugin_placeholder.cc
@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/json/string_escape.h"
#include "base/strings/string_piece.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "base/values.h"
@@ -35,9 +36,9 @@ using content::RenderThread;
namespace plugins {
-// TODO(tommycli): After an unthrottling size update, re-check the size after
-// this delay, as Blink can report incorrect sizes to plugins while the
-// compositing state is dirty. Chosen because it seems to work.
+// TODO(tommycli): After a size update, re-check the size after this delay, as
+// Blink can report incorrect sizes to plugins while the compositing state is
+// dirty. Chosen because it seems to work.
const int kSizeChangeRecheckDelayMilliseconds = 100;
void LoadablePluginPlaceholder::BlockForPowerSaverPoster() {
@@ -178,35 +179,29 @@ v8::Local<v8::Object> LoadablePluginPlaceholder::GetV8ScriptableObject(
return v8::Local<v8::Object>();
}
-void LoadablePluginPlaceholder::OnUnobscuredSizeUpdate(
- const gfx::Size& unobscured_size) {
+void LoadablePluginPlaceholder::OnUnobscuredRectUpdate(
+ const gfx::Rect& unobscured_rect) {
DCHECK(
content::RenderThread::Get()->GetTaskRunner()->BelongsToCurrentThread());
if (!power_saver_enabled_ || !premade_throttler_ || !finished_loading_)
return;
- unobscured_size_ = unobscured_size;
+ 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_)
return;
- if (PluginInstanceThrottler::IsLargeContent(unobscured_size.width(),
- unobscured_size.height())) {
- if (!size_update_timer_.IsRunning()) {
- // TODO(tommycli): We have to post a delayed task to recheck the size, as
- // Blink can report wrong sizes for partially obscured plugins while the
- // compositing state is dirty. https://crbug.com/343769
- size_update_timer_.Start(
- FROM_HERE, base::TimeDelta::FromMilliseconds(
- kSizeChangeRecheckDelayMilliseconds),
- base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle,
- weak_factory_.GetWeakPtr()));
- }
- } else {
- // Cancel any pending unthrottle due to resize calls.
- size_update_timer_.Stop();
+ if (!size_update_timer_.IsRunning()) {
+ // TODO(tommycli): We have to post a delayed task to recheck the size, as
+ // Blink can report wrong sizes for partially obscured plugins while the
+ // compositing state is dirty. https://crbug.com/343769
+ size_update_timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kSizeChangeRecheckDelayMilliseconds),
+ base::Bind(&LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle,
+ weak_factory_.GetWeakPtr()));
}
}
@@ -340,8 +335,18 @@ void LoadablePluginPlaceholder::RecheckSizeAndMaybeUnthrottle() {
// Re-check the size in case the reported size was incorrect.
plugin()->container()->reportGeometry();
- if (PluginInstanceThrottler::IsLargeContent(unobscured_size_.width(),
- unobscured_size_.height())) {
+ // Adjust padding using clip coordinates to center play button for plugins
+ // that have their top or left portions obscured.
+ if (is_blocked_for_power_saver_poster_) {
+ std::string script =
+ base::StringPrintf("window.setPosterMargin('%dpx', '%dpx')",
+ unobscured_rect_.x(), unobscured_rect_.y());
+ plugin()->web_view()->mainFrame()->executeScript(
+ blink::WebScriptSource(base::UTF8ToUTF16(script)));
+ }
+
+ if (PluginInstanceThrottler::IsLargeContent(unobscured_rect_.width(),
+ unobscured_rect_.height())) {
MarkPluginEssential(
PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_SIZE_CHANGE);
}
diff --git a/components/plugins/renderer/loadable_plugin_placeholder.h b/components/plugins/renderer/loadable_plugin_placeholder.h
index 13b903d..0221a0f 100644
--- a/components/plugins/renderer/loadable_plugin_placeholder.h
+++ b/components/plugins/renderer/loadable_plugin_placeholder.h
@@ -76,7 +76,7 @@ class LoadablePluginPlaceholder : public PluginPlaceholderBase {
void PluginDestroyed() override;
v8::Local<v8::Object> GetV8ScriptableObject(
v8::Isolate* isolate) const override;
- void OnUnobscuredSizeUpdate(const gfx::Size& unobscured_size) override;
+ void OnUnobscuredRectUpdate(const gfx::Rect& unobscured_rect) override;
// RenderFrameObserver methods:
void WasShown() override;
@@ -118,7 +118,7 @@ class LoadablePluginPlaceholder : public PluginPlaceholderBase {
// Used to prevent re-entrancy during the size recheck for throttled plugins.
bool in_size_recheck_;
- gfx::Size unobscured_size_;
+ gfx::Rect unobscured_rect_;
base::OneShotTimer<LoadablePluginPlaceholder> size_update_timer_;
base::WeakPtrFactory<LoadablePluginPlaceholder> weak_factory_;
diff --git a/components/plugins/renderer/webview_plugin.cc b/components/plugins/renderer/webview_plugin.cc
index 329a10c7..9d2ac91 100644
--- a/components/plugins/renderer/webview_plugin.cc
+++ b/components/plugins/renderer/webview_plugin.cc
@@ -175,7 +175,7 @@ void WebViewPlugin::updateGeometry(const WebRect& window_rect,
}
if (delegate_)
- delegate_->OnUnobscuredSizeUpdate(gfx::Rect(unobscured_rect).size());
+ delegate_->OnUnobscuredRectUpdate(gfx::Rect(unobscured_rect));
}
void WebViewPlugin::updateFocus(bool focused, blink::WebFocusType focus_type) {
diff --git a/components/plugins/renderer/webview_plugin.h b/components/plugins/renderer/webview_plugin.h
index fdb9777..e804fd3 100644
--- a/components/plugins/renderer/webview_plugin.h
+++ b/components/plugins/renderer/webview_plugin.h
@@ -56,8 +56,8 @@ class WebViewPlugin : public blink::WebPlugin,
// loaded but idle. Doesn't work for blocked plugins, which is not loaded.
virtual v8::Local<v8::Object> GetV8ScriptableObject(v8::Isolate*) const = 0;
- // Called when the unobscured size of the plugin is updated.
- virtual void OnUnobscuredSizeUpdate(const gfx::Size& unobscured_size) {}
+ // Called when the unobscured rect of the plugin is updated.
+ virtual void OnUnobscuredRectUpdate(const gfx::Rect& unobscured_rect) {}
};
// Convenience method to set up a new WebViewPlugin using |preferences|