| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pepper_plugin_instance_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 : RenderFrameObserver(render_frame), | 488 : RenderFrameObserver(render_frame), |
| 489 render_frame_(render_frame), | 489 render_frame_(render_frame), |
| 490 module_(module), | 490 module_(module), |
| 491 instance_interface_(instance_interface), | 491 instance_interface_(instance_interface), |
| 492 pp_instance_(0), | 492 pp_instance_(0), |
| 493 container_(container), | 493 container_(container), |
| 494 layer_bound_to_fullscreen_(false), | 494 layer_bound_to_fullscreen_(false), |
| 495 layer_is_hardware_(false), | 495 layer_is_hardware_(false), |
| 496 plugin_url_(plugin_url), | 496 plugin_url_(plugin_url), |
| 497 power_saver_enabled_(false), | 497 power_saver_enabled_(false), |
| 498 is_peripheral_content_(false), |
| 498 plugin_throttled_(false), | 499 plugin_throttled_(false), |
| 499 full_frame_(false), | 500 full_frame_(false), |
| 500 sent_initial_did_change_view_(false), | 501 sent_initial_did_change_view_(false), |
| 501 bound_graphics_2d_platform_(NULL), | 502 bound_graphics_2d_platform_(NULL), |
| 502 bound_compositor_(NULL), | 503 bound_compositor_(NULL), |
| 503 has_webkit_focus_(false), | 504 has_webkit_focus_(false), |
| 504 has_content_area_focus_(false), | 505 has_content_area_focus_(false), |
| 505 find_identifier_(-1), | 506 find_identifier_(-1), |
| 506 plugin_find_interface_(NULL), | 507 plugin_find_interface_(NULL), |
| 507 plugin_input_event_interface_(NULL), | 508 plugin_input_event_interface_(NULL), |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 bool full_frame) { | 850 bool full_frame) { |
| 850 if (!render_frame_) | 851 if (!render_frame_) |
| 851 return false; | 852 return false; |
| 852 | 853 |
| 853 PluginPowerSaverHelper* power_saver_helper = | 854 PluginPowerSaverHelper* power_saver_helper = |
| 854 render_frame_->plugin_power_saver_helper(); | 855 render_frame_->plugin_power_saver_helper(); |
| 855 GURL content_origin = plugin_url_.GetOrigin(); | 856 GURL content_origin = plugin_url_.GetOrigin(); |
| 856 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | 857 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| 857 | 858 |
| 858 bool cross_origin = false; | 859 bool cross_origin = false; |
| 859 power_saver_enabled_ = | 860 is_peripheral_content_ = |
| 860 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 861 switches::kEnablePluginPowerSaver) && | |
| 862 IsFlashPlugin(module_.get()) && | 861 IsFlashPlugin(module_.get()) && |
| 863 power_saver_helper->ShouldThrottleContent( | 862 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, |
| 864 content_origin, bounds.width, bounds.height, &cross_origin); | 863 bounds.height, &cross_origin); |
| 865 | 864 |
| 866 if (power_saver_enabled_) { | 865 power_saver_enabled_ = is_peripheral_content_ && |
| 866 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 867 switches::kEnablePluginPowerSaver); |
| 868 |
| 869 if (is_peripheral_content_) { |
| 870 // To collect UMAs, register peripheral content even if we don't throttle. |
| 867 power_saver_helper->RegisterPeripheralPlugin( | 871 power_saver_helper->RegisterPeripheralPlugin( |
| 868 content_origin, | 872 content_origin, |
| 869 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, | 873 base::Bind( |
| 870 weak_factory_.GetWeakPtr())); | 874 &PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist, |
| 875 weak_factory_.GetWeakPtr())); |
| 871 | 876 |
| 872 throttler_.reset(new PepperPluginInstanceThrottler( | 877 if (power_saver_enabled_) { |
| 873 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, | 878 throttler_.reset(new PepperPluginInstanceThrottler( |
| 874 weak_factory_.GetWeakPtr(), true /* throttled */))); | 879 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, |
| 880 weak_factory_.GetWeakPtr(), true /* throttled */))); |
| 881 } |
| 875 } else if (cross_origin) { | 882 } else if (cross_origin) { |
| 876 power_saver_helper->WhitelistContentOrigin(content_origin); | 883 power_saver_helper->WhitelistContentOrigin(content_origin); |
| 877 } | 884 } |
| 878 | 885 |
| 879 message_channel_ = MessageChannel::Create(this, &message_channel_object_); | 886 message_channel_ = MessageChannel::Create(this, &message_channel_object_); |
| 880 | 887 |
| 881 full_frame_ = full_frame; | 888 full_frame_ = full_frame; |
| 882 | 889 |
| 883 UpdateTouchEventRequest(); | 890 UpdateTouchEventRequest(); |
| 884 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); | 891 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 gfx::Rect caret(text_input_caret_); | 1131 gfx::Rect caret(text_input_caret_); |
| 1125 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1132 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
| 1126 return caret; | 1133 return caret; |
| 1127 } | 1134 } |
| 1128 | 1135 |
| 1129 bool PepperPluginInstanceImpl::HandleInputEvent( | 1136 bool PepperPluginInstanceImpl::HandleInputEvent( |
| 1130 const blink::WebInputEvent& event, | 1137 const blink::WebInputEvent& event, |
| 1131 WebCursorInfo* cursor_info) { | 1138 WebCursorInfo* cursor_info) { |
| 1132 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1139 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
| 1133 | 1140 |
| 1134 if (event.type == blink::WebInputEvent::MouseUp && power_saver_enabled_) | 1141 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { |
| 1142 is_peripheral_content_ = false; |
| 1135 power_saver_enabled_ = false; | 1143 power_saver_enabled_ = false; |
| 1136 | 1144 |
| 1137 if (plugin_throttled_) { | 1145 RenderThread::Get()->RecordAction( |
| 1138 if (event.type == blink::WebInputEvent::MouseUp) | 1146 base::UserMetricsAction("Flash.PluginInstanceUnthrottledByClick")); |
| 1147 |
| 1148 if (plugin_throttled_) { |
| 1139 SetPluginThrottled(false /* throttled */); | 1149 SetPluginThrottled(false /* throttled */); |
| 1140 | 1150 return true; |
| 1141 return true; | 1151 } |
| 1142 } | 1152 } |
| 1143 | 1153 |
| 1144 if (!render_frame_) | 1154 if (!render_frame_) |
| 1145 return false; | 1155 return false; |
| 1146 if (WebInputEvent::isMouseEventType(event.type)) { | 1156 if (WebInputEvent::isMouseEventType(event.type)) { |
| 1147 render_frame_->PepperDidReceiveMouseEvent(this); | 1157 render_frame_->PepperDidReceiveMouseEvent(this); |
| 1148 } | 1158 } |
| 1149 | 1159 |
| 1150 // Don't dispatch input events to crashed plugins. | 1160 // Don't dispatch input events to crashed plugins. |
| 1151 if (module()->is_crashed()) | 1161 if (module()->is_crashed()) |
| (...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3325 | 3335 |
| 3326 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { | 3336 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
| 3327 // Do not throttle if we've already disabled power saver. | 3337 // Do not throttle if we've already disabled power saver. |
| 3328 if (!power_saver_enabled_ && throttled) | 3338 if (!power_saver_enabled_ && throttled) |
| 3329 return; | 3339 return; |
| 3330 | 3340 |
| 3331 plugin_throttled_ = throttled; | 3341 plugin_throttled_ = throttled; |
| 3332 SendDidChangeView(); | 3342 SendDidChangeView(); |
| 3333 } | 3343 } |
| 3334 | 3344 |
| 3335 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { | 3345 void PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist() { |
| 3336 DCHECK(power_saver_enabled_); | 3346 if (!is_peripheral_content_) |
| 3347 return; |
| 3348 |
| 3349 is_peripheral_content_ = false; |
| 3337 power_saver_enabled_ = false; | 3350 power_saver_enabled_ = false; |
| 3338 SetPluginThrottled(false); | 3351 SetPluginThrottled(false); |
| 3352 |
| 3353 RenderThread::Get()->RecordAction( |
| 3354 base::UserMetricsAction("Flash.PluginInstanceUnthrottledByWhitelist")); |
| 3339 } | 3355 } |
| 3340 | 3356 |
| 3341 } // namespace content | 3357 } // namespace content |
| OLD | NEW |