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

Unified Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 1528653002: Revert of 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | chrome/renderer/plugins/chrome_plugin_placeholder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/chrome_content_renderer_client.cc
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index a2019a0adf4adb4e1f33af57f71f742cda9cc9ef..c596aadd2118e25f7f65c374579bf40c29a2821c 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -124,7 +124,6 @@
#if defined(ENABLE_PLUGINS)
#include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
-#include "chrome/renderer/plugins/power_saver_info.h"
#endif
#if defined(ENABLE_PRINTING)
@@ -258,6 +257,60 @@
DCHECK(provider);
provider->set_spellcheck(spellcheck_);
return true;
+}
+#endif
+
+#if defined(ENABLE_PLUGINS)
+// Presence of the poster param within plugin object tags.
+// These numeric values are used in UMA logs; do not change them.
+enum PosterParamPresence {
+ POSTER_PRESENCE_NO_PARAM_PPS_DISABLED = 0,
+ POSTER_PRESENCE_NO_PARAM_PPS_ENABLED = 1,
+ POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED = 2,
+ POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED = 3,
+ POSTER_PRESENCE_NUM_ITEMS
+};
+
+const char kPluginPowerSaverPosterParamPresenceHistogram[] =
+ "Plugin.PowerSaver.PosterParamPresence";
+
+void RecordPosterParamPresence(PosterParamPresence presence) {
+ UMA_HISTOGRAM_ENUMERATION(kPluginPowerSaverPosterParamPresenceHistogram,
+ presence, POSTER_PRESENCE_NUM_ITEMS);
+}
+
+void TrackPosterParamPresence(const blink::WebPluginParams& params,
+ bool power_saver_enabled) {
+ DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
+
+ for (size_t i = 0; i < params.attributeNames.size(); ++i) {
+ if (params.attributeNames[i].utf8() == "poster") {
+ if (power_saver_enabled)
+ RecordPosterParamPresence(POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED);
+ else
+ RecordPosterParamPresence(POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED);
+
+ return;
+ }
+ }
+
+ if (power_saver_enabled)
+ RecordPosterParamPresence(POSTER_PRESENCE_NO_PARAM_PPS_ENABLED);
+ else
+ RecordPosterParamPresence(POSTER_PRESENCE_NO_PARAM_PPS_DISABLED);
+}
+
+std::string GetPluginInstancePosterAttribute(
+ const blink::WebPluginParams& params) {
+ DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
+
+ for (size_t i = 0; i < params.attributeNames.size(); ++i) {
+ if (params.attributeNames[i].utf8() == "poster" &&
+ !params.attributeValues[i].isEmpty()) {
+ return params.attributeValues[i].utf8();
+ }
+ }
+ return std::string();
}
#endif
@@ -675,13 +728,14 @@
}
#endif
- auto create_blocked_plugin = [&render_frame, &frame, &params, &info,
- &identifier, &group_name](
- int template_id, const base::string16& message) {
- return ChromePluginPlaceholder::CreateBlockedPlugin(
- render_frame, frame, params, info, identifier, group_name,
- template_id, message, PowerSaverInfo());
- };
+ base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
+ auto create_blocked_plugin =
+ [&render_frame, &frame, &params, &info, &identifier, &group_name](
+ int template_id, const base::string16& message) {
+ return ChromePluginPlaceholder::CreateBlockedPlugin(
+ render_frame, frame, params, info, identifier, group_name,
+ template_id, message, PlaceholderPosterInfo());
+ };
switch (status) {
case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: {
NOTREACHED();
@@ -700,8 +754,7 @@
bool is_nacl_unrestricted = false;
if (is_nacl_mime_type) {
is_nacl_unrestricted =
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableNaCl);
+ command_line->HasSwitch(switches::kEnableNaCl);
} else if (is_pnacl_mime_type) {
is_nacl_unrestricted = true;
}
@@ -757,28 +810,54 @@
bool is_prerendering =
prerender::PrerenderHelper::IsPrerendering(render_frame);
+ bool is_flash = info.name == ASCIIToUTF16(content::kFlashPluginName);
+
+ std::string override_for_testing = command_line->GetSwitchValueASCII(
+ switches::kOverridePluginPowerSaverForTesting);
+
+ // This feature has only been tested throughly with Flash thus far.
+ // It is also enabled for the Power Saver test plugin for browser tests.
+ bool can_throttle_plugin_type =
+ is_flash || override_for_testing == "ignore-list";
+
bool power_saver_setting_on =
status ==
ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
- PowerSaverInfo power_saver_info =
- PowerSaverInfo::Get(render_frame, power_saver_setting_on, params,
- info, frame->document().url());
- if (power_saver_info.blocked_for_background_tab || is_prerendering ||
- !power_saver_info.poster_attribute.empty()) {
+
+ bool power_saver_enabled =
+ override_for_testing == "always" ||
+ (power_saver_setting_on && can_throttle_plugin_type);
+ bool blocked_for_background_tab =
+ power_saver_enabled && render_frame->IsHidden();
+
+ PlaceholderPosterInfo poster_info;
+ if (power_saver_enabled) {
+ poster_info.poster_attribute =
+ GetPluginInstancePosterAttribute(params);
+ poster_info.base_url = frame->document().url();
+ }
+
+ if (is_flash)
+ TrackPosterParamPresence(params, power_saver_enabled);
+
+ if (blocked_for_background_tab || is_prerendering ||
+ !poster_info.poster_attribute.empty()) {
placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
render_frame, frame, params, info, identifier, group_name,
- power_saver_info.poster_attribute.empty()
- ? IDR_BLOCKED_PLUGIN_HTML
- : IDR_PLUGIN_POSTER_HTML,
+ poster_info.poster_attribute.empty() ? IDR_BLOCKED_PLUGIN_HTML
+ : IDR_PLUGIN_POSTER_HTML,
l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
- power_saver_info);
+ poster_info);
+ placeholder->set_blocked_for_background_tab(
+ blocked_for_background_tab);
placeholder->set_blocked_for_prerendering(is_prerendering);
+ placeholder->set_power_saver_enabled(power_saver_enabled);
placeholder->AllowLoading();
break;
}
scoped_ptr<content::PluginInstanceThrottler> throttler;
- if (power_saver_info.power_saver_enabled) {
+ if (power_saver_enabled) {
throttler = PluginInstanceThrottler::Create();
// PluginPreroller manages its own lifetime.
new PluginPreroller(
« no previous file with comments | « chrome/chrome_renderer.gypi ('k') | chrome/renderer/plugins/chrome_plugin_placeholder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698