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