Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1455)

Unified Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: merge with master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/presentation/presentation_dispatcher.cc
diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc
index 325cac65c7892474fdff2f974d21d4bd3557c4bf..9e97d881b32428132346911b7936884c63a8e9dd 100644
--- a/content/renderer/presentation/presentation_dispatcher.cc
+++ b/content/renderer/presentation/presentation_dispatcher.cc
@@ -13,6 +13,7 @@
#include "content/public/common/presentation_constants.h"
#include "content/public/renderer/render_frame.h"
#include "content/renderer/presentation/presentation_connection_client.h"
+#include "content/renderer/presentation/presentation_connection_proxy.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebURL.h"
@@ -75,6 +76,26 @@ GetWebPresentationConnectionCloseReasonFromMojo(
}
}
+blink::mojom::SessionMessagePtr ToMojoTextMessage(
+ const blink::WebString& message) {
+ blink::mojom::SessionMessagePtr session_message =
+ blink::mojom::SessionMessage::New();
+ session_message->type = blink::mojom::PresentationMessageType::TEXT;
+ session_message->message = message.utf8();
+ return session_message;
+}
+
+blink::mojom::SessionMessagePtr ToMojoBinaryMessage(
+ blink::mojom::PresentationMessageType type,
+ const uint8_t* data,
+ size_t length) {
+ blink::mojom::SessionMessagePtr session_message =
+ blink::mojom::SessionMessage::New();
+ session_message->type = type;
+ session_message->data = std::vector<uint8_t>(data, data + length);
+ return session_message;
+}
+
} // namespace
namespace content {
@@ -82,8 +103,8 @@ namespace content {
PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
: RenderFrameObserver(render_frame),
controller_(nullptr),
- binding_(this) {
-}
+ receiver_(nullptr),
+ binding_(this) {}
PresentationDispatcher::~PresentationDispatcher() {
// Controller should be destroyed before the dispatcher when frame is
@@ -376,11 +397,15 @@ void PresentationDispatcher::OnDefaultSessionStarted(
if (!controller_)
return;
- if (!session_info.is_null()) {
+ if (session_info.is_null())
+ return;
+
+ if (!session_info->is_offscreen)
presentation_service_->ListenForSessionMessages(session_info.Clone());
- controller_->didStartDefaultSession(
- new PresentationConnectionClient(std::move(session_info)));
- }
+
+ controller_->didStartDefaultSession(new PresentationConnectionClient(
+ session_info.Clone(),
+ CreateAndSetControllerConnectionProxy(session_info.Clone())));
}
void PresentationDispatcher::OnSessionCreated(
@@ -397,17 +422,28 @@ void PresentationDispatcher::OnSessionCreated(
}
DCHECK(!session_info.is_null());
- presentation_service_->ListenForSessionMessages(session_info.Clone());
- callback->onSuccess(
- base::MakeUnique<PresentationConnectionClient>(std::move(session_info)));
+ if (!session_info->is_offscreen)
+ presentation_service_->ListenForSessionMessages(session_info.Clone());
+
+ callback->onSuccess(base::MakeUnique<PresentationConnectionClient>(
+ session_info.Clone(),
+ CreateAndSetControllerConnectionProxy(session_info.Clone())));
}
void PresentationDispatcher::OnReceiverConnectionAvailable(
- blink::mojom::PresentationSessionInfoPtr session_info) {
- if (receiver_) {
- receiver_->onReceiverConnectionAvailable(
- new PresentationConnectionClient(std::move(session_info)));
- }
+ blink::mojom::PresentationSessionInfoPtr session_info,
+ blink::mojom::PresentationConnectionPtr controller) {
+ DCHECK(receiver_);
+
+ std::unique_ptr<PresentationConnectionProxy> receiver_connection_proxy =
+ base::MakeUnique<PresentationConnectionProxy>();
+
+ controller->SetTargetConnection(receiver_connection_proxy->Bind());
+ receiver_connection_proxy->SetTargetConnection(std::move(controller));
+ // Bind receiver_connection_proxy with PresentationConnection
+ // in receiver page.
+ receiver_->onReceiverConnectionAvailable(new PresentationConnectionClient(
+ std::move(session_info), std::move(receiver_connection_proxy)));
}
void PresentationDispatcher::OnConnectionStateChanged(
@@ -446,7 +482,7 @@ void PresentationDispatcher::OnSessionMessagesReceived(
// Note: Passing batches of messages to the Blink layer would be more
// efficient.
std::unique_ptr<PresentationConnectionClient> session_client(
- new PresentationConnectionClient(session_info->url, session_info->id));
+ new PresentationConnectionClient(session_info.Clone()));
switch (messages[i]->type) {
case blink::mojom::PresentationMessageType::TEXT: {
// TODO(mfoltz): Do we need to DCHECK(messages[i]->message)?
@@ -497,6 +533,22 @@ void PresentationDispatcher::UpdateListeningState(AvailabilityStatus* status) {
}
}
+std::unique_ptr<PresentationConnectionProxy>
+PresentationDispatcher::CreateAndSetControllerConnectionProxy(
+ blink::mojom::PresentationSessionInfoPtr session_info) {
+ if (session_info->is_offscreen) {
+ std::unique_ptr<PresentationConnectionProxy> controller_connection_proxy =
+ base::MakeUnique<PresentationConnectionProxy>();
+ // Pass controller_connection_proxy to PSImpl and register
+ // it with OffscreenPresentationManager.
+ presentation_service_->SetPresentationConnection(
+ session_info.Clone(), controller_connection_proxy->Bind());
+
+ return controller_connection_proxy;
+ }
+ return nullptr;
+}
+
PresentationDispatcher::SendMessageRequest::SendMessageRequest(
blink::mojom::PresentationSessionInfoPtr session_info,
blink::mojom::SessionMessagePtr message)
@@ -515,12 +567,8 @@ PresentationDispatcher::CreateSendTextMessageRequest(
session_info->url = presentationUrl;
session_info->id = presentationId.utf8();
- blink::mojom::SessionMessagePtr session_message =
- blink::mojom::SessionMessage::New();
- session_message->type = blink::mojom::PresentationMessageType::TEXT;
- session_message->message = message.utf8();
return new SendMessageRequest(std::move(session_info),
- std::move(session_message));
+ ToMojoTextMessage(message));
}
// static
@@ -536,12 +584,8 @@ PresentationDispatcher::CreateSendBinaryMessageRequest(
session_info->url = presentationUrl;
session_info->id = presentationId.utf8();
- blink::mojom::SessionMessagePtr session_message =
- blink::mojom::SessionMessage::New();
- session_message->type = type;
- session_message->data = std::vector<uint8_t>(data, data + length);
return new SendMessageRequest(std::move(session_info),
- std::move(session_message));
+ ToMojoBinaryMessage(type, data, length));
}
PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | extensions/renderer/resources/media_router_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698