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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/crash_logging.h" 8 #include "base/debug/crash_logging.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 #include "extensions/renderer/dispatcher.h" 117 #include "extensions/renderer/dispatcher.h"
118 #include "extensions/renderer/renderer_extension_registry.h" 118 #include "extensions/renderer/renderer_extension_registry.h"
119 #endif 119 #endif
120 120
121 #if defined(ENABLE_IPC_FUZZER) 121 #if defined(ENABLE_IPC_FUZZER)
122 #include "chrome/common/external_ipc_dumper.h" 122 #include "chrome/common/external_ipc_dumper.h"
123 #endif 123 #endif
124 124
125 #if defined(ENABLE_PLUGINS) 125 #if defined(ENABLE_PLUGINS)
126 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" 126 #include "chrome/renderer/plugins/chrome_plugin_placeholder.h"
127 #include "chrome/renderer/plugins/power_saver_info.h"
128 #endif 127 #endif
129 128
130 #if defined(ENABLE_PRINTING) 129 #if defined(ENABLE_PRINTING)
131 #include "chrome/common/chrome_content_client.h" 130 #include "chrome/common/chrome_content_client.h"
132 #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h" 131 #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h"
133 #include "components/printing/renderer/print_web_view_helper.h" 132 #include "components/printing/renderer/print_web_view_helper.h"
134 #include "printing/print_settings.h" 133 #include "printing/print_settings.h"
135 #endif 134 #endif
136 135
137 #if defined(ENABLE_PRINT_PREVIEW) 136 #if defined(ENABLE_PRINT_PREVIEW)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 }; 253 };
255 254
256 bool SpellCheckReplacer::Visit(content::RenderView* render_view) { 255 bool SpellCheckReplacer::Visit(content::RenderView* render_view) {
257 SpellCheckProvider* provider = SpellCheckProvider::Get(render_view); 256 SpellCheckProvider* provider = SpellCheckProvider::Get(render_view);
258 DCHECK(provider); 257 DCHECK(provider);
259 provider->set_spellcheck(spellcheck_); 258 provider->set_spellcheck(spellcheck_);
260 return true; 259 return true;
261 } 260 }
262 #endif 261 #endif
263 262
263 #if defined(ENABLE_PLUGINS)
264 // Presence of the poster param within plugin object tags.
265 // These numeric values are used in UMA logs; do not change them.
266 enum PosterParamPresence {
267 POSTER_PRESENCE_NO_PARAM_PPS_DISABLED = 0,
268 POSTER_PRESENCE_NO_PARAM_PPS_ENABLED = 1,
269 POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED = 2,
270 POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED = 3,
271 POSTER_PRESENCE_NUM_ITEMS
272 };
273
274 const char kPluginPowerSaverPosterParamPresenceHistogram[] =
275 "Plugin.PowerSaver.PosterParamPresence";
276
277 void RecordPosterParamPresence(PosterParamPresence presence) {
278 UMA_HISTOGRAM_ENUMERATION(kPluginPowerSaverPosterParamPresenceHistogram,
279 presence, POSTER_PRESENCE_NUM_ITEMS);
280 }
281
282 void TrackPosterParamPresence(const blink::WebPluginParams& params,
283 bool power_saver_enabled) {
284 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
285
286 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
287 if (params.attributeNames[i].utf8() == "poster") {
288 if (power_saver_enabled)
289 RecordPosterParamPresence(POSTER_PRESENCE_PARAM_EXISTS_PPS_ENABLED);
290 else
291 RecordPosterParamPresence(POSTER_PRESENCE_PARAM_EXISTS_PPS_DISABLED);
292
293 return;
294 }
295 }
296
297 if (power_saver_enabled)
298 RecordPosterParamPresence(POSTER_PRESENCE_NO_PARAM_PPS_ENABLED);
299 else
300 RecordPosterParamPresence(POSTER_PRESENCE_NO_PARAM_PPS_DISABLED);
301 }
302
303 std::string GetPluginInstancePosterAttribute(
304 const blink::WebPluginParams& params) {
305 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
306
307 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
308 if (params.attributeNames[i].utf8() == "poster" &&
309 !params.attributeValues[i].isEmpty()) {
310 return params.attributeValues[i].utf8();
311 }
312 }
313 return std::string();
314 }
315 #endif
316
264 #if defined(ENABLE_EXTENSIONS) 317 #if defined(ENABLE_EXTENSIONS)
265 bool IsStandaloneExtensionProcess() { 318 bool IsStandaloneExtensionProcess() {
266 return base::CommandLine::ForCurrentProcess()->HasSwitch( 319 return base::CommandLine::ForCurrentProcess()->HasSwitch(
267 extensions::switches::kExtensionProcess); 320 extensions::switches::kExtensionProcess);
268 } 321 }
269 #endif 322 #endif
270 323
271 // Defers media player loading in background pages until they're visible. 324 // Defers media player loading in background pages until they're visible.
272 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135 325 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135
273 class MediaLoadDeferrer : public content::RenderFrameObserver { 326 class MediaLoadDeferrer : public content::RenderFrameObserver {
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 // If user is on ALLOW or DETECT setting, loading needs to be blocked here. 721 // If user is on ALLOW or DETECT setting, loading needs to be blocked here.
669 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed || 722 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed ||
670 status == 723 status ==
671 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) && 724 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) &&
672 info.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) { 725 info.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) {
673 if (observer->AreNPAPIPluginsBlocked()) 726 if (observer->AreNPAPIPluginsBlocked())
674 status = ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported; 727 status = ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported;
675 } 728 }
676 #endif 729 #endif
677 730
678 auto create_blocked_plugin = [&render_frame, &frame, &params, &info, 731 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
679 &identifier, &group_name]( 732 auto create_blocked_plugin =
680 int template_id, const base::string16& message) { 733 [&render_frame, &frame, &params, &info, &identifier, &group_name](
681 return ChromePluginPlaceholder::CreateBlockedPlugin( 734 int template_id, const base::string16& message) {
682 render_frame, frame, params, info, identifier, group_name, 735 return ChromePluginPlaceholder::CreateBlockedPlugin(
683 template_id, message, PowerSaverInfo()); 736 render_frame, frame, params, info, identifier, group_name,
684 }; 737 template_id, message, PlaceholderPosterInfo());
738 };
685 switch (status) { 739 switch (status) {
686 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { 740 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: {
687 NOTREACHED(); 741 NOTREACHED();
688 break; 742 break;
689 } 743 }
690 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed: 744 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed:
691 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: { 745 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
692 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 746 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
693 const bool is_nacl_plugin = 747 const bool is_nacl_plugin =
694 info.name == ASCIIToUTF16(nacl::kNaClPluginName); 748 info.name == ASCIIToUTF16(nacl::kNaClPluginName);
695 const bool is_nacl_mime_type = 749 const bool is_nacl_mime_type =
696 actual_mime_type == nacl::kNaClPluginMimeType; 750 actual_mime_type == nacl::kNaClPluginMimeType;
697 const bool is_pnacl_mime_type = 751 const bool is_pnacl_mime_type =
698 actual_mime_type == nacl::kPnaclPluginMimeType; 752 actual_mime_type == nacl::kPnaclPluginMimeType;
699 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) { 753 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) {
700 bool is_nacl_unrestricted = false; 754 bool is_nacl_unrestricted = false;
701 if (is_nacl_mime_type) { 755 if (is_nacl_mime_type) {
702 is_nacl_unrestricted = 756 is_nacl_unrestricted =
703 base::CommandLine::ForCurrentProcess()->HasSwitch( 757 command_line->HasSwitch(switches::kEnableNaCl);
704 switches::kEnableNaCl);
705 } else if (is_pnacl_mime_type) { 758 } else if (is_pnacl_mime_type) {
706 is_nacl_unrestricted = true; 759 is_nacl_unrestricted = true;
707 } 760 }
708 GURL manifest_url; 761 GURL manifest_url;
709 GURL app_url; 762 GURL app_url;
710 if (is_nacl_mime_type || is_pnacl_mime_type) { 763 if (is_nacl_mime_type || is_pnacl_mime_type) {
711 // Normal NaCl/PNaCl embed. The app URL is the page URL. 764 // Normal NaCl/PNaCl embed. The app URL is the page URL.
712 manifest_url = url; 765 manifest_url = url;
713 app_url = frame->top()->document().url(); 766 app_url = frame->top()->document().url();
714 } else { 767 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 } 803 }
751 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 804 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
752 805
753 // Delay loading plugins if prerendering. 806 // Delay loading plugins if prerendering.
754 // TODO(mmenke): In the case of prerendering, feed into 807 // TODO(mmenke): In the case of prerendering, feed into
755 // ChromeContentRendererClient::CreatePlugin instead, to 808 // ChromeContentRendererClient::CreatePlugin instead, to
756 // reduce the chance of future regressions. 809 // reduce the chance of future regressions.
757 bool is_prerendering = 810 bool is_prerendering =
758 prerender::PrerenderHelper::IsPrerendering(render_frame); 811 prerender::PrerenderHelper::IsPrerendering(render_frame);
759 812
813 bool is_flash = info.name == ASCIIToUTF16(content::kFlashPluginName);
814
815 std::string override_for_testing = command_line->GetSwitchValueASCII(
816 switches::kOverridePluginPowerSaverForTesting);
817
818 // This feature has only been tested throughly with Flash thus far.
819 // It is also enabled for the Power Saver test plugin for browser tests.
820 bool can_throttle_plugin_type =
821 is_flash || override_for_testing == "ignore-list";
822
760 bool power_saver_setting_on = 823 bool power_saver_setting_on =
761 status == 824 status ==
762 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent; 825 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
763 PowerSaverInfo power_saver_info = 826
764 PowerSaverInfo::Get(render_frame, power_saver_setting_on, params, 827 bool power_saver_enabled =
765 info, frame->document().url()); 828 override_for_testing == "always" ||
766 if (power_saver_info.blocked_for_background_tab || is_prerendering || 829 (power_saver_setting_on && can_throttle_plugin_type);
767 !power_saver_info.poster_attribute.empty()) { 830 bool blocked_for_background_tab =
831 power_saver_enabled && render_frame->IsHidden();
832
833 PlaceholderPosterInfo poster_info;
834 if (power_saver_enabled) {
835 poster_info.poster_attribute =
836 GetPluginInstancePosterAttribute(params);
837 poster_info.base_url = frame->document().url();
838 }
839
840 if (is_flash)
841 TrackPosterParamPresence(params, power_saver_enabled);
842
843 if (blocked_for_background_tab || is_prerendering ||
844 !poster_info.poster_attribute.empty()) {
768 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( 845 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
769 render_frame, frame, params, info, identifier, group_name, 846 render_frame, frame, params, info, identifier, group_name,
770 power_saver_info.poster_attribute.empty() 847 poster_info.poster_attribute.empty() ? IDR_BLOCKED_PLUGIN_HTML
771 ? IDR_BLOCKED_PLUGIN_HTML 848 : IDR_PLUGIN_POSTER_HTML,
772 : IDR_PLUGIN_POSTER_HTML,
773 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 849 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
774 power_saver_info); 850 poster_info);
851 placeholder->set_blocked_for_background_tab(
852 blocked_for_background_tab);
775 placeholder->set_blocked_for_prerendering(is_prerendering); 853 placeholder->set_blocked_for_prerendering(is_prerendering);
854 placeholder->set_power_saver_enabled(power_saver_enabled);
776 placeholder->AllowLoading(); 855 placeholder->AllowLoading();
777 break; 856 break;
778 } 857 }
779 858
780 scoped_ptr<content::PluginInstanceThrottler> throttler; 859 scoped_ptr<content::PluginInstanceThrottler> throttler;
781 if (power_saver_info.power_saver_enabled) { 860 if (power_saver_enabled) {
782 throttler = PluginInstanceThrottler::Create(); 861 throttler = PluginInstanceThrottler::Create();
783 // PluginPreroller manages its own lifetime. 862 // PluginPreroller manages its own lifetime.
784 new PluginPreroller( 863 new PluginPreroller(
785 render_frame, frame, params, info, identifier, group_name, 864 render_frame, frame, params, info, identifier, group_name,
786 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 865 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
787 throttler.get()); 866 throttler.get());
788 } 867 }
789 868
790 return render_frame->CreatePlugin(frame, info, params, 869 return render_frame->CreatePlugin(frame, info, params,
791 throttler.Pass()); 870 throttler.Pass());
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 // chrome.system.network.getNetworkInterfaces provides the same 1486 // chrome.system.network.getNetworkInterfaces provides the same
1408 // information. Also, the enforcement of sending and binding UDP is already done 1487 // information. Also, the enforcement of sending and binding UDP is already done
1409 // by chrome extension permission model. 1488 // by chrome extension permission model.
1410 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { 1489 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() {
1411 #if defined(ENABLE_EXTENSIONS) 1490 #if defined(ENABLE_EXTENSIONS)
1412 return !IsStandaloneExtensionProcess(); 1491 return !IsStandaloneExtensionProcess();
1413 #else 1492 #else
1414 return true; 1493 return true;
1415 #endif 1494 #endif
1416 } 1495 }
OLDNEW
« 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