OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/renderer/plugins/power_saver_info.h" | 10 #include "chrome/renderer/plugins/power_saver_info.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 !params.attributeValues[i].isEmpty()) { | 64 !params.attributeValues[i].isEmpty()) { |
65 return params.attributeValues[i].utf8(); | 65 return params.attributeValues[i].utf8(); |
66 } | 66 } |
67 } | 67 } |
68 return std::string(); | 68 return std::string(); |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 PowerSaverInfo::PowerSaverInfo() | 73 PowerSaverInfo::PowerSaverInfo() |
74 : is_eligible(false), | 74 : power_saver_enabled(false), blocked_for_background_tab(false) {} |
75 power_saver_enabled(false), | |
76 blocked_for_background_tab(false) {} | |
77 | 75 |
78 PowerSaverInfo::PowerSaverInfo(const PowerSaverInfo& other) = default; | 76 PowerSaverInfo::PowerSaverInfo(const PowerSaverInfo& other) = default; |
79 | 77 |
80 PowerSaverInfo PowerSaverInfo::Get(content::RenderFrame* render_frame, | 78 PowerSaverInfo PowerSaverInfo::Get(content::RenderFrame* render_frame, |
81 bool power_saver_setting_on, | 79 bool power_saver_setting_on, |
82 const blink::WebPluginParams& params, | 80 const blink::WebPluginParams& params, |
83 const content::WebPluginInfo& plugin_info, | 81 const content::WebPluginInfo& plugin_info, |
84 const GURL& document_url) { | 82 const GURL& document_url) { |
85 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 83 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
86 std::string override_for_testing = command_line->GetSwitchValueASCII( | 84 std::string override_for_testing = command_line->GetSwitchValueASCII( |
87 switches::kOverridePluginPowerSaverForTesting); | 85 switches::kOverridePluginPowerSaverForTesting); |
88 | 86 |
89 // This feature has only been tested thoroughly with Flash thus far. | 87 // This feature has only been tested thoroughly with Flash thus far. |
90 // It is also enabled for the Power Saver test plugin for browser tests. | 88 // It is also enabled for the Power Saver test plugin for browser tests. |
91 bool is_flash = | 89 bool is_flash = |
92 plugin_info.name == base::ASCIIToUTF16(content::kFlashPluginName); | 90 plugin_info.name == base::ASCIIToUTF16(content::kFlashPluginName); |
93 | 91 |
94 PowerSaverInfo info; | 92 PowerSaverInfo info; |
95 info.is_eligible = power_saver_setting_on && | 93 bool is_eligible = power_saver_setting_on && |
96 (is_flash || override_for_testing == "ignore-list"); | 94 (is_flash || override_for_testing == "ignore-list"); |
97 info.power_saver_enabled = override_for_testing == "always" || | 95 info.power_saver_enabled = override_for_testing == "always" || |
98 (power_saver_setting_on && info.is_eligible); | 96 (power_saver_setting_on && is_eligible); |
99 | 97 |
100 if (info.power_saver_enabled) { | 98 if (info.power_saver_enabled) { |
101 // Even if we disable PPS in the next block because content is same-origin, | 99 // Even if we disable PPS in the next block because content is same-origin, |
102 // it should still be eligible for background tab deferral if PPS is on. | 100 // it should still be eligible for background tab deferral if PPS is on. |
103 info.blocked_for_background_tab = render_frame->IsHidden(); | 101 info.blocked_for_background_tab = render_frame->IsHidden(); |
104 | 102 |
105 auto status = render_frame->GetPeripheralContentStatus( | 103 auto status = render_frame->GetPeripheralContentStatus( |
106 render_frame->GetWebFrame()->top()->getSecurityOrigin(), | 104 render_frame->GetWebFrame()->top()->getSecurityOrigin(), |
107 url::Origin(params.url), gfx::Size()); | 105 url::Origin(params.url), gfx::Size()); |
108 | 106 |
(...skipping 11 matching lines...) Expand all Loading... |
120 info.poster_attribute = GetPluginInstancePosterAttribute(params); | 118 info.poster_attribute = GetPluginInstancePosterAttribute(params); |
121 info.base_url = document_url; | 119 info.base_url = document_url; |
122 } | 120 } |
123 } | 121 } |
124 | 122 |
125 if (is_flash) | 123 if (is_flash) |
126 TrackPosterParamPresence(params, info.power_saver_enabled); | 124 TrackPosterParamPresence(params, info.power_saver_enabled); |
127 | 125 |
128 return info; | 126 return info; |
129 } | 127 } |
OLD | NEW |