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

Side by Side Diff: content/renderer/peripheral_content_heuristic.cc

Issue 2627493002: [PPS] Exclude same-origin tiny plugins. (Closed)
Patch Set: fix test Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/renderer/peripheral_content_heuristic.h" 5 #include "content/renderer/peripheral_content_heuristic.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/feature_list.h"
10 #include "content/public/common/content_features.h"
9 #include "ui/gfx/geometry/size.h" 11 #include "ui/gfx/geometry/size.h"
10 12
11 namespace content { 13 namespace content {
12 14
13 namespace { 15 namespace {
14 16
15 // Content below this size in height and width is considered "tiny". 17 // Content below this size in height and width is considered "tiny".
16 // Tiny content is never peripheral, as tiny plugins often serve a critical 18 // Tiny content is never peripheral, as tiny plugins often serve a critical
17 // purpose, and the user often cannot find and click to unthrottle it. 19 // purpose, and the user often cannot find and click to unthrottle it.
18 const int kTinyContentSize = 5; 20 const int kTinyContentSize = 5;
19 21
20 // Cross-origin content must have a width and height both exceeding these 22 // Cross-origin content must have a width and height both exceeding these
21 // minimums to be considered "large", and thus not peripheral. 23 // minimums to be considered "large", and thus not peripheral.
22 const int kLargeContentMinWidth = 398; 24 const int kLargeContentMinWidth = 398;
23 const int kLargeContentMinHeight = 298; 25 const int kLargeContentMinHeight = 298;
24 26
25 // Mark some 16:9 aspect ratio content as essential (not peripheral). This is to 27 // Mark some 16:9 aspect ratio content as essential (not peripheral). This is to
26 // mark as "large" some medium sized video content that meets a minimum area 28 // mark as "large" some medium sized video content that meets a minimum area
27 // requirement, even if it is below the max width/height above. 29 // requirement, even if it is below the max width/height above.
28 const double kEssentialVideoAspectRatio = 16.0 / 9.0; 30 const double kEssentialVideoAspectRatio = 16.0 / 9.0;
29 const double kAspectRatioEpsilon = 0.01; 31 const double kAspectRatioEpsilon = 0.01;
30 const int kEssentialVideoMinimumArea = 120000; 32 const int kEssentialVideoMinimumArea = 120000;
31 33
34 bool IsTiny(const gfx::Size& unobscured_size) {
35 // Empty plugins can't be classified as tiny - they might just be of unknown
36 // size.
37 if (unobscured_size.IsEmpty())
38 return false;
39
40 return unobscured_size.width() <= kTinyContentSize &&
41 unobscured_size.height() <= kTinyContentSize;
42 }
43
32 } // namespace 44 } // namespace
33 45
34 // static 46 // static
35 RenderFrame::PeripheralContentStatus 47 RenderFrame::PeripheralContentStatus
36 PeripheralContentHeuristic::GetPeripheralStatus( 48 PeripheralContentHeuristic::GetPeripheralStatus(
37 const std::set<url::Origin>& origin_whitelist, 49 const std::set<url::Origin>& origin_whitelist,
38 const url::Origin& main_frame_origin, 50 const url::Origin& main_frame_origin,
39 const url::Origin& content_origin, 51 const url::Origin& content_origin,
40 const gfx::Size& unobscured_size) { 52 const gfx::Size& unobscured_size) {
53 if (base::FeatureList::IsEnabled(features::kFilterSameOriginTinyPlugin) &&
54 IsTiny(unobscured_size)) {
55 return RenderFrame::CONTENT_STATUS_TINY;
56 }
57
41 if (main_frame_origin.IsSameOriginWith(content_origin)) 58 if (main_frame_origin.IsSameOriginWith(content_origin))
42 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN; 59 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN;
43 60
44 if (origin_whitelist.count(content_origin)) 61 if (origin_whitelist.count(content_origin))
45 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED; 62 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED;
46 63
47 if (unobscured_size.IsEmpty()) 64 if (unobscured_size.IsEmpty())
48 return RenderFrame::CONTENT_STATUS_UNKNOWN_SIZE; 65 return RenderFrame::CONTENT_STATUS_UNKNOWN_SIZE;
49 66
50 if (unobscured_size.width() <= kTinyContentSize && 67 if (IsTiny(unobscured_size))
51 unobscured_size.height() <= kTinyContentSize) {
52 return RenderFrame::CONTENT_STATUS_TINY; 68 return RenderFrame::CONTENT_STATUS_TINY;
53 }
54 69
55 if (IsLargeContent(unobscured_size)) 70 if (IsLargeContent(unobscured_size))
56 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG; 71 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG;
57 72
58 return RenderFrame::CONTENT_STATUS_PERIPHERAL; 73 return RenderFrame::CONTENT_STATUS_PERIPHERAL;
59 } 74 }
60 75
61 // static 76 // static
62 bool PeripheralContentHeuristic::IsLargeContent( 77 bool PeripheralContentHeuristic::IsLargeContent(
63 const gfx::Size& unobscured_size) { 78 const gfx::Size& unobscured_size) {
64 int width = unobscured_size.width(); 79 int width = unobscured_size.width();
65 int height = unobscured_size.height(); 80 int height = unobscured_size.height();
66 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight) 81 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight)
67 return true; 82 return true;
68 83
69 double aspect_ratio = static_cast<double>(width) / height; 84 double aspect_ratio = static_cast<double>(width) / height;
70 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) < 85 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) <
71 kAspectRatioEpsilon && 86 kAspectRatioEpsilon &&
72 width * height >= kEssentialVideoMinimumArea) { 87 width * height >= kEssentialVideoMinimumArea) {
73 return true; 88 return true;
74 } 89 }
75 90
76 return false; 91 return false;
77 } 92 }
78 93
79 } // namespace content 94 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698