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

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: Remove keyframe size tracking. Unnecessary. Created 5 years, 8 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 bool PepperPluginInstanceImpl::Initialize( 802 bool PepperPluginInstanceImpl::Initialize(
803 const std::vector<std::string>& arg_names, 803 const std::vector<std::string>& arg_names,
804 const std::vector<std::string>& arg_values, 804 const std::vector<std::string>& arg_values,
805 bool full_frame, 805 bool full_frame,
806 scoped_ptr<PluginInstanceThrottlerImpl> throttler) { 806 scoped_ptr<PluginInstanceThrottlerImpl> throttler) {
807 DCHECK(!throttler_); 807 DCHECK(!throttler_);
808 808
809 if (!render_frame_) 809 if (!render_frame_)
810 return false; 810 return false;
811 811
812 if (is_flash_plugin_ && RenderThread::Get()) {
813 RenderThread::Get()->RecordAction(
814 base::UserMetricsAction("Flash.PluginInstanceCreated"));
815 blink::WebRect bounds = container()->element().boundsInViewportSpace();
816 RecordFlashSizeMetric(bounds.width, bounds.height);
817 }
818
819 if (throttler) { 812 if (throttler) {
820 throttler_ = throttler.Pass(); 813 throttler_ = throttler.Pass();
821 throttler_->AddObserver(this); 814 throttler_->AddObserver(this);
822 throttler_->Initialize(render_frame_, plugin_url_.GetOrigin(),
823 module()->name(),
824 container()->element().boundsInViewportSpace());
825 } 815 }
826 816
827 message_channel_ = MessageChannel::Create(this, &message_channel_object_); 817 message_channel_ = MessageChannel::Create(this, &message_channel_object_);
828 818
829 full_frame_ = full_frame; 819 full_frame_ = full_frame;
830 820
831 UpdateTouchEventRequest(); 821 UpdateTouchEventRequest();
832 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); 822 container_->setWantsWheelEvents(IsAcceptingWheelEvents());
833 823
834 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build( 824 SetGPUHistogram(ppapi::Preferences(PpapiPreferencesBuilder::Build(
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 RecordFlashJavaScriptUse(); 1216 RecordFlashJavaScriptUse();
1227 1217
1228 // If the plugin supports the private instance interface, try to retrieve its 1218 // If the plugin supports the private instance interface, try to retrieve its
1229 // instance object. 1219 // instance object.
1230 if (LoadPrivateInterface()) 1220 if (LoadPrivateInterface())
1231 return plugin_private_interface_->GetInstanceObject(pp_instance()); 1221 return plugin_private_interface_->GetInstanceObject(pp_instance());
1232 return PP_MakeUndefined(); 1222 return PP_MakeUndefined();
1233 } 1223 }
1234 1224
1235 void PepperPluginInstanceImpl::ViewChanged( 1225 void PepperPluginInstanceImpl::ViewChanged(
1236 const gfx::Rect& position, 1226 const gfx::Rect& window,
1237 const gfx::Rect& clip, 1227 const gfx::Rect& clip,
1228 const gfx::Rect& unobscured,
1238 const std::vector<gfx::Rect>& cut_outs_rects) { 1229 const std::vector<gfx::Rect>& cut_outs_rects) {
1239 // WebKit can give weird (x,y) positions for empty clip rects (since the 1230 // WebKit can give weird (x,y) positions for empty clip rects (since the
1240 // position technically doesn't matter). But we want to make these 1231 // position technically doesn't matter). But we want to make these
1241 // consistent since this is given to the plugin, so force everything to 0 1232 // consistent since this is given to the plugin, so force everything to 0
1242 // in the "everything is clipped" case. 1233 // in the "everything is clipped" case.
1243 gfx::Rect new_clip; 1234 gfx::Rect new_clip;
1244 if (!clip.IsEmpty()) 1235 if (!clip.IsEmpty())
1245 new_clip = clip; 1236 new_clip = clip;
1246 1237
1238 unobscured_ = unobscured;
1239
1247 cut_outs_rects_ = cut_outs_rects; 1240 cut_outs_rects_ = cut_outs_rects;
1248 1241
1249 view_data_.rect = PP_FromGfxRect(position); 1242 view_data_.rect = PP_FromGfxRect(window);
1250 view_data_.clip_rect = PP_FromGfxRect(clip); 1243 view_data_.clip_rect = PP_FromGfxRect(clip);
1251 view_data_.device_scale = container_->deviceScaleFactor(); 1244 view_data_.device_scale = container_->deviceScaleFactor();
1252 view_data_.css_scale = 1245 view_data_.css_scale =
1253 container_->pageZoomFactor() * container_->pageScaleFactor(); 1246 container_->pageZoomFactor() * container_->pageScaleFactor();
1254 1247
1255 gfx::Size scroll_offset = 1248 gfx::Size scroll_offset =
1256 container_->element().document().frame()->scrollOffset(); 1249 container_->element().document().frame()->scrollOffset();
1257 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(), 1250 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(),
1258 scroll_offset.height()); 1251 scroll_offset.height());
1259 1252
(...skipping 21 matching lines...) Expand all
1281 // Reset the size attributes that we hacked to fill in the screen and 1274 // Reset the size attributes that we hacked to fill in the screen and
1282 // retrigger ViewChanged. Make sure we don't forward duplicates of 1275 // retrigger ViewChanged. Make sure we don't forward duplicates of
1283 // this view to the plugin. 1276 // this view to the plugin.
1284 ResetSizeAttributesAfterFullscreen(); 1277 ResetSizeAttributesAfterFullscreen();
1285 return; 1278 return;
1286 } 1279 }
1287 } 1280 }
1288 1281
1289 UpdateFlashFullscreenState(fullscreen_container_ != NULL); 1282 UpdateFlashFullscreenState(fullscreen_container_ != NULL);
1290 1283
1291 SendDidChangeView(); 1284 // During plugin initialization, there are often re-layouts. Avoid sending
1285 // intermediate sizes the plugin and throttler.
1286 if (sent_initial_did_change_view_)
1287 SendDidChangeView();
1288 else
1289 ScheduleAsyncDidChangeView();
1292 } 1290 }
1293 1291
1294 void PepperPluginInstanceImpl::SetWebKitFocus(bool has_focus) { 1292 void PepperPluginInstanceImpl::SetWebKitFocus(bool has_focus) {
1295 if (has_webkit_focus_ == has_focus) 1293 if (has_webkit_focus_ == has_focus)
1296 return; 1294 return;
1297 1295
1298 bool old_plugin_focus = PluginHasFocus(); 1296 bool old_plugin_focus = PluginHasFocus();
1299 has_webkit_focus_ = has_focus; 1297 has_webkit_focus_ = has_focus;
1300 if (PluginHasFocus() != old_plugin_focus) 1298 if (PluginHasFocus() != old_plugin_focus)
1301 SendFocusChangeNotification(); 1299 SendFocusChangeNotification();
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 SendDidChangeView(); 1621 SendDidChangeView();
1624 } 1622 }
1625 1623
1626 void PepperPluginInstanceImpl::SendDidChangeView() { 1624 void PepperPluginInstanceImpl::SendDidChangeView() {
1627 // Don't send DidChangeView to crashed plugins. 1625 // Don't send DidChangeView to crashed plugins.
1628 if (module()->is_crashed()) 1626 if (module()->is_crashed())
1629 return; 1627 return;
1630 1628
1631 ppapi::ViewData view_data = view_data_; 1629 ppapi::ViewData view_data = view_data_;
1632 1630
1631 if (!sent_initial_did_change_view_) {
piman 2015/04/01 01:02:41 So, you may be getting into this code more than on
tommycli 2015/04/01 18:55:28 Done. Thanks for the explanation. That's a pretty
1632 if (is_flash_plugin_ && RenderThread::Get()) {
1633 RenderThread::Get()->RecordAction(
1634 base::UserMetricsAction("Flash.PluginInstanceCreated"));
1635 RecordFlashSizeMetric(unobscured_.width(), unobscured_.height());
1636 }
1637
1638 // Initialize the throttler if necessary.
1639 if (throttler_) {
1640 throttler_->Initialize(render_frame_, plugin_url_.GetOrigin(),
1641 module()->name(), unobscured_.size());
1642 }
1643 }
1644
1633 // When plugin content is throttled, fake the page being offscreen. We cannot 1645 // When plugin content is throttled, fake the page being offscreen. We cannot
1634 // send empty view data here, as some plugins rely on accurate view data. 1646 // send empty view data here, as some plugins rely on accurate view data.
1635 if (throttler_ && throttler_->IsThrottled()) { 1647 if (throttler_ && throttler_->IsThrottled()) {
1636 view_data.is_page_visible = false; 1648 view_data.is_page_visible = false;
1637 view_data.clip_rect.point.x = 0; 1649 view_data.clip_rect.point.x = 0;
1638 view_data.clip_rect.point.y = 0; 1650 view_data.clip_rect.point.y = 0;
1639 view_data.clip_rect.size.width = 0; 1651 view_data.clip_rect.size.width = 0;
1640 view_data.clip_rect.size.height = 0; 1652 view_data.clip_rect.size.height = 0;
1641 } 1653 }
1642 1654
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after
3312 3324
3313 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { 3325 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() {
3314 if (initialized_ && !javascript_used_ && is_flash_plugin_) { 3326 if (initialized_ && !javascript_used_ && is_flash_plugin_) {
3315 javascript_used_ = true; 3327 javascript_used_ = true;
3316 RenderThread::Get()->RecordAction( 3328 RenderThread::Get()->RecordAction(
3317 base::UserMetricsAction("Flash.JavaScriptUsed")); 3329 base::UserMetricsAction("Flash.JavaScriptUsed"));
3318 } 3330 }
3319 } 3331 }
3320 3332
3321 } // namespace content 3333 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698