diff options
author | derekjchow <derekjchow@chromium.org> | 2014-12-22 14:13:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-22 22:14:21 +0000 |
commit | d355ff75f2eb9129cb06e160c5beb1590d7d0ee3 (patch) | |
tree | c8f9aa313a5645cb0bda231159e873c860e9f0cd /chromecast | |
parent | 05cb187d507e5f5f69b0011e3b87cbba94216435 (diff) | |
download | chromium_src-d355ff75f2eb9129cb06e160c5beb1590d7d0ee3.zip chromium_src-d355ff75f2eb9129cb06e160c5beb1590d7d0ee3.tar.gz chromium_src-d355ff75f2eb9129cb06e160c5beb1590d7d0ee3.tar.bz2 |
Support for defered media load to cast_content_render_client.
Adds cast_media_load_dererrer to prevent unwanted media from being
played in web_contents that are not currently visible.
R=gunsch@chromium.org
BUG=
Review URL: https://codereview.chromium.org/824733002
Cr-Commit-Position: refs/heads/master@{#309471}
Diffstat (limited to 'chromecast')
-rw-r--r-- | chromecast/chromecast.gyp | 2 | ||||
-rw-r--r-- | chromecast/renderer/cast_content_renderer_client.cc | 13 | ||||
-rw-r--r-- | chromecast/renderer/cast_content_renderer_client.h | 2 | ||||
-rw-r--r-- | chromecast/renderer/cast_media_load_deferrer.cc | 27 | ||||
-rw-r--r-- | chromecast/renderer/cast_media_load_deferrer.h | 35 |
5 files changed, 79 insertions, 0 deletions
diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index cf7ed71..b8595ba 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -174,6 +174,8 @@ 'common/pref_names.h', 'renderer/cast_content_renderer_client.cc', 'renderer/cast_content_renderer_client.h', + 'renderer/cast_media_load_deferrer.cc', + 'renderer/cast_media_load_deferrer.h', 'renderer/key_systems_cast.cc', 'renderer/key_systems_cast.h', ], diff --git a/chromecast/renderer/cast_content_renderer_client.cc b/chromecast/renderer/cast_content_renderer_client.cc index c2d91de..a01ea77 100644 --- a/chromecast/renderer/cast_content_renderer_client.cc +++ b/chromecast/renderer/cast_content_renderer_client.cc @@ -9,6 +9,7 @@ #include "base/command_line.h" #include "base/memory/memory_pressure_listener.h" #include "chromecast/common/chromecast_switches.h" +#include "chromecast/renderer/cast_media_load_deferrer.h" #include "chromecast/renderer/key_systems_cast.h" #include "chromecast/renderer/media/cma_media_renderer_factory.h" #include "components/dns_prefetch/renderer/prescient_networking_dispatcher.h" @@ -89,5 +90,17 @@ CastContentRendererClient::GetPrescientNetworking() { return prescient_networking_dispatcher_.get(); } +void CastContentRendererClient::DeferMediaLoad( + content::RenderFrame* render_frame, + const base::Closure& closure) { + if (!render_frame->IsHidden()) { + closure.Run(); + return; + } + + // Lifetime is tied to |render_frame| via content::RenderFrameObserver. + new CastMediaLoadDeferrer(render_frame, closure); +} + } // namespace shell } // namespace chromecast diff --git a/chromecast/renderer/cast_content_renderer_client.h b/chromecast/renderer/cast_content_renderer_client.h index 7b60e6e..67c4529 100644 --- a/chromecast/renderer/cast_content_renderer_client.h +++ b/chromecast/renderer/cast_content_renderer_client.h @@ -30,6 +30,8 @@ class CastContentRendererClient : public content::ContentRendererClient { scoped_ptr<media::RendererFactory> CreateMediaRendererFactory( content::RenderFrame* render_frame) override; blink::WebPrescientNetworking* GetPrescientNetworking() override; + void DeferMediaLoad(content::RenderFrame* render_frame, + const base::Closure& closure) override; private: scoped_ptr<dns_prefetch::PrescientNetworkingDispatcher> diff --git a/chromecast/renderer/cast_media_load_deferrer.cc b/chromecast/renderer/cast_media_load_deferrer.cc new file mode 100644 index 0000000..0f84657 --- /dev/null +++ b/chromecast/renderer/cast_media_load_deferrer.cc @@ -0,0 +1,27 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromecast/renderer/cast_media_load_deferrer.h" + +#include "base/callback_helpers.h" +#include "base/logging.h" + +namespace chromecast { + +CastMediaLoadDeferrer::CastMediaLoadDeferrer( + content::RenderFrame* render_frame, + const base::Closure& continue_loading_cb) + : content::RenderFrameObserver(render_frame), + continue_loading_cb_(continue_loading_cb) { + DCHECK(!continue_loading_cb_.is_null()); +} + +CastMediaLoadDeferrer::~CastMediaLoadDeferrer() {} + +void CastMediaLoadDeferrer::WasShown() { + continue_loading_cb_.Run(); + delete this; +} + +} // namespace chromecast diff --git a/chromecast/renderer/cast_media_load_deferrer.h b/chromecast/renderer/cast_media_load_deferrer.h new file mode 100644 index 0000000..72a57ca --- /dev/null +++ b/chromecast/renderer/cast_media_load_deferrer.h @@ -0,0 +1,35 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMECAST_RENDERER_CAST_MEDIA_LOAD_DEFERRER_H_ +#define CHROMECAST_RENDERER_CAST_MEDIA_LOAD_DEFERRER_H_ + +#include "base/callback.h" +#include "base/macros.h" +#include "content/public/renderer/render_frame_observer.h" + +namespace chromecast { + +// Defers media player loading in background web apps until brought into +// foreground. +class CastMediaLoadDeferrer : public content::RenderFrameObserver { + public: + // Will run |closure| to continue loading the media resource once the page is + // swapped in. + CastMediaLoadDeferrer(content::RenderFrame* render_frame, + const base::Closure& continue_loading_cb); + ~CastMediaLoadDeferrer() override; + + private: + // content::RenderFrameObserver implementation: + void WasShown() override; + + base::Closure continue_loading_cb_; + + DISALLOW_COPY_AND_ASSIGN(CastMediaLoadDeferrer); +}; + +} // namespace chromecast + +#endif // CHROMECAST_RENDERER_CAST_MEDIA_LOAD_DEFERRER_H_ |