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

Unified Diff: chrome/renderer/chrome_content_renderer_client.cc

Issue 1292433002: Defer media playback in background tabs. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/chrome_content_renderer_client.cc
diff --git a/chrome/renderer/chrome_content_renderer_client.cc b/chrome/renderer/chrome_content_renderer_client.cc
index 34ee044bb0c95869961b4de2c882d3ddaa164ebe..88a3fe084708ef6fbf9c87aca2a33b89ff89aaf1 100644
--- a/chrome/renderer/chrome_content_renderer_client.cc
+++ b/chrome/renderer/chrome_content_renderer_client.cc
@@ -46,7 +46,6 @@
#include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h"
#include "chrome/renderer/prerender/prerender_dispatcher.h"
#include "chrome/renderer/prerender/prerender_helper.h"
-#include "chrome/renderer/prerender/prerender_media_load_deferrer.h"
#include "chrome/renderer/prerender/prerenderer_client.h"
#include "chrome/renderer/safe_browsing/malware_dom_details.h"
#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
@@ -341,6 +340,29 @@ bool IsStandaloneExtensionProcess() {
extensions::switches::kExtensionProcess);
}
#endif
+
+// Defers media player loading in background pages until they're visible.
+// TODO(dalecurtis): Include an idle listener too. http://crbug.com/509135
+class MediaLoadDeferrer : public content::RenderFrameObserver {
+ public:
+ MediaLoadDeferrer(content::RenderFrame* render_frame,
+ const base::Closure& continue_loading_cb)
+ : content::RenderFrameObserver(render_frame),
+ continue_loading_cb_(continue_loading_cb) {}
+ ~MediaLoadDeferrer() override {}
+
+ private:
+ // content::RenderFrameObserver implementation:
+ void WasShown() override {
+ continue_loading_cb_.Run();
+ delete this;
+ }
+
+ const base::Closure continue_loading_cb_;
+
+ DISALLOW_COPY_AND_ASSIGN(MediaLoadDeferrer);
+};
+
} // namespace
ChromeContentRendererClient::ChromeContentRendererClient() {
@@ -683,20 +705,22 @@ WebPlugin* ChromeContentRendererClient::CreatePluginReplacement(
void ChromeContentRendererClient::DeferMediaLoad(
content::RenderFrame* render_frame,
+ bool has_played_media_before,
const base::Closure& closure) {
-#if defined(OS_ANDROID)
- // Chromium for Android doesn't support prerender yet.
- closure.Run();
- return;
-#else
- if (!prerender::PrerenderHelper::IsPrerendering(render_frame)) {
- closure.Run();
+ // Don't allow autoplay/autoload of media resources in a RenderFrame that is
+ // hidden and has never played any media before. We want to allow future
+ // loads even when hidden to allow playlist-like functionality.
+ //
+ // NOTE: This is also used to defer media loading for prerender.
+ //
+ // TODO(dalecurtis): Include an idle check too. http://crbug.com/509135
+ if (render_frame->IsHidden() && !has_played_media_before) {
+ // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
+ new MediaLoadDeferrer(render_frame, closure);
return;
}
- // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
- new prerender::PrerenderMediaLoadDeferrer(render_frame, closure);
-#endif
+ closure.Run();
}
#if defined(ENABLE_PLUGINS)
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.h ('k') | chrome/renderer/prerender/prerender_media_load_deferrer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698