| OLD | NEW |
| 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" | 9 #include "base/feature_list.h" |
| 10 #include "content/public/common/content_features.h" | 10 #include "content/public/common/content_features.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 const int kLargeContentMinHeight = 298; | 25 const int kLargeContentMinHeight = 298; |
| 26 | 26 |
| 27 // 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 |
| 28 // 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 |
| 29 // requirement, even if it is below the max width/height above. | 29 // requirement, even if it is below the max width/height above. |
| 30 const double kEssentialVideoAspectRatio = 16.0 / 9.0; | 30 const double kEssentialVideoAspectRatio = 16.0 / 9.0; |
| 31 const double kAspectRatioEpsilon = 0.01; | 31 const double kAspectRatioEpsilon = 0.01; |
| 32 const int kEssentialVideoMinimumArea = 120000; | 32 const int kEssentialVideoMinimumArea = 120000; |
| 33 | 33 |
| 34 bool IsTiny(const gfx::Size& unobscured_size) { | 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 && | 35 return unobscured_size.width() <= kTinyContentSize && |
| 41 unobscured_size.height() <= kTinyContentSize; | 36 unobscured_size.height() <= kTinyContentSize; |
| 42 } | 37 } |
| 43 | 38 |
| 44 } // namespace | 39 } // namespace |
| 45 | 40 |
| 46 // static | 41 // static |
| 47 RenderFrame::PeripheralContentStatus | 42 RenderFrame::PeripheralContentStatus |
| 48 PeripheralContentHeuristic::GetPeripheralStatus( | 43 PeripheralContentHeuristic::GetPeripheralStatus( |
| 49 const std::set<url::Origin>& origin_whitelist, | 44 const std::set<url::Origin>& origin_whitelist, |
| 50 const url::Origin& main_frame_origin, | 45 const url::Origin& main_frame_origin, |
| 51 const url::Origin& content_origin, | 46 const url::Origin& content_origin, |
| 52 const gfx::Size& unobscured_size) { | 47 const gfx::Size& unobscured_size) { |
| 53 if (base::FeatureList::IsEnabled(features::kFilterSameOriginTinyPlugin) && | 48 if (base::FeatureList::IsEnabled(features::kFilterSameOriginTinyPlugin) && |
| 54 IsTiny(unobscured_size)) { | 49 IsTiny(unobscured_size)) { |
| 55 return RenderFrame::CONTENT_STATUS_TINY; | 50 return RenderFrame::CONTENT_STATUS_TINY; |
| 56 } | 51 } |
| 57 | 52 |
| 58 if (main_frame_origin.IsSameOriginWith(content_origin)) | 53 if (main_frame_origin.IsSameOriginWith(content_origin)) |
| 59 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN; | 54 return RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN; |
| 60 | 55 |
| 61 if (origin_whitelist.count(content_origin)) | 56 if (origin_whitelist.count(content_origin)) |
| 62 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED; | 57 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED; |
| 63 | 58 |
| 64 if (unobscured_size.IsEmpty()) | |
| 65 return RenderFrame::CONTENT_STATUS_UNKNOWN_SIZE; | |
| 66 | |
| 67 if (IsTiny(unobscured_size)) | 59 if (IsTiny(unobscured_size)) |
| 68 return RenderFrame::CONTENT_STATUS_TINY; | 60 return RenderFrame::CONTENT_STATUS_TINY; |
| 69 | 61 |
| 70 if (IsLargeContent(unobscured_size)) | 62 if (IsLargeContent(unobscured_size)) |
| 71 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG; | 63 return RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG; |
| 72 | 64 |
| 73 return RenderFrame::CONTENT_STATUS_PERIPHERAL; | 65 return RenderFrame::CONTENT_STATUS_PERIPHERAL; |
| 74 } | 66 } |
| 75 | 67 |
| 76 // static | 68 // static |
| 77 bool PeripheralContentHeuristic::IsLargeContent( | 69 bool PeripheralContentHeuristic::IsLargeContent( |
| 78 const gfx::Size& unobscured_size) { | 70 const gfx::Size& unobscured_size) { |
| 79 int width = unobscured_size.width(); | 71 int width = unobscured_size.width(); |
| 80 int height = unobscured_size.height(); | 72 int height = unobscured_size.height(); |
| 81 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight) | 73 if (width >= kLargeContentMinWidth && height >= kLargeContentMinHeight) |
| 82 return true; | 74 return true; |
| 83 | 75 |
| 84 double aspect_ratio = static_cast<double>(width) / height; | 76 double aspect_ratio = static_cast<double>(width) / height; |
| 85 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) < | 77 if (std::abs(aspect_ratio - kEssentialVideoAspectRatio) < |
| 86 kAspectRatioEpsilon && | 78 kAspectRatioEpsilon && |
| 87 width * height >= kEssentialVideoMinimumArea) { | 79 width * height >= kEssentialVideoMinimumArea) { |
| 88 return true; | 80 return true; |
| 89 } | 81 } |
| 90 | 82 |
| 91 return false; | 83 return false; |
| 92 } | 84 } |
| 93 | 85 |
| 94 } // namespace content | 86 } // namespace content |
| OLD | NEW |