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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 904913003: Plugin Power Saver: Fix implicitly sized and below the fold plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix windows compile Created 5 years, 10 months 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 #if defined(OS_WIN) 148 #if defined(OS_WIN)
149 #include "chrome_elf/blacklist/blacklist.h" 149 #include "chrome_elf/blacklist/blacklist.h"
150 #endif 150 #endif
151 151
152 using autofill::AutofillAgent; 152 using autofill::AutofillAgent;
153 using autofill::PasswordAutofillAgent; 153 using autofill::PasswordAutofillAgent;
154 using autofill::PasswordGenerationAgent; 154 using autofill::PasswordGenerationAgent;
155 using base::ASCIIToUTF16; 155 using base::ASCIIToUTF16;
156 using base::UserMetricsAction; 156 using base::UserMetricsAction;
157 using content::PluginInstanceThrottler; 157 using content::PluginInstanceThrottler;
158 using content::PluginPowerSaverMode;
159 using content::RenderFrame; 158 using content::RenderFrame;
160 using content::RenderThread; 159 using content::RenderThread;
161 using content::WebPluginInfo; 160 using content::WebPluginInfo;
162 using extensions::Extension; 161 using extensions::Extension;
163 using blink::WebCache; 162 using blink::WebCache;
164 using blink::WebConsoleMessage; 163 using blink::WebConsoleMessage;
165 using blink::WebDataSource; 164 using blink::WebDataSource;
166 using blink::WebDocument; 165 using blink::WebDocument;
167 using blink::WebFrame; 166 using blink::WebFrame;
168 using blink::WebLocalFrame; 167 using blink::WebLocalFrame;
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 #if defined(OS_CHROMEOS) 788 #if defined(OS_CHROMEOS)
790 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED)); 789 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED));
791 #else 790 #else
792 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); 791 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name));
793 #endif 792 #endif
794 break; 793 break;
795 } 794 }
796 } 795 }
797 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) 796 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS)
798 797
799 scoped_ptr<content::PluginInstanceThrottler> throttler;
800 #if defined(ENABLE_PLUGINS) 798 #if defined(ENABLE_PLUGINS)
801 PluginPowerSaverMode power_saver_mode = 799 bool power_saver_enabled =
802 PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL; 800 status_value ==
803 bool show_poster = false; 801 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
802 bool blocked_for_background_tab =
803 render_frame->IsHidden() && power_saver_enabled;
804
804 GURL poster_url; 805 GURL poster_url;
805 bool cross_origin_main_content = false; 806 if (power_saver_enabled) {
806 bool blocked_for_background_tab = 807 poster_url = PluginInstanceThrottler::GetPluginInstancePosterImage(
807 render_frame->IsHidden() && 808 params, frame->document().url());
808 status_value ==
809 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent;
810 if (render_frame->ShouldThrottleContent(params, frame->document().url(),
811 &poster_url,
812 &cross_origin_main_content)) {
813 // TODO(tommycli): Apply throttler behavior to all plugins.
814 if (info.name == base::ASCIIToUTF16(content::kFlashPluginName) &&
815 status_value == ChromeViewHostMsg_GetPluginInfo_Status::
816 kPlayImportantContent) {
817 power_saver_mode =
818 PluginPowerSaverMode::POWER_SAVER_MODE_PERIPHERAL_THROTTLED;
819 show_poster = poster_url.is_valid();
820 } else {
821 power_saver_mode =
822 PluginPowerSaverMode::POWER_SAVER_MODE_PERIPHERAL_UNTHROTTLED;
823 }
824
825 throttler = content::PluginInstanceThrottler::Get(render_frame, url,
826 power_saver_mode);
827 } 809 }
828 810
829 // Delay loading plugins if prerendering. 811 // Delay loading plugins if prerendering.
830 // TODO(mmenke): In the case of prerendering, feed into 812 // TODO(mmenke): In the case of prerendering, feed into
831 // ChromeContentRendererClient::CreatePlugin instead, to 813 // ChromeContentRendererClient::CreatePlugin instead, to
832 // reduce the chance of future regressions. 814 // reduce the chance of future regressions.
833 bool is_prerendering = 815 bool is_prerendering =
834 prerender::PrerenderHelper::IsPrerendering(render_frame); 816 prerender::PrerenderHelper::IsPrerendering(render_frame);
835 if (blocked_for_background_tab || is_prerendering || show_poster) { 817 if (blocked_for_background_tab || is_prerendering ||
818 poster_url.is_valid()) {
836 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( 819 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin(
837 render_frame, frame, params, info, identifier, group_name, 820 render_frame, frame, params, info, identifier, group_name,
838 show_poster ? IDR_PLUGIN_POSTER_HTML : IDR_BLOCKED_PLUGIN_HTML, 821 poster_url.is_valid() ? IDR_PLUGIN_POSTER_HTML
822 : IDR_BLOCKED_PLUGIN_HTML,
839 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 823 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
840 poster_url); 824 poster_url);
841 placeholder->set_blocked_for_background_tab( 825 placeholder->set_blocked_for_background_tab(
842 blocked_for_background_tab); 826 blocked_for_background_tab);
843 placeholder->set_blocked_for_prerendering(is_prerendering); 827 placeholder->set_blocked_for_prerendering(is_prerendering);
844 placeholder->set_power_saver_mode(power_saver_mode); 828 placeholder->set_power_saver_enabled(power_saver_enabled);
845 placeholder->set_allow_loading(true); 829 placeholder->set_allow_loading(true);
846 break; 830 break;
847 } else if (cross_origin_main_content) {
848 GURL content_origin = GURL(params.url).GetOrigin();
849 render_frame->WhitelistContentOrigin(content_origin);
850 } 831 }
851 832
852 if (power_saver_mode == 833 scoped_ptr<content::PluginInstanceThrottler> throttler =
853 PluginPowerSaverMode::POWER_SAVER_MODE_PERIPHERAL_THROTTLED) { 834 PluginInstanceThrottler::Create(power_saver_enabled);
854 content::PluginInstanceThrottler* throttler_raw = throttler.get(); 835 content::PluginInstanceThrottler* throttler_raw = throttler.get();
855 blink::WebPlugin* plugin = 836 blink::WebPlugin* plugin =
856 render_frame->CreatePlugin(frame, info, params, throttler.Pass()); 837 render_frame->CreatePlugin(frame, info, params, throttler.Pass());
857 838
839 if (power_saver_enabled) {
858 // PluginPreroller manages its own lifetime. 840 // PluginPreroller manages its own lifetime.
859 new PluginPreroller( 841 new PluginPreroller(
860 render_frame, frame, params, info, identifier, group_name, 842 render_frame, frame, params, info, identifier, group_name,
861 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), 843 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name),
862 plugin, throttler_raw); 844 plugin, throttler_raw);
863
864 return plugin;
865 } 845 }
866 846
847 return plugin;
848 #else // !defined(ENABLE_PLUGINS)
849 return render_frame->CreatePlugin(frame, info, params, nullptr);
867 #endif // defined(ENABLE_PLUGINS) 850 #endif // defined(ENABLE_PLUGINS)
868 return render_frame->CreatePlugin(frame, info, params,
869 throttler.Pass());
870 } 851 }
871 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported: { 852 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported: {
872 RenderThread::Get()->RecordAction( 853 RenderThread::Get()->RecordAction(
873 UserMetricsAction("Plugin_NPAPINotSupported")); 854 UserMetricsAction("Plugin_NPAPINotSupported"));
874 placeholder = create_blocked_plugin( 855 placeholder = create_blocked_plugin(
875 IDR_BLOCKED_PLUGIN_HTML, 856 IDR_BLOCKED_PLUGIN_HTML,
876 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO)); 857 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO));
877 render_frame->Send(new ChromeViewHostMsg_NPAPINotSupported( 858 render_frame->Send(new ChromeViewHostMsg_NPAPINotSupported(
878 render_frame->GetRoutingID(), identifier)); 859 render_frame->GetRoutingID(), identifier));
879 break; 860 break;
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 if (mime_type == content::kBrowserPluginMimeType) { 1583 if (mime_type == content::kBrowserPluginMimeType) {
1603 return new extensions::ExtensionsGuestViewContainer(render_frame); 1584 return new extensions::ExtensionsGuestViewContainer(render_frame);
1604 } else { 1585 } else {
1605 return new extensions::MimeHandlerViewContainer( 1586 return new extensions::MimeHandlerViewContainer(
1606 render_frame, mime_type, original_url); 1587 render_frame, mime_type, original_url);
1607 } 1588 }
1608 #else 1589 #else
1609 return NULL; 1590 return NULL;
1610 #endif 1591 #endif
1611 } 1592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698