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

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: 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_rect_ = 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 // The bound callback that owns the weak pointer is still valid until after 1615 // The bound callback that owns the weak pointer is still valid until after
1618 // this function returns. SendDidChangeView checks HasWeakPtrs, so we need to 1616 // this function returns. SendDidChangeView checks HasWeakPtrs, so we need to
1619 // invalidate them here. 1617 // invalidate them here.
1620 // NOTE: If we ever want to have more than one pending callback, it should 1618 // NOTE: If we ever want to have more than one pending callback, it should
1621 // use a different factory, or we should have a different strategy here. 1619 // use a different factory, or we should have a different strategy here.
1622 view_change_weak_ptr_factory_.InvalidateWeakPtrs(); 1620 view_change_weak_ptr_factory_.InvalidateWeakPtrs();
1623 SendDidChangeView(); 1621 SendDidChangeView();
1624 } 1622 }
1625 1623
1626 void PepperPluginInstanceImpl::SendDidChangeView() { 1624 void PepperPluginInstanceImpl::SendDidChangeView() {
1625 // An asynchronous view update is scheduled. Skip sending this update.
1626 if (view_change_weak_ptr_factory_.HasWeakPtrs())
1627 return;
1628
1627 // Don't send DidChangeView to crashed plugins. 1629 // Don't send DidChangeView to crashed plugins.
1628 if (module()->is_crashed()) 1630 if (module()->is_crashed())
1629 return; 1631 return;
1630 1632
1633 // During the first view update, initialize the throttler.
1634 if (!sent_initial_did_change_view_) {
1635 if (is_flash_plugin_ && RenderThread::Get()) {
1636 RenderThread::Get()->RecordAction(
1637 base::UserMetricsAction("Flash.PluginInstanceCreated"));
1638 RecordFlashSizeMetric(unobscured_rect_.width(),
1639 unobscured_rect_.height());
1640 }
1641
1642 if (throttler_) {
1643 throttler_->Initialize(render_frame_, plugin_url_.GetOrigin(),
1644 module()->name(), unobscured_rect_.size());
1645 }
1646 }
1647
1631 ppapi::ViewData view_data = view_data_; 1648 ppapi::ViewData view_data = view_data_;
1632 1649
1633 // When plugin content is throttled, fake the page being offscreen. We cannot 1650 // 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. 1651 // send empty view data here, as some plugins rely on accurate view data.
1635 if (throttler_ && throttler_->IsThrottled()) { 1652 if (throttler_ && throttler_->IsThrottled()) {
1636 view_data.is_page_visible = false; 1653 view_data.is_page_visible = false;
1637 view_data.clip_rect.point.x = 0; 1654 view_data.clip_rect.point.x = 0;
1638 view_data.clip_rect.point.y = 0; 1655 view_data.clip_rect.point.y = 0;
1639 view_data.clip_rect.size.width = 0; 1656 view_data.clip_rect.size.width = 0;
1640 view_data.clip_rect.size.height = 0; 1657 view_data.clip_rect.size.height = 0;
1641 } 1658 }
1642 1659
1643 if (view_change_weak_ptr_factory_.HasWeakPtrs() || 1660 if (sent_initial_did_change_view_ && last_sent_view_data_.Equals(view_data))
1644 (sent_initial_did_change_view_ &&
1645 last_sent_view_data_.Equals(view_data)))
1646 return; // Nothing to update. 1661 return; // Nothing to update.
1647 1662
1648 sent_initial_did_change_view_ = true; 1663 sent_initial_did_change_view_ = true;
1649 last_sent_view_data_ = view_data; 1664 last_sent_view_data_ = view_data;
1650 ScopedPPResource resource( 1665 ScopedPPResource resource(
1651 ScopedPPResource::PassRef(), 1666 ScopedPPResource::PassRef(),
1652 (new PPB_View_Shared(ppapi::OBJECT_IS_IMPL, pp_instance(), view_data)) 1667 (new PPB_View_Shared(ppapi::OBJECT_IS_IMPL, pp_instance(), view_data))
1653 ->GetReference()); 1668 ->GetReference());
1654 1669
1655 UpdateLayerTransform(); 1670 UpdateLayerTransform();
(...skipping 1656 matching lines...) Expand 10 before | Expand all | Expand 10 after
3312 3327
3313 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { 3328 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() {
3314 if (initialized_ && !javascript_used_ && is_flash_plugin_) { 3329 if (initialized_ && !javascript_used_ && is_flash_plugin_) {
3315 javascript_used_ = true; 3330 javascript_used_ = true;
3316 RenderThread::Get()->RecordAction( 3331 RenderThread::Get()->RecordAction(
3317 base::UserMetricsAction("Flash.JavaScriptUsed")); 3332 base::UserMetricsAction("Flash.JavaScriptUsed"));
3318 } 3333 }
3319 } 3334 }
3320 3335
3321 } // namespace content 3336 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | content/renderer/pepper/pepper_webplugin_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698