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

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

Issue 1015023002: Plugin Power Saver: Throttle 'large' plugins that appear small. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use gfx::Size Created 5 years, 9 months 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
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/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 bool PepperPluginInstanceImpl::Initialize( 800 bool PepperPluginInstanceImpl::Initialize(
801 const std::vector<std::string>& arg_names, 801 const std::vector<std::string>& arg_names,
802 const std::vector<std::string>& arg_values, 802 const std::vector<std::string>& arg_values,
803 bool full_frame, 803 bool full_frame,
804 scoped_ptr<PluginInstanceThrottlerImpl> throttler) { 804 scoped_ptr<PluginInstanceThrottlerImpl> throttler) {
805 DCHECK(!throttler_); 805 DCHECK(!throttler_);
806 806
807 if (!render_frame_) 807 if (!render_frame_)
808 return false; 808 return false;
809 809
810 // Get plugin dimensions directly.
811 blink::WebElement element = container()->element();
812 blink::WebRect bounds = element.boundsInViewportSpace();
813 int width = bounds.width;
814 int height = bounds.height;
815
816 // Plugins are sometimes only partially visible. This is to support content
817 // that may expand. Walk up the DOM tree here to find a parent container
818 // that is smaller, and use that as the plugin's effective visible size.
819 blink::WebNode node = element.parentNode();
820 while (!node.isNull() && node.isElementNode()) {
821 blink::WebRect bounds = node.to<WebElement>().boundsInViewportSpace();
Lei Zhang 2015/03/18 00:48:12 You can change the type of |bounds| to gfx::Rect()
tommycli 2015/03/19 22:10:12 Done.
822
823 if (bounds.width < width)
824 width = bounds.width;
825 if (bounds.height < height)
826 height = bounds.height;
827
828 node = node.parentNode();
829 }
830
810 if (is_flash_plugin_ && RenderThread::Get()) { 831 if (is_flash_plugin_ && RenderThread::Get()) {
811 RenderThread::Get()->RecordAction( 832 RenderThread::Get()->RecordAction(
812 base::UserMetricsAction("Flash.PluginInstanceCreated")); 833 base::UserMetricsAction("Flash.PluginInstanceCreated"));
813 blink::WebRect bounds = container()->element().boundsInViewportSpace(); 834 RecordFlashSizeMetric(width, height);
814 RecordFlashSizeMetric(bounds.width, bounds.height);
815 } 835 }
816 836
817 if (throttler) { 837 if (throttler) {
818 throttler_ = throttler.Pass(); 838 throttler_ = throttler.Pass();
819 throttler_->AddObserver(this); 839 throttler_->AddObserver(this);
820 throttler_->Initialize(render_frame_, plugin_url_.GetOrigin(), 840 throttler_->Initialize(render_frame_, plugin_url_.GetOrigin(),
821 module()->name(), 841 module()->name(), gfx::Size(width, height));
822 container()->element().boundsInViewportSpace());
823 } 842 }
824 843
825 message_channel_ = MessageChannel::Create(this, &message_channel_object_); 844 message_channel_ = MessageChannel::Create(this, &message_channel_object_);
826 845
827 full_frame_ = full_frame; 846 full_frame_ = full_frame;
828 847
829 UpdateTouchEventRequest(); 848 UpdateTouchEventRequest();
830 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); 849 container_->setWantsWheelEvents(IsAcceptingWheelEvents());
831 850
832 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( 851 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build(
(...skipping 2483 matching lines...) Expand 10 before | Expand all | Expand 10 after
3316 3335
3317 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { 3336 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() {
3318 if (initialized_ && !javascript_used_ && is_flash_plugin_) { 3337 if (initialized_ && !javascript_used_ && is_flash_plugin_) {
3319 javascript_used_ = true; 3338 javascript_used_ = true;
3320 RenderThread::Get()->RecordAction( 3339 RenderThread::Get()->RecordAction(
3321 base::UserMetricsAction("Flash.JavaScriptUsed")); 3340 base::UserMetricsAction("Flash.JavaScriptUsed"));
3322 } 3341 }
3323 } 3342 }
3324 3343
3325 } // namespace content 3344 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698