Skip to content

Commit

Permalink
Mirroring service: Observe the target WebContents for tab mirroring.
Browse files Browse the repository at this point in the history
Observe the target WebContents for Tab/OffscreenTab mirroring.

Bug: 734672
Change-Id: I65194a345f81b38967396c80e5f614d4119782e4
Reviewed-on: https://chromium-review.googlesource.com/1176110
Reviewed-by: Yuri Wiitala <[email protected]>
Commit-Queue: Xiangjun Zhang <[email protected]>
Cr-Commit-Position: refs/heads/master@{#586097}
  • Loading branch information
Xiangjun Zhang authored and Commit Bot committed Aug 25, 2018
1 parent 9a4042a commit 8183538
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions chrome/browser/media/cast_mirroring_service_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -199,13 +199,17 @@ 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));
}
}
}

void CastMirroringServiceHost::WebContentsDestroyed() {
// TODO(xjz): Stop the mirroring if connected to the MirroringService.
// Implementation will be added in a later CL.
}

} // namespace mirroring
7 changes: 6 additions & 1 deletion chrome/browser/media/cast_mirroring_service_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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_;

Expand Down

0 comments on commit 8183538

Please sign in to comment.