Commit 4d26738f authored by tommycli's avatar tommycli Committed by Commit bot

[PPS] Exclude same-origin tiny plugins.

Tiny plugins will now always be disabled by plugin power saver, even if they have the same origin as the main page.

BUG=675707

patch from issue 2576893003 at patchset 1 (http://crrev.com/2576893003#ps1)

Review-Url: https://codereview.chromium.org/2627493002
Cr-Commit-Position: refs/heads/master@{#443127}
parent f2a1967c
......@@ -28,6 +28,7 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/ppapi_test_utils.h"
......@@ -599,6 +600,32 @@ IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingTinyPlugins) {
VerifyPluginMarkedEssential(GetActiveWebContents(), "expand_to_essential");
}
// Separate test case with FilterSameOriginTinyPlugins feature flag on.
class PluginPowerSaverFilterSameOriginTinyPluginsBrowserTest
: public PluginPowerSaverBrowserTest {
public:
void SetUpInProcessBrowserTestFixture() override {
// Although this is redundant with the Field Trial testing configuration,
// the official builders don't read that.
feature_list.InitWithFeatures({features::kFilterSameOriginTinyPlugin},
{features::kPreferHtmlOverPlugins});
}
private:
base::test::ScopedFeatureList feature_list;
};
IN_PROC_BROWSER_TEST_F(PluginPowerSaverFilterSameOriginTinyPluginsBrowserTest,
BlockSameOriginTinyPlugin) {
LoadHTML("/same_origin_tiny_plugin.html");
VerifyPluginIsPlaceholderOnly("tiny_same_origin");
TabSpecificContentSettings* tab_specific_content_settings =
TabSpecificContentSettings::FromWebContents(GetActiveWebContents());
EXPECT_FALSE(tab_specific_content_settings->blocked_plugin_names().empty());
}
// Separate test case with HTML By Default feature flag on.
class PluginPowerSaverPreferHtmlBrowserTest
: public PluginPowerSaverBrowserTest {
......
......@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/renderer/plugins/power_saver_info.h"
#include "content/public/common/content_constants.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/webplugininfo.h"
#include "content/public/renderer/render_frame.h"
......@@ -107,12 +108,14 @@ PowerSaverInfo PowerSaverInfo::Get(content::RenderFrame* render_frame,
// Early-exit from the whole Power Saver system if the content is
// same-origin or whitelisted-origin. We ignore the other possibilities,
// because we don't know the unobscured size of the plugin content yet.
// If we are filtering same-origin tiny content, we cannot early exit here.
//
// Once the plugin is loaded, the peripheral content status is re-tested
// with the actual unobscured plugin size.
if (status == content::RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN ||
status == content::RenderFrame::
CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED) {
if (!base::FeatureList::IsEnabled(features::kFilterSameOriginTinyPlugin) &&
(status == content::RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN ||
status == content::RenderFrame::
CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED)) {
info.power_saver_enabled = false;
} else {
info.poster_attribute = GetPluginInstancePosterAttribute(params);
......
<object id='tiny_same_origin' data='fake.swf'
type='application/x-shockwave-flash' width='3' height='3'></object>
......@@ -75,6 +75,10 @@ const base::Feature kFasterLocationReload{"FasterLocationReload",
const base::Feature kFeaturePolicy{"FeaturePolicy",
base::FEATURE_DISABLED_BY_DEFAULT};
// Enable filtering of same-origin tiny plugins
const base::Feature kFilterSameOriginTinyPlugin{
"FilterSameOriginTinyPlugins", base::FEATURE_DISABLED_BY_DEFAULT};
// Enables a blink::FontCache optimization that reuses a font to serve different
// size of font.
const base::Feature kFontCacheScaling{"FontCacheScaling",
......
......@@ -28,6 +28,7 @@ CONTENT_EXPORT extern const base::Feature kDocumentWriteEvaluator;
CONTENT_EXPORT extern const base::Feature kExpensiveBackgroundTimerThrottling;
CONTENT_EXPORT extern const base::Feature kFasterLocationReload;
CONTENT_EXPORT extern const base::Feature kFeaturePolicy;
CONTENT_EXPORT extern const base::Feature kFilterSameOriginTinyPlugin;
CONTENT_EXPORT extern const base::Feature kFontCacheScaling;
CONTENT_EXPORT extern const base::Feature
kFramebustingNeedsSameOriginOrUserGesture;
......
......@@ -6,6 +6,8 @@
#include <cmath>
#include "base/feature_list.h"
#include "content/public/common/content_features.h"
#include "ui/gfx/geometry/size.h"
namespace content {
......@@ -29,6 +31,16 @@ const double kEssentialVideoAspectRatio = 16.0 / 9.0;
const double kAspectRatioEpsilon = 0.01;
const int kEssentialVideoMinimumArea = 120000;
bool IsTiny(const gfx::Size& unobscured_size) {
// Empty plugins can't be classified as tiny - they might just be of unknown
// size.
if (unobscured_size.IsEmpty())
return false;
return unobscured_size.width() <= kTinyContentSize &&
unobscured_size.height() <= kTinyContentSize;
}
} // namespace
// static
......@@ -38,6 +50,11 @@ PeripheralContentHeuristic::GetPeripheralStatus(
const url::Origin& main_frame_origin,
const url::Origin& content_origin,
const gfx::Size& unobscured_size) {
if (base::FeatureList::IsEnabled(features::kFilterSameOriginTinyPlugin) &&
IsTiny(unobscured_size)) {
return RenderFrame::CONTENT_STATUS_TINY;
}
if (main_frame_origin.IsSameOriginWith(content_origin))
return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN;
......@@ -47,10 +64,8 @@ PeripheralContentHeuristic::GetPeripheralStatus(
if (unobscured_size.IsEmpty())
return RenderFrame::CONTENT_STATUS_UNKNOWN_SIZE;
if (unobscured_size.width() <= kTinyContentSize &&
unobscured_size.height() <= kTinyContentSize) {
if (IsTiny(unobscured_size))
return RenderFrame::CONTENT_STATUS_TINY;
}
if (IsLargeContent(unobscured_size))
return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG;
......
......@@ -4,6 +4,8 @@
#include "content/renderer/peripheral_content_heuristic.h"
#include "base/test/scoped_feature_list.h"
#include "content/public/common/content_features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
#include "url/gurl.h"
......@@ -59,6 +61,16 @@ TEST(PeripheralContentHeuristic, TinyContent) {
url::Origin(GURL(kOtherOrigin)), gfx::Size(10, 10)));
}
TEST(PeripheralContentHeuristic, FilterSameOriginTinyPlugins) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndEnableFeature(features::kFilterSameOriginTinyPlugin);
EXPECT_EQ(RenderFrame::CONTENT_STATUS_TINY,
PeripheralContentHeuristic::GetPeripheralStatus(
std::set<url::Origin>(), url::Origin(GURL(kSameOrigin)),
url::Origin(GURL(kSameOrigin)), gfx::Size(1, 1)));
}
TEST(PeripheralContentHeuristic, TemporaryOriginWhitelist) {
EXPECT_EQ(RenderFrame::CONTENT_STATUS_PERIPHERAL,
PeripheralContentHeuristic::GetPeripheralStatus(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment