[fuchsia] Enforce AUDIO ContextFeatureFlag
Before using the audio service, check that the AUDIO feature flag is enabled. Test: WebEngineIntegrationTest.PlayAudio* Bug: 1070571 Change-Id: I4f88887e24dd899748fa7959875b5c2b5753eee3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365992 Reviewed-by: Sergey Ulanov <sergeyu@chromium.org> Reviewed-by: Becca Hughes <beccahughes@chromium.org> Reviewed-by: Wez <wez@chromium.org> Reviewed-by: David Dorwin <ddorwin@chromium.org> Commit-Queue: Sharon Yang <yangsharon@chromium.org> Cr-Commit-Position: refs/heads/master@{#807189}
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
#include "content/public/browser/storage_partition.h"
|
||||
#include "fuchsia/engine/browser/frame_impl.h"
|
||||
#include "fuchsia/engine/switches.h"
|
||||
#include "media/base/media_switches.h"
|
||||
#include "media/base/provision_fetcher.h"
|
||||
#include "media/fuchsia/cdm/service/fuchsia_cdm_manager.h"
|
||||
#include "third_party/widevine/cdm/widevine_cdm_common.h"
|
||||
@ -81,6 +82,14 @@ void MediaResourceProviderImpl::CreateCdm(
|
||||
|
||||
void MediaResourceProviderImpl::CreateAudioConsumer(
|
||||
fidl::InterfaceRequest<fuchsia::media::AudioConsumer> request) {
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kDisableAudioOutput)) {
|
||||
LOG(WARNING)
|
||||
<< "Could not create AudioConsumer because audio output feature flag "
|
||||
"was not enabled.";
|
||||
return;
|
||||
}
|
||||
|
||||
auto factory = base::ComponentContextForProcess()
|
||||
->svc()
|
||||
->Connect<fuchsia::media::SessionAudioConsumerFactory>();
|
||||
@ -91,6 +100,14 @@ void MediaResourceProviderImpl::CreateAudioConsumer(
|
||||
|
||||
void MediaResourceProviderImpl::CreateAudioCapturer(
|
||||
fidl::InterfaceRequest<fuchsia::media::AudioCapturer> request) {
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kDisableAudioInput)) {
|
||||
LOG(WARNING)
|
||||
<< "Could not create AudioCapturer because audio input feature flag "
|
||||
"was not enabled.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (FrameImpl::FromRenderFrameHost(render_frame_host())
|
||||
->permission_controller()
|
||||
->GetPermissionState(content::PermissionType::AUDIO_CAPTURE,
|
||||
|
@ -447,6 +447,15 @@ void ContextProviderImpl::Create(
|
||||
key_system);
|
||||
}
|
||||
|
||||
bool enable_audio = (features & fuchsia::web::ContextFeatureFlags::AUDIO) ==
|
||||
fuchsia::web::ContextFeatureFlags::AUDIO;
|
||||
if (!enable_audio) {
|
||||
// TODO(fxbug.dev/58902): Split up audio input and output in
|
||||
// ContextFeatureFlags.
|
||||
launch_command.AppendSwitch(switches::kDisableAudioOutput);
|
||||
launch_command.AppendSwitch(switches::kDisableAudioInput);
|
||||
}
|
||||
|
||||
zx::channel cdm_data_directory_channel;
|
||||
if (enable_widevine || enable_playready) {
|
||||
DCHECK(params.has_cdm_data_directory());
|
||||
|
@ -6,6 +6,9 @@
|
||||
mediaSource = new MediaSource();
|
||||
audio.src = URL.createObjectURL(mediaSource);
|
||||
|
||||
audio.onended = function() { document.title = 'ended'; }
|
||||
audio.onerror = function() { document.title = 'error'; }
|
||||
|
||||
// Play two files with different sample rate to force mid-stream
|
||||
// re-initialization.
|
||||
var files = ["bear-44.1kHz.webm", "bear-48kHz.webm"];
|
||||
@ -40,7 +43,6 @@
|
||||
}
|
||||
|
||||
audio.play();
|
||||
audio.onended = function() { document.title = 'ended'; }
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -128,14 +128,13 @@ class WebEngineIntegrationTest : public testing::Test {
|
||||
// service.
|
||||
fuchsia::web::CreateContextParams create_params =
|
||||
ContextParamsWithFilteredServiceDirectory();
|
||||
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
|
||||
|
||||
fake_audio_consumer_service_ =
|
||||
std::make_unique<media::FakeAudioConsumerService>(
|
||||
filtered_service_directory_->outgoing_directory()
|
||||
->GetOrCreateDirectory("svc"));
|
||||
|
||||
create_params.set_features(fuchsia::web::ContextFeatureFlags::AUDIO);
|
||||
|
||||
return create_params;
|
||||
}
|
||||
|
||||
@ -526,6 +525,32 @@ TEST_F(WebEngineIntegrationTest, PlayAudio) {
|
||||
EXPECT_FALSE(fake_audio_consumer_service_->instance(0)->is_muted());
|
||||
}
|
||||
|
||||
// Check that audio cannot play when the AUDIO ContextFeatureFlag is not
|
||||
// provided.
|
||||
TEST_F(WebEngineIntegrationTest, PlayAudio_NoFlag) {
|
||||
StartWebEngine();
|
||||
|
||||
// Both FilteredServiceDirectory and test data are needed.
|
||||
fuchsia::web::CreateContextParams create_params =
|
||||
ContextParamsWithFilteredServiceDirectory();
|
||||
create_params.mutable_content_directories()->push_back(
|
||||
CreateTestDataDirectoryProvider());
|
||||
CreateContextAndFrame(std::move(create_params));
|
||||
|
||||
bool is_requested = false;
|
||||
filtered_service_directory_->outgoing_directory()->AddPublicService(
|
||||
std::make_unique<vfs::Service>(
|
||||
[&is_requested](zx::channel channel, async_dispatcher_t* dispatcher) {
|
||||
is_requested = true;
|
||||
}),
|
||||
fuchsia::media::SessionAudioConsumerFactory::Name_);
|
||||
|
||||
LoadUrlWithUserActivation("fuchsia-dir://testdata/play_audio.html");
|
||||
|
||||
navigation_listener_->RunUntilTitleEquals("error");
|
||||
EXPECT_FALSE(is_requested);
|
||||
}
|
||||
|
||||
TEST_F(WebEngineIntegrationTest, PlayVideo) {
|
||||
StartWebEngine();
|
||||
CreateContextAndFrame(ContextParamsWithAudioAndTestData());
|
||||
|
@ -6,7 +6,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "media/audio/fuchsia/audio_output_stream_fuchsia.h"
|
||||
#include "media/base/media_switches.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
@ -31,6 +33,11 @@ bool AudioManagerFuchsia::HasAudioInputDevices() {
|
||||
|
||||
void AudioManagerFuchsia::GetAudioInputDeviceNames(
|
||||
AudioDeviceNames* device_names) {
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kDisableAudioInput)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(crbug.com/852834): Fuchsia currently doesn't provide an API for device
|
||||
// enumeration. Update this method when that functionality is implemented.
|
||||
*device_names = {AudioDeviceName::CreateDefault()};
|
||||
@ -38,6 +45,11 @@ void AudioManagerFuchsia::GetAudioInputDeviceNames(
|
||||
|
||||
void AudioManagerFuchsia::GetAudioOutputDeviceNames(
|
||||
AudioDeviceNames* device_names) {
|
||||
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
||||
switches::kDisableAudioOutput)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO(crbug.com/852834): Fuchsia currently doesn't provide an API for device
|
||||
// enumeration. Update this method when that functionality is implemented.
|
||||
*device_names = {AudioDeviceName::CreateDefault()};
|
||||
|
@ -78,6 +78,7 @@ const char kEnableProtectedVideoBuffers[] = "enable-protected-video-buffers";
|
||||
const char kForceProtectedVideoOutputBuffers[] =
|
||||
"force-protected-video-output-buffers";
|
||||
|
||||
const char kDisableAudioInput[] = "disable-audio-input";
|
||||
#endif // defined(OS_FUCHSIA)
|
||||
|
||||
#if defined(USE_CRAS)
|
||||
|
@ -51,6 +51,7 @@ MEDIA_EXPORT extern const char kWaveOutBuffers[];
|
||||
#if defined(OS_FUCHSIA)
|
||||
MEDIA_EXPORT extern const char kEnableProtectedVideoBuffers[];
|
||||
MEDIA_EXPORT extern const char kForceProtectedVideoOutputBuffers[];
|
||||
MEDIA_EXPORT extern const char kDisableAudioInput[];
|
||||
#endif
|
||||
|
||||
#if defined(OS_CHROMEOS)
|
||||
|
Reference in New Issue
Block a user