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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 578 } |
577 } | 579 } |
578 | 580 |
579 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); | 581 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); |
580 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); | 582 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); |
581 | 583 |
582 if (GetContentClient()->renderer() && // NULL in unit tests. | 584 if (GetContentClient()->renderer() && // NULL in unit tests. |
583 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) | 585 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) |
584 external_document_load_ = true; | 586 external_document_load_ = true; |
585 | 587 |
586 power_saver_enabled_ = CommandLine::ForCurrentProcess()->HasSwitch( | 588 blink::WebRect bounds = container_->element().boundsInViewportSpace(); |
587 switches::kEnablePluginPowerSaver) && | 589 power_saver_enabled_ = |
588 IsPeripheralContent(); | 590 CommandLine::ForCurrentProcess()->HasSwitch( |
| 591 switches::kEnablePluginPowerSaver) && |
| 592 module_->name() == kFlashPluginName && |
| 593 render_frame_->GetPluginPowerSaverHelper()->ShouldThrottleContent( |
| 594 plugin_url_, |
| 595 bounds.width, |
| 596 bounds.height, |
| 597 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, |
| 598 weak_factory_.GetWeakPtr())); |
589 | 599 |
590 if (power_saver_enabled_) { | 600 if (power_saver_enabled_) { |
591 throttler_.reset(new PepperPluginInstanceThrottler( | 601 throttler_.reset(new PepperPluginInstanceThrottler( |
592 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, | 602 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, |
593 weak_factory_.GetWeakPtr(), true /* throttled */))); | 603 weak_factory_.GetWeakPtr(), true /* throttled */))); |
594 } | 604 } |
595 } | 605 } |
596 | 606 |
597 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { | 607 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { |
598 DCHECK(!fullscreen_container_); | 608 DCHECK(!fullscreen_container_); |
(...skipping 2689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3288 } else { | 3298 } else { |
3289 // Running out-of-process. Initiate an IPC call to notify the plugin | 3299 // Running out-of-process. Initiate an IPC call to notify the plugin |
3290 // process. | 3300 // process. |
3291 ppapi::proxy::HostDispatcher* dispatcher = | 3301 ppapi::proxy::HostDispatcher* dispatcher = |
3292 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); | 3302 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); |
3293 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( | 3303 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( |
3294 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); | 3304 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); |
3295 } | 3305 } |
3296 } | 3306 } |
3297 | 3307 |
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) { | 3308 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { |
3320 // Do not throttle if we've already disabled power saver. | 3309 // Do not throttle if we've already disabled power saver. |
3321 if (!power_saver_enabled_ && throttled) | 3310 if (!power_saver_enabled_ && throttled) |
3322 return; | 3311 return; |
3323 | 3312 |
3324 plugin_throttled_ = throttled; | 3313 plugin_throttled_ = throttled; |
3325 SendDidChangeView(); | 3314 SendDidChangeView(); |
3326 } | 3315 } |
3327 | 3316 |
| 3317 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { |
| 3318 DCHECK(power_saver_enabled_); |
| 3319 power_saver_enabled_ = false; |
| 3320 SetPluginThrottled(false); |
| 3321 } |
| 3322 |
3328 } // namespace content | 3323 } // namespace content |
OLD | NEW |