Commit 81835381 authored by Xiangjun Zhang's avatar Xiangjun Zhang Committed by Commit Bot

Mirroring service: Observe the target WebContents for tab mirroring.

Observe the target WebContents for Tab/OffscreenTab mirroring.

Bug: 734672
Change-Id: I65194a345f81b38967396c80e5f614d4119782e4
Reviewed-on: https://chromium-review.googlesource.com/1176110Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Commit-Queue: Xiangjun Zhang <xjz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586097}
parent 9a4042ac
......@@ -124,6 +124,9 @@ CastMirroringServiceHost::CastMirroringServiceHost(
content::DesktopMediaID source_media_id)
: source_media_id_(source_media_id) {
DCHECK(source_media_id_.type != content::DesktopMediaID::TYPE_NONE);
// Observe the target WebContents for Tab/OffscreenTab mirroring.
if (source_media_id_.type == content::DesktopMediaID::TYPE_WEB_CONTENTS)
Observe(GetContents(source_media_id_.web_contents_id));
}
CastMirroringServiceHost::~CastMirroringServiceHost() {
......@@ -165,10 +168,7 @@ void CastMirroringServiceHost::CreateAudioStream(
uint32_t total_segments) {
content::WebContents* source_web_contents = nullptr;
if (source_media_id_.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) {
source_web_contents = content::WebContents::FromRenderFrameHost(
content::RenderFrameHost::FromID(
source_media_id_.web_contents_id.render_process_id,
source_media_id_.web_contents_id.main_render_frame_id));
source_web_contents = web_contents();
if (!source_web_contents) {
VLOG(1) << "Failed to create audio stream: Invalid source.";
return;
......@@ -199,8 +199,7 @@ void CastMirroringServiceHost::ConnectToRemotingSource(
media::mojom::RemoterPtr remoter,
media::mojom::RemotingSourceRequest request) {
if (source_media_id_.type == content::DesktopMediaID::TYPE_WEB_CONTENTS) {
content::WebContents* source_contents =
GetContents(source_media_id_.web_contents_id);
content::WebContents* const source_contents = web_contents();
if (source_contents) {
CastRemotingConnector::Get(source_contents)
->ConnectWithMediaRemoter(std::move(remoter), std::move(request));
......@@ -208,4 +207,9 @@ void CastMirroringServiceHost::ConnectToRemotingSource(
}
}
void CastMirroringServiceHost::WebContentsDestroyed() {
// TODO(xjz): Stop the mirroring if connected to the MirroringService.
// Implementation will be added in a later CL.
}
} // namespace mirroring
......@@ -9,6 +9,7 @@
#include "components/mirroring/mojom/mirroring_service_host.mojom.h"
#include "components/mirroring/mojom/resource_provider.mojom.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/web_contents_observer.h"
namespace content {
class AudioLoopbackStreamCreator;
......@@ -22,7 +23,8 @@ namespace mirroring {
//
// TODO(xjz): Adds the implementation to connect to Mirroring Service.
class CastMirroringServiceHost final : public mojom::MirroringServiceHost,
public mojom::ResourceProvider {
public mojom::ResourceProvider,
public content::WebContentsObserver {
public:
static void GetForTab(content::WebContents* target_contents,
mojom::MirroringServiceHostRequest request);
......@@ -57,6 +59,9 @@ class CastMirroringServiceHost final : public mojom::MirroringServiceHost,
media::mojom::RemoterPtr remoter,
media::mojom::RemotingSourceRequest request) override;
// content::WebContentsObserver implementation.
void WebContentsDestroyed() override;
// Describes the media source for this mirroring session.
const content::DesktopMediaID source_media_id_;
......
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