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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 return std::string(); | 334 return std::string(); |
335 } | 335 } |
336 #endif | 336 #endif |
337 | 337 |
338 #if defined(ENABLE_EXTENSIONS) | 338 #if defined(ENABLE_EXTENSIONS) |
339 bool IsStandaloneExtensionProcess() { | 339 bool IsStandaloneExtensionProcess() { |
340 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 340 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
341 extensions::switches::kExtensionProcess); | 341 extensions::switches::kExtensionProcess); |
342 } | 342 } |
343 #endif | 343 #endif |
344 | |
345 // Defers media player loading in background pages until they're visible. | |
346 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135 | |
347 class MediaLoadDeferrer : public content::RenderFrameObserver { | |
348 public: | |
349 MediaLoadDeferrer(content::RenderFrame* render_frame, | |
350 const base::Closure& continue_loading_cb) | |
351 : content::RenderFrameObserver(render_frame), | |
352 continue_loading_cb_(continue_loading_cb) {} | |
353 ~MediaLoadDeferrer() override {} | |
354 | |
355 private: | |
356 // content::RenderFrameObserver implementation: | |
357 void WasShown() override { | |
358 continue_loading_cb_.Run(); | |
359 delete this; | |
360 } | |
361 | |
362 const base::Closure continue_loading_cb_; | |
363 | |
364 DISALLOW_COPY_AND_ASSIGN(MediaLoadDeferrer); | |
365 }; | |
366 | |
344 } // namespace | 367 } // namespace |
345 | 368 |
346 ChromeContentRendererClient::ChromeContentRendererClient() { | 369 ChromeContentRendererClient::ChromeContentRendererClient() { |
347 g_current_client = this; | 370 g_current_client = this; |
348 | 371 |
349 #if defined(ENABLE_EXTENSIONS) | 372 #if defined(ENABLE_EXTENSIONS) |
350 extensions::ExtensionsClient::Set( | 373 extensions::ExtensionsClient::Set( |
351 extensions::ChromeExtensionsClient::GetInstance()); | 374 extensions::ChromeExtensionsClient::GetInstance()); |
352 extensions::ExtensionsRendererClient::Set( | 375 extensions::ExtensionsRendererClient::Set( |
353 ChromeExtensionsRendererClient::GetInstance()); | 376 ChromeExtensionsRendererClient::GetInstance()); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 | 699 |
677 WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( | 700 WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( |
678 content::RenderFrame* render_frame, | 701 content::RenderFrame* render_frame, |
679 const base::FilePath& plugin_path) { | 702 const base::FilePath& plugin_path) { |
680 return NonLoadablePluginPlaceholder::CreateErrorPlugin(render_frame, | 703 return NonLoadablePluginPlaceholder::CreateErrorPlugin(render_frame, |
681 plugin_path)->plugin(); | 704 plugin_path)->plugin(); |
682 } | 705 } |
683 | 706 |
684 void ChromeContentRendererClient::DeferMediaLoad( | 707 void ChromeContentRendererClient::DeferMediaLoad( |
685 content::RenderFrame* render_frame, | 708 content::RenderFrame* render_frame, |
709 bool render_frame_has_played_media_before, | |
686 const base::Closure& closure) { | 710 const base::Closure& closure) { |
687 #if defined(OS_ANDROID) | 711 #if defined(OS_ANDROID) |
688 // Chromium for Android doesn't support prerender yet. | 712 // Chromium for Android doesn't support prerender yet. |
tommycli
2015/08/13 21:50:07
Although we don't have prerender on Android, it se
DaleCurtis
2015/08/13 22:24:30
Android doesn't use WebMediaPlayerImpl and ignores
| |
689 closure.Run(); | 713 closure.Run(); |
690 return; | 714 return; |
691 #else | 715 #else |
692 if (!prerender::PrerenderHelper::IsPrerendering(render_frame)) { | 716 if (prerender::PrerenderHelper::IsPrerendering(render_frame)) { |
tommycli
2015/08/13 21:50:06
Does this mean that pages that are pre-rendered ar
DaleCurtis
2015/08/13 22:24:30
Hmm, I was counting on prerender not taking affect
mmenke
2015/08/13 22:36:10
Prerendered frames should always be hidden. I don
| |
693 closure.Run(); | 717 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. |
718 new prerender::PrerenderMediaLoadDeferrer(render_frame, closure); | |
694 return; | 719 return; |
695 } | 720 } |
696 | 721 |
697 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. | 722 // Don't allow autoplay/autoload of media resources in a RenderFrame that is |
698 new prerender::PrerenderMediaLoadDeferrer(render_frame, closure); | 723 // hidden and has never played any media before. We want to allow future |
724 // loads even when hidden to allow playlist-like functionality. | |
725 // | |
726 // TODO(dalecurtis): Include an idle check too. http://crbug.com/509135 | |
727 if (render_frame->IsHidden() && !render_frame_has_played_media_before) { | |
728 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. | |
729 new MediaLoadDeferrer(render_frame, closure); | |
730 return; | |
731 } | |
732 | |
733 closure.Run(); | |
699 #endif | 734 #endif |
700 } | 735 } |
701 | 736 |
702 #if defined(ENABLE_PLUGINS) | 737 #if defined(ENABLE_PLUGINS) |
703 WebPlugin* ChromeContentRendererClient::CreatePlugin( | 738 WebPlugin* ChromeContentRendererClient::CreatePlugin( |
704 content::RenderFrame* render_frame, | 739 content::RenderFrame* render_frame, |
705 blink::WebLocalFrame* frame, | 740 blink::WebLocalFrame* frame, |
706 const WebPluginParams& original_params, | 741 const WebPluginParams& original_params, |
707 const ChromeViewHostMsg_GetPluginInfo_Output& output) { | 742 const ChromeViewHostMsg_GetPluginInfo_Output& output) { |
708 const WebPluginInfo& info = output.plugin; | 743 const WebPluginInfo& info = output.plugin; |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1624 WebString header_key(ASCIIToUTF16( | 1659 WebString header_key(ASCIIToUTF16( |
1625 data_reduction_proxy::chrome_proxy_header())); | 1660 data_reduction_proxy::chrome_proxy_header())); |
1626 if (!response.httpHeaderField(header_key).isNull() && | 1661 if (!response.httpHeaderField(header_key).isNull() && |
1627 response.httpHeaderField(header_key).utf8().find( | 1662 response.httpHeaderField(header_key).utf8().find( |
1628 data_reduction_proxy::chrome_proxy_lo_fi_directive()) != | 1663 data_reduction_proxy::chrome_proxy_lo_fi_directive()) != |
1629 std::string::npos) { | 1664 std::string::npos) { |
1630 (*properties)[data_reduction_proxy::chrome_proxy_header()] = | 1665 (*properties)[data_reduction_proxy::chrome_proxy_header()] = |
1631 data_reduction_proxy::chrome_proxy_lo_fi_directive(); | 1666 data_reduction_proxy::chrome_proxy_lo_fi_directive(); |
1632 } | 1667 } |
1633 } | 1668 } |
OLD | NEW |