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

Side by Side Diff: content/renderer/pepper/plugin_power_saver_helper.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: fix shutdown crash 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/common/frame_messages.h"
6 #include "content/public/renderer/render_frame.h"
7 #include "content/renderer/pepper/plugin_power_saver_helper.h"
8 #include "third_party/WebKit/public/web/WebDocument.h"
9 #include "third_party/WebKit/public/web/WebLocalFrame.h"
10 #include "third_party/WebKit/public/web/WebView.h"
11
12 namespace content {
13
14 namespace {
15
16 // Maximum dimensions plug-in content may have while still being considered
17 // peripheral content. These match the sizes used by Safari.
18 const int kPeripheralContentMaxWidth = 400;
19 const int kPeripheralContentMaxHeight = 300;
20 }
Lei Zhang 2014/10/29 09:26:47 nit: blank line before and // namespace
tommycli 2014/10/29 19:59:23 Done.
21
22 PluginPowerSaverHelper::PeripheralPlugin::PeripheralPlugin(
23 const GURL& content_origin,
24 const base::Closure& unthrottle)
25 : content_origin(content_origin), unthrottle(unthrottle) {
26 }
27
28 PluginPowerSaverHelper::PeripheralPlugin::~PeripheralPlugin() {
29 }
30
31 PluginPowerSaverHelper::PluginPowerSaverHelper(RenderFrame* render_frame)
32 : RenderFrameObserver(render_frame) {
33 }
34
35 PluginPowerSaverHelper::~PluginPowerSaverHelper() {
36 }
37
38 bool PluginPowerSaverHelper::OnMessageReceived(const IPC::Message& message) {
39 bool handled = true;
40 IPC_BEGIN_MESSAGE_MAP(PluginPowerSaverHelper, message)
41 IPC_MESSAGE_HANDLER(FrameMsg_UpdatePluginContentOriginWhitelist,
42 OnUpdatePluginContentOriginWhitelist)
43 IPC_MESSAGE_UNHANDLED(handled = false)
44 IPC_END_MESSAGE_MAP()
45 return handled;
46 }
47
48 void PluginPowerSaverHelper::OnUpdatePluginContentOriginWhitelist(
49 const std::set<GURL>& origin_whitelist) {
50 origin_whitelist_ = origin_whitelist;
51
52 // Check throttled plugin instances to see if any can be unthrottled.
53 auto it = peripheral_plugins_.begin();
54 while (it != peripheral_plugins_.end()) {
55 if (origin_whitelist.count(it->content_origin)) {
56 it->unthrottle.Run();
57 it = peripheral_plugins_.erase(it);
58 } else {
59 ++it;
60 }
61 }
62 }
63
64 bool PluginPowerSaverHelper::ShouldThrottleContent(
65 const GURL& plugin_url,
66 int width,
67 int height,
68 const base::Closure& unthrottle) {
69 GURL plugin_origin = plugin_url.GetOrigin();
70
71 // TODO(alexmos): Update this to use the origin of the RemoteFrame when 426512
72 // is fixed. For now, case 3 in the comment above doesn't work in
73 // --site-per-process mode.
74 blink::WebFrame* main_frame =
75 render_frame()->GetWebFrame()->view()->mainFrame();
76 if (main_frame->isWebRemoteFrame()) {
77 peripheral_plugins_.push_back(PeripheralPlugin(plugin_origin, unthrottle));
Lei Zhang 2014/10/29 09:26:47 ShouldThrottleContent() should be const. You can c
tommycli 2014/10/29 19:59:23 Done.
78 return true;
79 }
80
81 // All same-origin plugin content is essential.
82 GURL main_frame_origin = GURL(main_frame->document().url()).GetOrigin();
83 if (plugin_origin == main_frame_origin)
84 return false;
85
86 // Whitelisted plugin origins are also essential.
87 if (origin_whitelist_.count(plugin_origin))
88 return false;
89
90 // Cross-origin plugin content is peripheral if smaller than a maximum size.
91 bool content_is_small = width < kPeripheralContentMaxWidth ||
92 height < kPeripheralContentMaxHeight;
93
94 if (content_is_small) {
95 peripheral_plugins_.push_back(PeripheralPlugin(plugin_origin, unthrottle));
96 return true;
97 } else {
Lei Zhang 2014/10/29 09:26:47 nit: you don't need the else, but if you make this
tommycli 2014/10/29 19:59:23 Done.
98 origin_whitelist_.insert(plugin_origin);
99 Send(new FrameHostMsg_PluginContentOriginAllowed(
Lei Zhang 2014/10/29 09:26:47 You only need to send the message if you actually
tommycli 2014/10/29 19:59:23 Done.
100 render_frame()->GetRoutingID(), plugin_origin));
101 return false;
102 }
103 }
104
105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698