Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 container_->element().document().url(), | 581 container_->element().document().url(), |
| 581 GetPluginURL()); | 582 GetPluginURL()); |
| 582 } | 583 } |
| 583 | 584 |
| 584 PluginPowerSaverHelper* power_saver_helper = | 585 PluginPowerSaverHelper* power_saver_helper = |
| 585 render_frame_->plugin_power_saver_helper(); | 586 render_frame_->plugin_power_saver_helper(); |
| 586 GURL content_origin = plugin_url_.GetOrigin(); | 587 GURL content_origin = plugin_url_.GetOrigin(); |
| 587 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | 588 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| 588 | 589 |
| 589 bool cross_origin = false; | 590 bool cross_origin = false; |
| 590 power_saver_enabled_ = | 591 is_peripheral_content_ = |
| 591 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 592 switches::kEnablePluginPowerSaver) && | |
| 593 IsFlashPlugin(module_.get()) && | 592 IsFlashPlugin(module_.get()) && |
| 594 power_saver_helper->ShouldThrottleContent( | 593 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width, |
|
Lei Zhang
2014/11/05 01:23:49
curious, is this part of the change due to git cl
tommycli
2014/11/05 19:01:41
Yes. It was a change by git cl format.
| |
| 595 content_origin, bounds.width, bounds.height, &cross_origin); | 594 bounds.height, &cross_origin); |
| 596 | 595 |
| 597 if (power_saver_enabled_) { | 596 power_saver_enabled_ = is_peripheral_content_ && |
| 597 CommandLine::ForCurrentProcess()->HasSwitch( | |
|
Lei Zhang
2014/11/05 01:23:49
nit: base::CommandLine
tommycli
2014/11/05 19:01:41
Done.
| |
| 598 switches::kEnablePluginPowerSaver); | |
| 599 | |
| 600 if (is_peripheral_content_) { | |
| 601 // To collect UMAs, register peripheral content even if we don't throttle. | |
| 598 power_saver_helper->RegisterPeripheralPlugin( | 602 power_saver_helper->RegisterPeripheralPlugin( |
| 599 content_origin, | 603 content_origin, |
| 600 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, | 604 base::Bind(&PepperPluginInstanceImpl:: |
| 605 DisablePowerSaverByRetroactiveWhitelist, | |
| 601 weak_factory_.GetWeakPtr())); | 606 weak_factory_.GetWeakPtr())); |
| 602 | 607 |
| 603 throttler_.reset(new PepperPluginInstanceThrottler( | 608 if (power_saver_enabled_) { |
| 604 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, | 609 throttler_.reset(new PepperPluginInstanceThrottler( |
| 605 weak_factory_.GetWeakPtr(), true /* throttled */))); | 610 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, |
| 611 weak_factory_.GetWeakPtr(), true /* throttled */))); | |
| 612 } | |
| 606 } else if (cross_origin) { | 613 } else if (cross_origin) { |
| 607 power_saver_helper->WhitelistContentOrigin(content_origin); | 614 power_saver_helper->WhitelistContentOrigin(content_origin); |
| 608 } | 615 } |
| 609 } | 616 } |
| 610 | 617 |
| 611 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 618 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
| 612 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 619 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
| 613 | 620 |
| 614 if (GetContentClient()->renderer() && // NULL in unit tests. | 621 if (GetContentClient()->renderer() && // NULL in unit tests. |
| 615 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 622 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
| 616 external_document_load_ = true; | 623 external_document_load_ = true; |
| 617 | |
| 618 if (IsFlashPlugin(module_.get())) { | |
| 619 RenderThread::Get()->RecordAction( | |
|
Lei Zhang
2014/11/05 01:23:49
The sum of the Plugin.PowerSaverPeripheralHeuristi
tommycli
2014/11/05 19:01:41
I think we should keep it if you can think of any
| |
| 620 base::UserMetricsAction("Flash.PluginInstanceCreated")); | |
| 621 } | |
| 622 } | 624 } |
| 623 | 625 |
| 624 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 626 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
| 625 DCHECK(!fullscreen_container_); | 627 DCHECK(!fullscreen_container_); |
| 626 | 628 |
| 627 // Notify all the plugin objects of deletion. This will prevent blink from | 629 // Notify all the plugin objects of deletion. This will prevent blink from |
| 628 // calling into the plugin any more. | 630 // calling into the plugin any more. |
| 629 // | 631 // |
| 630 // Swap out the set so we can delete from it (the objects will try to | 632 // Swap out the set so we can delete from it (the objects will try to |
| 631 // unregister themselves inside the delete call). | 633 // unregister themselves inside the delete call). |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1123 gfx::Rect caret(text_input_caret_); | 1125 gfx::Rect caret(text_input_caret_); |
| 1124 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); | 1126 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); |
| 1125 return caret; | 1127 return caret; |
| 1126 } | 1128 } |
| 1127 | 1129 |
| 1128 bool PepperPluginInstanceImpl::HandleInputEvent( | 1130 bool PepperPluginInstanceImpl::HandleInputEvent( |
| 1129 const blink::WebInputEvent& event, | 1131 const blink::WebInputEvent& event, |
| 1130 WebCursorInfo* cursor_info) { | 1132 WebCursorInfo* cursor_info) { |
| 1131 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); | 1133 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); |
| 1132 | 1134 |
| 1133 if (event.type == blink::WebInputEvent::MouseUp && power_saver_enabled_) | 1135 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) { |
| 1136 is_peripheral_content_ = false; | |
| 1134 power_saver_enabled_ = false; | 1137 power_saver_enabled_ = false; |
| 1135 | 1138 |
| 1136 if (plugin_throttled_) { | 1139 RenderThread::Get()->RecordAction( |
| 1137 if (event.type == blink::WebInputEvent::MouseUp) | 1140 base::UserMetricsAction("Flash.PluginInstanceUnthrottledByClick")); |
| 1141 | |
| 1142 if (plugin_throttled_) { | |
| 1138 SetPluginThrottled(false /* throttled */); | 1143 SetPluginThrottled(false /* throttled */); |
| 1139 | 1144 return true; |
| 1140 return true; | 1145 } |
| 1141 } | 1146 } |
| 1142 | 1147 |
| 1143 if (!render_frame_) | 1148 if (!render_frame_) |
| 1144 return false; | 1149 return false; |
| 1145 if (WebInputEvent::isMouseEventType(event.type)) { | 1150 if (WebInputEvent::isMouseEventType(event.type)) { |
| 1146 render_frame_->PepperDidReceiveMouseEvent(this); | 1151 render_frame_->PepperDidReceiveMouseEvent(this); |
| 1147 } | 1152 } |
| 1148 | 1153 |
| 1149 // Don't dispatch input events to crashed plugins. | 1154 // Don't dispatch input events to crashed plugins. |
| 1150 if (module()->is_crashed()) | 1155 if (module()->is_crashed()) |
| (...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3324 | 3329 |
| 3325 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { | 3330 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
| 3326 // Do not throttle if we've already disabled power saver. | 3331 // Do not throttle if we've already disabled power saver. |
| 3327 if (!power_saver_enabled_ && throttled) | 3332 if (!power_saver_enabled_ && throttled) |
| 3328 return; | 3333 return; |
| 3329 | 3334 |
| 3330 plugin_throttled_ = throttled; | 3335 plugin_throttled_ = throttled; |
| 3331 SendDidChangeView(); | 3336 SendDidChangeView(); |
| 3332 } | 3337 } |
| 3333 | 3338 |
| 3334 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { | 3339 void PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist() { |
| 3335 DCHECK(power_saver_enabled_); | 3340 if (!is_peripheral_content_) |
| 3341 return; | |
| 3342 | |
| 3343 is_peripheral_content_ = false; | |
| 3336 power_saver_enabled_ = false; | 3344 power_saver_enabled_ = false; |
| 3337 SetPluginThrottled(false); | 3345 SetPluginThrottled(false); |
| 3346 | |
| 3347 RenderThread::Get()->RecordAction( | |
| 3348 base::UserMetricsAction("Flash.PluginInstanceUnthrottledByWhitelist")); | |
| 3338 } | 3349 } |
| 3339 | 3350 |
| 3340 } // namespace content | 3351 } // namespace content |
| OLD | NEW |