-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> Reviewed-by: Ken Buchanan <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Reviewed-by: Kinuko Yasuda <[email protected]> Reviewed-by: Nasko Oskov <[email protected]> Reviewed-by: Hongchan Choi <[email protected]> Commit-Queue: Raymond Toy <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#587867}(cherry picked from commit e413650) Reviewed-on: https://chromium-review.googlesource.com/1207810 Reviewed-by: Raymond Toy <[email protected]> Cr-Commit-Position: refs/branch-heads/3538@{#55} Cr-Branched-From: 79f7c91-refs/heads/master@{#587811}
- Loading branch information
Raymond Toy
committed
Sep 5, 2018
1 parent
84a07b5
commit 833b84f
Showing
22 changed files
with
315 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
content/browser/media/webaudio/audio_context_manager_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
46 changes: 46 additions & 0 deletions
46
content/browser/media/webaudio/audio_context_manager_impl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AudioContextManagerImpl>(render_frame_host), | ||
std::move(request)); | ||
} | ||
|
||
AudioContextManagerImpl::AudioContextManagerImpl( | ||
RenderFrameHost* render_frame_host) | ||
: render_frame_host_impl_( | ||
static_cast<RenderFrameHostImpl*>(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 |
41 changes: 41 additions & 0 deletions
41
content/browser/media/webaudio/audio_context_manager_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Test AudioContextManager Audible Playback</title> | ||
</head> | ||
|
||
<body> | ||
<script> | ||
let context = new AudioContext(); | ||
let osc = new OscillatorNode(context); | ||
// Set initial gain to 0 to make sure we start with silence. | ||
let gain = new GainNode(context, {gain: 0}); | ||
|
||
// Connect everything and start the oscillator. The browser test will set the gain value as | ||
// needed to test if the messages are being sent. | ||
osc.connect(gain).connect(context.destination); | ||
osc.start(); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
19 changes: 19 additions & 0 deletions
19
third_party/blink/public/mojom/webaudio/audio_context_manager.mojom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
Oops, something went wrong.