Chromium Code Reviews| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 #if defined(ENABLE_EXTENSIONS) | 261 #if defined(ENABLE_EXTENSIONS) |
| 263 void IsGuestViewApiAvailableToScriptContext( | 262 void IsGuestViewApiAvailableToScriptContext( |
| 264 bool* api_is_available, | 263 bool* api_is_available, |
| 265 extensions::ScriptContext* context) { | 264 extensions::ScriptContext* context) { |
| 266 if (context->GetAvailability("guestViewInternal").is_available()) { | 265 if (context->GetAvailability("guestViewInternal").is_available()) { |
| 267 *api_is_available = true; | 266 *api_is_available = true; |
| 268 } | 267 } |
| 269 } | 268 } |
| 270 #endif | 269 #endif |
| 271 | 270 |
| 271 #if defined(ENABLE_PLUGINS) | |
| 272 GURL GetPluginInstancePosterImage(const blink::WebPluginParams& params, | |
| 273 const GURL& page_base_url) { | |
| 274 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size()); | |
| 275 | |
| 276 for (size_t i = 0; i < params.attributeNames.size(); ++i) { | |
| 277 if (params.attributeNames[i] == "poster") { | |
|
Lei Zhang
2015/02/09 20:02:05
Should this be params.attributeNames[i].utf8() ? N
tommycli
2015/02/09 20:12:16
Done.
| |
| 278 std::string poster_value(params.attributeValues[i].utf8()); | |
| 279 if (!poster_value.empty()) | |
|
Lei Zhang
2015/02/09 20:02:05
You can call isEmpty() on the WebString, and only
tommycli
2015/02/09 20:12:16
Done.
| |
| 280 return page_base_url.Resolve(poster_value); | |
| 281 } | |
| 282 } | |
| 283 return GURL(); | |
| 284 } | |
| 285 #endif | |
| 286 | |
| 272 } // namespace | 287 } // namespace |
| 273 | 288 |
| 274 ChromeContentRendererClient::ChromeContentRendererClient() { | 289 ChromeContentRendererClient::ChromeContentRendererClient() { |
| 275 g_current_client = this; | 290 g_current_client = this; |
| 276 | 291 |
| 277 #if defined(ENABLE_EXTENSIONS) | 292 #if defined(ENABLE_EXTENSIONS) |
| 278 extensions::ExtensionsClient::Set( | 293 extensions::ExtensionsClient::Set( |
| 279 extensions::ChromeExtensionsClient::GetInstance()); | 294 extensions::ChromeExtensionsClient::GetInstance()); |
| 280 extensions::ExtensionsRendererClient::Set( | 295 extensions::ExtensionsRendererClient::Set( |
| 281 ChromeExtensionsRendererClient::GetInstance()); | 296 ChromeExtensionsRendererClient::GetInstance()); |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 #if defined(OS_CHROMEOS) | 804 #if defined(OS_CHROMEOS) |
| 790 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED)); | 805 l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED)); |
| 791 #else | 806 #else |
| 792 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); | 807 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); |
| 793 #endif | 808 #endif |
| 794 break; | 809 break; |
| 795 } | 810 } |
| 796 } | 811 } |
| 797 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) | 812 #endif // !defined(DISABLE_NACL) && defined(ENABLE_EXTENSIONS) |
| 798 | 813 |
| 799 scoped_ptr<content::PluginInstanceThrottler> throttler; | |
| 800 #if defined(ENABLE_PLUGINS) | 814 #if defined(ENABLE_PLUGINS) |
| 801 PluginPowerSaverMode power_saver_mode = | 815 bool power_saver_enabled = |
| 802 PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL; | 816 status_value == |
| 803 bool show_poster = false; | 817 ChromeViewHostMsg_GetPluginInfo_Status::kPlayImportantContent; |
| 818 bool blocked_for_background_tab = | |
| 819 render_frame->IsHidden() && power_saver_enabled; | |
| 820 | |
| 804 GURL poster_url; | 821 GURL poster_url; |
| 805 bool cross_origin_main_content = false; | 822 if (power_saver_enabled) { |
| 806 bool blocked_for_background_tab = | 823 poster_url = |
| 807 render_frame->IsHidden() && | 824 GetPluginInstancePosterImage(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 } | 825 } |
| 828 | 826 |
| 829 // Delay loading plugins if prerendering. | 827 // Delay loading plugins if prerendering. |
| 830 // TODO(mmenke): In the case of prerendering, feed into | 828 // TODO(mmenke): In the case of prerendering, feed into |
| 831 // ChromeContentRendererClient::CreatePlugin instead, to | 829 // ChromeContentRendererClient::CreatePlugin instead, to |
| 832 // reduce the chance of future regressions. | 830 // reduce the chance of future regressions. |
| 833 bool is_prerendering = | 831 bool is_prerendering = |
| 834 prerender::PrerenderHelper::IsPrerendering(render_frame); | 832 prerender::PrerenderHelper::IsPrerendering(render_frame); |
| 835 if (blocked_for_background_tab || is_prerendering || show_poster) { | 833 if (blocked_for_background_tab || is_prerendering || |
| 834 poster_url.is_valid()) { | |
| 836 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( | 835 placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( |
| 837 render_frame, frame, params, info, identifier, group_name, | 836 render_frame, frame, params, info, identifier, group_name, |
| 838 show_poster ? IDR_PLUGIN_POSTER_HTML : IDR_BLOCKED_PLUGIN_HTML, | 837 poster_url.is_valid() ? IDR_PLUGIN_POSTER_HTML |
| 838 : IDR_BLOCKED_PLUGIN_HTML, | |
| 839 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), | 839 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), |
| 840 poster_url); | 840 poster_url); |
| 841 placeholder->set_blocked_for_background_tab( | 841 placeholder->set_blocked_for_background_tab( |
| 842 blocked_for_background_tab); | 842 blocked_for_background_tab); |
| 843 placeholder->set_blocked_for_prerendering(is_prerendering); | 843 placeholder->set_blocked_for_prerendering(is_prerendering); |
| 844 placeholder->set_power_saver_mode(power_saver_mode); | 844 placeholder->set_power_saver_enabled(power_saver_enabled); |
| 845 placeholder->set_allow_loading(true); | 845 placeholder->set_allow_loading(true); |
| 846 break; | 846 break; |
| 847 } else if (cross_origin_main_content) { | |
| 848 GURL content_origin = GURL(params.url).GetOrigin(); | |
| 849 render_frame->WhitelistContentOrigin(content_origin); | |
| 850 } | 847 } |
| 851 | 848 |
| 852 if (power_saver_mode == | 849 scoped_ptr<content::PluginInstanceThrottler> throttler = |
| 853 PluginPowerSaverMode::POWER_SAVER_MODE_PERIPHERAL_THROTTLED) { | 850 PluginInstanceThrottler::Create(power_saver_enabled); |
| 854 content::PluginInstanceThrottler* throttler_raw = throttler.get(); | 851 content::PluginInstanceThrottler* throttler_raw = throttler.get(); |
| 855 blink::WebPlugin* plugin = | 852 blink::WebPlugin* plugin = |
| 856 render_frame->CreatePlugin(frame, info, params, throttler.Pass()); | 853 render_frame->CreatePlugin(frame, info, params, throttler.Pass()); |
| 857 | 854 |
| 855 if (power_saver_enabled) { | |
| 858 // PluginPreroller manages its own lifetime. | 856 // PluginPreroller manages its own lifetime. |
| 859 new PluginPreroller( | 857 new PluginPreroller( |
| 860 render_frame, frame, params, info, identifier, group_name, | 858 render_frame, frame, params, info, identifier, group_name, |
| 861 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), | 859 l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name), |
| 862 plugin, throttler_raw); | 860 plugin, throttler_raw); |
| 863 | |
| 864 return plugin; | |
| 865 } | 861 } |
| 866 | 862 |
| 863 return plugin; | |
| 864 #else // !defined(ENABLE_PLUGINS) | |
| 865 return render_frame->CreatePlugin(frame, info, params, nullptr); | |
| 867 #endif // defined(ENABLE_PLUGINS) | 866 #endif // defined(ENABLE_PLUGINS) |
| 868 return render_frame->CreatePlugin(frame, info, params, | |
| 869 throttler.Pass()); | |
| 870 } | 867 } |
| 871 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported: { | 868 case ChromeViewHostMsg_GetPluginInfo_Status::kNPAPINotSupported: { |
| 872 RenderThread::Get()->RecordAction( | 869 RenderThread::Get()->RecordAction( |
| 873 UserMetricsAction("Plugin_NPAPINotSupported")); | 870 UserMetricsAction("Plugin_NPAPINotSupported")); |
| 874 placeholder = create_blocked_plugin( | 871 placeholder = create_blocked_plugin( |
| 875 IDR_BLOCKED_PLUGIN_HTML, | 872 IDR_BLOCKED_PLUGIN_HTML, |
| 876 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO)); | 873 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED_METRO)); |
| 877 render_frame->Send(new ChromeViewHostMsg_NPAPINotSupported( | 874 render_frame->Send(new ChromeViewHostMsg_NPAPINotSupported( |
| 878 render_frame->GetRoutingID(), identifier)); | 875 render_frame->GetRoutingID(), identifier)); |
| 879 break; | 876 break; |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1602 if (mime_type == content::kBrowserPluginMimeType) { | 1599 if (mime_type == content::kBrowserPluginMimeType) { |
| 1603 return new extensions::ExtensionsGuestViewContainer(render_frame); | 1600 return new extensions::ExtensionsGuestViewContainer(render_frame); |
| 1604 } else { | 1601 } else { |
| 1605 return new extensions::MimeHandlerViewContainer( | 1602 return new extensions::MimeHandlerViewContainer( |
| 1606 render_frame, mime_type, original_url); | 1603 render_frame, mime_type, original_url); |
| 1607 } | 1604 } |
| 1608 #else | 1605 #else |
| 1609 return NULL; | 1606 return NULL; |
| 1610 #endif | 1607 #endif |
| 1611 } | 1608 } |
| OLD | NEW |