OLD | NEW |
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 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 ContentSettingsObserver* observer = | 677 ContentSettingsObserver* observer = |
678 ContentSettingsObserver::Get(render_frame); | 678 ContentSettingsObserver::Get(render_frame); |
679 | 679 |
680 const ContentSettingsType content_type = | 680 const ContentSettingsType content_type = |
681 ShouldUseJavaScriptSettingForPlugin(plugin) ? | 681 ShouldUseJavaScriptSettingForPlugin(plugin) ? |
682 CONTENT_SETTINGS_TYPE_JAVASCRIPT : | 682 CONTENT_SETTINGS_TYPE_JAVASCRIPT : |
683 CONTENT_SETTINGS_TYPE_PLUGINS; | 683 CONTENT_SETTINGS_TYPE_PLUGINS; |
684 | 684 |
685 if ((status_value == | 685 if ((status_value == |
686 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized || | 686 ChromeViewHostMsg_GetPluginInfo_Status::kUnauthorized || |
687 status_value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay || | |
688 status_value == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked) && | 687 status_value == ChromeViewHostMsg_GetPluginInfo_Status::kBlocked) && |
689 observer->IsPluginTemporarilyAllowed(identifier)) { | 688 observer->IsPluginTemporarilyAllowed(identifier)) { |
690 status_value = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed; | 689 status_value = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed; |
691 } | 690 } |
692 | 691 |
693 // Allow full-page plug-ins for click-to-play. | 692 #if defined(ENABLE_PLUGINS) |
694 if (status_value == ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay && | 693 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
695 !frame->parent() && | 694 switches::kEnablePluginPowerSaver)) { |
696 !frame->opener() && | 695 status_value = |
697 frame->document().isPluginDocument()) { | 696 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent; |
698 status_value = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed; | |
699 } | 697 } |
| 698 #endif |
700 | 699 |
701 #if defined(OS_WIN) | 700 #if defined(OS_WIN) |
702 // In Windows we need to check if we can load NPAPI plugins. | 701 // In Windows we need to check if we can load NPAPI plugins. |
703 // For example, if the render view is in the Ash desktop, we should not. | 702 // For example, if the render view is in the Ash desktop, we should not. |
704 if (status_value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed && | 703 if (status_value == ChromeViewHostMsg_GetPluginInfo_Status::kAllowed && |
705 plugin.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) { | 704 plugin.type == content::WebPluginInfo::PLUGIN_TYPE_NPAPI) { |
706 if (observer->AreNPAPIPluginsBlocked()) | 705 if (observer->AreNPAPIPluginsBlocked()) |
707 status_value = | 706 status_value = |
708 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported; | 707 ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported; |
709 } | 708 } |
710 #endif | 709 #endif |
711 | 710 |
712 auto create_blocked_plugin = | 711 auto create_blocked_plugin = |
713 [&render_frame, &frame, ¶ms, &plugin, &identifier, &group_name]( | 712 [&render_frame, &frame, ¶ms, &plugin, &identifier, &group_name]( |
714 int template_id, const base::string16& message, | 713 int template_id, const base::string16& message, |
715 const GURL& poster_url) { | 714 const GURL& poster_url) { |
716 return ChromePluginPlaceholder::CreateBlockedPlugin( | 715 return ChromePluginPlaceholder::CreateBlockedPlugin( |
717 render_frame, frame, params, plugin, identifier, group_name, | 716 render_frame, frame, params, plugin, identifier, group_name, |
718 template_id, message, poster_url); | 717 template_id, message, poster_url); |
719 }; | 718 }; |
720 switch (status_value) { | 719 switch (status_value) { |
721 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { | 720 case ChromeViewHostMsg_GetPluginInfo_Status::kNotFound: { |
722 NOTREACHED(); | 721 NOTREACHED(); |
723 break; | 722 break; |
724 } | 723 } |
725 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed: { | 724 case ChromeViewHostMsg_GetPluginInfo_Status::kAllowed: |
| 725 case ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent: { |
726 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) | 726 #if !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) |
727 const bool is_nacl_plugin = | 727 const bool is_nacl_plugin = |
728 plugin.name == ASCIIToUTF16(nacl::kNaClPluginName); | 728 plugin.name == ASCIIToUTF16(nacl::kNaClPluginName); |
729 const bool is_nacl_mime_type = | 729 const bool is_nacl_mime_type = |
730 actual_mime_type == nacl::kNaClPluginMimeType; | 730 actual_mime_type == nacl::kNaClPluginMimeType; |
731 const bool is_pnacl_mime_type = | 731 const bool is_pnacl_mime_type = |
732 actual_mime_type == nacl::kPnaclPluginMimeType; | 732 actual_mime_type == nacl::kPnaclPluginMimeType; |
733 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) { | 733 if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) { |
734 bool is_nacl_unrestricted = false; | 734 bool is_nacl_unrestricted = false; |
735 if (is_nacl_mime_type) { | 735 if (is_nacl_mime_type) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 | 787 |
788 RenderFrame::PluginPowerSaverMode power_saver_mode = | 788 RenderFrame::PluginPowerSaverMode power_saver_mode = |
789 RenderFrame::POWER_SAVER_MODE_ESSENTIAL; | 789 RenderFrame::POWER_SAVER_MODE_ESSENTIAL; |
790 #if defined(ENABLE_PLUGINS) | 790 #if defined(ENABLE_PLUGINS) |
791 bool show_poster = false; | 791 bool show_poster = false; |
792 GURL poster_url; | 792 GURL poster_url; |
793 bool cross_origin_main_content = false; | 793 bool cross_origin_main_content = false; |
794 if (render_frame->ShouldThrottleContent(params, frame->document().url(), | 794 if (render_frame->ShouldThrottleContent(params, frame->document().url(), |
795 &poster_url, | 795 &poster_url, |
796 &cross_origin_main_content)) { | 796 &cross_origin_main_content)) { |
797 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 797 if (status_value == |
798 switches::kEnablePluginPowerSaver)) { | 798 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent) { |
799 power_saver_mode = | 799 power_saver_mode = |
800 RenderFrame::POWER_SAVER_MODE_PERIPHERAL_THROTTLED; | 800 RenderFrame::POWER_SAVER_MODE_PERIPHERAL_THROTTLED; |
801 show_poster = poster_url.is_valid(); | 801 show_poster = poster_url.is_valid(); |
802 } else { | 802 } else { |
803 power_saver_mode = | 803 power_saver_mode = |
804 RenderFrame::POWER_SAVER_MODE_PERIPHERAL_UNTHROTTLED; | 804 RenderFrame::POWER_SAVER_MODE_PERIPHERAL_UNTHROTTLED; |
805 } | 805 } |
806 } | 806 } |
807 | 807 |
808 // Delay loading plugins if prerendering. | 808 // Delay loading plugins if prerendering. |
809 // TODO(mmenke): In the case of prerendering, feed into | 809 // TODO(mmenke): In the case of prerendering, feed into |
810 // ChromeContentRendererClient::CreatePlugin instead, to | 810 // ChromeContentRendererClient::CreatePlugin instead, to |
811 // reduce the chance of future regressions. | 811 // reduce the chance of future regressions. |
812 bool is_prerendering = | 812 bool is_prerendering = |
813 prerender::PrerenderHelper::IsPrerendering(render_frame); | 813 prerender::PrerenderHelper::IsPrerendering(render_frame); |
814 if (is_prerendering || show_poster) { | 814 if (is_prerendering || show_poster) { |
815 placeholder = create_blocked_plugin( | 815 placeholder = create_blocked_plugin( |
816 show_poster ? IDR_PLUGIN_POSTER_HTML | 816 show_poster ? IDR_PLUGIN_POSTER_HTML : IDR_BLOCKED_PLUGIN_HTML, |
817 : IDR_CLICK_TO_PLAY_PLUGIN_HTML, | 817 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), |
818 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD, group_name), | |
819 poster_url); | 818 poster_url); |
820 placeholder->set_blocked_for_prerendering(is_prerendering); | 819 placeholder->set_blocked_for_prerendering(is_prerendering); |
821 placeholder->set_power_saver_mode(power_saver_mode); | 820 placeholder->set_power_saver_mode(power_saver_mode); |
822 placeholder->set_allow_loading(true); | 821 placeholder->set_allow_loading(true); |
823 break; | 822 break; |
824 } else if (cross_origin_main_content) { | 823 } else if (cross_origin_main_content) { |
825 GURL content_origin = GURL(params.url).GetOrigin(); | 824 GURL content_origin = GURL(params.url).GetOrigin(); |
826 render_frame->WhitelistContentOrigin(content_origin); | 825 render_frame->WhitelistContentOrigin(content_origin); |
827 } | 826 } |
828 #endif // defined(ENABLE_PLUGINS) | 827 #endif // defined(ENABLE_PLUGINS) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 render_frame->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin( | 884 render_frame->Send(new ChromeViewHostMsg_BlockedUnauthorizedPlugin( |
886 render_frame->GetRoutingID(), | 885 render_frame->GetRoutingID(), |
887 group_name, | 886 group_name, |
888 identifier)); | 887 identifier)); |
889 } else { | 888 } else { |
890 // Send IPC for showing blocked plugins page action. | 889 // Send IPC for showing blocked plugins page action. |
891 observer->DidBlockContentType(content_type, group_name); | 890 observer->DidBlockContentType(content_type, group_name); |
892 } | 891 } |
893 break; | 892 break; |
894 } | 893 } |
895 case ChromeViewHostMsg_GetPluginInfo_Status::kClickToPlay: { | |
896 placeholder = create_blocked_plugin( | |
897 IDR_CLICK_TO_PLAY_PLUGIN_HTML, | |
898 l10n_util::GetStringFUTF16(IDS_PLUGIN_LOAD, group_name), GURL()); | |
899 placeholder->set_allow_loading(true); | |
900 RenderThread::Get()->RecordAction( | |
901 UserMetricsAction("Plugin_ClickToPlay")); | |
902 observer->DidBlockContentType(content_type, group_name); | |
903 break; | |
904 } | |
905 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked: { | 894 case ChromeViewHostMsg_GetPluginInfo_Status::kBlocked: { |
906 placeholder = create_blocked_plugin( | 895 placeholder = create_blocked_plugin( |
907 IDR_BLOCKED_PLUGIN_HTML, | 896 IDR_BLOCKED_PLUGIN_HTML, |
908 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), GURL()); | 897 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), GURL()); |
909 placeholder->set_allow_loading(true); | 898 placeholder->set_allow_loading(true); |
910 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked")); | 899 RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked")); |
911 observer->DidBlockContentType(content_type, group_name); | 900 observer->DidBlockContentType(content_type, group_name); |
912 break; | 901 break; |
913 } | 902 } |
914 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy: { | 903 case ChromeViewHostMsg_GetPluginInfo_Status::kBlockedByPolicy: { |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 if (mime_type == content::kBrowserPluginMimeType) { | 1570 if (mime_type == content::kBrowserPluginMimeType) { |
1582 return new extensions::ExtensionsGuestViewContainer(render_frame); | 1571 return new extensions::ExtensionsGuestViewContainer(render_frame); |
1583 } else { | 1572 } else { |
1584 return new extensions::MimeHandlerViewContainer( | 1573 return new extensions::MimeHandlerViewContainer( |
1585 render_frame, mime_type, original_url); | 1574 render_frame, mime_type, original_url); |
1586 } | 1575 } |
1587 #else | 1576 #else |
1588 return NULL; | 1577 return NULL; |
1589 #endif | 1578 #endif |
1590 } | 1579 } |
OLD | NEW |