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

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

Powered by Google App Engine
This is Rietveld 408576698