Commit ef3e7f97 authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

[Native Cast MRP] Presentation connection for site-initiated mirroring

This fixes a regression relative to the extension MRP where we were
establishing a presentation connection only if a client ID is set.
If mirroring is initiated by a site with cast:0F5096E8 there is no
client ID but we still need a presentation connection.

Bug: 1114891, b/163366468
Change-Id: Ib66768c52851bb87aba307775d917b81bf669572
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347890
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796940}
parent 8e045915
......@@ -193,7 +193,7 @@ void CastActivityManager::DoLaunchSession(DoLaunchSessionParams params) {
? AddMirroringActivity(route, app_id, tab_id, sink.cast_data())
: AddAppActivity(route, app_id);
const std::string& client_id = cast_source.client_id();
if (!client_id.empty()) {
if (MediaSource(cast_source.source_id()).IsCastPresentationUrl()) {
presentation_connection =
activity_ptr->AddClient(cast_source, params.origin, tab_id);
activity_ptr->SendMessageToClient(
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/media/router/test/mock_logger.h"
#include "chrome/browser/media/router/test/mock_mojo_media_router.h"
#include "chrome/browser/media/router/test/test_helper.h"
#include "chrome/common/media_router/media_source.h"
#include "chrome/common/media_router/test/test_helper.h"
#include "components/cast_channel/cast_test_util.h"
#include "content/public/browser/browser_task_traits.h"
......@@ -56,6 +57,7 @@ namespace media_router {
namespace {
constexpr int kChannelId = 42;
constexpr int kChannelId2 = 43;
constexpr char kClientId[] = "theClientId";
constexpr char kOrigin[] = "https://google.com";
constexpr int kTabId = 1;
constexpr int kTabId2 = 2;
......@@ -76,9 +78,10 @@ constexpr char kPresentationId[] = "presentationId";
constexpr char kPresentationId2[] = "presentationId2";
std::string MakeSourceId(const std::string& app_id = kAppId1,
const std::string& app_params = "") {
const std::string& app_params = "",
const std::string& client_id = kClientId) {
return base::StrCat(
{"cast:", app_id, "?clientId=theClientId&appParams=", app_params});
{"cast:", app_id, "?clientId=", client_id, "&appParams=", app_params});
}
base::Value MakeReceiverStatus(const std::string& app_id,
......@@ -207,6 +210,7 @@ class CastActivityManagerTest : public testing::Test,
media_router::RouteRequestResult::ResultCode) {
ASSERT_TRUE(route);
route_ = std::make_unique<MediaRoute>(*route);
presentation_connections_ = std::move(presentation_connections);
}
void ExpectLaunchSessionFailure(
......@@ -219,7 +223,8 @@ class CastActivityManagerTest : public testing::Test,
}
void CallLaunchSession(const std::string& app_id = kAppId1,
const std::string& app_params = "") {
const std::string& app_params = "",
const std::string& client_id = kClientId) {
// MediaRouter is notified of new route.
ExpectSingleRouteUpdate();
......@@ -234,8 +239,8 @@ class CastActivityManagerTest : public testing::Test,
launch_session_callback_ = std::move(callback);
}));
auto source =
CastMediaSource::FromMediaSourceId(MakeSourceId(app_id, app_params));
auto source = CastMediaSource::FromMediaSourceId(
MakeSourceId(app_id, app_params, client_id));
ASSERT_TRUE(source);
cast_activity_callback_ =
......@@ -403,6 +408,7 @@ class CastActivityManagerTest : public testing::Test,
base::Optional<MediaRoute> updated_route_;
cast_channel::ResultCallback stop_session_callback_;
MockLogger logger_;
mojom::RoutePresentationConnectionPtr presentation_connections_;
};
TEST_F(CastActivityManagerTest, LaunchCastAppSession) {
......@@ -420,6 +426,14 @@ TEST_F(CastActivityManagerTest, LaunchMirroringSession) {
EXPECT_EQ(RouteControllerType::kMirroring, route_->controller_type());
}
TEST_F(CastActivityManagerTest, LaunchSiteInitiatedMirroringSession) {
// For a session initiated by a website with the mirroring source we should be
// establishing a presentation connection, even if the client ID isn't set.
CallLaunchSession(kCastStreamingAppId, /*app_params*/ "", /*client_id*/ "");
EXPECT_FALSE(presentation_connections_.is_null());
EXPECT_EQ(RouteControllerType::kMirroring, route_->controller_type());
}
TEST_F(CastActivityManagerTest, MirroringSessionStopped) {
CallLaunchSession(kCastStreamingAppId);
auto response = GetSuccessLaunchResponse();
......
......@@ -209,6 +209,16 @@ void MirroringActivity::Send(mirroring::mojom::CastMessagePtr message) {
weak_ptr_factory_.GetWeakPtr(), route().media_route_id()));
}
void MirroringActivity::SendMessageToClient(
const std::string& client_id,
blink::mojom::PresentationConnectionMessagePtr message) {
// A client exists if this is a site-initiated mirroring session. Given client
// ID is a Cast SDK concept, the client may not have an ID if it joined by
// directly using the Presentation API, and we wouldn't be able to distinguish
// them. We also do not expect the mirroring receiver to send any messages, so
// we drop them.
}
void MirroringActivity::OnAppMessage(
const cast::channel::CastMessage& message) {
if (!route_.is_local())
......
......@@ -62,6 +62,9 @@ class MirroringActivity : public CastActivity,
void Send(mirroring::mojom::CastMessagePtr message) override;
// CastActivity implementation
void SendMessageToClient(
const std::string& client_id,
blink::mojom::PresentationConnectionMessagePtr message) override;
void OnAppMessage(const cast::channel::CastMessage& message) override;
void OnInternalMessage(const cast_channel::InternalMessage& message) override;
......
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