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

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

Issue 1497623002: Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 namespace content { 9 namespace content {
10 10
(...skipping 22 matching lines...) Expand all
33 PeripheralContentHeuristic::Decision 33 PeripheralContentHeuristic::Decision
34 PeripheralContentHeuristic::GetPeripheralStatus( 34 PeripheralContentHeuristic::GetPeripheralStatus(
35 const std::set<url::Origin>& origin_whitelist, 35 const std::set<url::Origin>& origin_whitelist,
36 const url::Origin& main_frame_origin, 36 const url::Origin& main_frame_origin,
37 const url::Origin& content_origin, 37 const url::Origin& content_origin,
38 int width, 38 int width,
39 int height) { 39 int height) {
40 if (main_frame_origin.IsSameOriginWith(content_origin)) 40 if (main_frame_origin.IsSameOriginWith(content_origin))
41 return HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN; 41 return HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN;
42 42
43 if (origin_whitelist.count(content_origin))
groby-ooo-7-16 2015/12/04 22:06:56 Since order matters, probably worth having either
tommycli 2015/12/07 22:06:18 Sounds good. I added a test.
44 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED;
45
43 if (width <= 0 || height <= 0) 46 if (width <= 0 || height <= 0)
44 return HEURISTIC_DECISION_ESSENTIAL_UNKNOWN_SIZE; 47 return HEURISTIC_DECISION_ESSENTIAL_UNKNOWN_SIZE;
45 48
46 if (origin_whitelist.count(content_origin))
47 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED;
48
49 if (width <= kTinyContentSize && height <= kTinyContentSize) 49 if (width <= kTinyContentSize && height <= kTinyContentSize)
50 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY; 50 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY;
51 51
52 if (IsLargeContent(width, height)) 52 if (IsLargeContent(width, height))
53 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG; 53 return HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG;
54 54
55 return HEURISTIC_DECISION_PERIPHERAL; 55 return HEURISTIC_DECISION_PERIPHERAL;
56 } 56 }
57 57
58 // static 58 // static
59 bool PeripheralContentHeuristic::IsLargeContent(int width, int height) { 59 bool PeripheralContentHeuristic::IsLargeContent(int width, int height) {
60 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight) 60 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight)
61 return true; 61 return true;
62 62
63 double aspect_ratio = static_cast<double>(width) / height; 63 double aspect_ratio = static_cast<double>(width) / height;
64 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) < 64 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) <
65 kAspectRatioEpsilon && 65 kAspectRatioEpsilon &&
66 width * height >= kEssentialVideoMinimumArea) { 66 width * height >= kEssentialVideoMinimumArea) {
67 return true; 67 return true;
68 } 68 }
69 69
70 return false; 70 return false;
71 } 71 }
72 72
73 } // namespace content 73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698