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

Side by Side Diff: chrome/renderer/plugins/power_saver_info.cc

Issue 1497623002: Plugin Power Saver: Improve Poster behavior for essential plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 2015 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 "base/command_line.h"
6 #include "base/metrics/histogram_macros.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/renderer/plugins/power_saver_info.h"
9 #include "content/public/common/content_constants.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/common/webplugininfo.h"
12 #include "content/public/renderer/render_frame.h"
13 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "third_party/WebKit/public/web/WebPluginParams.h"
16 #include "url/origin.h"
17
18 namespace {
19
20 // Presence of the poster param within plugin object tags.
21 // These numeric values are used in UMA logs; do not change them.
22 enum PosterParamPresence {
23 POSTER_PRESENCE_NO_PARAM_PPS_DISABLED = 0,
24 POSTER_PRESENCE_NO_PARAM_PPS_ENABLED = 1,
25 POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED = 2,
26 POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED = 3,
27 POSTER_PRESENCE_NUM_ITEMS
28 };
29
30 const char kPluginPowerSaverPosterParamPresenceHistogram[] =
31 "Plugin.PowerSaver.PosterParamPresence";
32
33 void RecordPosterParamPresence(PosterParamPresence presence) {
34 UMA_HISTOGRAM_ENUMERATION(kPluginPowerSaverPosterParamPresenceHistogram,
35 presence, POSTER_PRESENCE_NUM_ITEMS);
36 }
37
38 void TrackPosterParamPresence(const blink::WebPluginParams& params,
39 bool power_saver_enabled) {
40 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
41
42 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
43 if (params.attributeNames[i].utf8() == "poster") {
44 RecordPosterParamPresence(
45 power_saver_enabled ? POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED
46 : POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED);
47 return;
48 }
49 }
50
51 RecordPosterParamPresence(power_saver_enabled
52 ? POSTER_PRESENCE_NO_PARAM_PPS_ENABLED
53 : POSTER_PRESENCE_NO_PARAM_PPS_DISABLED);
54 }
55
56 std::string GetPluginInstancePosterAttribute(
57 const blink::WebPluginParams& params) {
58 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
59
60 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
61 if (params.attributeNames[i].utf8() == "poster" &&
62 !params.attributeValues[i].isEmpty()) {
63 return params.attributeValues[i].utf8();
64 }
65 }
66 return std::string();
67 }
68
69 } // namespace
70
71 PowerSaverInfo::PowerSaverInfo()
72 : power_saver_enabled(false), blocked_for_background_tab(false) {}
73
74 PowerSaverInfo PowerSaverInfo::Get(content::RenderFrame* render_frame,
75 bool power_saver_setting_on,
76 const blink::WebPluginParams& params,
77 const content::WebPluginInfo& plugin_info,
78 const GURL& document_url) {
79 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
80 std::string override_for_testing = command_line->GetSwitchValueASCII(
81 switches::kOverridePluginPowerSaverForTesting);
82
83 // This feature has only been tested thoroughly with Flash thus far.
84 // It is also enabled for the Power Saver test plugin for browser tests.
85 bool is_flash =
86 plugin_info.name == base::ASCIIToUTF16(content::kFlashPluginName);
87 bool can_throttle_plugin_type =
88 is_flash || override_for_testing == "ignore-list";
89
90 PowerSaverInfo info;
91 info.power_saver_enabled =
92 override_for_testing == "always" ||
93 (power_saver_setting_on && can_throttle_plugin_type);
94
95 if (info.power_saver_enabled) {
96 // Even if we disable PPS in the next block because content is same-origin,
97 // it should still be eligible for background tab deferral if PPS is on.
98 info.blocked_for_background_tab = render_frame->IsHidden();
99
100 auto status = render_frame->GetPeripheralContentStatus(
101 render_frame->GetWebFrame()->top()->securityOrigin(),
102 url::Origin(params.url), gfx::Size());
103
104 if (status == content::RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN ||
Lei Zhang 2015/12/11 00:07:34 So why only these 2 essential types? Why not: if (
tommycli 2015/12/11 00:22:11 I added a comment to this effect.
105 status == content::RenderFrame::
106 CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED) {
107 info.power_saver_enabled = false;
108 } else {
109 info.poster_attribute = GetPluginInstancePosterAttribute(params);
110 info.base_url = document_url;
111 }
112 }
113
114 if (is_flash)
115 TrackPosterParamPresence(params, info.power_saver_enabled);
116
117 return info;
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698