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 "content/renderer/pepper/plugin_instance_throttler_impl.h" | 5 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "content/public/common/content_constants.h" | 11 #include "content/public/common/content_constants.h" |
| 12 #include "content/public/renderer/render_thread.h" | 12 #include "content/public/renderer/render_thread.h" |
| 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 14 #include "content/renderer/render_frame_impl.h" | 14 #include "content/renderer/render_frame_impl.h" |
| 15 #include "ppapi/shared_impl/ppapi_constants.h" | 15 #include "ppapi/shared_impl/ppapi_constants.h" |
| 16 #include "third_party/WebKit/public/platform/WebRect.h" | 16 #include "third_party/WebKit/public/platform/WebRect.h" |
| 17 #include "third_party/WebKit/public/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
| 18 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 19 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 19 #include "third_party/WebKit/public/web/WebPluginParams.h" | 20 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 21 #include "third_party/WebKit/public/web/WebView.h" | |
| 20 #include "ui/gfx/color_utils.h" | 22 #include "ui/gfx/color_utils.h" |
| 21 #include "url/gurl.h" | 23 #include "url/origin.h" |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 // Cross-origin plugin content must have a width and height both exceeding | 29 // Cross-origin plugin content must have a width and height both exceeding |
| 28 // these minimums to be considered "large", and thus not peripheral. | 30 // these minimums to be considered "large", and thus not peripheral. |
| 29 const int kLargeContentMinWidth = 398; | 31 const int kLargeContentMinWidth = 398; |
| 30 const int kLargeContentMinHeight = 298; | 32 const int kLargeContentMinHeight = 298; |
| 31 | 33 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 153 } |
| 152 | 154 |
| 153 void PluginInstanceThrottlerImpl::SetWebPlugin( | 155 void PluginInstanceThrottlerImpl::SetWebPlugin( |
| 154 PepperWebPluginImpl* web_plugin) { | 156 PepperWebPluginImpl* web_plugin) { |
| 155 DCHECK(!web_plugin_); | 157 DCHECK(!web_plugin_); |
| 156 web_plugin_ = web_plugin; | 158 web_plugin_ = web_plugin; |
| 157 } | 159 } |
| 158 | 160 |
| 159 void PluginInstanceThrottlerImpl::Initialize( | 161 void PluginInstanceThrottlerImpl::Initialize( |
| 160 RenderFrameImpl* frame, | 162 RenderFrameImpl* frame, |
| 161 const GURL& content_origin, | 163 const url::Origin& content_origin, |
| 162 const std::string& plugin_module_name, | 164 const std::string& plugin_module_name, |
| 163 const gfx::Size& unobscured_size) { | 165 const gfx::Size& unobscured_size) { |
| 164 DCHECK(unobscured_size_.IsEmpty()); | 166 DCHECK(unobscured_size_.IsEmpty()); |
| 165 unobscured_size_ = unobscured_size; | 167 unobscured_size_ = unobscured_size; |
| 166 | 168 |
| 167 // |frame| may be nullptr in tests. | 169 // |frame| may be nullptr in tests. |
| 168 if (frame) { | 170 if (frame) { |
| 169 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); | 171 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); |
| 170 bool cross_origin_main_content = false; | 172 bool cross_origin_main_content = false; |
| 171 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); | 173 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); |
| 172 if (!helper->ShouldThrottleContent( | 174 if (!helper->ShouldThrottleContent( |
| 175 frame->GetWebFrame()->view()->mainFrame()->securityOrigin(), | |
|
piman
2015/09/14 23:58:23
Should this be frame->GetWebFrame()->top()->securi
tommycli
2015/09/15 00:38:19
Done. I think this should be equivalent.
| |
| 173 content_origin, plugin_module_name, | 176 content_origin, plugin_module_name, |
| 174 roundf(unobscured_size.width() / zoom_factor), | 177 roundf(unobscured_size.width() / zoom_factor), |
| 175 roundf(unobscured_size.height() / zoom_factor), | 178 roundf(unobscured_size.height() / zoom_factor), |
| 176 &cross_origin_main_content)) { | 179 &cross_origin_main_content)) { |
| 177 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); | 180 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); |
| 178 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 181 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| 179 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); | 182 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); |
| 180 | 183 |
| 181 if (cross_origin_main_content) | 184 if (cross_origin_main_content) |
| 182 helper->WhitelistContentOrigin(content_origin); | 185 helper->WhitelistContentOrigin(content_origin); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 | 246 |
| 244 // Release our reference to the underlying pixel data. | 247 // Release our reference to the underlying pixel data. |
| 245 last_received_frame_.reset(); | 248 last_received_frame_.reset(); |
| 246 } | 249 } |
| 247 | 250 |
| 248 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 251 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
| 249 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 252 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
| 250 } | 253 } |
| 251 | 254 |
| 252 } // namespace content | 255 } // namespace content |
| OLD | NEW |