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

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

Issue 1522173002: Reland: Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix an NPE crash/race on plugin destruction Created 5 years 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 "ui/gfx/geometry/size.h"
10
9 namespace content { 11 namespace content {
10 12
11 namespace { 13 namespace {
12 14
13 // Content below this size in height and width is considered "tiny". 15 // Content below this size in height and width is considered "tiny".
14 // Tiny content is never peripheral, as tiny plugins often serve a critical 16 // Tiny content is never peripheral, as tiny plugins often serve a critical
15 // purpose, and the user often cannot find and click to unthrottle it. 17 // purpose, and the user often cannot find and click to unthrottle it.
16 const int kTinyContentSize = 5; 18 const int kTinyContentSize = 5;
17 19
18 // Cross-origin content must have a width and height both exceeding these 20 // Cross-origin content must have a width and height both exceeding these
19 // minimums to be considered "large", and thus not peripheral. 21 // minimums to be considered "large", and thus not peripheral.
20 const int kLargeContentMinWidth = 398; 22 const int kLargeContentMinWidth = 398;
21 const int kLargeContentMinHeight = 298; 23 const int kLargeContentMinHeight = 298;
22 24
23 // Mark some 16:9 aspect ratio content as essential (not peripheral). This is to 25 // Mark some 16:9 aspect ratio content as essential (not peripheral). This is to
24 // mark as "large" some medium sized video content that meets a minimum area 26 // mark as "large" some medium sized video content that meets a minimum area
25 // requirement, even if it is below the max width/height above. 27 // requirement, even if it is below the max width/height above.
26 const double kEssentialVideoAspectRatio = 16.0 / 9.0; 28 const double kEssentialVideoAspectRatio = 16.0 / 9.0;
27 const double kAspectRatioEpsilon = 0.01; 29 const double kAspectRatioEpsilon = 0.01;
28 const int kEssentialVideoMinimumArea = 120000; 30 const int kEssentialVideoMinimumArea = 120000;
29 31
30 } // namespace 32 } // namespace
31 33
32 // static 34 // static
33 PeripheralContentHeuristic::Decision 35 RenderFrame::PeripheralContentStatus
34 PeripheralContentHeuristic::GetPeripheralStatus( 36 PeripheralContentHeuristic::GetPeripheralStatus(
35 const std::set<url::Origin>& origin_whitelist, 37 const std::set<url::Origin>& origin_whitelist,
36 const url::Origin& main_frame_origin, 38 const url::Origin& main_frame_origin,
37 const url::Origin& content_origin, 39 const url::Origin& content_origin,
38 int width, 40 const gfx::Size& unobscured_size) {
39 int height) {
40 if (main_frame_origin.IsSameOriginWith(content_origin)) 41 if (main_frame_origin.IsSameOriginWith(content_origin))
41 return HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN; 42 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN;
42
43 if (width <= 0 || height <= 0)
44 return HEURISTIC_DECISION_ESSENTIAL_UNKNOWN_SIZE;
45 43
46 if (origin_whitelist.count(content_origin)) 44 if (origin_whitelist.count(content_origin))
47 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED; 45 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED;
48 46
49 if (width <= kTinyContentSize && height <= kTinyContentSize) 47 if (unobscured_size.IsEmpty())
50 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY; 48 return RenderFrame::CONTENT_STATUS_ESSENTIAL_UNKNOWN_SIZE;
51 49
52 if (IsLargeContent(width, height)) 50 if (unobscured_size.width() <= kTinyContentSize &&
53 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG; 51 unobscured_size.height() <= kTinyContentSize) {
52 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_TINY;
53 }
54 54
55 return HEURISTIC_DECISION_PERIPHERAL; 55 if (IsLargeContent(unobscured_size))
56 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG;
57
58 return RenderFrame::CONTENT_STATUS_PERIPHERAL;
56 } 59 }
57 60
58 // static 61 // static
59 bool PeripheralContentHeuristic::IsLargeContent(int width, int height) { 62 bool PeripheralContentHeuristic::IsLargeContent(
63 const gfx::Size& unobscured_size) {
64 int width = unobscured_size.width();
65 int height = unobscured_size.height();
60 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight) 66 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight)
61 return true; 67 return true;
62 68
63 double aspect_ratio = static_cast<double>(width) / height; 69 double aspect_ratio = static_cast<double>(width) / height;
64 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) < 70 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) <
65 kAspectRatioEpsilon && 71 kAspectRatioEpsilon &&
66 width * height >= kEssentialVideoMinimumArea) { 72 width * height >= kEssentialVideoMinimumArea) {
67 return true; 73 return true;
68 } 74 }
69 75
70 return false; 76 return false;
71 } 77 }
72 78
73 } // namespace content 79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698