Chromium Code Reviews| 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/metrics/histogram.h" | |
| 6 #include "content/common/frame_messages.h" | 7 #include "content/common/frame_messages.h" |
| 7 #include "content/public/renderer/document_state.h" | 8 #include "content/public/renderer/document_state.h" |
| 8 #include "content/public/renderer/navigation_state.h" | 9 #include "content/public/renderer/navigation_state.h" |
| 9 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
| 10 #include "content/renderer/pepper/plugin_power_saver_helper.h" | 11 #include "content/renderer/pepper/plugin_power_saver_helper.h" |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" | 12 #include "third_party/WebKit/public/web/WebDocument.h" |
| 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 13 #include "third_party/WebKit/public/web/WebView.h" | 14 #include "third_party/WebKit/public/web/WebView.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 20 // Initial decision of the peripheral content decision. | |
| 21 // These numeric values are used in UMA logs; do not change them. | |
| 22 enum PeripheralHeuristicDecision { | |
| 23 PERIPHERAL_HEURISTIC_DECISION_PERIPHERAL = 0, | |
| 24 PERIPHERAL_HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN = 1, | |
| 25 PERIPHERAL_HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG = 2, | |
| 26 PERIPHERAL_HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED = 2, | |
|
Lei Zhang
2014/11/05 01:23:49
value should be 3?
tommycli
2014/11/05 19:01:41
Done.
| |
| 27 PERIPHERAL_HEURISTIC_DECISION_NUM_ITEMS | |
| 28 }; | |
| 29 | |
| 30 const char kPeripheralHeuristicHistogram[] = | |
| 31 "Plugin.PowerSaverPeripheralHeuristic"; | |
| 32 | |
| 19 // Maximum dimensions plug-in content may have while still being considered | 33 // Maximum dimensions plug-in content may have while still being considered |
| 20 // peripheral content. These match the sizes used by Safari. | 34 // peripheral content. These match the sizes used by Safari. |
| 21 const int kPeripheralContentMaxWidth = 400; | 35 const int kPeripheralContentMaxWidth = 400; |
| 22 const int kPeripheralContentMaxHeight = 300; | 36 const int kPeripheralContentMaxHeight = 300; |
| 23 | 37 |
| 24 } // namespace | 38 } // namespace |
| 25 | 39 |
| 26 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( | 40 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( |
| 27 const GURL& content_origin, | 41 const GURL& content_origin, |
| 28 const base::Closure& unthrottle_callback) | 42 const base::Closure& unthrottle_callback) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 int height, | 96 int height, |
| 83 bool* cross_origin) const { | 97 bool* cross_origin) const { |
| 84 DCHECK(cross_origin); | 98 DCHECK(cross_origin); |
| 85 *cross_origin = true; | 99 *cross_origin = true; |
| 86 | 100 |
| 87 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 | 101 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 |
| 88 // is fixed. For now, case 3 in the class level comment doesn't work in | 102 // is fixed. For now, case 3 in the class level comment doesn't work in |
| 89 // --site-per-process mode. | 103 // --site-per-process mode. |
| 90 blink::WebFrame* main_frame = | 104 blink::WebFrame* main_frame = |
| 91 render_frame()->GetWebFrame()->view()->mainFrame(); | 105 render_frame()->GetWebFrame()->view()->mainFrame(); |
| 92 if (main_frame->isWebRemoteFrame()) | 106 if (main_frame->isWebRemoteFrame()) { |
| 107 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, | |
| 108 PERIPHERAL_HEURISTIC_DECISION_PERIPHERAL, | |
| 109 PERIPHERAL_HEURISTIC_DECISION_NUM_ITEMS); | |
| 93 return true; | 110 return true; |
| 111 } | |
| 94 | 112 |
| 95 // All same-origin plugin content is essential. | 113 // All same-origin plugin content is essential. |
| 96 GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin(); | 114 GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin(); |
| 97 if (content_origin == main_frame_origin) { | 115 if (content_origin == main_frame_origin) { |
| 116 UMA_HISTOGRAM_ENUMERATION( | |
| 117 kPeripheralHeuristicHistogram, | |
| 118 PERIPHERAL_HEURISTIC_DECISION_ESSENTIAL_SAME_ORIGIN, | |
| 119 PERIPHERAL_HEURISTIC_DECISION_NUM_ITEMS); | |
| 98 *cross_origin = false; | 120 *cross_origin = false; |
| 99 return false; | 121 return false; |
| 100 } | 122 } |
| 101 | 123 |
| 102 // Whitelisted plugin origins are also essential. | 124 // Whitelisted plugin origins are also essential. |
| 103 if (origin_whitelist_.count(content_origin)) | 125 if (origin_whitelist_.count(content_origin)) { |
| 126 UMA_HISTOGRAM_ENUMERATION( | |
| 127 kPeripheralHeuristicHistogram, | |
| 128 PERIPHERAL_HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_WHITELISTED, | |
| 129 PERIPHERAL_HEURISTIC_DECISION_NUM_ITEMS); | |
| 104 return false; | 130 return false; |
| 131 } | |
| 105 | 132 |
| 106 // Cross-origin plugin content is peripheral if smaller than a maximum size. | 133 // Cross-origin plugin content is peripheral if smaller than a maximum size. |
| 107 bool content_is_small = width < kPeripheralContentMaxWidth || | 134 bool content_is_small = width < kPeripheralContentMaxWidth || |
| 108 height < kPeripheralContentMaxHeight; | 135 height < kPeripheralContentMaxHeight; |
| 109 | 136 |
| 137 if (content_is_small) { | |
| 138 UMA_HISTOGRAM_ENUMERATION(kPeripheralHeuristicHistogram, | |
| 139 PERIPHERAL_HEURISTIC_DECISION_PERIPHERAL, | |
| 140 PERIPHERAL_HEURISTIC_DECISION_NUM_ITEMS); | |
| 141 } else { | |
| 142 UMA_HISTOGRAM_ENUMERATION( | |
| 143 kPeripheralHeuristicHistogram, | |
| 144 PERIPHERAL_HEURISTIC_DECISION_ESSENTIAL_CROSS_ORIGIN_BIG, | |
| 145 PERIPHERAL_HEURISTIC_DECISION_NUM_ITEMS); | |
| 146 } | |
| 110 return content_is_small; | 147 return content_is_small; |
| 111 } | 148 } |
| 112 | 149 |
| 113 void PluginPowerSaverHelper::RegisterPeripheralPlugin( | 150 void PluginPowerSaverHelper::RegisterPeripheralPlugin( |
| 114 const GURL& content_origin, | 151 const GURL& content_origin, |
| 115 const base::Closure& unthrottle_callback) { | 152 const base::Closure& unthrottle_callback) { |
| 116 peripheral_plugins_.push_back( | 153 peripheral_plugins_.push_back( |
| 117 PeripheralPlugin(content_origin, unthrottle_callback)); | 154 PeripheralPlugin(content_origin, unthrottle_callback)); |
| 118 } | 155 } |
| 119 | 156 |
| 120 void PluginPowerSaverHelper::WhitelistContentOrigin( | 157 void PluginPowerSaverHelper::WhitelistContentOrigin( |
| 121 const GURL& content_origin) { | 158 const GURL& content_origin) { |
| 122 if (origin_whitelist_.insert(content_origin).second) { | 159 if (origin_whitelist_.insert(content_origin).second) { |
| 123 Send(new FrameHostMsg_PluginContentOriginAllowed( | 160 Send(new FrameHostMsg_PluginContentOriginAllowed( |
| 124 render_frame()->GetRoutingID(), content_origin)); | 161 render_frame()->GetRoutingID(), content_origin)); |
| 125 } | 162 } |
| 126 } | 163 } |
| 127 | 164 |
| 128 } // namespace content | 165 } // namespace content |
| OLD | NEW |