| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 input_sequence); | 383 input_sequence); |
| 384 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); | 384 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); |
| 385 if (old_latency) { | 385 if (old_latency) { |
| 386 new_latency->CopyLatencyFrom(*old_latency, | 386 new_latency->CopyLatencyFrom(*old_latency, |
| 387 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); | 387 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); |
| 388 new_latency->CopyLatencyFrom(*old_latency, | 388 new_latency->CopyLatencyFrom(*old_latency, |
| 389 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); | 389 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 | 392 |
| 393 bool IsFlashPlugin(PluginModule* module) { |
| 394 return module->name() == kFlashPluginName; |
| 395 } |
| 396 |
| 393 } // namespace | 397 } // namespace |
| 394 | 398 |
| 395 // static | 399 // static |
| 396 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( | 400 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( |
| 397 RenderFrameImpl* render_frame, | 401 RenderFrameImpl* render_frame, |
| 398 PluginModule* module, | 402 PluginModule* module, |
| 399 WebPluginContainer* container, | 403 WebPluginContainer* container, |
| 400 const GURL& plugin_url) { | 404 const GURL& plugin_url) { |
| 401 base::Callback<const void*(const char*)> get_plugin_interface_func = | 405 base::Callback<const void*(const char*)> get_plugin_interface_func = |
| 402 base::Bind(&PluginModule::GetPluginInterface, module); | 406 base::Bind(&PluginModule::GetPluginInterface, module); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 583 |
| 580 PluginPowerSaverHelper* power_saver_helper = | 584 PluginPowerSaverHelper* power_saver_helper = |
| 581 render_frame_->plugin_power_saver_helper(); | 585 render_frame_->plugin_power_saver_helper(); |
| 582 GURL content_origin = plugin_url_.GetOrigin(); | 586 GURL content_origin = plugin_url_.GetOrigin(); |
| 583 blink::WebRect bounds = container_->element().boundsInViewportSpace(); | 587 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| 584 | 588 |
| 585 bool cross_origin = false; | 589 bool cross_origin = false; |
| 586 power_saver_enabled_ = | 590 power_saver_enabled_ = |
| 587 CommandLine::ForCurrentProcess()->HasSwitch( | 591 CommandLine::ForCurrentProcess()->HasSwitch( |
| 588 switches::kEnablePluginPowerSaver) && | 592 switches::kEnablePluginPowerSaver) && |
| 589 module_->name() == kFlashPluginName && | 593 IsFlashPlugin(module_.get()) && |
| 590 power_saver_helper->ShouldThrottleContent( | 594 power_saver_helper->ShouldThrottleContent( |
| 591 content_origin, bounds.width, bounds.height, &cross_origin); | 595 content_origin, bounds.width, bounds.height, &cross_origin); |
| 592 | 596 |
| 593 if (power_saver_enabled_) { | 597 if (power_saver_enabled_) { |
| 594 power_saver_helper->RegisterPeripheralPlugin( | 598 power_saver_helper->RegisterPeripheralPlugin( |
| 595 content_origin, | 599 content_origin, |
| 596 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, | 600 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, |
| 597 weak_factory_.GetWeakPtr())); | 601 weak_factory_.GetWeakPtr())); |
| 598 | 602 |
| 599 throttler_.reset(new PepperPluginInstanceThrottler( | 603 throttler_.reset(new PepperPluginInstanceThrottler( |
| 600 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, | 604 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, |
| 601 weak_factory_.GetWeakPtr(), true /* throttled */))); | 605 weak_factory_.GetWeakPtr(), true /* throttled */))); |
| 602 } else if (cross_origin) { | 606 } else if (cross_origin) { |
| 603 power_saver_helper->WhitelistContentOrigin(content_origin); | 607 power_saver_helper->WhitelistContentOrigin(content_origin); |
| 604 } | 608 } |
| 605 } | 609 } |
| 606 | 610 |
| 607 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 611 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
| 608 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 612 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
| 609 | 613 |
| 610 if (GetContentClient()->renderer() && // NULL in unit tests. | 614 if (GetContentClient()->renderer() && // NULL in unit tests. |
| 611 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 615 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
| 612 external_document_load_ = true; | 616 external_document_load_ = true; |
| 617 |
| 618 if (IsFlashPlugin(module_.get())) { |
| 619 RenderThread::Get()->RecordAction( |
| 620 base::UserMetricsAction("Flash.PluginInstanceCreated")); |
| 621 } |
| 613 } | 622 } |
| 614 | 623 |
| 615 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 624 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
| 616 DCHECK(!fullscreen_container_); | 625 DCHECK(!fullscreen_container_); |
| 617 | 626 |
| 618 // Notify all the plugin objects of deletion. This will prevent blink from | 627 // Notify all the plugin objects of deletion. This will prevent blink from |
| 619 // calling into the plugin any more. | 628 // calling into the plugin any more. |
| 620 // | 629 // |
| 621 // Swap out the set so we can delete from it (the objects will try to | 630 // Swap out the set so we can delete from it (the objects will try to |
| 622 // unregister themselves inside the delete call). | 631 // unregister themselves inside the delete call). |
| (...skipping 2699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3322 SendDidChangeView(); | 3331 SendDidChangeView(); |
| 3323 } | 3332 } |
| 3324 | 3333 |
| 3325 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { | 3334 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { |
| 3326 DCHECK(power_saver_enabled_); | 3335 DCHECK(power_saver_enabled_); |
| 3327 power_saver_enabled_ = false; | 3336 power_saver_enabled_ = false; |
| 3328 SetPluginThrottled(false); | 3337 SetPluginThrottled(false); |
| 3329 } | 3338 } |
| 3330 | 3339 |
| 3331 } // namespace content | 3340 } // namespace content |
| OLD | NEW |