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

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

Issue 2627513002: Plugin Power Saver: Refactor some Tiny plugin code and tests. (Closed)
Patch Set: Also update histograms.xml 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 "ui/gfx/geometry/size.h" 9 #include "ui/gfx/geometry/size.h"
10 10
(...skipping 27 matching lines...) Expand all
38 const url::Origin& main_frame_origin, 38 const url::Origin& main_frame_origin,
39 const url::Origin& content_origin, 39 const url::Origin& content_origin,
40 const gfx::Size& unobscured_size) { 40 const gfx::Size& unobscured_size) {
41 if (main_frame_origin.IsSameOriginWith(content_origin)) 41 if (main_frame_origin.IsSameOriginWith(content_origin))
42 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN; 42 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN;
43 43
44 if (origin_whitelist.count(content_origin)) 44 if (origin_whitelist.count(content_origin))
45 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED; 45 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED;
46 46
47 if (unobscured_size.IsEmpty()) 47 if (unobscured_size.IsEmpty())
48 return RenderFrame::CONTENT_STATUS_ESSENTIAL_UNKNOWN_SIZE; 48 return RenderFrame::CONTENT_STATUS_UNKNOWN_SIZE;
49 49
50 if (unobscured_size.width() <= kTinyContentSize && 50 if (unobscured_size.width() <= kTinyContentSize &&
51 unobscured_size.height() <= kTinyContentSize) { 51 unobscured_size.height() <= kTinyContentSize) {
52 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_TINY; 52 return RenderFrame::CONTENT_STATUS_TINY;
53 } 53 }
54 54
55 if (IsLargeContent(unobscured_size)) 55 if (IsLargeContent(unobscured_size))
56 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG; 56 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG;
57 57
58 return RenderFrame::CONTENT_STATUS_PERIPHERAL; 58 return RenderFrame::CONTENT_STATUS_PERIPHERAL;
59 } 59 }
60 60
61 // static 61 // static
62 bool PeripheralContentHeuristic::IsLargeContent( 62 bool PeripheralContentHeuristic::IsLargeContent(
63 const gfx::Size& unobscured_size) { 63 const gfx::Size& unobscured_size) {
64 int width = unobscured_size.width(); 64 int width = unobscured_size.width();
65 int height = unobscured_size.height(); 65 int height = unobscured_size.height();
66 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight) 66 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight)
67 return true; 67 return true;
68 68
69 double aspect_ratio = static_cast<double>(width) / height; 69 double aspect_ratio = static_cast<double>(width) / height;
70 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) < 70 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) <
71 kAspectRatioEpsilon && 71 kAspectRatioEpsilon &&
72 width * height >= kEssentialVideoMinimumArea) { 72 width * height >= kEssentialVideoMinimumArea) {
73 return true; 73 return true;
74 } 74 }
75 75
76 return false; 76 return false;
77 } 77 }
78 78
79 } // namespace content 79 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.cc ('k') | content/renderer/peripheral_content_heuristic_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698