Commit 4b081628 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate references to mirroring.mojom.MirroringServiceHost to new mojo types

Convert the remaining bits that still use the old mojo types for
mirroring::mojom::MirroringServiceHost to the new mojo types, and adapt
unit tests.

Bug: 955171
Change-Id: I99bbae16c05ad044daf27e76cea48594677dfe71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807318
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarBrandon Tolsch <btolsch@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697942}
parent ad938f30
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "content/public/browser/video_capture_device_launcher.h" #include "content/public/browser/video_capture_device_launcher.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "services/network/public/mojom/network_service.mojom.h" #include "services/network/public/mojom/network_service.mojom.h"
#include "services/viz/public/mojom/gpu.mojom.h" #include "services/viz/public/mojom/gpu.mojom.h"
#include "ui/display/display.h" #include "ui/display/display.h"
...@@ -122,13 +121,13 @@ base::Optional<gfx::Size> GetScreenResolution() { ...@@ -122,13 +121,13 @@ base::Optional<gfx::Size> GetScreenResolution() {
// static // static
void CastMirroringServiceHost::GetForTab( void CastMirroringServiceHost::GetForTab(
content::WebContents* target_contents, content::WebContents* target_contents,
mojom::MirroringServiceHostRequest request) { mojo::PendingReceiver<mojom::MirroringServiceHost> receiver) {
if (target_contents) { if (target_contents) {
const content::DesktopMediaID media_id = const content::DesktopMediaID media_id =
BuildMediaIdForWebContents(target_contents); BuildMediaIdForWebContents(target_contents);
mojo::MakeStrongBinding( mojo::MakeSelfOwnedReceiver(
std::make_unique<CastMirroringServiceHost>(media_id), std::make_unique<CastMirroringServiceHost>(media_id),
std::move(request)); std::move(receiver));
} }
} }
...@@ -136,7 +135,7 @@ void CastMirroringServiceHost::GetForTab( ...@@ -136,7 +135,7 @@ void CastMirroringServiceHost::GetForTab(
void CastMirroringServiceHost::GetForDesktop( void CastMirroringServiceHost::GetForDesktop(
content::WebContents* initiator_contents, content::WebContents* initiator_contents,
const std::string& desktop_stream_id, const std::string& desktop_stream_id,
mojom::MirroringServiceHostRequest request) { mojo::PendingReceiver<mojom::MirroringServiceHost> receiver) {
DCHECK(!desktop_stream_id.empty()); DCHECK(!desktop_stream_id.empty());
if (initiator_contents) { if (initiator_contents) {
std::string original_extension_name; std::string original_extension_name;
...@@ -147,9 +146,9 @@ void CastMirroringServiceHost::GetForDesktop( ...@@ -147,9 +146,9 @@ void CastMirroringServiceHost::GetForDesktop(
initiator_contents->GetMainFrame()->GetRoutingID(), initiator_contents->GetMainFrame()->GetRoutingID(),
initiator_contents->GetVisibleURL().GetOrigin(), initiator_contents->GetVisibleURL().GetOrigin(),
&original_extension_name, content::kRegistryStreamTypeDesktop); &original_extension_name, content::kRegistryStreamTypeDesktop);
mojo::MakeStrongBinding( mojo::MakeSelfOwnedReceiver(
std::make_unique<CastMirroringServiceHost>(media_id), std::make_unique<CastMirroringServiceHost>(media_id),
std::move(request)); std::move(receiver));
} }
} }
...@@ -158,12 +157,12 @@ void CastMirroringServiceHost::GetForOffscreenTab( ...@@ -158,12 +157,12 @@ void CastMirroringServiceHost::GetForOffscreenTab(
content::BrowserContext* context, content::BrowserContext* context,
const GURL& presentation_url, const GURL& presentation_url,
const std::string& presentation_id, const std::string& presentation_id,
mojom::MirroringServiceHostRequest request) { mojo::PendingReceiver<mojom::MirroringServiceHost> receiver) {
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
auto host = auto host =
std::make_unique<CastMirroringServiceHost>(content::DesktopMediaID()); std::make_unique<CastMirroringServiceHost>(content::DesktopMediaID());
host->OpenOffscreenTab(context, presentation_url, presentation_id); host->OpenOffscreenTab(context, presentation_url, presentation_id);
mojo::MakeStrongBinding(std::move(host), std::move(request)); mojo::MakeSelfOwnedReceiver(std::move(host), std::move(receiver));
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "extensions/buildflags/buildflags.h" #include "extensions/buildflags/buildflags.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -49,17 +50,20 @@ class CastMirroringServiceHost final : public mojom::MirroringServiceHost, ...@@ -49,17 +50,20 @@ class CastMirroringServiceHost final : public mojom::MirroringServiceHost,
#endif // BUILDFLAG(ENABLE_EXTENSIONS) #endif // BUILDFLAG(ENABLE_EXTENSIONS)
public content::WebContentsObserver { public content::WebContentsObserver {
public: public:
static void GetForTab(content::WebContents* target_contents, static void GetForTab(
mojom::MirroringServiceHostRequest request); content::WebContents* target_contents,
mojo::PendingReceiver<mojom::MirroringServiceHost> receiver);
static void GetForDesktop(content::WebContents* initiator_contents,
const std::string& desktop_stream_id, static void GetForDesktop(
mojom::MirroringServiceHostRequest request); content::WebContents* initiator_contents,
const std::string& desktop_stream_id,
static void GetForOffscreenTab(content::BrowserContext* context, mojo::PendingReceiver<mojom::MirroringServiceHost> receiver);
const GURL& presentation_url,
const std::string& presentation_id, static void GetForOffscreenTab(
mojom::MirroringServiceHostRequest request); content::BrowserContext* context,
const GURL& presentation_url,
const std::string& presentation_id,
mojo::PendingReceiver<mojom::MirroringServiceHost> receiver);
// |source_media_id| indicates the mirroring source. // |source_media_id| indicates the mirroring source.
explicit CastMirroringServiceHost(content::DesktopMediaID source_media_id); explicit CastMirroringServiceHost(content::DesktopMediaID source_media_id);
......
...@@ -935,36 +935,36 @@ void MediaRouterMojoImpl::GetMediaSinkServiceStatus( ...@@ -935,36 +935,36 @@ void MediaRouterMojoImpl::GetMediaSinkServiceStatus(
void MediaRouterMojoImpl::GetMirroringServiceHostForTab( void MediaRouterMojoImpl::GetMirroringServiceHostForTab(
int32_t target_tab_id, int32_t target_tab_id,
mirroring::mojom::MirroringServiceHostRequest request) { mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost> receiver) {
if (ShouldUseMirroringService()) { if (ShouldUseMirroringService()) {
mirroring::CastMirroringServiceHost::GetForTab( mirroring::CastMirroringServiceHost::GetForTab(
GetWebContentsFromId(target_tab_id, context_, GetWebContentsFromId(target_tab_id, context_,
true /* include_incognito */), true /* include_incognito */),
std::move(request)); std::move(receiver));
} }
} }
void MediaRouterMojoImpl::GetMirroringServiceHostForDesktop( void MediaRouterMojoImpl::GetMirroringServiceHostForDesktop(
int32_t initiator_tab_id, int32_t initiator_tab_id,
const std::string& desktop_stream_id, const std::string& desktop_stream_id,
mirroring::mojom::MirroringServiceHostRequest request) { mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost> receiver) {
if (ShouldUseMirroringService()) { if (ShouldUseMirroringService()) {
// TODO(crbug.com/974335): Remove this code once we fully launch the native // TODO(crbug.com/974335): Remove this code once we fully launch the native
// Cast Media Route Provider. // Cast Media Route Provider.
mirroring::CastMirroringServiceHost::GetForDesktop( mirroring::CastMirroringServiceHost::GetForDesktop(
EventPageRequestManagerFactory::GetApiForBrowserContext(context_) EventPageRequestManagerFactory::GetApiForBrowserContext(context_)
->GetEventPageWebContents(), ->GetEventPageWebContents(),
desktop_stream_id, std::move(request)); desktop_stream_id, std::move(receiver));
} }
} }
void MediaRouterMojoImpl::GetMirroringServiceHostForOffscreenTab( void MediaRouterMojoImpl::GetMirroringServiceHostForOffscreenTab(
const GURL& presentation_url, const GURL& presentation_url,
const std::string& presentation_id, const std::string& presentation_id,
mirroring::mojom::MirroringServiceHostRequest request) { mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost> receiver) {
if (ShouldUseMirroringService() && IsValidPresentationUrl(presentation_url)) { if (ShouldUseMirroringService() && IsValidPresentationUrl(presentation_url)) {
mirroring::CastMirroringServiceHost::GetForOffscreenTab( mirroring::CastMirroringServiceHost::GetForOffscreenTab(
context_, presentation_url, presentation_id, std::move(request)); context_, presentation_url, presentation_id, std::move(receiver));
} }
} }
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
#include "chrome/common/media_router/mojom/media_router.mojom.h" #include "chrome/common/media_router/mojom/media_router.mojom.h"
#include "chrome/common/media_router/route_request_result.h" #include "chrome/common/media_router/route_request_result.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/public/mojom/presentation/presentation.mojom.h" #include "third_party/blink/public/mojom/presentation/presentation.mojom.h"
namespace content { namespace content {
...@@ -345,15 +345,18 @@ class MediaRouterMojoImpl : public MediaRouterBase, public mojom::MediaRouter { ...@@ -345,15 +345,18 @@ class MediaRouterMojoImpl : public MediaRouterBase, public mojom::MediaRouter {
mojom::MediaRouter::GetMediaSinkServiceStatusCallback callback) override; mojom::MediaRouter::GetMediaSinkServiceStatusCallback callback) override;
void GetMirroringServiceHostForTab( void GetMirroringServiceHostForTab(
int32_t target_tab_id, int32_t target_tab_id,
mirroring::mojom::MirroringServiceHostRequest request) override; mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost> receiver)
override;
void GetMirroringServiceHostForDesktop( void GetMirroringServiceHostForDesktop(
int32_t initiator_tab_id, int32_t initiator_tab_id,
const std::string& desktop_stream_id, const std::string& desktop_stream_id,
mirroring::mojom::MirroringServiceHostRequest request) override; mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost> receiver)
override;
void GetMirroringServiceHostForOffscreenTab( void GetMirroringServiceHostForOffscreenTab(
const GURL& presentation_url, const GURL& presentation_url,
const std::string& presentation_id, const std::string& presentation_id,
mirroring::mojom::MirroringServiceHostRequest request) override; mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost> receiver)
override;
// Result callback when Mojo TerminateRoute is invoked. // Result callback when Mojo TerminateRoute is invoked.
// |route_id|: ID of MediaRoute passed to the TerminateRoute request. // |route_id|: ID of MediaRoute passed to the TerminateRoute request.
......
...@@ -68,8 +68,8 @@ MirroringActivityRecord::MirroringActivityRecord( ...@@ -68,8 +68,8 @@ MirroringActivityRecord::MirroringActivityRecord(
mirroring_tab_id_ = target_tab_id; mirroring_tab_id_ = target_tab_id;
// Get a reference to the mirroring service host. // Get a reference to the mirroring service host.
media_router->GetMirroringServiceHostForTab(target_tab_id, media_router->GetMirroringServiceHostForTab(
mojo::MakeRequest(&host_)); target_tab_id, host_.BindNewPipeAndPassReceiver());
// Create Mojo bindings for the interfaces this object implements. // Create Mojo bindings for the interfaces this object implements.
SessionObserverPtr observer_ptr; SessionObserverPtr observer_ptr;
......
...@@ -90,7 +90,7 @@ class MirroringActivityRecord : public ActivityRecord, ...@@ -90,7 +90,7 @@ class MirroringActivityRecord : public ActivityRecord,
void StopMirroring(); void StopMirroring();
mirroring::mojom::MirroringServiceHostPtr host_; mojo::Remote<mirroring::mojom::MirroringServiceHost> host_;
// Sends Cast messages from the mirroring receiver to the mirroring service. // Sends Cast messages from the mirroring receiver to the mirroring service.
mirroring::mojom::CastMessageChannelPtr channel_to_service_; mirroring::mojom::CastMessageChannelPtr channel_to_service_;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "chrome/browser/media/router/test/mock_media_router.h" #include "chrome/browser/media/router/test/mock_media_router.h"
#include "chrome/common/media_router/media_route_provider_helper.h" #include "chrome/common/media_router/media_route_provider_helper.h"
#include "chrome/common/media_router/mojom/media_router.mojom.h" #include "chrome/common/media_router/mojom/media_router.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace media_router { namespace media_router {
...@@ -75,17 +76,23 @@ class MockMojoMediaRouter : public MockMediaRouter, public mojom::MediaRouter { ...@@ -75,17 +76,23 @@ class MockMojoMediaRouter : public MockMediaRouter, public mojom::MediaRouter {
GetMediaSinkServiceStatusInternal, GetMediaSinkServiceStatusInternal,
void(mojom::MediaRouter::GetMediaSinkServiceStatusCallback& callback)); void(mojom::MediaRouter::GetMediaSinkServiceStatusCallback& callback));
MOCK_METHOD0(GetMediaSinkServiceStatus, std::string()); MOCK_METHOD0(GetMediaSinkServiceStatus, std::string());
MOCK_METHOD2(GetMirroringServiceHostForTab, MOCK_METHOD2(
void(int32_t target_tab_id, GetMirroringServiceHostForTab,
mirroring::mojom::MirroringServiceHostRequest request)); void(int32_t target_tab_id,
MOCK_METHOD3(GetMirroringServiceHostForDesktop, mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost>
void(int32_t initiator_tab_id, receiver));
const std::string& desktop_stream_id, MOCK_METHOD3(
mirroring::mojom::MirroringServiceHostRequest request)); GetMirroringServiceHostForDesktop,
MOCK_METHOD3(GetMirroringServiceHostForOffscreenTab, void(int32_t initiator_tab_id,
void(const GURL& presentation_url, const std::string& desktop_stream_id,
const std::string& presentation_id, mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost>
mirroring::mojom::MirroringServiceHostRequest request)); receiver));
MOCK_METHOD3(
GetMirroringServiceHostForOffscreenTab,
void(const GURL& presentation_url,
const std::string& presentation_id,
mojo::PendingReceiver<mirroring::mojom::MirroringServiceHost>
receiver));
}; };
} // namespace media_router } // namespace media_router
......
...@@ -584,13 +584,13 @@ interface MediaRouter { ...@@ -584,13 +584,13 @@ interface MediaRouter {
// TODO(http://crbug.com/809249): Remove these APIs when native Cast MRP with // TODO(http://crbug.com/809249): Remove these APIs when native Cast MRP with
// mirroring support is rolled out. // mirroring support is rolled out.
GetMirroringServiceHostForTab(int32 target_tab_id, GetMirroringServiceHostForTab(int32 target_tab_id,
mirroring.mojom.MirroringServiceHost& request); pending_receiver<mirroring.mojom.MirroringServiceHost> receiver);
GetMirroringServiceHostForDesktop( GetMirroringServiceHostForDesktop(
int32 initiator_tab_id, // The tab used to register the stream. int32 initiator_tab_id, // The tab used to register the stream.
string desktop_stream_id, string desktop_stream_id,
mirroring.mojom.MirroringServiceHost& request); pending_receiver<mirroring.mojom.MirroringServiceHost> receiver);
GetMirroringServiceHostForOffscreenTab( GetMirroringServiceHostForOffscreenTab(
url.mojom.Url presentation_url, url.mojom.Url presentation_url,
string presentation_id, string presentation_id,
mirroring.mojom.MirroringServiceHost& request); pending_receiver<mirroring.mojom.MirroringServiceHost> receiver);
}; };
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