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

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

Issue 2471573005: [Presentation API] (5th) (1-UA) integrate controller and receiver side for 1-UA messaging (Closed)
Patch Set: rebase 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 d6a299bc59d7ec88d6e27e4c0cd0231943a8230a..34a1cfe1286da2772e792a59fc4924c14c7c162d 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(
mark a. foltz 2016/11/16 01:25:37 We should really implement Mojo type traits for se
+ 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) {
mark a. foltz 2016/11/16 01:25:37 We'd have to implement a converter between blink::
+ 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(
@@ -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)
+ return nullptr;
+
+ 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;
+}
+
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(

Powered by Google App Engine
This is Rietveld 408576698