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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_offset_string_conversions.h" | 16 #include "base/strings/utf_offset_string_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "cc/base/latency_info_swap_promise.h" | 19 #include "cc/base/latency_info_swap_promise.h" |
20 #include "cc/blink/web_layer_impl.h" | 20 #include "cc/blink/web_layer_impl.h" |
21 #include "cc/layers/texture_layer.h" | 21 #include "cc/layers/texture_layer.h" |
22 #include "cc/trees/layer_tree_host.h" | 22 #include "cc/trees/layer_tree_host.h" |
23 #include "content/common/content_constants_internal.h" | 23 #include "content/common/content_constants_internal.h" |
| 24 #include "content/common/frame_messages.h" |
24 #include "content/common/input/web_input_event_traits.h" | 25 #include "content/common/input/web_input_event_traits.h" |
25 #include "content/public/common/content_constants.h" | 26 #include "content/public/common/content_constants.h" |
26 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
27 #include "content/public/common/page_zoom.h" | 28 #include "content/public/common/page_zoom.h" |
28 #include "content/public/renderer/content_renderer_client.h" | 29 #include "content/public/renderer/content_renderer_client.h" |
29 #include "content/renderer/gpu/render_widget_compositor.h" | 30 #include "content/renderer/gpu/render_widget_compositor.h" |
30 #include "content/renderer/pepper/content_decryptor_delegate.h" | 31 #include "content/renderer/pepper/content_decryptor_delegate.h" |
31 #include "content/renderer/pepper/event_conversion.h" | 32 #include "content/renderer/pepper/event_conversion.h" |
32 #include "content/renderer/pepper/fullscreen_container.h" | 33 #include "content/renderer/pepper/fullscreen_container.h" |
33 #include "content/renderer/pepper/gfx_conversion.h" | 34 #include "content/renderer/pepper/gfx_conversion.h" |
34 #include "content/renderer/pepper/host_dispatcher_wrapper.h" | 35 #include "content/renderer/pepper/host_dispatcher_wrapper.h" |
35 #include "content/renderer/pepper/host_globals.h" | 36 #include "content/renderer/pepper/host_globals.h" |
36 #include "content/renderer/pepper/message_channel.h" | 37 #include "content/renderer/pepper/message_channel.h" |
37 #include "content/renderer/pepper/pepper_browser_connection.h" | 38 #include "content/renderer/pepper/pepper_browser_connection.h" |
38 #include "content/renderer/pepper/pepper_compositor_host.h" | 39 #include "content/renderer/pepper/pepper_compositor_host.h" |
39 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" | 40 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
40 #include "content/renderer/pepper/pepper_graphics_2d_host.h" | 41 #include "content/renderer/pepper/pepper_graphics_2d_host.h" |
41 #include "content/renderer/pepper/pepper_in_process_router.h" | 42 #include "content/renderer/pepper/pepper_in_process_router.h" |
42 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 43 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
43 #include "content/renderer/pepper/pepper_plugin_instance_throttler.h" | 44 #include "content/renderer/pepper/pepper_plugin_instance_throttler.h" |
44 #include "content/renderer/pepper/pepper_try_catch.h" | 45 #include "content/renderer/pepper/pepper_try_catch.h" |
45 #include "content/renderer/pepper/pepper_url_loader_host.h" | 46 #include "content/renderer/pepper/pepper_url_loader_host.h" |
46 #include "content/renderer/pepper/plugin_module.h" | 47 #include "content/renderer/pepper/plugin_module.h" |
47 #include "content/renderer/pepper/plugin_object.h" | 48 #include "content/renderer/pepper/plugin_object.h" |
| 49 #include "content/renderer/pepper/plugin_power_saver_helper.h" |
48 #include "content/renderer/pepper/ppapi_preferences_builder.h" | 50 #include "content/renderer/pepper/ppapi_preferences_builder.h" |
49 #include "content/renderer/pepper/ppb_buffer_impl.h" | 51 #include "content/renderer/pepper/ppb_buffer_impl.h" |
50 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 52 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
51 #include "content/renderer/pepper/ppb_image_data_impl.h" | 53 #include "content/renderer/pepper/ppb_image_data_impl.h" |
52 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 54 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
53 #include "content/renderer/pepper/url_request_info_util.h" | 55 #include "content/renderer/pepper/url_request_info_util.h" |
54 #include "content/renderer/pepper/url_response_info_util.h" | 56 #include "content/renderer/pepper/url_response_info_util.h" |
55 #include "content/renderer/render_frame_impl.h" | 57 #include "content/renderer/render_frame_impl.h" |
56 #include "content/renderer/render_thread_impl.h" | 58 #include "content/renderer/render_thread_impl.h" |
57 #include "content/renderer/render_view_impl.h" | 59 #include "content/renderer/render_view_impl.h" |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 | 569 |
568 if (!module_->IsProxied()) { | 570 if (!module_->IsProxied()) { |
569 PepperBrowserConnection* browser_connection = | 571 PepperBrowserConnection* browser_connection = |
570 PepperBrowserConnection::Get(render_frame_); | 572 PepperBrowserConnection::Get(render_frame_); |
571 browser_connection->DidCreateInProcessInstance( | 573 browser_connection->DidCreateInProcessInstance( |
572 pp_instance(), | 574 pp_instance(), |
573 render_frame_->GetRoutingID(), | 575 render_frame_->GetRoutingID(), |
574 container_->element().document().url(), | 576 container_->element().document().url(), |
575 GetPluginURL()); | 577 GetPluginURL()); |
576 } | 578 } |
| 579 |
| 580 PluginPowerSaverHelper* power_saver_helper = |
| 581 render_frame_->plugin_power_saver_helper(); |
| 582 GURL content_origin = plugin_url_.GetOrigin(); |
| 583 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
| 584 |
| 585 bool cross_origin = false; |
| 586 power_saver_enabled_ = |
| 587 CommandLine::ForCurrentProcess()->HasSwitch( |
| 588 switches::kEnablePluginPowerSaver) && |
| 589 module_->name() == kFlashPluginName && |
| 590 power_saver_helper->ShouldThrottleContent( |
| 591 content_origin, bounds.width, bounds.height, &cross_origin); |
| 592 |
| 593 if (power_saver_enabled_) { |
| 594 power_saver_helper->RegisterPeripheralPlugin( |
| 595 content_origin, |
| 596 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, |
| 597 weak_factory_.GetWeakPtr())); |
| 598 |
| 599 throttler_.reset(new PepperPluginInstanceThrottler( |
| 600 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, |
| 601 weak_factory_.GetWeakPtr(), true /* throttled */))); |
| 602 } else if (cross_origin) { |
| 603 power_saver_helper->WhitelistContentOrigin(content_origin); |
| 604 } |
577 } | 605 } |
578 | 606 |
579 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 607 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
580 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 608 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
581 | 609 |
582 if (GetContentClient()->renderer() && // NULL in unit tests. | 610 if (GetContentClient()->renderer() && // NULL in unit tests. |
583 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 611 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
584 external_document_load_ = true; | 612 external_document_load_ = true; |
585 | |
586 power_saver_enabled_ = CommandLine::ForCurrentProcess()->HasSwitch( | |
587 switches::kEnablePluginPowerSaver) && | |
588 IsPeripheralContent(); | |
589 | |
590 if (power_saver_enabled_) { | |
591 throttler_.reset(new PepperPluginInstanceThrottler( | |
592 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, | |
593 weak_factory_.GetWeakPtr(), true /* throttled */))); | |
594 } | |
595 } | 613 } |
596 | 614 |
597 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 615 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
598 DCHECK(!fullscreen_container_); | 616 DCHECK(!fullscreen_container_); |
599 | 617 |
600 // Notify all the plugin objects of deletion. This will prevent blink from | 618 // Notify all the plugin objects of deletion. This will prevent blink from |
601 // calling into the plugin any more. | 619 // calling into the plugin any more. |
602 // | 620 // |
603 // Swap out the set so we can delete from it (the objects will try to | 621 // Swap out the set so we can delete from it (the objects will try to |
604 // unregister themselves inside the delete call). | 622 // unregister themselves inside the delete call). |
(...skipping 2683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3288 } else { | 3306 } else { |
3289 // Running out-of-process. Initiate an IPC call to notify the plugin | 3307 // Running out-of-process. Initiate an IPC call to notify the plugin |
3290 // process. | 3308 // process. |
3291 ppapi::proxy::HostDispatcher* dispatcher = | 3309 ppapi::proxy::HostDispatcher* dispatcher = |
3292 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3310 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
3293 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3311 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
3294 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3312 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
3295 } | 3313 } |
3296 } | 3314 } |
3297 | 3315 |
3298 bool PepperPluginInstanceImpl::IsPeripheralContent() const { | |
3299 if (module_->name() != kFlashPluginName) | |
3300 return false; | |
3301 | |
3302 // Peripheral plugin content is defined to be peripheral when the plugin | |
3303 // content's origin differs from the top level frame's origin. For example: | |
3304 // - Peripheral: a.com -> b.com/plugin.swf | |
3305 // - Peripheral: a.com -> b.com/iframe.html -> b.com/plugin.swf | |
3306 // - NOT peripheral: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf | |
3307 | |
3308 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 | |
3309 // is fixed. For now, case 3 in the comment above doesn't work in | |
3310 // --site-per-process mode. | |
3311 WebFrame* main_frame = render_frame_->GetWebFrame()->view()->mainFrame(); | |
3312 if (main_frame->isWebRemoteFrame()) | |
3313 return true; | |
3314 | |
3315 GURL main_frame_url = main_frame->document().url(); | |
3316 return plugin_url_.GetOrigin() != main_frame_url.GetOrigin(); | |
3317 } | |
3318 | |
3319 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { | 3316 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
3320 // Do not throttle if we've already disabled power saver. | 3317 // Do not throttle if we've already disabled power saver. |
3321 if (!power_saver_enabled_ && throttled) | 3318 if (!power_saver_enabled_ && throttled) |
3322 return; | 3319 return; |
3323 | 3320 |
3324 plugin_throttled_ = throttled; | 3321 plugin_throttled_ = throttled; |
3325 SendDidChangeView(); | 3322 SendDidChangeView(); |
3326 } | 3323 } |
3327 | 3324 |
| 3325 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { |
| 3326 DCHECK(power_saver_enabled_); |
| 3327 power_saver_enabled_ = false; |
| 3328 SetPluginThrottled(false); |
| 3329 } |
| 3330 |
3328 } // namespace content | 3331 } // namespace content |
OLD | NEW |