From 833b84f4ac4e5a794b88ce0638c2a2bdac08fce5 Mon Sep 17 00:00:00 2001 From: Raymond Toy Date: Wed, 5 Sep 2018 17:57:03 +0000 Subject: [PATCH] Record whether AudioContext was audible for Autoplay UKM Implements AudioContextManager mojo interface that can be obtained from a frame so that audible playback from WebAudio can be recorded by the browser. Whenever audible playback starts or stops, a message is sent to the browser indicating such. Bug: 855069 Change-Id: Ib236a9506a2a6d9b53e95948eb5519145805a2cb Reviewed-on: https://chromium-review.googlesource.com/1114147 Reviewed-by: Mounir Lamouri Reviewed-by: Ken Buchanan Reviewed-by: Kentaro Hara Reviewed-by: Kinuko Yasuda Reviewed-by: Nasko Oskov Reviewed-by: Hongchan Choi Commit-Queue: Raymond Toy Cr-Original-Commit-Position: refs/heads/master@{#587867}(cherry picked from commit e413650c2e245c5e87b87bde97f15ab9f280ec9e) Reviewed-on: https://chromium-review.googlesource.com/1207810 Reviewed-by: Raymond Toy Cr-Commit-Position: refs/branch-heads/3538@{#55} Cr-Branched-From: 79f7c91a2b2a2932cd447fa6f865cb6662fa8fa6-refs/heads/master@{#587811} --- content/browser/BUILD.gn | 2 + .../frame_host/interstitial_page_impl.cc | 12 +++ .../frame_host/interstitial_page_impl.h | 4 + .../frame_host/render_frame_host_delegate.h | 7 ++ .../frame_host/render_frame_host_impl.cc | 12 +++ .../frame_host/render_frame_host_impl.h | 5 ++ .../audio_context_manager_browsertest.cc | 75 +++++++++++++++++++ .../webaudio/audio_context_manager_impl.cc | 46 ++++++++++++ .../webaudio/audio_context_manager_impl.h | 41 ++++++++++ .../browser/web_contents/web_contents_impl.cc | 14 ++++ .../browser/web_contents/web_contents_impl.h | 8 ++ .../app/mojo/content_browser_manifest.json | 1 + .../public/browser/web_contents_observer.h | 7 ++ content/test/BUILD.gn | 1 + .../data/media/webaudio/playback-test.html | 21 ++++++ third_party/blink/public/mojom/BUILD.gn | 1 + .../blink/public/mojom/webaudio/OWNERS | 6 ++ .../webaudio/audio_context_manager.mojom | 19 +++++ .../modules/webaudio/audio_context.cc | 20 +++++ .../renderer/modules/webaudio/audio_context.h | 9 +++ .../modules/webaudio/base_audio_context.cc | 14 ---- .../modules/webaudio/base_audio_context.h | 7 +- 22 files changed, 315 insertions(+), 17 deletions(-) create mode 100644 content/browser/media/webaudio/audio_context_manager_browsertest.cc create mode 100644 content/browser/media/webaudio/audio_context_manager_impl.cc create mode 100644 content/browser/media/webaudio/audio_context_manager_impl.h create mode 100644 content/test/data/media/webaudio/playback-test.html create mode 100644 third_party/blink/public/mojom/webaudio/OWNERS create mode 100644 third_party/blink/public/mojom/webaudio/audio_context_manager.mojom diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index 39243079b533..02d6ebe936c1 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -1171,6 +1171,8 @@ jumbo_source_set("browser") { "media/url_provision_fetcher.h", "media/video_decoder_proxy.cc", "media/video_decoder_proxy.h", + "media/webaudio/audio_context_manager_impl.cc", + "media/webaudio/audio_context_manager_impl.h", "memory/memory_condition_observer.cc", "memory/memory_condition_observer.h", "memory/memory_coordinator_default_policy.cc", diff --git a/content/browser/frame_host/interstitial_page_impl.cc b/content/browser/frame_host/interstitial_page_impl.cc index 26debf62bf01..6a26f13d2466 100644 --- a/content/browser/frame_host/interstitial_page_impl.cc +++ b/content/browser/frame_host/interstitial_page_impl.cc @@ -1090,4 +1090,16 @@ InterstitialPageImpl::GetOrCreateRootBrowserAccessibilityManager() { return web_contents_impl->GetOrCreateRootBrowserAccessibilityManager(); } +void InterstitialPageImpl::AudioContextPlaybackStarted(RenderFrameHost* host, + int context_id) { + // Interstitial pages should not be playing any sound via WebAudio + NOTREACHED(); +} + +void InterstitialPageImpl::AudioContextPlaybackStopped(RenderFrameHost* host, + int context_id) { + // Interstitial pages should not be playing any sound via WebAudio. + NOTREACHED(); +} + } // namespace content diff --git a/content/browser/frame_host/interstitial_page_impl.h b/content/browser/frame_host/interstitial_page_impl.h index 45c1eef235f1..bb4b5f7771dc 100644 --- a/content/browser/frame_host/interstitial_page_impl.h +++ b/content/browser/frame_host/interstitial_page_impl.h @@ -138,6 +138,10 @@ class CONTENT_EXPORT InterstitialPageImpl : public InterstitialPage, bool user_gesture) override; void SetFocusedFrame(FrameTreeNode* node, SiteInstance* source) override; Visibility GetVisibility() const override; + void AudioContextPlaybackStarted(RenderFrameHost* host, + int context_id) override; + void AudioContextPlaybackStopped(RenderFrameHost* host, + int context_id) override; // RenderViewHostDelegate implementation: RenderViewHostDelegateView* GetDelegateView() override; diff --git a/content/browser/frame_host/render_frame_host_delegate.h b/content/browser/frame_host/render_frame_host_delegate.h index aed7c27ab9e9..9ac81d17f614 100644 --- a/content/browser/frame_host/render_frame_host_delegate.h +++ b/content/browser/frame_host/render_frame_host_delegate.h @@ -386,6 +386,13 @@ class CONTENT_EXPORT RenderFrameHostDelegate { // Note: This is also exposed by the RenderWidgetHostDelegate. virtual ukm::SourceId GetUkmSourceIdForLastCommittedSource() const; + // Notify observers if WebAudio AudioContext has started (or stopped) playing + // audible sounds. + virtual void AudioContextPlaybackStarted(RenderFrameHost* host, + int context_id){}; + virtual void AudioContextPlaybackStopped(RenderFrameHost* host, + int context_id){}; + protected: virtual ~RenderFrameHostDelegate() {} }; diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc index 60b610202e7d..5be5a5b57a6b 100644 --- a/content/browser/frame_host/render_frame_host_impl.cc +++ b/content/browser/frame_host/render_frame_host_impl.cc @@ -66,6 +66,7 @@ #include "content/browser/media/capture/audio_mirroring_manager.h" #include "content/browser/media/media_interface_proxy.h" #include "content/browser/media/session/media_session_service_impl.h" +#include "content/browser/media/webaudio/audio_context_manager_impl.h" #include "content/browser/payments/payment_app_context_impl.h" #include "content/browser/permissions/permission_controller_impl.h" #include "content/browser/permissions/permission_service_context.h" @@ -782,6 +783,14 @@ void RenderFrameHostImpl::DidCommitProvisionalLoadForTesting( std::move(interface_provider_request)); } +void RenderFrameHostImpl::AudioContextPlaybackStarted(int audio_context_id) { + delegate_->AudioContextPlaybackStarted(this, audio_context_id); +} + +void RenderFrameHostImpl::AudioContextPlaybackStopped(int audio_context_id) { + delegate_->AudioContextPlaybackStopped(this, audio_context_id); +} + SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() { return site_instance_.get(); } @@ -3594,6 +3603,9 @@ void RenderFrameHostImpl::RegisterMojoInterfaces() { registry_->AddInterface(base::BindRepeating( &BackgroundFetchServiceImpl::CreateForFrame, GetProcess(), routing_id_)); + + registry_->AddInterface(base::BindRepeating(&AudioContextManagerImpl::Create, + base::Unretained(this))); } void RenderFrameHostImpl::ResetWaitingState() { diff --git a/content/browser/frame_host/render_frame_host_impl.h b/content/browser/frame_host/render_frame_host_impl.h index 3ae5bcf7fcf7..d71a3c050e65 100644 --- a/content/browser/frame_host/render_frame_host_impl.h +++ b/content/browser/frame_host/render_frame_host_impl.h @@ -784,6 +784,11 @@ class CONTENT_EXPORT RenderFrameHostImpl return *registry_; } + // Called when the WebAudio AudioContext given by |audio_context_id| has + // started (or stopped) playing audible audio. + void AudioContextPlaybackStarted(int audio_context_id); + void AudioContextPlaybackStopped(int audio_context_id); + protected: friend class RenderFrameHostFactory; diff --git a/content/browser/media/webaudio/audio_context_manager_browsertest.cc b/content/browser/media/webaudio/audio_context_manager_browsertest.cc new file mode 100644 index 000000000000..9ab3e351ae6e --- /dev/null +++ b/content/browser/media/webaudio/audio_context_manager_browsertest.cc @@ -0,0 +1,75 @@ +// Copyright 2018 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 "content/public/browser/web_contents_observer.h" +#include "content/public/test/browser_test_utils.h" +#include "content/public/test/content_browser_test.h" +#include "content/public/test/content_browser_test_utils.h" +#include "content/shell/browser/shell.h" + +namespace content { + +namespace { +// Test for audible playback message. +class WaitForAudioContextAudible : WebContentsObserver { + public: + explicit WaitForAudioContextAudible(WebContents* web_contents) + : WebContentsObserver(web_contents) { + run_loop_.Run(); + } + + void AudioContextPlaybackStarted(const AudioContextId&) final { + // Stop the run loop when we get the message + run_loop_.Quit(); + } + + private: + base::RunLoop run_loop_; + + DISALLOW_COPY_AND_ASSIGN(WaitForAudioContextAudible); +}; + +// Test for silent playback started (audible playback stopped). +class WaitForAudioContextSilent : WebContentsObserver { + public: + explicit WaitForAudioContextSilent(WebContents* web_contents) + : WebContentsObserver(web_contents) { + run_loop_.Run(); + } + + void AudioContextPlaybackStopped(const AudioContextId&) final { + // Stop the run loop when we get the message + run_loop_.Quit(); + } + + private: + base::RunLoop run_loop_; + + DISALLOW_COPY_AND_ASSIGN(WaitForAudioContextSilent); +}; + +} // namespace + +class AudioContextManagerTest : public ContentBrowserTest {}; + +IN_PROC_BROWSER_TEST_F(AudioContextManagerTest, AudioContextPlaybackRecorded) { + NavigateToURL(shell(), + content::GetTestUrl("media/webaudio/", "playback-test.html")); + + // Set gain to 1 to start audible audio and verify we got the + // playback started message. + { + ASSERT_TRUE(ExecuteScript(shell()->web_contents(), "gain.gain.value = 1;")); + WaitForAudioContextAudible wait(shell()->web_contents()); + } + + // Set gain to 0 to stop audible audio and verify we got the + // playback stopped message. + { + ASSERT_TRUE(ExecuteScript(shell()->web_contents(), "gain.gain.value = 0;")); + WaitForAudioContextSilent wait(shell()->web_contents()); + } +} + +} // namespace content diff --git a/content/browser/media/webaudio/audio_context_manager_impl.cc b/content/browser/media/webaudio/audio_context_manager_impl.cc new file mode 100644 index 000000000000..6660e4bd126a --- /dev/null +++ b/content/browser/media/webaudio/audio_context_manager_impl.cc @@ -0,0 +1,46 @@ +// Copyright 2018 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 "content/browser/media/webaudio/audio_context_manager_impl.h" + +#include "content/browser/frame_host/render_frame_host_impl.h" +#include "content/browser/web_contents/web_contents_impl.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/web_contents.h" +#include "mojo/public/cpp/bindings/strong_binding.h" + +namespace content { + +void AudioContextManagerImpl::Create( + RenderFrameHost* render_frame_host, + blink::mojom::AudioContextManagerRequest request) { + mojo::MakeStrongBinding( + std::make_unique(render_frame_host), + std::move(request)); +} + +AudioContextManagerImpl::AudioContextManagerImpl( + RenderFrameHost* render_frame_host) + : render_frame_host_impl_( + static_cast(render_frame_host)) { + DCHECK(render_frame_host); +} + +AudioContextManagerImpl::~AudioContextManagerImpl() = default; + +void AudioContextManagerImpl::AudioContextAudiblePlaybackStarted( + int32_t audio_context_id) { + // Notify observers that audible audio started playing from a WebAudio + // AudioContext. + render_frame_host_impl_->AudioContextPlaybackStarted(audio_context_id); +} + +void AudioContextManagerImpl::AudioContextAudiblePlaybackStopped( + int32_t audio_context_id) { + // Notify observers that audible audio stopped playing from a WebAudio + // AudioContext. + render_frame_host_impl_->AudioContextPlaybackStopped(audio_context_id); +} + +} // namespace content diff --git a/content/browser/media/webaudio/audio_context_manager_impl.h b/content/browser/media/webaudio/audio_context_manager_impl.h new file mode 100644 index 000000000000..cc03296f9ac0 --- /dev/null +++ b/content/browser/media/webaudio/audio_context_manager_impl.h @@ -0,0 +1,41 @@ +// Copyright 2018 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 CONTENT_BROWSER_MEDIA_WEBAUDIO_AUDIO_CONTEXT_MANAGER_IMPL_H_ +#define CONTENT_BROWSER_MEDIA_WEBAUDIO_AUDIO_CONTEXT_MANAGER_IMPL_H_ + +#include "content/common/content_export.h" +#include "mojo/public/cpp/bindings/binding.h" +#include "third_party/blink/public/mojom/webaudio/audio_context_manager.mojom.h" + +namespace content { + +class RenderFrameHost; +class RenderFrameHostImpl; + +// Implements the mojo interface between WebAudio and the browser so that +// WebAudio can report when audible sounds from an AudioContext starts and +// stops. +class CONTENT_EXPORT AudioContextManagerImpl + : public blink::mojom::AudioContextManager { + public: + explicit AudioContextManagerImpl(RenderFrameHost* render_frame_host); + ~AudioContextManagerImpl() override; + + static void Create(RenderFrameHost* render_frame_host, + blink::mojom::AudioContextManagerRequest request); + + // Called when AudioContext starts or stops playing audible audio. + void AudioContextAudiblePlaybackStarted(int32_t audio_context_id) final; + void AudioContextAudiblePlaybackStopped(int32_t audio_context_id) final; + + private: + RenderFrameHostImpl* const render_frame_host_impl_; + + DISALLOW_COPY_AND_ASSIGN(AudioContextManagerImpl); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_MEDIA_WEBAUDIO_AUDIO_CONTEXT_MANAGER_IMPL_H_ diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index 36dab1bdee1d..49f26c7bde40 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -6517,6 +6517,20 @@ int WebContentsImpl::GetCurrentlyPlayingVideoCount() { return currently_playing_video_count_; } +void WebContentsImpl::AudioContextPlaybackStarted(RenderFrameHost* host, + int context_id) { + WebContentsObserver::AudioContextId audio_context_id(host, context_id); + for (auto& observer : observers_) + observer.AudioContextPlaybackStarted(audio_context_id); +} + +void WebContentsImpl::AudioContextPlaybackStopped(RenderFrameHost* host, + int context_id) { + WebContentsObserver::AudioContextId audio_context_id(host, context_id); + for (auto& observer : observers_) + observer.AudioContextPlaybackStopped(audio_context_id); +} + void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) { // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled // (for power and speed impact assessment) or when diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 6e047068256a..2687e87ea2da 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -584,6 +584,14 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, RenderFrameHost* render_frame_host, const GlobalRequestID& request_id, mojom::ResourceLoadInfoPtr resource_load_information) override; + + // Called when WebAudio starts or stops playing audible audio in an + // AudioContext. + void AudioContextPlaybackStarted(RenderFrameHost* host, + int context_id) override; + void AudioContextPlaybackStopped(RenderFrameHost* host, + int context_id) override; + // RenderViewHostDelegate ---------------------------------------------------- RenderViewHostDelegateView* GetDelegateView() override; bool OnMessageReceived(RenderViewHostImpl* render_view_host, diff --git a/content/public/app/mojo/content_browser_manifest.json b/content/public/app/mojo/content_browser_manifest.json index d440e94e8f2d..c2e72da4f59a 100644 --- a/content/public/app/mojo/content_browser_manifest.json +++ b/content/public/app/mojo/content_browser_manifest.json @@ -151,6 +151,7 @@ "autofill.mojom.AutofillDriver", "autofill.mojom.PasswordManagerDriver", "blink.mojom.AnchorElementMetricsHost", + "blink.mojom.AudioContextManager", "blink.mojom.Authenticator", "blink.mojom.BackgroundFetchService", "blink.mojom.CacheStorage", diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h index 0194c382622d..458b71354dd7 100644 --- a/content/public/browser/web_contents_observer.h +++ b/content/public/browser/web_contents_observer.h @@ -542,6 +542,13 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener { // tab. virtual void DidCommitAndDrawCompositorFrame() {} + // Called when "audible" playback starts or stops on a WebAudio AudioContext. + using AudioContextId = std::pair; + virtual void AudioContextPlaybackStarted( + const AudioContextId& audio_context_id) {} + virtual void AudioContextPlaybackStopped( + const AudioContextId& audio_context_id) {} + // IPC::Listener implementation. // DEPRECATED: Use (i.e. override) the other overload instead: // virtual bool OnMessageReceived(const IPC::Message& message, diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn index 77b6ffcbd6f2..862228af1202 100644 --- a/content/test/BUILD.gn +++ b/content/test/BUILD.gn @@ -802,6 +802,7 @@ test("content_browsertests") { "../browser/media/session/media_session_service_impl_browsertest.cc", "../browser/media/session/mock_media_session_player_observer.cc", "../browser/media/session/mock_media_session_player_observer.h", + "../browser/media/webaudio/audio_context_manager_browsertest.cc", "../browser/memory/memory_coordinator_impl_browsertest.cc", "../browser/message_port_provider_browsertest.cc", "../browser/mojo_sandbox_browsertest.cc", diff --git a/content/test/data/media/webaudio/playback-test.html b/content/test/data/media/webaudio/playback-test.html new file mode 100644 index 000000000000..0a201b7d6364 --- /dev/null +++ b/content/test/data/media/webaudio/playback-test.html @@ -0,0 +1,21 @@ + + + + Test AudioContextManager Audible Playback + + + + + + diff --git a/third_party/blink/public/mojom/BUILD.gn b/third_party/blink/public/mojom/BUILD.gn index 46834da18722..e3f0d9e8042d 100644 --- a/third_party/blink/public/mojom/BUILD.gn +++ b/third_party/blink/public/mojom/BUILD.gn @@ -62,6 +62,7 @@ mojom("mojom_platform") { "speech/speech_recognizer.mojom", "use_counter/css_property_id.mojom", "web_package/web_package_internals.mojom", + "webaudio/audio_context_manager.mojom", ] public_deps = [ diff --git a/third_party/blink/public/mojom/webaudio/OWNERS b/third_party/blink/public/mojom/webaudio/OWNERS new file mode 100644 index 000000000000..c7c1217b39e9 --- /dev/null +++ b/third_party/blink/public/mojom/webaudio/OWNERS @@ -0,0 +1,6 @@ +file://third_party/blink/renderer/modules/webaudio/OWNERS + +# COMPONENT: Blink>WebAudio + +per-file *.mojom=set noparent +per-file *.mojom=file://ipc/SECURITY_OWNERS diff --git a/third_party/blink/public/mojom/webaudio/audio_context_manager.mojom b/third_party/blink/public/mojom/webaudio/audio_context_manager.mojom new file mode 100644 index 000000000000..5ea8602a958b --- /dev/null +++ b/third_party/blink/public/mojom/webaudio/audio_context_manager.mojom @@ -0,0 +1,19 @@ +// Copyright 2018 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. + +module blink.mojom; + +// Interface for allowing a real-time AudioContext to send +// notifications to browser that the AudioContext has started (or +// stopped) playing audible sounds. Audibility is computed by the +// AudioContext. +interface AudioContextManager { + // AudioContext started producing audible sound. The id is the ID + // of the AudioContext. + AudioContextAudiblePlaybackStarted(int32 id); + + // AudioContext stopped producing audible sound. The id is the ID + // of the AudioContext. + AudioContextAudiblePlaybackStopped(int32 id); +}; diff --git a/third_party/blink/renderer/modules/webaudio/audio_context.cc b/third_party/blink/renderer/modules/webaudio/audio_context.cc index 99cb78ea9df1..78bb32516d66 100644 --- a/third_party/blink/renderer/modules/webaudio/audio_context.cc +++ b/third_party/blink/renderer/modules/webaudio/audio_context.cc @@ -7,10 +7,12 @@ #include "build/build_config.h" #include "services/metrics/public/cpp/ukm_builders.h" #include "services/metrics/public/cpp/ukm_recorder.h" +#include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/blink/public/platform/web_audio_latency_hint.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/inspector/console_message.h" #include "third_party/blink/renderer/core/probe/core_probes.h" @@ -467,4 +469,22 @@ void AudioContext::ContextDestroyed(ExecutionContext*) { Uninitialize(); } +void AudioContext::NotifyAudibleAudioStarted() { + DCHECK(IsMainThread()); + + if (!audio_context_manager_) { + GetDocument()->GetFrame()->GetInterfaceProvider().GetInterface( + mojo::MakeRequest(&audio_context_manager_)); + } + + audio_context_manager_->AudioContextAudiblePlaybackStarted(context_id_); +} + +void AudioContext::NotifyAudibleAudioStopped() { + DCHECK(IsMainThread()); + DCHECK(audio_context_manager_); + + audio_context_manager_->AudioContextAudiblePlaybackStopped(context_id_); +} + } // namespace blink diff --git a/third_party/blink/renderer/modules/webaudio/audio_context.h b/third_party/blink/renderer/modules/webaudio/audio_context.h index a239599207a5..d93934e4e0c7 100644 --- a/third_party/blink/renderer/modules/webaudio/audio_context.h +++ b/third_party/blink/renderer/modules/webaudio/audio_context.h @@ -5,6 +5,7 @@ #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_CONTEXT_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_AUDIO_CONTEXT_H_ +#include "third_party/blink/public/mojom/webaudio/audio_context_manager.mojom-blink.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/core/html/media/autoplay_policy.h" @@ -105,6 +106,11 @@ class MODULES_EXPORT AudioContext : public BaseAudioContext { void DidClose(); + // Send notification to browser that an AudioContext has started or stopped + // playing audible audio. + void NotifyAudibleAudioStarted() final; + void NotifyAudibleAudioStopped() final; + unsigned context_id_; Member close_resolver_; @@ -123,6 +129,9 @@ class MODULES_EXPORT AudioContext : public BaseAudioContext { // Records if start() was ever called for any source node in this context. bool source_node_started_ = false; + + // AudioContextManager for reporting audibility. + mojom::blink::AudioContextManagerPtr audio_context_manager_; }; } // namespace blink diff --git a/third_party/blink/renderer/modules/webaudio/base_audio_context.cc b/third_party/blink/renderer/modules/webaudio/base_audio_context.cc index f6f89b1501da..a697dcdb9fa6 100644 --- a/third_party/blink/renderer/modules/webaudio/base_audio_context.cc +++ b/third_party/blink/renderer/modules/webaudio/base_audio_context.cc @@ -1001,18 +1001,4 @@ bool BaseAudioContext::WouldTaintOrigin(const KURL& url) const { return true; } -void BaseAudioContext::NotifyAudibleAudioStarted() { - DCHECK(IsMainThread()); - // TODO(crbug.com/855069): Actually notify the browser that audible audio has - // started. - VLOG(1) << this << ": Audible audio started @" << currentTime(); -} - -void BaseAudioContext::NotifyAudibleAudioStopped() { - DCHECK(IsMainThread()); - // TODO(crbug.com/855069): Actually notify the browser that audible audio has - // started. - VLOG(1) << this << ": Audible audio stopped @" << currentTime(); -} - } // namespace blink diff --git a/third_party/blink/renderer/modules/webaudio/base_audio_context.h b/third_party/blink/renderer/modules/webaudio/base_audio_context.h index bc0b0fe7d494..fadb4834357b 100644 --- a/third_party/blink/renderer/modules/webaudio/base_audio_context.h +++ b/third_party/blink/renderer/modules/webaudio/base_audio_context.h @@ -453,9 +453,10 @@ class MODULES_EXPORT BaseAudioContext // the BaseAudioContext goes away. WorkerThread* audio_worklet_thread_ = nullptr; - // Notifies browser when audible audio started or stopped. - void NotifyAudibleAudioStarted(); - void NotifyAudibleAudioStopped(); + // Notifies browser when audible audio starts or stops. This should + // only apply for AudioContexts. + virtual void NotifyAudibleAudioStarted() { NOTREACHED(); } + virtual void NotifyAudibleAudioStopped() { NOTREACHED(); } // Keeps track if the output of this destination was audible, before the // current rendering quantum. Used for recording "playback" time.