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

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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); 304 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
305 305
306 for (size_t i = 0; i < params.attributeNames.size(); ++i) { 306 for (size_t i = 0; i < params.attributeNames.size(); ++i) {
307 if (params.attributeNames[i].utf8() == "poster" && 307 if (params.attributeNames[i].utf8() == "poster" &&
308 !params.attributeValues[i].isEmpty()) { 308 !params.attributeValues[i].isEmpty()) {
309 return params.attributeValues[i].utf8(); 309 return params.attributeValues[i].utf8();
310 } 310 }
311 } 311 }
312 return std::string(); 312 return std::string();
313 } 313 }
314
315 PowerSaverInfo GetPowerSaverInfo(
groby-ooo-7-16 2015/12/09 02:17:15 Dare I suggest that this is now pretty unit-testab
tommycli 2015/12/09 23:25:45 Done. I moved this block of code to its own file.
316 RenderFrame* render_frame,
317 const WebPluginParams& params,
318 ChromeViewHostMsg_GetPluginInfo_Status plugin_info_status,
groby-ooo-7-16 2015/12/09 02:17:15 I wonder if this should be instead "bool power_sav
tommycli 2015/12/09 23:25:45 Done. Though I didn't move this to content/, since
319 const WebPluginInfo& plugin_info,
320 const GURL& document_url) {
321 bool is_flash = plugin_info.name == ASCIIToUTF16(content::kFlashPluginName);
322
323 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
324 std::string override_for_testing = command_line->GetSwitchValueASCII(
325 switches::kOverridePluginPowerSaverForTesting);
326
327 // This feature has only been tested throughly with Flash thus far.
groby-ooo-7-16 2015/12/09 02:17:15 thoroughly
tommycli 2015/12/09 23:25:45 Done.
328 // It is also enabled for the Power Saver test plugin for browser tests.
329 bool can_throttle_plugin_type =
330 is_flash || override_for_testing == "ignore-list";
331
332 bool power_saver_setting_on =
333 plugin_info_status ==
334 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
335
336 PowerSaverInfo power_saver_info;
337 power_saver_info.power_saver_enabled =
338 override_for_testing == "always" ||
339 (power_saver_setting_on && can_throttle_plugin_type);
340
341 if (power_saver_info.power_saver_enabled) {
342 // Even if we disable PPS in the next block because content is same-origin,
343 // it should still be eligible for background tab deferral if PPS is on.
344 power_saver_info.blocked_for_background_tab = render_frame->IsHidden();
345
346 auto status = render_frame->GetPeripheralContentStatus(
347 render_frame->GetWebFrame()->top()->securityOrigin(),
groby-ooo-7-16 2015/12/09 02:17:15 Weird question: Is that function ever called with
tommycli 2015/12/09 23:25:45 I think ... we specifically want to get the top-le
348 url::Origin(params.url), gfx::Size());
349
350 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_SAME_ORIGIN ||
351 status ==
352 RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_WHITELISTED) {
353 power_saver_info.power_saver_enabled = false;
354 } else {
355 power_saver_info.poster_attribute =
356 GetPluginInstancePosterAttribute(params);
357 power_saver_info.base_url = document_url;
358 }
359 }
360
361 if (is_flash)
362 TrackPosterParamPresence(params, power_saver_info.power_saver_enabled);
363
364 return power_saver_info;
365 }
314 #endif 366 #endif
315 367
316 #if defined(ENABLE_EXTENSIONS) 368 #if defined(ENABLE_EXTENSIONS)
317 bool IsStandaloneExtensionProcess() { 369 bool IsStandaloneExtensionProcess() {
318 return base::CommandLine::ForCurrentProcess()->HasSwitch( 370 return base::CommandLine::ForCurrentProcess()->HasSwitch(
319 extensions::switches::kExtensionProcess); 371 extensions::switches::kExtensionProcess);
320 } 372 }
321 #endif 373 #endif
322 374
323 // Defers media player loading in background pages until they're visible. 375 // Defers media player loading in background pages until they're visible.
(...skipping 393 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. 769 // If user is on ALLOW or DETECT setting, loading needs to be blocked here.
718 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed || 770 if ((status == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed ||
719 status == 771 status ==
720 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) && 772 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) &&
721 info.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) { 773 info.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) {
722 if (observer->AreNPAPIPluginsBlocked()) 774 if (observer->AreNPAPIPluginsBlocked())
723 status = ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported; 775 status = ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported;
724 } 776 }
725 #endif 777 #endif
726 778
727 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 779 auto create_blocked_plugin = [&render_frame, &frame, &params, &info,
728 auto create_blocked_plugin = 780 &identifier, &group_name](
729 [&render_frame, &frame, &params, &info, &identifier, &group_name]( 781 int template_id, const base::string16& message) {
730 int template_id, const base::string16& message) { 782 return ChromePluginPlaceholder::CreateBlockedPlugin(
731 return ChromePluginPlaceholder::CreateBlockedPlugin( 783 render_frame, frame, params, info, identifier, group_name,
732 render_frame, frame, params, info, identifier, group_name, 784 template_id, message, PowerSaverInfo());
733 template_id, message, PlaceholderPosterInfo()); 785 };
734 };
735 switch (status) { 786 switch (status) {
736 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { 787 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: {
737 NOTREACHED(); 788 NOTREACHED();
738 break; 789 break;
739 } 790 }
740 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed: 791 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed:
741 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: { 792 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: {
742 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 793 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
743 const bool is_nacl_plugin = 794 const bool is_nacl_plugin =
744 info.name == ASCIIToUTF16(nacl::kNaClPluginName); 795 info.name == ASCIIToUTF16(nacl::kNaClPluginName);
745 const bool is_nacl_mime_type = 796 const bool is_nacl_mime_type =
746 actual_mime_type == nacl::kNaClPluginMimeType; 797 actual_mime_type == nacl::kNaClPluginMimeType;
747 const bool is_pnacl_mime_type = 798 const bool is_pnacl_mime_type =
748 actual_mime_type == nacl::kPnaclPluginMimeType; 799 actual_mime_type == nacl::kPnaclPluginMimeType;
749 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) { 800 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) {
750 bool is_nacl_unrestricted = false; 801 bool is_nacl_unrestricted = false;
751 if (is_nacl_mime_type) { 802 if (is_nacl_mime_type) {
752 is_nacl_unrestricted = 803 is_nacl_unrestricted =
753 command_line->HasSwitch(switches::kEnableNaCl); 804 base::CommandLine::ForCurrentProcess()->HasSwitch(
805 switches::kEnableNaCl);
754 } else if (is_pnacl_mime_type) { 806 } else if (is_pnacl_mime_type) {
755 is_nacl_unrestricted = true; 807 is_nacl_unrestricted = true;
756 } 808 }
757 GURL manifest_url; 809 GURL manifest_url;
758 GURL app_url; 810 GURL app_url;
759 if (is_nacl_mime_type || is_pnacl_mime_type) { 811 if (is_nacl_mime_type || is_pnacl_mime_type) {
760 // Normal NaCl/PNaCl embed. The app URL is the page URL. 812 // Normal NaCl/PNaCl embed. The app URL is the page URL.
761 manifest_url = url; 813 manifest_url = url;
762 app_url = frame->top()->document().url(); 814 app_url = frame->top()->document().url();
763 } else { 815 } else {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 } 851 }
800 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 852 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
801 853
802 // Delay loading plugins if prerendering. 854 // Delay loading plugins if prerendering.
803 // TODO(mmenke): In the case of prerendering, feed into 855 // TODO(mmenke): In the case of prerendering, feed into
804 // ChromeContentRendererClient::CreatePlugin instead, to 856 // ChromeContentRendererClient::CreatePlugin instead, to
805 // reduce the chance of future regressions. 857 // reduce the chance of future regressions.
806 bool is_prerendering = 858 bool is_prerendering =
807 prerender::PrerenderHelper::IsPrerendering(render_frame); 859 prerender::PrerenderHelper::IsPrerendering(render_frame);
808 860
809 bool is_flash = info.name == ASCIIToUTF16(content::kFlashPluginName); 861 PowerSaverInfo power_saver_info = GetPowerSaverInfo(
810 862 render_frame, params, status, info, frame->document().url());
811 std::string override_for_testing = command_line->GetSwitchValueASCII( 863 if (power_saver_info.blocked_for_background_tab || is_prerendering ||
groby-ooo-7-16 2015/12/09 02:17:15 Can we combine the two power_saver_info members in
tommycli 2015/12/09 23:25:45 Don't think so. We have to set a separate 'block'
812 switches::kOverridePluginPowerSaverForTesting); 864 !power_saver_info.poster_attribute.empty()) {
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 =
820 status ==
821 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
822
823 bool power_saver_enabled =
824 override_for_testing == "always" ||
825 (power_saver_setting_on && can_throttle_plugin_type);
826 bool blocked_for_background_tab =
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( 865 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
842 render_frame, frame, params, info, identifier, group_name, 866 render_frame, frame, params, info, identifier, group_name,
843 poster_info.poster_attribute.empty() ? IDR_BLOCKED_PLUGIN_HTML 867 power_saver_info.poster_attribute.empty()
844 : IDR_PLUGIN_POSTER_HTML, 868 ? IDR_BLOCKED_PLUGIN_HTML
869 : IDR_PLUGIN_POSTER_HTML,
845 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 870 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
846 poster_info); 871 power_saver_info);
847 placeholder->set_blocked_for_background_tab(
848 blocked_for_background_tab);
849 placeholder->set_blocked_for_prerendering(is_prerendering); 872 placeholder->set_blocked_for_prerendering(is_prerendering);
850 placeholder->set_power_saver_enabled(power_saver_enabled);
851 placeholder->AllowLoading(); 873 placeholder->AllowLoading();
852 break; 874 break;
853 } 875 }
854 876
855 scoped_ptr<content::PluginInstanceThrottler> throttler; 877 scoped_ptr<content::PluginInstanceThrottler> throttler;
856 if (power_saver_enabled) { 878 if (power_saver_info.power_saver_enabled) {
857 throttler = PluginInstanceThrottler::Create(); 879 throttler = PluginInstanceThrottler::Create();
858 // PluginPreroller manages its own lifetime. 880 // PluginPreroller manages its own lifetime.
859 new PluginPreroller( 881 new PluginPreroller(
860 render_frame, frame, params, info, identifier, group_name, 882 render_frame, frame, params, info, identifier, group_name,
861 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 883 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
862 throttler.get()); 884 throttler.get());
863 } 885 }
864 886
865 return render_frame->CreatePlugin(frame, info, params, 887 return render_frame->CreatePlugin(frame, info, params,
866 throttler.Pass()); 888 throttler.Pass());
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 // chrome.system.network.getNetworkInterfaces provides the same 1503 // chrome.system.network.getNetworkInterfaces provides the same
1482 // information. Also, the enforcement of sending and binding UDP is already done 1504 // information. Also, the enforcement of sending and binding UDP is already done
1483 // by chrome extension permission model. 1505 // by chrome extension permission model.
1484 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { 1506 bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() {
1485 #if defined(ENABLE_EXTENSIONS) 1507 #if defined(ENABLE_EXTENSIONS)
1486 return !IsStandaloneExtensionProcess(); 1508 return !IsStandaloneExtensionProcess();
1487 #else 1509 #else
1488 return true; 1510 return true;
1489 #endif 1511 #endif
1490 } 1512 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698