Commit 23a91b2d authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate references of blink::mojom::PresentationReceiver to new Mojo types

Convert both the implementation and clients in the browser and renderer
processes for the blink.mojom.PresentationReceiver interface, and
adapt unit tests.

Bug: 955171, 978694
Change-Id: I5b3db354a14cca90841a71df8e67cc778c53a1df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764188
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690364}
parent 2ae29e5a
......@@ -139,7 +139,8 @@ void PresentationServiceImpl::SetController(
}
void PresentationServiceImpl::SetReceiver(
blink::mojom::PresentationReceiverPtr receiver) {
mojo::PendingRemote<blink::mojom::PresentationReceiver>
presentation_receiver_remote) {
// Presentation receiver virtual web tests (which have the flag set) has no
// ReceiverPresentationServiceDelegate implementation.
// TODO(imcheng): Refactor content_browser_client to return a no-op
......@@ -156,13 +157,13 @@ void PresentationServiceImpl::SetReceiver(
return;
}
if (receiver_) {
if (presentation_receiver_remote_) {
mojo::ReportBadMessage("SetReceiver can only be called once.");
return;
}
receiver_ = std::move(receiver);
receiver_.set_connection_error_handler(base::BindOnce(
presentation_receiver_remote_.Bind(std::move(presentation_receiver_remote));
presentation_receiver_remote_.set_disconnect_handler(base::BindOnce(
&PresentationServiceImpl::OnConnectionError, base::Unretained(this)));
receiver_delegate_->RegisterReceiverConnectionAvailableCallback(
base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
......@@ -442,7 +443,7 @@ void PresentationServiceImpl::OnReceiverConnectionAvailable(
receiver_connection_receiver) {
DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
receiver_->OnReceiverConnectionAvailable(
presentation_receiver_remote_->OnReceiverConnectionAvailable(
std::move(presentation_info), std::move(controller_connection_remote),
std::move(receiver_connection_receiver));
}
......@@ -485,7 +486,7 @@ void PresentationServiceImpl::Reset() {
binding_.Close();
presentation_controller_remote_.reset();
receiver_.reset();
presentation_receiver_remote_.reset();
}
void PresentationServiceImpl::OnDelegateDestroyed() {
......
......@@ -73,7 +73,8 @@ class CONTENT_EXPORT PresentationServiceImpl
const std::vector<GURL>& presentation_urls) override;
void SetController(mojo::PendingRemote<blink::mojom::PresentationController>
presentation_controller_remote) override;
void SetReceiver(blink::mojom::PresentationReceiverPtr receiver) override;
void SetReceiver(mojo::PendingRemote<blink::mojom::PresentationReceiver>
presentation_receiver_remote) override;
void ListenForScreenAvailability(const GURL& url) override;
void StopListeningForScreenAvailability(const GURL& url) override;
void StartPresentation(const std::vector<GURL>& presentation_urls,
......@@ -257,7 +258,8 @@ class CONTENT_EXPORT PresentationServiceImpl
presentation_controller_remote_;
// Pointer to the PresentationReceiver implementation in the renderer.
blink::mojom::PresentationReceiverPtr receiver_;
mojo::Remote<blink::mojom::PresentationReceiver>
presentation_receiver_remote_;
std::vector<GURL> default_presentation_urls_;
......
......@@ -24,7 +24,6 @@
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
......@@ -164,7 +163,7 @@ class MockPresentationReceiver : public blink::mojom::PresentationReceiver {
void(PresentationInfoPtr info,
mojo::PendingRemote<PresentationConnection> controller_connection,
mojo::PendingReceiver<PresentationConnection>
receiver_connection_receiver));
presentation_receiver_receiver));
};
class MockReceiverPresentationServiceDelegate
......@@ -413,12 +412,13 @@ TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrls) {
});
EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _));
mojo::PendingRemote<PresentationConnection> receiver_remote;
mojo::PendingRemote<PresentationConnection> presentation_connection_remote;
mojo::Remote<PresentationConnection> controller_remote;
ignore_result(receiver_remote.InitWithNewPipeAndPassReceiver());
ignore_result(
presentation_connection_remote.InitWithNewPipeAndPassReceiver());
std::move(callback).Run(PresentationConnectionResult::New(
blink::mojom::PresentationInfo::New(presentation_url2_, kPresentationId),
std::move(receiver_remote),
std::move(presentation_connection_remote),
controller_remote.BindNewPipeAndPassReceiver()));
base::RunLoop().RunUntilIdle();
}
......@@ -617,11 +617,10 @@ TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) {
.WillOnce(SaveArg<0>(&callback));
MockPresentationReceiver mock_receiver;
blink::mojom::PresentationReceiverPtr receiver_ptr;
mojo::Binding<blink::mojom::PresentationReceiver> receiver_binding(
&mock_receiver, mojo::MakeRequest(&receiver_ptr));
service_impl.controller_delegate_ = nullptr;
service_impl.SetReceiver(std::move(receiver_ptr));
mojo::Receiver<blink::mojom::PresentationReceiver>
presentation_receiver_receiver(&mock_receiver);
service_impl.SetReceiver(
presentation_receiver_receiver.BindNewPipeAndPassRemote());
EXPECT_FALSE(callback.is_null());
PresentationInfo expected(presentation_url1_, kPresentationId);
......
......@@ -113,7 +113,7 @@ interface PresentationService {
// connections (initiated by a controller) becoming available.
// TODO(crbug.com/749327): Move this method out of PresentationService and
// define a new interface that implements only Presentation Receiver APIs.
SetReceiver(PresentationReceiver receiver);
SetReceiver(pending_remote<PresentationReceiver> receiver);
///////////// Functions here are for the controller part of the API. /////////
......
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_MOCK_PRESENTATION_SERVICE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_MOCK_PRESENTATION_SERVICE_H_
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/mojom/presentation/presentation.mojom-blink.h"
......@@ -14,7 +15,8 @@ class MockPresentationService : public mojom::blink::PresentationService {
public:
void SetController(
mojo::PendingRemote<mojom::blink::PresentationController>) override {}
void SetReceiver(mojom::blink::PresentationReceiverPtr) override {}
void SetReceiver(
mojo::PendingRemote<mojom::blink::PresentationReceiver>) override {}
MOCK_METHOD1(SetDefaultPresentationUrls, void(const Vector<KURL>&));
MOCK_METHOD1(ListenForScreenAvailability, void(const KURL&));
MOCK_METHOD1(StopListeningForScreenAvailability, void(const KURL&));
......
......@@ -26,17 +26,14 @@ namespace blink {
PresentationReceiver::PresentationReceiver(LocalFrame* frame)
: ContextLifecycleObserver(frame->GetDocument()),
connection_list_(MakeGarbageCollected<PresentationConnectionList>(
frame->GetDocument())),
receiver_binding_(this) {
frame->GetDocument())) {
auto* interface_provider = GetFrame()->Client()->GetInterfaceProvider();
interface_provider->GetInterface(mojo::MakeRequest(&presentation_service_));
mojom::blink::PresentationReceiverPtr receiver_ptr;
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
frame->GetTaskRunner(TaskType::kPresentation);
receiver_binding_.Bind(mojo::MakeRequest(&receiver_ptr, task_runner),
task_runner);
presentation_service_->SetReceiver(std::move(receiver_ptr));
presentation_service_->SetReceiver(
presentation_receiver_receiver_.BindNewPipeAndPassRemote(task_runner));
}
// static
......@@ -128,7 +125,7 @@ void PresentationReceiver::RecordOriginTypeAccess(
}
void PresentationReceiver::ContextDestroyed(ExecutionContext*) {
receiver_binding_.Close();
presentation_receiver_receiver_.reset();
presentation_service_.reset();
}
......
......@@ -5,9 +5,9 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_PRESENTATION_RECEIVER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_PRESENTATION_PRESENTATION_RECEIVER_H_
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "third_party/blink/public/mojom/presentation/presentation.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_property.h"
......@@ -71,7 +71,8 @@ class MODULES_EXPORT PresentationReceiver final
Member<ConnectionListProperty> connection_list_property_;
Member<PresentationConnectionList> connection_list_;
mojo::Binding<mojom::blink::PresentationReceiver> receiver_binding_;
mojo::Receiver<mojom::blink::PresentationReceiver>
presentation_receiver_receiver_{this};
mojom::blink::PresentationServicePtr presentation_service_;
};
......
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