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

Side by Side Diff: content/renderer/pepper/plugin_power_saver_helper.cc

Issue 1341563002: Plugin Power Saver: Improve origin handling esp. with OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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/pepper/plugin_power_saver_helper.h" 5 #include "content/renderer/pepper/plugin_power_saver_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 14 matching lines...) Expand all
25 namespace { 25 namespace {
26 26
27 // Initial decision of the peripheral content decision. 27 // Initial decision of the peripheral content decision.
28 // These numeric values are used in UMA logs; do not change them. 28 // These numeric values are used in UMA logs; do not change them.
29 enum PeripheralHeuristicDecision { 29 enum PeripheralHeuristicDecision {
30 HEURISTIC_DECISION_PERIPHERAL = 0, 30 HEURISTIC_DECISION_PERIPHERAL = 0,
31 HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1, 31 HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1,
32 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2, 32 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2,
33 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 3, 33 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 3,
34 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY = 4, 34 HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY = 4,
35 HEURISTIC_DECISION_ESSENTIAL_UNKNOWN_SIZE = 5,
35 HEURISTIC_DECISION_NUM_ITEMS 36 HEURISTIC_DECISION_NUM_ITEMS
36 }; 37 };
37 38
38 const char kPeripheralHeuristicHistogram[] = 39 const char kPeripheralHeuristicHistogram[] =
39 "Plugin.PowerSaver.PeripheralHeuristic"; 40 "Plugin.PowerSaver.PeripheralHeuristic";
40 41
41 // Plugin content below this size in height and width is considered "tiny". 42 // Plugin content below this size in height and width is considered "tiny".
42 // Tiny content is never peripheral, as tiny plugins often serve a critical 43 // Tiny content is never peripheral, as tiny plugins often serve a critical
43 // purpose, and the user often cannot find and click to unthrottle it. 44 // purpose, and the user often cannot find and click to unthrottle it.
44 const int kPeripheralContentTinySize = 5; 45 const int kPeripheralContentTinySize = 5;
45 46
46 void RecordDecisionMetric(PeripheralHeuristicDecision decision) { 47 void RecordDecisionMetric(PeripheralHeuristicDecision decision) {
47 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, decision, 48 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, decision,
48 HEURISTIC_DECISION_NUM_ITEMS); 49 HEURISTIC_DECISION_NUM_ITEMS);
49 } 50 }
50 51
51 } // namespace 52 } // namespace
52 53
53 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( 54 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin(
54 const GURL& content_origin, 55 const url::Origin& content_origin,
55 const base::Closure& unthrottle_callback) 56 const base::Closure& unthrottle_callback)
56 : content_origin(content_origin), unthrottle_callback(unthrottle_callback) { 57 : content_origin(content_origin), unthrottle_callback(unthrottle_callback) {
57 } 58 }
58 59
59 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() { 60 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() {
60 } 61 }
61 62
62 PluginPowerSaverHelper::PluginPowerSaverHelper(RenderFrame* render_frame) 63 PluginPowerSaverHelper::PluginPowerSaverHelper(RenderFrame* render_frame)
63 : RenderFrameObserver(render_frame) 64 : RenderFrameObserver(render_frame)
64 , override_for_testing_(Normal) { 65 , override_for_testing_(Normal) {
(...skipping 26 matching lines...) Expand all
91 bool handled = true; 92 bool handled = true;
92 IPC_BEGIN_MESSAGE_MAP(PluginPowerSaverHelper, message) 93 IPC_BEGIN_MESSAGE_MAP(PluginPowerSaverHelper, message)
93 IPC_MESSAGE_HANDLER(FrameMsg_UpdatePluginContentOriginWhitelist, 94 IPC_MESSAGE_HANDLER(FrameMsg_UpdatePluginContentOriginWhitelist,
94 OnUpdatePluginContentOriginWhitelist) 95 OnUpdatePluginContentOriginWhitelist)
95 IPC_MESSAGE_UNHANDLED(handled = false) 96 IPC_MESSAGE_UNHANDLED(handled = false)
96 IPC_END_MESSAGE_MAP() 97 IPC_END_MESSAGE_MAP()
97 return handled; 98 return handled;
98 } 99 }
99 100
100 void PluginPowerSaverHelper::OnUpdatePluginContentOriginWhitelist( 101 void PluginPowerSaverHelper::OnUpdatePluginContentOriginWhitelist(
101 const std::set<GURL>& origin_whitelist) { 102 const std::set<url::Origin>& origin_whitelist) {
102 origin_whitelist_ = origin_whitelist; 103 origin_whitelist_ = origin_whitelist;
103 104
104 // Check throttled plugin instances to see if any can be unthrottled. 105 // Check throttled plugin instances to see if any can be unthrottled.
105 auto it = peripheral_plugins_.begin(); 106 auto it = peripheral_plugins_.begin();
106 while (it != peripheral_plugins_.end()) { 107 while (it != peripheral_plugins_.end()) {
107 if (origin_whitelist.count(it->content_origin)) { 108 if (origin_whitelist.count(it->content_origin)) {
108 it->unthrottle_callback.Run(); 109 it->unthrottle_callback.Run();
109 it = peripheral_plugins_.erase(it); 110 it = peripheral_plugins_.erase(it);
110 } else { 111 } else {
111 ++it; 112 ++it;
112 } 113 }
113 } 114 }
114 } 115 }
115 116
116 void PluginPowerSaverHelper::RegisterPeripheralPlugin( 117 void PluginPowerSaverHelper::RegisterPeripheralPlugin(
117 const GURL& content_origin, 118 const url::Origin& content_origin,
118 const base::Closure& unthrottle_callback) { 119 const base::Closure& unthrottle_callback) {
119 DCHECK_EQ(content_origin.GetOrigin(), content_origin);
120 peripheral_plugins_.push_back( 120 peripheral_plugins_.push_back(
121 PeripheralPlugin(content_origin, unthrottle_callback)); 121 PeripheralPlugin(content_origin, unthrottle_callback));
122 } 122 }
123 123
124 bool PluginPowerSaverHelper::ShouldThrottleContent( 124 bool PluginPowerSaverHelper::ShouldThrottleContent(
125 const GURL& content_origin, 125 const url::Origin& content_origin,
126 const std::string& plugin_module_name, 126 const std::string& plugin_module_name,
127 int width, 127 int width,
128 int height, 128 int height,
129 bool* cross_origin_main_content) const { 129 bool* cross_origin_main_content) const {
130 DCHECK_EQ(content_origin.GetOrigin(), content_origin);
131 if (cross_origin_main_content) 130 if (cross_origin_main_content)
132 *cross_origin_main_content = false; 131 *cross_origin_main_content = false;
133 132
134 // This feature has only been tested throughly with Flash thus far. 133 // This feature has only been tested throughly with Flash thus far.
135 // It is also enabled for the Power Saver test plugin for browser tests. 134 // It is also enabled for the Power Saver test plugin for browser tests.
136 if (override_for_testing_ == Always) { 135 if (override_for_testing_ == Always) {
137 return true; 136 return true;
138 } else if (override_for_testing_ == Never) { 137 } else if (override_for_testing_ == Never) {
139 return false; 138 return false;
140 } else if (override_for_testing_ == Normal && 139 } else if (override_for_testing_ == Normal &&
141 plugin_module_name != content::kFlashPluginName) { 140 plugin_module_name != content::kFlashPluginName) {
142 return false; 141 return false;
143 } 142 }
144 143
145 if (width <= 0 || height <= 0)
146 return false;
147
148 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512
149 // is fixed. For now, case 3 in the class level comment doesn't work in
150 // --site-per-process mode.
151 blink::WebFrame* main_frame = 144 blink::WebFrame* main_frame =
152 render_frame()->GetWebFrame()->view()->mainFrame(); 145 render_frame()->GetWebFrame()->view()->mainFrame();
153 if (main_frame->isWebRemoteFrame()) { 146
154 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL); 147 url::Origin document_origin = main_frame->document().securityOrigin();
alexmos 2015/09/14 17:32:50 You probably want to use main_frame->securityOrigi
tommycli 2015/09/14 20:23:56 Done.
155 return true; 148 if (document_origin.IsSameOriginWith(content_origin)) {
149 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN);
150 return false;
156 } 151 }
157 152
158 // All same-origin plugin content is essential. 153 if (width <= 0 || height <= 0) {
159 GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin(); 154 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_UNKNOWN_SIZE);
160 if (content_origin == main_frame_origin) {
161 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN);
162 return false; 155 return false;
163 } 156 }
164 157
165 // Whitelisted plugin origins are also essential. 158 // Whitelisted plugin origins are also essential.
166 if (origin_whitelist_.count(content_origin)) { 159 if (origin_whitelist_.count(content_origin)) {
167 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED); 160 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED);
168 return false; 161 return false;
169 } 162 }
170 163
171 // Never mark tiny content as peripheral. 164 // Never mark tiny content as peripheral.
172 if (width <= kPeripheralContentTinySize && 165 if (width <= kPeripheralContentTinySize &&
173 height <= kPeripheralContentTinySize) { 166 height <= kPeripheralContentTinySize) {
174 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY); 167 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_TINY);
175 return false; 168 return false;
176 } 169 }
177 170
178 // Plugin content large in both dimensions are the "main attraction". 171 // Plugin content large in both dimensions are the "main attraction".
179 if (PluginInstanceThrottler::IsLargeContent(width, height)) { 172 if (PluginInstanceThrottler::IsLargeContent(width, height)) {
180 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG); 173 RecordDecisionMetric(HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG);
181 if (cross_origin_main_content) 174 if (cross_origin_main_content)
182 *cross_origin_main_content = true; 175 *cross_origin_main_content = true;
183 return false; 176 return false;
184 } 177 }
185 178
186 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL); 179 RecordDecisionMetric(HEURISTIC_DECISION_PERIPHERAL);
187 return true; 180 return true;
188 } 181 }
189 182
190 void PluginPowerSaverHelper::WhitelistContentOrigin( 183 void PluginPowerSaverHelper::WhitelistContentOrigin(
191 const GURL& content_origin) { 184 const url::Origin& content_origin) {
192 DCHECK_EQ(content_origin.GetOrigin(), content_origin);
193 if (origin_whitelist_.insert(content_origin).second) { 185 if (origin_whitelist_.insert(content_origin).second) {
194 Send(new FrameHostMsg_PluginContentOriginAllowed( 186 Send(new FrameHostMsg_PluginContentOriginAllowed(
195 render_frame()->GetRoutingID(), content_origin)); 187 render_frame()->GetRoutingID(), content_origin));
196 } 188 }
197 } 189 }
198 190
199 } // namespace content 191 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698