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

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 2562603002: Updates SessionMessage to ConnectionMessage. (Closed)
Patch Set: More edits to test. Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/presentation/presentation_dispatcher.h" 5 #include "content/renderer/presentation/presentation_dispatcher.h"
6 6
7 #include <string>
7 #include <utility> 8 #include <utility>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "content/public/common/presentation_constants.h" 14 #include "content/public/common/presentation_constants.h"
14 #include "content/public/renderer/render_frame.h" 15 #include "content/public/renderer/render_frame.h"
15 #include "content/renderer/presentation/presentation_connection_client.h" 16 #include "content/renderer/presentation/presentation_connection_client.h"
16 #include "services/service_manager/public/cpp/interface_provider.h" 17 #include "services/service_manager/public/cpp/interface_provider.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // to be destroyed so we transfer its ownership to the mojo callback. 136 // to be destroyed so we transfer its ownership to the mojo callback.
136 presentation_service_->JoinSession( 137 presentation_service_->JoinSession(
137 urls, presentationId.utf8(), 138 urls, presentationId.utf8(),
138 base::Bind(&PresentationDispatcher::OnSessionCreated, 139 base::Bind(&PresentationDispatcher::OnSessionCreated,
139 base::Unretained(this), base::Passed(&callback))); 140 base::Unretained(this), base::Passed(&callback)));
140 } 141 }
141 142
142 void PresentationDispatcher::sendString(const blink::WebURL& presentationUrl, 143 void PresentationDispatcher::sendString(const blink::WebURL& presentationUrl,
143 const blink::WebString& presentationId, 144 const blink::WebString& presentationId,
144 const blink::WebString& message) { 145 const blink::WebString& message) {
145 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { 146 if (message.utf8().size() > kMaxPresentationConnectionMessageSize) {
146 // TODO(crbug.com/459008): Limit the size of individual messages to 64k 147 // TODO(crbug.com/459008): Limit the size of individual messages to 64k
147 // for now. Consider throwing DOMException or splitting bigger messages 148 // for now. Consider throwing DOMException or splitting bigger messages
148 // into smaller chunks later. 149 // into smaller chunks later.
149 LOG(WARNING) << "message size exceeded limit!"; 150 LOG(WARNING) << "message size exceeded limit!";
150 return; 151 return;
151 } 152 }
152 153
153 message_request_queue_.push(base::WrapUnique( 154 message_request_queue_.push(base::WrapUnique(
154 CreateSendTextMessageRequest(presentationUrl, presentationId, message))); 155 CreateSendTextMessageRequest(presentationUrl, presentationId, message)));
155 // Start processing request if only one in the queue. 156 // Start processing request if only one in the queue.
156 if (message_request_queue_.size() == 1) 157 if (message_request_queue_.size() == 1)
157 DoSendMessage(message_request_queue_.front().get()); 158 DoSendMessage(message_request_queue_.front().get());
158 } 159 }
159 160
160 void PresentationDispatcher::sendArrayBuffer( 161 void PresentationDispatcher::sendArrayBuffer(
161 const blink::WebURL& presentationUrl, 162 const blink::WebURL& presentationUrl,
162 const blink::WebString& presentationId, 163 const blink::WebString& presentationId,
163 const uint8_t* data, 164 const uint8_t* data,
164 size_t length) { 165 size_t length) {
165 DCHECK(data); 166 DCHECK(data);
166 if (length > kMaxPresentationSessionMessageSize) { 167 if (length > kMaxPresentationConnectionMessageSize) {
167 // TODO(crbug.com/459008): Same as in sendString(). 168 // TODO(crbug.com/459008): Same as in sendString().
168 LOG(WARNING) << "data size exceeded limit!"; 169 LOG(WARNING) << "data size exceeded limit!";
169 return; 170 return;
170 } 171 }
171 172
172 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( 173 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest(
173 presentationUrl, presentationId, 174 presentationUrl, presentationId,
174 blink::mojom::PresentationMessageType::ARRAY_BUFFER, data, length))); 175 blink::mojom::PresentationMessageType::BINARY, data, length)));
175 // Start processing request if only one in the queue. 176 // Start processing request if only one in the queue.
176 if (message_request_queue_.size() == 1) 177 if (message_request_queue_.size() == 1)
177 DoSendMessage(message_request_queue_.front().get()); 178 DoSendMessage(message_request_queue_.front().get());
178 } 179 }
179 180
180 void PresentationDispatcher::sendBlobData( 181 void PresentationDispatcher::sendBlobData(
181 const blink::WebURL& presentationUrl, 182 const blink::WebURL& presentationUrl,
182 const blink::WebString& presentationId, 183 const blink::WebString& presentationId,
183 const uint8_t* data, 184 const uint8_t* data,
184 size_t length) { 185 size_t length) {
185 DCHECK(data); 186 DCHECK(data);
186 if (length > kMaxPresentationSessionMessageSize) { 187 if (length > kMaxPresentationConnectionMessageSize) {
187 // TODO(crbug.com/459008): Same as in sendString(). 188 // TODO(crbug.com/459008): Same as in sendString().
188 LOG(WARNING) << "data size exceeded limit!"; 189 LOG(WARNING) << "data size exceeded limit!";
189 return; 190 return;
190 } 191 }
191 192
192 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( 193 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest(
193 presentationUrl, presentationId, 194 presentationUrl, presentationId,
194 blink::mojom::PresentationMessageType::BLOB, data, length))); 195 blink::mojom::PresentationMessageType::BINARY, data, length)));
195 // Start processing request if only one in the queue. 196 // Start processing request if only one in the queue.
196 if (message_request_queue_.size() == 1) 197 if (message_request_queue_.size() == 1)
197 DoSendMessage(message_request_queue_.front().get()); 198 DoSendMessage(message_request_queue_.front().get());
198 } 199 }
199 200
200 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { 201 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) {
201 ConnectToPresentationServiceIfNeeded(); 202 ConnectToPresentationServiceIfNeeded();
202 203
203 presentation_service_->SendSessionMessage( 204 presentation_service_->SendConnectionMessage(
204 std::move(request->session_info), std::move(request->message), 205 std::move(request->session_info), std::move(request->message),
205 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, 206 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
206 base::Unretained(this))); 207 base::Unretained(this)));
207 } 208 }
208 209
209 void PresentationDispatcher::HandleSendMessageRequests(bool success) { 210 void PresentationDispatcher::HandleSendMessageRequests(bool success) {
210 // In normal cases, message_request_queue_ should not be empty at this point 211 // In normal cases, message_request_queue_ should not be empty at this point
211 // of time, but when DidCommitProvisionalLoad() is invoked before receiving 212 // of time, but when DidCommitProvisionalLoad() is invoked before receiving
212 // the callback for previous send mojo call, queue would have been emptied. 213 // the callback for previous send mojo call, queue would have been emptied.
213 if (message_request_queue_.empty()) 214 if (message_request_queue_.empty())
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 status->availability_callbacks.Clear(); 370 status->availability_callbacks.Clear();
370 UpdateListeningState(status); 371 UpdateListeningState(status);
371 } 372 }
372 373
373 void PresentationDispatcher::OnDefaultSessionStarted( 374 void PresentationDispatcher::OnDefaultSessionStarted(
374 blink::mojom::PresentationSessionInfoPtr session_info) { 375 blink::mojom::PresentationSessionInfoPtr session_info) {
375 if (!controller_) 376 if (!controller_)
376 return; 377 return;
377 378
378 if (!session_info.is_null()) { 379 if (!session_info.is_null()) {
379 presentation_service_->ListenForSessionMessages(session_info.Clone()); 380 presentation_service_->ListenForConnectionMessages(session_info.Clone());
380 controller_->didStartDefaultSession( 381 controller_->didStartDefaultSession(
381 new PresentationConnectionClient(std::move(session_info))); 382 new PresentationConnectionClient(std::move(session_info)));
382 } 383 }
383 } 384 }
384 385
385 void PresentationDispatcher::OnSessionCreated( 386 void PresentationDispatcher::OnSessionCreated(
386 std::unique_ptr<blink::WebPresentationConnectionClientCallbacks> callback, 387 std::unique_ptr<blink::WebPresentationConnectionClientCallbacks> callback,
387 blink::mojom::PresentationSessionInfoPtr session_info, 388 blink::mojom::PresentationSessionInfoPtr session_info,
388 blink::mojom::PresentationErrorPtr error) { 389 blink::mojom::PresentationErrorPtr error) {
389 DCHECK(callback); 390 DCHECK(callback);
390 if (!error.is_null()) { 391 if (!error.is_null()) {
391 DCHECK(session_info.is_null()); 392 DCHECK(session_info.is_null());
392 callback->onError(blink::WebPresentationError( 393 callback->onError(blink::WebPresentationError(
393 GetWebPresentationErrorTypeFromMojo(error->error_type), 394 GetWebPresentationErrorTypeFromMojo(error->error_type),
394 blink::WebString::fromUTF8(error->message))); 395 blink::WebString::fromUTF8(error->message)));
395 return; 396 return;
396 } 397 }
397 398
398 DCHECK(!session_info.is_null()); 399 DCHECK(!session_info.is_null());
399 presentation_service_->ListenForSessionMessages(session_info.Clone()); 400 presentation_service_->ListenForConnectionMessages(session_info.Clone());
400 callback->onSuccess( 401 callback->onSuccess(
401 base::MakeUnique<PresentationConnectionClient>(std::move(session_info))); 402 base::MakeUnique<PresentationConnectionClient>(std::move(session_info)));
402 } 403 }
403 404
404 void PresentationDispatcher::OnReceiverConnectionAvailable( 405 void PresentationDispatcher::OnReceiverConnectionAvailable(
405 blink::mojom::PresentationSessionInfoPtr session_info) { 406 blink::mojom::PresentationSessionInfoPtr session_info) {
406 if (receiver_) { 407 if (receiver_) {
407 receiver_->onReceiverConnectionAvailable( 408 receiver_->onReceiverConnectionAvailable(
408 new PresentationConnectionClient(std::move(session_info))); 409 new PresentationConnectionClient(std::move(session_info)));
409 } 410 }
(...skipping 18 matching lines...) Expand all
428 if (!controller_) 429 if (!controller_)
429 return; 430 return;
430 431
431 DCHECK(!connection.is_null()); 432 DCHECK(!connection.is_null());
432 controller_->didCloseConnection( 433 controller_->didCloseConnection(
433 new PresentationConnectionClient(std::move(connection)), 434 new PresentationConnectionClient(std::move(connection)),
434 GetWebPresentationConnectionCloseReasonFromMojo(reason), 435 GetWebPresentationConnectionCloseReasonFromMojo(reason),
435 blink::WebString::fromUTF8(message)); 436 blink::WebString::fromUTF8(message));
436 } 437 }
437 438
438 void PresentationDispatcher::OnSessionMessagesReceived( 439 void PresentationDispatcher::OnConnectionMessagesReceived(
439 blink::mojom::PresentationSessionInfoPtr session_info, 440 blink::mojom::PresentationSessionInfoPtr session_info,
440 std::vector<blink::mojom::SessionMessagePtr> messages) { 441 std::vector<blink::mojom::ConnectionMessagePtr> messages) {
441 if (!controller_) 442 if (!controller_)
442 return; 443 return;
443 444
444 for (size_t i = 0; i < messages.size(); ++i) { 445 for (size_t i = 0; i < messages.size(); ++i) {
445 // Note: Passing batches of messages to the Blink layer would be more 446 // Note: Passing batches of messages to the Blink layer would be more
446 // efficient. 447 // efficient.
447 std::unique_ptr<PresentationConnectionClient> session_client( 448 std::unique_ptr<PresentationConnectionClient> session_client(
448 new PresentationConnectionClient(session_info->url, session_info->id)); 449 new PresentationConnectionClient(session_info->url, session_info->id));
449 switch (messages[i]->type) { 450 switch (messages[i]->type) {
450 case blink::mojom::PresentationMessageType::TEXT: { 451 case blink::mojom::PresentationMessageType::TEXT: {
451 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)? 452 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)?
452 controller_->didReceiveSessionTextMessage( 453 controller_->didReceiveSessionTextMessage(
453 session_client.release(), 454 session_client.release(),
454 blink::WebString::fromUTF8(messages[i]->message.value())); 455 blink::WebString::fromUTF8(messages[i]->message.value()));
455 break; 456 break;
456 } 457 }
457 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: 458 case blink::mojom::PresentationMessageType::BINARY: {
458 case blink::mojom::PresentationMessageType::BLOB: {
459 // TODO(mfoltz): Do we need to DCHECK(messages[i]->data)? 459 // TODO(mfoltz): Do we need to DCHECK(messages[i]->data)?
460 controller_->didReceiveSessionBinaryMessage( 460 controller_->didReceiveSessionBinaryMessage(
461 session_client.release(), &(messages[i]->data->front()), 461 session_client.release(), &(messages[i]->data->front()),
462 messages[i]->data->size()); 462 messages[i]->data->size());
463 break; 463 break;
464 } 464 }
465 default: { 465 default: {
466 NOTREACHED(); 466 NOTREACHED();
467 break; 467 break;
468 } 468 }
(...skipping 22 matching lines...) Expand all
491 status->listening_state = ListeningState::WAITING; 491 status->listening_state = ListeningState::WAITING;
492 presentation_service_->ListenForScreenAvailability(status->url); 492 presentation_service_->ListenForScreenAvailability(status->url);
493 } else { 493 } else {
494 status->listening_state = ListeningState::INACTIVE; 494 status->listening_state = ListeningState::INACTIVE;
495 presentation_service_->StopListeningForScreenAvailability(status->url); 495 presentation_service_->StopListeningForScreenAvailability(status->url);
496 } 496 }
497 } 497 }
498 498
499 PresentationDispatcher::SendMessageRequest::SendMessageRequest( 499 PresentationDispatcher::SendMessageRequest::SendMessageRequest(
500 blink::mojom::PresentationSessionInfoPtr session_info, 500 blink::mojom::PresentationSessionInfoPtr session_info,
501 blink::mojom::SessionMessagePtr message) 501 blink::mojom::ConnectionMessagePtr message)
502 : session_info(std::move(session_info)), message(std::move(message)) {} 502 : session_info(std::move(session_info)), message(std::move(message)) {}
503 503
504 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} 504 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {}
505 505
506 // static 506 // static
507 PresentationDispatcher::SendMessageRequest* 507 PresentationDispatcher::SendMessageRequest*
508 PresentationDispatcher::CreateSendTextMessageRequest( 508 PresentationDispatcher::CreateSendTextMessageRequest(
509 const blink::WebURL& presentationUrl, 509 const blink::WebURL& presentationUrl,
510 const blink::WebString& presentationId, 510 const blink::WebString& presentationId,
511 const blink::WebString& message) { 511 const blink::WebString& message) {
512 blink::mojom::PresentationSessionInfoPtr session_info = 512 blink::mojom::PresentationSessionInfoPtr session_info =
513 blink::mojom::PresentationSessionInfo::New(); 513 blink::mojom::PresentationSessionInfo::New();
514 session_info->url = presentationUrl; 514 session_info->url = presentationUrl;
515 session_info->id = presentationId.utf8(); 515 session_info->id = presentationId.utf8();
516 516
517 blink::mojom::SessionMessagePtr session_message = 517 blink::mojom::ConnectionMessagePtr session_message =
518 blink::mojom::SessionMessage::New(); 518 blink::mojom::ConnectionMessage::New();
519 session_message->type = blink::mojom::PresentationMessageType::TEXT; 519 session_message->type = blink::mojom::PresentationMessageType::TEXT;
520 session_message->message = message.utf8(); 520 session_message->message = message.utf8();
521 return new SendMessageRequest(std::move(session_info), 521 return new SendMessageRequest(std::move(session_info),
522 std::move(session_message)); 522 std::move(session_message));
523 } 523 }
524 524
525 // static 525 // static
526 PresentationDispatcher::SendMessageRequest* 526 PresentationDispatcher::SendMessageRequest*
527 PresentationDispatcher::CreateSendBinaryMessageRequest( 527 PresentationDispatcher::CreateSendBinaryMessageRequest(
528 const blink::WebURL& presentationUrl, 528 const blink::WebURL& presentationUrl,
529 const blink::WebString& presentationId, 529 const blink::WebString& presentationId,
530 blink::mojom::PresentationMessageType type, 530 blink::mojom::PresentationMessageType type,
531 const uint8_t* data, 531 const uint8_t* data,
532 size_t length) { 532 size_t length) {
533 blink::mojom::PresentationSessionInfoPtr session_info = 533 blink::mojom::PresentationSessionInfoPtr session_info =
534 blink::mojom::PresentationSessionInfo::New(); 534 blink::mojom::PresentationSessionInfo::New();
535 session_info->url = presentationUrl; 535 session_info->url = presentationUrl;
536 session_info->id = presentationId.utf8(); 536 session_info->id = presentationId.utf8();
537 537
538 blink::mojom::SessionMessagePtr session_message = 538 blink::mojom::ConnectionMessagePtr session_message =
539 blink::mojom::SessionMessage::New(); 539 blink::mojom::ConnectionMessage::New();
540 session_message->type = type; 540 session_message->type = type;
541 session_message->data = std::vector<uint8_t>(data, data + length); 541 session_message->data = std::vector<uint8_t>(data, data + length);
542 return new SendMessageRequest(std::move(session_info), 542 return new SendMessageRequest(std::move(session_info),
543 std::move(session_message)); 543 std::move(session_message));
544 } 544 }
545 545
546 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( 546 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
547 const GURL& availability_url) 547 const GURL& availability_url)
548 : url(availability_url), 548 : url(availability_url),
549 last_known_availability(false), 549 last_known_availability(false),
550 listening_state(ListeningState::INACTIVE) {} 550 listening_state(ListeningState::INACTIVE) {}
551 551
552 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { 552 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() {
553 } 553 }
554 554
555 } // namespace content 555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698