Commit 2e2cf73e authored by Noah Rose Ledesma's avatar Noah Rose Ledesma Committed by Commit Bot

GMC: Allow recipient of OnAudioOutputSinkChanged IPC to translate device id

In order for the global media controls dialog to display the currently
used audio device in the UI the renderer needs to report what device is
in use. Currently, MediaWebContentsObserver will receive messages when
the output device is switched. However, the device id reported by the
renderer is hashed so that it may be only used on one origin.

This change has the MediaWebContentsObserver translate the device ID
before passing it off to the MediaSessionControllersManager.

Bug: 1111432
Change-Id: I11d161ff5f89525b4c465f01a779bdd30e31c823
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2331330
Commit-Queue: Noah Rose Ledesma <noahrose@google.com>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795175}
parent 54fca90d
...@@ -7,9 +7,13 @@ ...@@ -7,9 +7,13 @@
#include <memory> #include <memory>
#include <tuple> #include <tuple>
#include "base/bind.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/media/audible_metrics.h" #include "content/browser/media/audible_metrics.h"
#include "content/browser/media/audio_stream_monitor.h" #include "content/browser/media/audio_stream_monitor.h"
#include "content/browser/media/media_devices_util.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/media/media_player_delegate_messages.h" #include "content/common/media/media_player_delegate_messages.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
...@@ -18,6 +22,7 @@ ...@@ -18,6 +22,7 @@
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "services/device/public/mojom/wake_lock_context.mojom.h" #include "services/device/public/mojom/wake_lock_context.mojom.h"
#include "services/media_session/public/cpp/media_position.h" #include "services/media_session/public/cpp/media_position.h"
#include "third_party/blink/public/common/mediastream/media_devices.h"
#include "third_party/blink/public/platform/web_fullscreen_video_status.h" #include "third_party/blink/public/platform/web_fullscreen_video_status.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -381,10 +386,49 @@ void MediaWebContentsObserver::OnAudioOutputSinkChanged( ...@@ -381,10 +386,49 @@ void MediaWebContentsObserver::OnAudioOutputSinkChanged(
RenderFrameHost* render_frame_host, RenderFrameHost* render_frame_host,
int delegate_id, int delegate_id,
std::string hashed_device_id) { std::string hashed_device_id) {
// TODO(1111432): Translate |hashed_device_id| into a raw device id before auto salt_and_origin = content::GetMediaDeviceSaltAndOrigin(
// passing to controllers manager. render_frame_host->GetProcess()->GetID(),
session_controllers_manager_.OnAudioOutputSinkChanged( render_frame_host->GetRoutingID());
MediaPlayerId(render_frame_host, delegate_id), hashed_device_id);
auto callback_on_io_thread = base::BindOnce(
[](const std::string& salt, const url::Origin& origin,
const std::string& hashed_device_id,
base::OnceCallback<void(const base::Optional<std::string>&)>
callback) {
MediaStreamManager::GetMediaDeviceIDForHMAC(
blink::MediaDeviceType::MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, salt,
std::move(origin), hashed_device_id,
base::SequencedTaskRunnerHandle::Get(), std::move(callback));
},
salt_and_origin.device_id_salt, std::move(salt_and_origin.origin),
hashed_device_id,
base::BindOnce(&MediaWebContentsObserver::OnAudioOutputDeviceIdTranslated,
weak_ptr_factory_.GetWeakPtr(), render_frame_host,
delegate_id));
content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, std::move(callback_on_io_thread));
}
void MediaWebContentsObserver::OnAudioOutputDeviceIdTranslated(
RenderFrameHost* render_frame_host,
int delegate_id,
const base::Optional<std::string>& raw_device_id) {
if (!raw_device_id.has_value())
return;
auto callback_on_ui_thread = base::BindOnce(
[](MediaSessionControllersManager* controllers_manager,
RenderFrameHost* render_frame_host, int delegate_id,
const std::string& raw_device_id) {
controllers_manager->OnAudioOutputSinkChanged(
MediaPlayerId(render_frame_host, delegate_id), raw_device_id);
},
session_controllers_manager(), render_frame_host, delegate_id,
raw_device_id.value());
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, std::move(callback_on_ui_thread));
} }
void MediaWebContentsObserver::OnBufferUnderflow( void MediaWebContentsObserver::OnBufferUnderflow(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/media/media_power_experiment_manager.h" #include "content/browser/media/media_power_experiment_manager.h"
...@@ -151,6 +152,10 @@ class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver { ...@@ -151,6 +152,10 @@ class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver {
void OnAudioOutputSinkChanged(RenderFrameHost* render_frame_host, void OnAudioOutputSinkChanged(RenderFrameHost* render_frame_host,
int delegate_id, int delegate_id,
std::string hashed_device_id); std::string hashed_device_id);
void OnAudioOutputDeviceIdTranslated(
RenderFrameHost* render_frame_host,
int delegate_id,
const base::Optional<std::string>& raw_device_id);
void OnBufferUnderflow(RenderFrameHost* render_frame_host, int delegate_id); void OnBufferUnderflow(RenderFrameHost* render_frame_host, int delegate_id);
device::mojom::WakeLock* GetAudioWakeLock(); device::mojom::WakeLock* GetAudioWakeLock();
...@@ -190,6 +195,7 @@ class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver { ...@@ -190,6 +195,7 @@ class CONTENT_EXPORT MediaWebContentsObserver : public WebContentsObserver {
std::unique_ptr<base::WeakPtrFactory<MediaWebContentsObserver>>> std::unique_ptr<base::WeakPtrFactory<MediaWebContentsObserver>>>
per_frame_factory_; per_frame_factory_;
base::WeakPtrFactory<MediaWebContentsObserver> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver); DISALLOW_COPY_AND_ASSIGN(MediaWebContentsObserver);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment