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 28 matching lines...) Expand all Loading... |
39 #include "chrome/renderer/net/net_error_helper.h" | 39 #include "chrome/renderer/net/net_error_helper.h" |
40 #include "chrome/renderer/net_benchmarking_extension.h" | 40 #include "chrome/renderer/net_benchmarking_extension.h" |
41 #include "chrome/renderer/page_load_histograms.h" | 41 #include "chrome/renderer/page_load_histograms.h" |
42 #include "chrome/renderer/pepper/pepper_helper.h" | 42 #include "chrome/renderer/pepper/pepper_helper.h" |
43 #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h" | 43 #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h" |
44 #include "chrome/renderer/plugins/plugin_preroller.h" | 44 #include "chrome/renderer/plugins/plugin_preroller.h" |
45 #include "chrome/renderer/plugins/plugin_uma.h" | 45 #include "chrome/renderer/plugins/plugin_uma.h" |
46 #include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h" | 46 #include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h" |
47 #include "chrome/renderer/prerender/prerender_dispatcher.h" | 47 #include "chrome/renderer/prerender/prerender_dispatcher.h" |
48 #include "chrome/renderer/prerender/prerender_helper.h" | 48 #include "chrome/renderer/prerender/prerender_helper.h" |
49 #include "chrome/renderer/prerender/prerender_media_load_deferrer.h" | |
50 #include "chrome/renderer/prerender/prerenderer_client.h" | 49 #include "chrome/renderer/prerender/prerenderer_client.h" |
51 #include "chrome/renderer/safe_browsing/malware_dom_details.h" | 50 #include "chrome/renderer/safe_browsing/malware_dom_details.h" |
52 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" | 51 #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" |
53 #include "chrome/renderer/searchbox/search_bouncer.h" | 52 #include "chrome/renderer/searchbox/search_bouncer.h" |
54 #include "chrome/renderer/searchbox/searchbox.h" | 53 #include "chrome/renderer/searchbox/searchbox.h" |
55 #include "chrome/renderer/searchbox/searchbox_extension.h" | 54 #include "chrome/renderer/searchbox/searchbox_extension.h" |
56 #include "chrome/renderer/tts_dispatcher.h" | 55 #include "chrome/renderer/tts_dispatcher.h" |
57 #include "chrome/renderer/worker_content_settings_client_proxy.h" | 56 #include "chrome/renderer/worker_content_settings_client_proxy.h" |
58 #include "components/autofill/content/renderer/autofill_agent.h" | 57 #include "components/autofill/content/renderer/autofill_agent.h" |
59 #include "components/autofill/content/renderer/password_autofill_agent.h" | 58 #include "components/autofill/content/renderer/password_autofill_agent.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 return std::string(); | 333 return std::string(); |
335 } | 334 } |
336 #endif | 335 #endif |
337 | 336 |
338 #if defined(ENABLE_EXTENSIONS) | 337 #if defined(ENABLE_EXTENSIONS) |
339 bool IsStandaloneExtensionProcess() { | 338 bool IsStandaloneExtensionProcess() { |
340 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 339 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
341 extensions::switches::kExtensionProcess); | 340 extensions::switches::kExtensionProcess); |
342 } | 341 } |
343 #endif | 342 #endif |
| 343 |
| 344 // Defers media player loading in background pages until they're visible. |
| 345 // TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135 |
| 346 class MediaLoadDeferrer : public content::RenderFrameObserver { |
| 347 public: |
| 348 MediaLoadDeferrer(content::RenderFrame* render_frame, |
| 349 const base::Closure& continue_loading_cb) |
| 350 : content::RenderFrameObserver(render_frame), |
| 351 continue_loading_cb_(continue_loading_cb) {} |
| 352 ~MediaLoadDeferrer() override {} |
| 353 |
| 354 private: |
| 355 // content::RenderFrameObserver implementation: |
| 356 void WasShown() override { |
| 357 continue_loading_cb_.Run(); |
| 358 delete this; |
| 359 } |
| 360 |
| 361 const base::Closure continue_loading_cb_; |
| 362 |
| 363 DISALLOW_COPY_AND_ASSIGN(MediaLoadDeferrer); |
| 364 }; |
| 365 |
344 } // namespace | 366 } // namespace |
345 | 367 |
346 ChromeContentRendererClient::ChromeContentRendererClient() { | 368 ChromeContentRendererClient::ChromeContentRendererClient() { |
347 g_current_client = this; | 369 g_current_client = this; |
348 | 370 |
349 #if defined(ENABLE_EXTENSIONS) | 371 #if defined(ENABLE_EXTENSIONS) |
350 extensions::ExtensionsClient::Set( | 372 extensions::ExtensionsClient::Set( |
351 extensions::ChromeExtensionsClient::GetInstance()); | 373 extensions::ChromeExtensionsClient::GetInstance()); |
352 extensions::ExtensionsRendererClient::Set( | 374 extensions::ExtensionsRendererClient::Set( |
353 ChromeExtensionsRendererClient::GetInstance()); | 375 ChromeExtensionsRendererClient::GetInstance()); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 | 698 |
677 WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( | 699 WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( |
678 content::RenderFrame* render_frame, | 700 content::RenderFrame* render_frame, |
679 const base::FilePath& plugin_path) { | 701 const base::FilePath& plugin_path) { |
680 return NonLoadablePluginPlaceholder::CreateErrorPlugin(render_frame, | 702 return NonLoadablePluginPlaceholder::CreateErrorPlugin(render_frame, |
681 plugin_path)->plugin(); | 703 plugin_path)->plugin(); |
682 } | 704 } |
683 | 705 |
684 void ChromeContentRendererClient::DeferMediaLoad( | 706 void ChromeContentRendererClient::DeferMediaLoad( |
685 content::RenderFrame* render_frame, | 707 content::RenderFrame* render_frame, |
| 708 bool has_played_media_before, |
686 const base::Closure& closure) { | 709 const base::Closure& closure) { |
687 #if defined(OS_ANDROID) | 710 // Don't allow autoplay/autoload of media resources in a RenderFrame that is |
688 // Chromium for Android doesn't support prerender yet. | 711 // hidden and has never played any media before. We want to allow future |
689 closure.Run(); | 712 // loads even when hidden to allow playlist-like functionality. |
690 return; | 713 // |
691 #else | 714 // NOTE: This is also used to defer media loading for prerender. |
692 if (!prerender::PrerenderHelper::IsPrerendering(render_frame)) { | 715 // |
693 closure.Run(); | 716 // TODO(dalecurtis): Include an idle check too. http://crbug.com/509135 |
| 717 if (render_frame->IsHidden() && !has_played_media_before) { |
| 718 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. |
| 719 new MediaLoadDeferrer(render_frame, closure); |
694 return; | 720 return; |
695 } | 721 } |
696 | 722 |
697 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. | 723 closure.Run(); |
698 new prerender::PrerenderMediaLoadDeferrer(render_frame, closure); | |
699 #endif | |
700 } | 724 } |
701 | 725 |
702 #if defined(ENABLE_PLUGINS) | 726 #if defined(ENABLE_PLUGINS) |
703 WebPlugin* ChromeContentRendererClient::CreatePlugin( | 727 WebPlugin* ChromeContentRendererClient::CreatePlugin( |
704 content::RenderFrame* render_frame, | 728 content::RenderFrame* render_frame, |
705 blink::WebLocalFrame* frame, | 729 blink::WebLocalFrame* frame, |
706 const WebPluginParams& original_params, | 730 const WebPluginParams& original_params, |
707 const ChromeViewHostMsg_GetPluginInfo_Output& output) { | 731 const ChromeViewHostMsg_GetPluginInfo_Output& output) { |
708 const WebPluginInfo& info = output.plugin; | 732 const WebPluginInfo& info = output.plugin; |
709 const std::string& actual_mime_type = output.actual_mime_type; | 733 const std::string& actual_mime_type = output.actual_mime_type; |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 | 1661 |
1638 void | 1662 void |
1639 ChromeContentRendererClient::DidInitializeServiceWorkerContextOnWorkerThread( | 1663 ChromeContentRendererClient::DidInitializeServiceWorkerContextOnWorkerThread( |
1640 v8::Local<v8::Context> context, | 1664 v8::Local<v8::Context> context, |
1641 const GURL& url) { | 1665 const GURL& url) { |
1642 #if defined(ENABLE_EXTENSIONS) | 1666 #if defined(ENABLE_EXTENSIONS) |
1643 extensions::Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( | 1667 extensions::Dispatcher::DidInitializeServiceWorkerContextOnWorkerThread( |
1644 context, url); | 1668 context, url); |
1645 #endif | 1669 #endif |
1646 } | 1670 } |
OLD | NEW |