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

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

Issue 1141793002: Reland: Fix WebViewPlugin::scheduleAnimation crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix style nit Created 5 years, 7 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
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
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
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
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) {
127 plugin_module_name != ppapi::kPowerSaverTestPluginName) { 141 return true;
142 } else if (override_for_testing_ == Never) {
143 return false;
144 } else if (override_for_testing_ == Normal &&
145 plugin_module_name != content::kFlashPluginName) {
128 return false; 146 return false;
129 } 147 }
130 148
131 if (width <= 0 || height <= 0) 149 if (width <= 0 || height <= 0)
132 return false; 150 return false;
133 151
134 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 152 // 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 153 // is fixed. For now, case 3 in the class level comment doesn't work in
136 // --site-per-process mode. 154 // --site-per-process mode.
137 blink::WebFrame* main_frame = 155 blink::WebFrame* main_frame =
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void PluginPowerSaverHelper::WhitelistContentOrigin( 195 void PluginPowerSaverHelper::WhitelistContentOrigin(
178 const GURL& content_origin) { 196 const GURL& content_origin) {
179 DCHECK_EQ(content_origin.GetOrigin(), content_origin); 197 DCHECK_EQ(content_origin.GetOrigin(), content_origin);
180 if (origin_whitelist_.insert(content_origin).second) { 198 if (origin_whitelist_.insert(content_origin).second) {
181 Send(new FrameHostMsg_PluginContentOriginAllowed( 199 Send(new FrameHostMsg_PluginContentOriginAllowed(
182 render_frame()->GetRoutingID(), content_origin)); 200 render_frame()->GetRoutingID(), content_origin));
183 } 201 }
184 } 202 }
185 203
186 } // namespace content 204 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/plugin_power_saver_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698