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

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
« 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"
127 #endif 128 #endif
128 129
129 #if defined(ENABLE_PRINTING) 130 #if defined(ENABLE_PRINTING)
130 #include "chrome/common/chrome_content_client.h" 131 #include "chrome/common/chrome_content_client.h"
131 #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h" 132 #include "chrome/renderer/printing/chrome_print_web_view_helper_delegate.h"
132 #include "components/printing/renderer/print_web_view_helper.h" 133 #include "components/printing/renderer/print_web_view_helper.h"
133 #include "printing/print_settings.h" 134 #include "printing/print_settings.h"
134 #endif 135 #endif
135 136
136 #if defined(ENABLE_PRINT_PREVIEW) 137 #if defined(ENABLE_PRINT_PREVIEW)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 }; 254 };
254 255
255 bool SpellCheckReplacer::Visit(content::RenderView* render_view) { 256 bool SpellCheckReplacer::Visit(content::RenderView* render_view) {
256 SpellCheckProvider* provider = SpellCheckProvider::Get(render_view); 257 SpellCheckProvider* provider = SpellCheckProvider::Get(render_view);
257 DCHECK(provider); 258 DCHECK(provider);
258 provider->set_spellcheck(spellcheck_); 259 provider->set_spellcheck(spellcheck_);
259 return true; 260 return true;
260 } 261 }
261 #endif 262 #endif
262 263
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
317 #if defined(ENABLE_EXTENSIONS) 264 #if defined(ENABLE_EXTENSIONS)
318 bool IsStandaloneExtensionProcess() { 265 bool IsStandaloneExtensionProcess() {
319 return base::CommandLine::ForCurrentProcess()->HasSwitch( 266 return base::CommandLine::ForCurrentProcess()->HasSwitch(
320 extensions::switches::kExtensionProcess); 267 extensions::switches::kExtensionProcess);
321 } 268 }
322 #endif 269 #endif
323 270
324 // Defers media player loading in background pages until they're visible. 271 // Defers media player loading in background pages until they're visible.
325 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135 272 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135
326 class MediaLoadDeferrer : public content::RenderFrameObserver { 273 class MediaLoadDeferrer : public content::RenderFrameObserver {
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 // If user is on ALLOW or DETECT setting, loading needs to be blocked here. 668 // If user is on ALLOW or DETECT setting, loading needs to be blocked here.
722 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed || 669 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed ||
723 status == 670 status ==
724 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) && 671 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) &&
725 info.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) { 672 info.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) {
726 if (observer->AreNPAPIPluginsBlocked()) 673 if (observer->AreNPAPIPluginsBlocked())
727 status = ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported; 674 status = ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported;
728 } 675 }
729 #endif 676 #endif
730 677
731 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 678 auto create_blocked_plugin = [&render_frame, &frame, &params, &info,
732 auto create_blocked_plugin = 679 &identifier, &group_name](
733 [&render_frame, &frame, &params, &info, &identifier, &group_name]( 680 int template_id, const base::string16& message) {
734 int template_id, const base::string16& message) { 681 return ChromePluginPlaceholder::CreateBlockedPlugin(
735 return ChromePluginPlaceholder::CreateBlockedPlugin( 682 render_frame, frame, params, info, identifier, group_name,
736 render_frame, frame, params, info, identifier, group_name, 683 template_id, message, PowerSaverInfo());
737 template_id, message, PlaceholderPosterInfo()); 684 };
738 };
739 switch (status) { 685 switch (status) {
740 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { 686 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: {
741 NOTREACHED(); 687 NOTREACHED();
742 break; 688 break;
743 } 689 }
744 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed: 690 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed:
745 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: { 691 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
746 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 692 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
747 const bool is_nacl_plugin = 693 const bool is_nacl_plugin =
748 info.name == ASCIIToUTF16(nacl::kNaClPluginName); 694 info.name == ASCIIToUTF16(nacl::kNaClPluginName);
749 const bool is_nacl_mime_type = 695 const bool is_nacl_mime_type =
750 actual_mime_type == nacl::kNaClPluginMimeType; 696 actual_mime_type == nacl::kNaClPluginMimeType;
751 const bool is_pnacl_mime_type = 697 const bool is_pnacl_mime_type =
752 actual_mime_type == nacl::kPnaclPluginMimeType; 698 actual_mime_type == nacl::kPnaclPluginMimeType;
753 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) { 699 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) {
754 bool is_nacl_unrestricted = false; 700 bool is_nacl_unrestricted = false;
755 if (is_nacl_mime_type) { 701 if (is_nacl_mime_type) {
756 is_nacl_unrestricted = 702 is_nacl_unrestricted =
757 command_line->HasSwitch(switches::kEnableNaCl); 703 base::CommandLine::ForCurrentProcess()->HasSwitch(
704 switches::kEnableNaCl);
758 } else if (is_pnacl_mime_type) { 705 } else if (is_pnacl_mime_type) {
759 is_nacl_unrestricted = true; 706 is_nacl_unrestricted = true;
760 } 707 }
761 GURL manifest_url; 708 GURL manifest_url;
762 GURL app_url; 709 GURL app_url;
763 if (is_nacl_mime_type || is_pnacl_mime_type) { 710 if (is_nacl_mime_type || is_pnacl_mime_type) {
764 // Normal NaCl/PNaCl embed. The app URL is the page URL. 711 // Normal NaCl/PNaCl embed. The app URL is the page URL.
765 manifest_url = url; 712 manifest_url = url;
766 app_url = frame->top()->document().url(); 713 app_url = frame->top()->document().url();
767 } else { 714 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 750 }
804 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 751 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
805 752
806 // Delay loading plugins if prerendering. 753 // Delay loading plugins if prerendering.
807 // TODO(mmenke): In the case of prerendering, feed into 754 // TODO(mmenke): In the case of prerendering, feed into
808 // ChromeContentRendererClient::CreatePlugin instead, to 755 // ChromeContentRendererClient::CreatePlugin instead, to
809 // reduce the chance of future regressions. 756 // reduce the chance of future regressions.
810 bool is_prerendering = 757 bool is_prerendering =
811 prerender::PrerenderHelper::IsPrerendering(render_frame); 758 prerender::PrerenderHelper::IsPrerendering(render_frame);
812 759
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
823 bool power_saver_setting_on = 760 bool power_saver_setting_on =
824 status == 761 status ==
825 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent; 762 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
826 763 PowerSaverInfo power_saver_info =
827 bool power_saver_enabled = 764 PowerSaverInfo::Get(render_frame, power_saver_setting_on, params,
828 override_for_testing == "always" || 765 info, frame->document().url());
829 (power_saver_setting_on && can_throttle_plugin_type); 766 if (power_saver_info.blocked_for_background_tab || is_prerendering ||
830 bool blocked_for_background_tab = 767 !power_saver_info.poster_attribute.empty()) {
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()) {
845 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( 768 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
846 render_frame, frame, params, info, identifier, group_name, 769 render_frame, frame, params, info, identifier, group_name,
847 poster_info.poster_attribute.empty() ? IDR_BLOCKED_PLUGIN_HTML 770 power_saver_info.poster_attribute.empty()
848 : IDR_PLUGIN_POSTER_HTML, 771 ? IDR_BLOCKED_PLUGIN_HTML
772 : IDR_PLUGIN_POSTER_HTML,
849 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 773 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
850 poster_info); 774 power_saver_info);
851 placeholder->set_blocked_for_background_tab(
852 blocked_for_background_tab);
853 placeholder->set_blocked_for_prerendering(is_prerendering); 775 placeholder->set_blocked_for_prerendering(is_prerendering);
854 placeholder->set_power_saver_enabled(power_saver_enabled);
855 placeholder->AllowLoading(); 776 placeholder->AllowLoading();
856 break; 777 break;
857 } 778 }
858 779
859 scoped_ptr<content::PluginInstanceThrottler> throttler; 780 scoped_ptr<content::PluginInstanceThrottler> throttler;
860 if (power_saver_enabled) { 781 if (power_saver_info.power_saver_enabled) {
861 throttler = PluginInstanceThrottler::Create(); 782 throttler = PluginInstanceThrottler::Create();
862 // PluginPreroller manages its own lifetime. 783 // PluginPreroller manages its own lifetime.
863 new PluginPreroller( 784 new PluginPreroller(
864 render_frame, frame, params, info, identifier, group_name, 785 render_frame, frame, params, info, identifier, group_name,
865 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 786 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
866 throttler.get()); 787 throttler.get());
867 } 788 }
868 789
869 return render_frame->CreatePlugin(frame, info, params, 790 return render_frame->CreatePlugin(frame, info, params,
870 throttler.Pass()); 791 throttler.Pass());
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 // chrome.system.network.getNetworkInterfaces provides the same 1407 // chrome.system.network.getNetworkInterfaces provides the same
1487 // information. Also, the enforcement of sending and binding UDP is already done 1408 // information. Also, the enforcement of sending and binding UDP is already done
1488 // by chrome extension permission model. 1409 // by chrome extension permission model.
1489 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { 1410 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() {
1490 #if defined(ENABLE_EXTENSIONS) 1411 #if defined(ENABLE_EXTENSIONS)
1491 return !IsStandaloneExtensionProcess(); 1412 return !IsStandaloneExtensionProcess();
1492 #else 1413 #else
1493 return true; 1414 return true;
1494 #endif 1415 #endif
1495 } 1416 }
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