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

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

Issue 680193002: Plugin Power Saver: Implement size-based heuristic for peripheral content. (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
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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_offset_string_conversions.h" 16 #include "base/strings/utf_offset_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "cc/base/latency_info_swap_promise.h" 19 #include "cc/base/latency_info_swap_promise.h"
20 #include "cc/blink/web_layer_impl.h" 20 #include "cc/blink/web_layer_impl.h"
21 #include "cc/layers/texture_layer.h" 21 #include "cc/layers/texture_layer.h"
22 #include "cc/trees/layer_tree_host.h" 22 #include "cc/trees/layer_tree_host.h"
23 #include "content/common/content_constants_internal.h" 23 #include "content/common/content_constants_internal.h"
24 #include "content/common/frame_messages.h"
24 #include "content/common/input/web_input_event_traits.h" 25 #include "content/common/input/web_input_event_traits.h"
25 #include "content/public/common/content_constants.h" 26 #include "content/public/common/content_constants.h"
26 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
27 #include "content/public/common/page_zoom.h" 28 #include "content/public/common/page_zoom.h"
28 #include "content/public/renderer/content_renderer_client.h" 29 #include "content/public/renderer/content_renderer_client.h"
29 #include "content/renderer/gpu/render_widget_compositor.h" 30 #include "content/renderer/gpu/render_widget_compositor.h"
30 #include "content/renderer/pepper/content_decryptor_delegate.h" 31 #include "content/renderer/pepper/content_decryptor_delegate.h"
31 #include "content/renderer/pepper/event_conversion.h" 32 #include "content/renderer/pepper/event_conversion.h"
32 #include "content/renderer/pepper/fullscreen_container.h" 33 #include "content/renderer/pepper/fullscreen_container.h"
33 #include "content/renderer/pepper/gfx_conversion.h" 34 #include "content/renderer/pepper/gfx_conversion.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 #define COMPILE_ASSERT_PRINT_SCALING_MATCHING_ENUM(webkit_name, pp_name) \ 219 #define COMPILE_ASSERT_PRINT_SCALING_MATCHING_ENUM(webkit_name, pp_name) \
219 COMPILE_ASSERT(static_cast<int>(webkit_name) == static_cast<int>(pp_name), \ 220 COMPILE_ASSERT(static_cast<int>(webkit_name) == static_cast<int>(pp_name), \
220 mismatching_enums) 221 mismatching_enums)
221 222
222 // <embed>/<object> attributes. 223 // <embed>/<object> attributes.
223 const char kWidth[] = "width"; 224 const char kWidth[] = "width";
224 const char kHeight[] = "height"; 225 const char kHeight[] = "height";
225 const char kBorder[] = "border"; // According to w3c, deprecated. 226 const char kBorder[] = "border"; // According to w3c, deprecated.
226 const char kStyle[] = "style"; 227 const char kStyle[] = "style";
227 228
229 // Maximum dimensions plug-in content may have while still being considered
Lei Zhang 2014/10/28 02:16:23 Mention these match Safari's sizes.
tommycli 2014/10/28 22:18:07 Done.
230 // peripheral content.
231 const int kPeripheralContentMaxWidth = 400;
232 const int kPeripheralContentMaxHeight = 300;
233
228 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_MOUSECURSOR_TYPE_POINTER); 234 COMPILE_ASSERT_MATCHING_ENUM(TypePointer, PP_MOUSECURSOR_TYPE_POINTER);
229 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_MOUSECURSOR_TYPE_CROSS); 235 COMPILE_ASSERT_MATCHING_ENUM(TypeCross, PP_MOUSECURSOR_TYPE_CROSS);
230 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_MOUSECURSOR_TYPE_HAND); 236 COMPILE_ASSERT_MATCHING_ENUM(TypeHand, PP_MOUSECURSOR_TYPE_HAND);
231 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_MOUSECURSOR_TYPE_IBEAM); 237 COMPILE_ASSERT_MATCHING_ENUM(TypeIBeam, PP_MOUSECURSOR_TYPE_IBEAM);
232 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_MOUSECURSOR_TYPE_WAIT); 238 COMPILE_ASSERT_MATCHING_ENUM(TypeWait, PP_MOUSECURSOR_TYPE_WAIT);
233 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_MOUSECURSOR_TYPE_HELP); 239 COMPILE_ASSERT_MATCHING_ENUM(TypeHelp, PP_MOUSECURSOR_TYPE_HELP);
234 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_MOUSECURSOR_TYPE_EASTRESIZE); 240 COMPILE_ASSERT_MATCHING_ENUM(TypeEastResize, PP_MOUSECURSOR_TYPE_EASTRESIZE);
235 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_MOUSECURSOR_TYPE_NORTHRESIZE); 241 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthResize, PP_MOUSECURSOR_TYPE_NORTHRESIZE);
236 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize, 242 COMPILE_ASSERT_MATCHING_ENUM(TypeNorthEastResize,
237 PP_MOUSECURSOR_TYPE_NORTHEASTRESIZE); 243 PP_MOUSECURSOR_TYPE_NORTHEASTRESIZE);
(...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 scoped_ptr<cc::SingleReleaseCallback>* release_callback, 2051 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
2046 bool use_shared_memory) { 2052 bool use_shared_memory) {
2047 if (!bound_graphics_2d_platform_) 2053 if (!bound_graphics_2d_platform_)
2048 return false; 2054 return false;
2049 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, 2055 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox,
2050 release_callback); 2056 release_callback);
2051 } 2057 }
2052 2058
2053 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } 2059 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; }
2054 2060
2061 bool PepperPluginInstanceImpl::OnMessageReceived(const IPC::Message& message) {
2062 // We set "handled" to false here, because we want this broadcast message to
Lei Zhang 2014/10/28 02:16:23 Do you want to coordinate this at the PluginModule
tommycli 2014/10/28 22:18:07 Done. I made a PluginPowerSaverHelper class to con
2063 // be processed by every PepperPluginInstanceImpl, and not swallowed.
2064 bool handled = false;
tommycli 2014/10/27 23:35:53 I set (handled = false) to make sure every instanc
groby-ooo-7-16 2014/10/28 00:39:12 You don't need this - as is, the code will _always
2065 IPC_BEGIN_MESSAGE_MAP(PepperPluginInstanceImpl, message)
2066 IPC_MESSAGE_HANDLER(FrameMsg_PluginContentOriginWhitelisted,
2067 OnPluginContentOriginWhitelisted)
2068 IPC_MESSAGE_UNHANDLED(handled = false)
2069 IPC_END_MESSAGE_MAP()
2070 return handled;
2071 }
2072
2055 void PepperPluginInstanceImpl::AddLatencyInfo( 2073 void PepperPluginInstanceImpl::AddLatencyInfo(
2056 const std::vector<ui::LatencyInfo>& latency_info) { 2074 const std::vector<ui::LatencyInfo>& latency_info) {
2057 if (render_frame_ && render_frame_->GetRenderWidget()) { 2075 if (render_frame_ && render_frame_->GetRenderWidget()) {
2058 RenderWidgetCompositor* compositor = 2076 RenderWidgetCompositor* compositor =
2059 render_frame_->GetRenderWidget()->compositor(); 2077 render_frame_->GetRenderWidget()->compositor();
2060 if (compositor) { 2078 if (compositor) {
2061 for (size_t i = 0; i < latency_info.size(); i++) { 2079 for (size_t i = 0; i < latency_info.size(); i++) {
2062 scoped_ptr<cc::SwapPromise> swap_promise( 2080 scoped_ptr<cc::SwapPromise> swap_promise(
2063 new cc::LatencyInfoSwapPromise(latency_info[i])); 2081 new cc::LatencyInfoSwapPromise(latency_info[i]));
2064 compositor->QueueSwapPromise(swap_promise.Pass()); 2082 compositor->QueueSwapPromise(swap_promise.Pass());
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
3288 } else { 3306 } else {
3289 // Running out-of-process. Initiate an IPC call to notify the plugin 3307 // Running out-of-process. Initiate an IPC call to notify the plugin
3290 // process. 3308 // process.
3291 ppapi::proxy::HostDispatcher* dispatcher = 3309 ppapi::proxy::HostDispatcher* dispatcher =
3292 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3310 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3293 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3311 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3294 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3312 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3295 } 3313 }
3296 } 3314 }
3297 3315
3298 bool PepperPluginInstanceImpl::IsPeripheralContent() const { 3316 bool PepperPluginInstanceImpl::IsPeripheralContent() {
3299 if (module_->name() != kFlashPluginName) 3317 if (module_->name() != kFlashPluginName)
3300 return false; 3318 return false;
3301 3319
3302 // Peripheral plugin content is defined to be peripheral when the plugin 3320 // Plugin content is defined to be cross-origin when the plugin source's
3303 // content's origin differs from the top level frame's origin. For example: 3321 // origin differs from the top level frame's origin. For example:
3304 // - Peripheral: a.com -> b.com/plugin.swf 3322 // - Cross-origin: a.com -> b.com/plugin.swf
3305 // - Peripheral: a.com -> b.com/iframe.html -> b.com/plugin.swf 3323 // - Cross-origin: 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 3324 // - Same-origin: a.com -> b.com/iframe-to-a.html -> a.com/plugin.swf
3307 3325
3308 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512 3326 // 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 3327 // is fixed. For now, case 3 in the comment above doesn't work in
3310 // --site-per-process mode. 3328 // --site-per-process mode.
3311 WebFrame* main_frame = render_frame_->GetWebFrame()->view()->mainFrame(); 3329 WebFrame* main_frame = render_frame_->GetWebFrame()->view()->mainFrame();
3312 if (main_frame->isWebRemoteFrame()) 3330 if (main_frame->isWebRemoteFrame())
3313 return true; 3331 return true;
3314 3332
3333 // All same-origin plugin content is essential.
3315 GURL main_frame_url = main_frame->document().url(); 3334 GURL main_frame_url = main_frame->document().url();
Lei Zhang 2014/10/28 02:16:23 nit: replace |main_frame_url| with |main_frame_ori
tommycli 2014/10/28 22:18:07 Done.
3316 return plugin_url_.GetOrigin() != main_frame_url.GetOrigin(); 3335 GURL plugin_origin = plugin_url_.GetOrigin();
3336 if (plugin_origin == main_frame_url.GetOrigin())
3337 return false;
3338
3339 // Cross-origin plugin content is peripheral if smaller than a maximum size.
3340 blink::WebRect bounds = container()->element().boundsInViewportSpace();
3341 bool content_is_large = bounds.width < kPeripheralContentMaxWidth ||
Lei Zhang 2014/10/28 02:16:23 Shouldn't the variable be named "content_is_small"
tommycli 2014/10/28 22:18:07 Done.
3342 bounds.height < kPeripheralContentMaxHeight;
3343
3344 if (content_is_large) {
3345 // Large cross-origin plugin content should temporarily whitelist all
3346 // content from that origin for that top level frame. This whitelist is
3347 // cleared when this render frame is destroyed.
3348 Send(new FrameHostMsg_PluginContentOriginAllowed(
Lei Zhang 2014/10/28 02:16:23 It's weird that an IsFoo() method has side effects
tommycli 2014/10/28 22:18:07 Done.
3349 render_frame()->GetRoutingID(),
3350 plugin_origin));
3351 } else {
3352 Send(new FrameHostMsg_PluginContentMarkedPeripheral(
3353 render_frame()->GetRoutingID(),
3354 plugin_origin));
3355 }
3356
3357 return content_is_large;
3317 } 3358 }
3318 3359
3319 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { 3360 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) {
3320 // Do not throttle if we've already disabled power saver. 3361 // Do not throttle if we've already disabled power saver.
3321 if (!power_saver_enabled_ && throttled) 3362 if (!power_saver_enabled_ && throttled)
3322 return; 3363 return;
3323 3364
3324 plugin_throttled_ = throttled; 3365 plugin_throttled_ = throttled;
3325 SendDidChangeView(); 3366 SendDidChangeView();
3326 } 3367 }
3327 3368
3369 void PepperPluginInstanceImpl::OnPluginContentOriginWhitelisted(
3370 const GURL& content_origin) {
3371 if (content_origin == plugin_url_.GetOrigin()) {
3372 power_saver_enabled_ = false;
3373 SetPluginThrottled(false);
groby-ooo-7-16 2014/10/28 00:39:12 Why not just SetPluginThrottled(false)?
tommycli 2014/10/28 22:18:07 power_saver_enabled_ needs to be set to false, so
3374 }
3375 }
3376
3328 } // namespace content 3377 } // namespace content
OLDNEW
« content/common/frame_messages.h ('K') | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698