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/pepper/plugin_power_saver_helper.h" | 5 #include "content/renderer/pepper/plugin_power_saver_helper.h" |
6 | 6 |
7 #include <string> | |
8 | |
9 #include "base/command_line.h" | |
7 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
8 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
9 #include "content/common/frame_messages.h" | 12 #include "content/common/frame_messages.h" |
10 #include "content/public/common/content_constants.h" | 13 #include "content/public/common/content_constants.h" |
14 #include "content/public/common/content_switches.h" | |
11 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
12 #include "ppapi/shared_impl/ppapi_constants.h" | 16 #include "ppapi/shared_impl/ppapi_constants.h" |
13 #include "third_party/WebKit/public/web/WebDocument.h" | 17 #include "third_party/WebKit/public/web/WebDocument.h" |
14 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
15 #include "third_party/WebKit/public/web/WebPluginParams.h" | 19 #include "third_party/WebKit/public/web/WebPluginParams.h" |
16 #include "third_party/WebKit/public/web/WebView.h" | 20 #include "third_party/WebKit/public/web/WebView.h" |
17 | 21 |
18 namespace content { | 22 namespace content { |
19 | 23 |
20 namespace { | 24 namespace { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( | 57 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin( |
54 const GURL& content_origin, | 58 const GURL& content_origin, |
55 const base::Closure& unthrottle_callback) | 59 const base::Closure& unthrottle_callback) |
56 : content_origin(content_origin), unthrottle_callback(unthrottle_callback) { | 60 : content_origin(content_origin), unthrottle_callback(unthrottle_callback) { |
57 } | 61 } |
58 | 62 |
59 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() { | 63 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() { |
60 } | 64 } |
61 | 65 |
62 PluginPowerSaverHelper::PluginPowerSaverHelper(RenderFrame* render_frame) | 66 PluginPowerSaverHelper::PluginPowerSaverHelper(RenderFrame* render_frame) |
63 : RenderFrameObserver(render_frame) { | 67 : RenderFrameObserver(render_frame) |
68 , override_for_testing_(Normal) { | |
69 base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); | |
70 std::string override_for_testing = command_line.GetSwitchValueASCII( | |
71 switches::kOverridePluginPowerSaverForTesting); | |
72 if (override_for_testing == "never") | |
73 override_for_testing_ = Never; | |
74 else if (override_for_testing == "ignore-list") | |
75 override_for_testing_ = IgnoreList; | |
76 else if (override_for_testing == "always") | |
77 override_for_testing_ = Always; | |
64 } | 78 } |
65 | 79 |
66 PluginPowerSaverHelper::~PluginPowerSaverHelper() { | 80 PluginPowerSaverHelper::~PluginPowerSaverHelper() { |
67 } | 81 } |
68 | 82 |
69 void PluginPowerSaverHelper::DidCommitProvisionalLoad( | 83 void PluginPowerSaverHelper::DidCommitProvisionalLoad( |
70 bool is_new_navigation, | 84 bool is_new_navigation, |
71 bool is_same_page_navigation) { | 85 bool is_same_page_navigation) { |
72 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 86 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
73 // Only apply to top-level and new page navigation. | 87 // Only apply to top-level and new page navigation. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 const std::string& plugin_module_name, | 130 const std::string& plugin_module_name, |
117 int width, | 131 int width, |
118 int height, | 132 int height, |
119 bool* cross_origin_main_content) const { | 133 bool* cross_origin_main_content) const { |
120 DCHECK_EQ(content_origin.GetOrigin(), content_origin); | 134 DCHECK_EQ(content_origin.GetOrigin(), content_origin); |
121 if (cross_origin_main_content) | 135 if (cross_origin_main_content) |
122 *cross_origin_main_content = false; | 136 *cross_origin_main_content = false; |
123 | 137 |
124 // This feature has only been tested throughly with Flash thus far. | 138 // This feature has only been tested throughly with Flash thus far. |
125 // It is also enabled for the Power Saver test plugin for browser tests. | 139 // It is also enabled for the Power Saver test plugin for browser tests. |
126 if (plugin_module_name != content::kFlashPluginName && | 140 if (override_for_testing_ == Always) |
jam
2015/05/19 15:58:01
nit: i think you need brace brackets here per styl
| |
127 plugin_module_name != ppapi::kPowerSaverTestPluginName) { | 141 return true; |
142 else if (override_for_testing_ == Never) | |
128 return false; | 143 return false; |
129 } | 144 else if (override_for_testing_ == Normal && |
145 plugin_module_name != content::kFlashPluginName) | |
146 return false; | |
130 | 147 |
131 if (width <= 0 || height <= 0) | 148 if (width <= 0 || height <= 0) |
132 return false; | 149 return false; |
133 | 150 |
134 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 | 151 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 |
135 // is fixed. For now, case 3 in the class level comment doesn't work in | 152 // is fixed. For now, case 3 in the class level comment doesn't work in |
136 // --site-per-process mode. | 153 // --site-per-process mode. |
137 blink::WebFrame* main_frame = | 154 blink::WebFrame* main_frame = |
138 render_frame()->GetWebFrame()->view()->mainFrame(); | 155 render_frame()->GetWebFrame()->view()->mainFrame(); |
139 if (main_frame->isWebRemoteFrame()) { | 156 if (main_frame->isWebRemoteFrame()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 void PluginPowerSaverHelper::WhitelistContentOrigin( | 194 void PluginPowerSaverHelper::WhitelistContentOrigin( |
178 const GURL& content_origin) { | 195 const GURL& content_origin) { |
179 DCHECK_EQ(content_origin.GetOrigin(), content_origin); | 196 DCHECK_EQ(content_origin.GetOrigin(), content_origin); |
180 if (origin_whitelist_.insert(content_origin).second) { | 197 if (origin_whitelist_.insert(content_origin).second) { |
181 Send(new FrameHostMsg_PluginContentOriginAllowed( | 198 Send(new FrameHostMsg_PluginContentOriginAllowed( |
182 render_frame()->GetRoutingID(), content_origin)); | 199 render_frame()->GetRoutingID(), content_origin)); |
183 } | 200 } |
184 } | 201 } |
185 | 202 |
186 } // namespace content | 203 } // namespace content |
OLD | NEW |