Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 682813005: Plugin Power Saver: Fix (probably rare) crash in PepperPluginInstanceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 if (!module_->IsProxied()) { 574 if (!module_->IsProxied()) {
575 PepperBrowserConnection* browser_connection = 575 PepperBrowserConnection* browser_connection =
576 PepperBrowserConnection::Get(render_frame_); 576 PepperBrowserConnection::Get(render_frame_);
577 browser_connection->DidCreateInProcessInstance( 577 browser_connection->DidCreateInProcessInstance(
578 pp_instance(), 578 pp_instance(),
579 render_frame_->GetRoutingID(), 579 render_frame_->GetRoutingID(),
580 container_->element().document().url(), 580 container_->element().document().url(),
581 GetPluginURL()); 581 GetPluginURL());
582 } 582 }
583
584 PluginPowerSaverHelper* power_saver_helper =
585 render_frame_->plugin_power_saver_helper();
586 GURL content_origin = plugin_url_.GetOrigin();
587 blink::WebRect bounds = container_->element().boundsInViewportSpace();
588
589 bool cross_origin = false;
590 power_saver_enabled_ =
591 CommandLine::ForCurrentProcess()->HasSwitch(
592 switches::kEnablePluginPowerSaver) &&
593 IsFlashPlugin(module_.get()) &&
594 power_saver_helper->ShouldThrottleContent(
595 content_origin, bounds.width, bounds.height, &cross_origin);
596
597 if (power_saver_enabled_) {
598 power_saver_helper->RegisterPeripheralPlugin(
599 content_origin,
600 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle,
601 weak_factory_.GetWeakPtr()));
602
603 throttler_.reset(new PepperPluginInstanceThrottler(
604 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled,
605 weak_factory_.GetWeakPtr(), true /* throttled */)));
606 } else if (cross_origin) {
607 power_saver_helper->WhitelistContentOrigin(content_origin);
608 }
609 } 583 }
610 584
611 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); 585 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host();
612 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); 586 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this);
613 587
614 if (GetContentClient()->renderer() && // NULL in unit tests. 588 if (GetContentClient()->renderer() && // NULL in unit tests.
615 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) 589 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name()))
616 external_document_load_ = true; 590 external_document_load_ = true;
617 591
618 if (IsFlashPlugin(module_.get())) { 592 if (IsFlashPlugin(module_.get())) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8); 842 "Flash.UsesGPU", is_xp * 4 + needs_gpu * 2 + prefs.is_webgl_supported, 8);
869 #endif 843 #endif
870 } 844 }
871 845
872 bool PepperPluginInstanceImpl::Initialize( 846 bool PepperPluginInstanceImpl::Initialize(
873 const std::vector<std::string>& arg_names, 847 const std::vector<std::string>& arg_names,
874 const std::vector<std::string>& arg_values, 848 const std::vector<std::string>& arg_values,
875 bool full_frame) { 849 bool full_frame) {
876 if (!render_frame_) 850 if (!render_frame_)
877 return false; 851 return false;
852
853 PluginPowerSaverHelper* power_saver_helper =
854 render_frame_->plugin_power_saver_helper();
855 GURL content_origin = plugin_url_.GetOrigin();
856 blink::WebRect bounds = container_->element().boundsInViewportSpace();
857
858 bool cross_origin = false;
859 power_saver_enabled_ =
860 CommandLine::ForCurrentProcess()->HasSwitch(
861 switches::kEnablePluginPowerSaver) &&
862 IsFlashPlugin(module_.get()) &&
863 power_saver_helper->ShouldThrottleContent(
864 content_origin, bounds.width, bounds.height, &cross_origin);
865
866 if (power_saver_enabled_) {
867 power_saver_helper->RegisterPeripheralPlugin(
868 content_origin,
869 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle,
870 weak_factory_.GetWeakPtr()));
871
872 throttler_.reset(new PepperPluginInstanceThrottler(
873 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled,
874 weak_factory_.GetWeakPtr(), true /* throttled */)));
875 } else if (cross_origin) {
876 power_saver_helper->WhitelistContentOrigin(content_origin);
877 }
878
878 message_channel_ = MessageChannel::Create(this, &message_channel_object_); 879 message_channel_ = MessageChannel::Create(this, &message_channel_object_);
879 880
880 full_frame_ = full_frame; 881 full_frame_ = full_frame;
881 882
882 UpdateTouchEventRequest(); 883 UpdateTouchEventRequest();
883 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); 884 container_->setWantsWheelEvents(IsAcceptingWheelEvents());
884 885
885 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( 886 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build(
886 render_frame_->render_view()->webkit_preferences())), 887 render_frame_->render_view()->webkit_preferences())),
887 arg_names, 888 arg_names,
(...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 SendDidChangeView(); 3332 SendDidChangeView();
3332 } 3333 }
3333 3334
3334 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { 3335 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() {
3335 DCHECK(power_saver_enabled_); 3336 DCHECK(power_saver_enabled_);
3336 power_saver_enabled_ = false; 3337 power_saver_enabled_ = false;
3337 SetPluginThrottled(false); 3338 SetPluginThrottled(false);
3338 } 3339 }
3339 3340
3340 } // namespace content 3341 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698