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

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

Issue 1957143002: [OnionSoup] Move persentation_service.mojom from //content to //third_party/WebKit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "content/common/presentation/presentation_service.mojom.h"
14 #include "content/public/common/presentation_constants.h" 13 #include "content/public/common/presentation_constants.h"
15 #include "content/public/common/service_registry.h" 14 #include "content/public/common/service_registry.h"
16 #include "content/public/renderer/render_frame.h" 15 #include "content/public/renderer/render_frame.h"
17 #include "content/renderer/presentation/presentation_connection_client.h" 16 #include "content/renderer/presentation/presentation_connection_client.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 17 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebURL.h" 18 #include "third_party/WebKit/public/platform/WebURL.h"
20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h"
21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
22 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
23 #include "third_party/WebKit/public/web/WebLocalFrame.h" 23 #include "third_party/WebKit/public/web/WebLocalFrame.h"
24 #include "url/gurl.h" 24 #include "url/gurl.h"
25 25
26 namespace { 26 namespace {
27 27
28 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( 28 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo(
29 content::mojom::PresentationErrorType mojoErrorType) { 29 blink::mojom::PresentationErrorType mojoErrorType) {
30 switch (mojoErrorType) { 30 switch (mojoErrorType) {
31 case content::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS: 31 case blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS:
32 return blink::WebPresentationError::ErrorTypeNoAvailableScreens; 32 return blink::WebPresentationError::ErrorTypeNoAvailableScreens;
33 case content::mojom::PresentationErrorType::SESSION_REQUEST_CANCELLED: 33 case blink::mojom::PresentationErrorType::SESSION_REQUEST_CANCELLED:
34 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; 34 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled;
35 case content::mojom::PresentationErrorType::NO_PRESENTATION_FOUND: 35 case blink::mojom::PresentationErrorType::NO_PRESENTATION_FOUND:
36 return blink::WebPresentationError::ErrorTypeNoPresentationFound; 36 return blink::WebPresentationError::ErrorTypeNoPresentationFound;
37 case content::mojom::PresentationErrorType::UNKNOWN: 37 case blink::mojom::PresentationErrorType::UNKNOWN:
38 default: 38 default:
39 return blink::WebPresentationError::ErrorTypeUnknown; 39 return blink::WebPresentationError::ErrorTypeUnknown;
40 } 40 }
41 } 41 }
42 42
43 blink::WebPresentationConnectionState GetWebPresentationConnectionStateFromMojo( 43 blink::WebPresentationConnectionState GetWebPresentationConnectionStateFromMojo(
44 content::mojom::PresentationConnectionState mojoSessionState) { 44 blink::mojom::PresentationConnectionState mojoSessionState) {
45 switch (mojoSessionState) { 45 switch (mojoSessionState) {
46 // TODO(imcheng): Add Connecting state to Blink (crbug.com/575351). 46 // TODO(imcheng): Add Connecting state to Blink (crbug.com/575351).
47 case content::mojom::PresentationConnectionState::CONNECTED: 47 case blink::mojom::PresentationConnectionState::CONNECTED:
48 return blink::WebPresentationConnectionState::Connected; 48 return blink::WebPresentationConnectionState::Connected;
49 case content::mojom::PresentationConnectionState::CLOSED: 49 case blink::mojom::PresentationConnectionState::CLOSED:
50 return blink::WebPresentationConnectionState::Closed; 50 return blink::WebPresentationConnectionState::Closed;
51 case content::mojom::PresentationConnectionState::TERMINATED: 51 case blink::mojom::PresentationConnectionState::TERMINATED:
52 return blink::WebPresentationConnectionState::Terminated; 52 return blink::WebPresentationConnectionState::Terminated;
53 default: 53 default:
54 NOTREACHED(); 54 NOTREACHED();
55 return blink::WebPresentationConnectionState::Terminated; 55 return blink::WebPresentationConnectionState::Terminated;
56 } 56 }
57 } 57 }
58 58
59 blink::WebPresentationConnectionCloseReason 59 blink::WebPresentationConnectionCloseReason
60 GetWebPresentationConnectionCloseReasonFromMojo( 60 GetWebPresentationConnectionCloseReasonFromMojo(
61 content::mojom::PresentationConnectionCloseReason 61 blink::mojom::PresentationConnectionCloseReason mojoConnectionCloseReason) {
62 mojoConnectionCloseReason) {
63 switch (mojoConnectionCloseReason) { 62 switch (mojoConnectionCloseReason) {
64 case content::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR: 63 case blink::mojom::PresentationConnectionCloseReason::CONNECTION_ERROR:
65 return blink::WebPresentationConnectionCloseReason::Error; 64 return blink::WebPresentationConnectionCloseReason::Error;
66 case content::mojom::PresentationConnectionCloseReason::CLOSED: 65 case blink::mojom::PresentationConnectionCloseReason::CLOSED:
67 return blink::WebPresentationConnectionCloseReason::Closed; 66 return blink::WebPresentationConnectionCloseReason::Closed;
68 case content::mojom::PresentationConnectionCloseReason::WENT_AWAY: 67 case blink::mojom::PresentationConnectionCloseReason::WENT_AWAY:
69 return blink::WebPresentationConnectionCloseReason::WentAway; 68 return blink::WebPresentationConnectionCloseReason::WentAway;
70 default: 69 default:
71 NOTREACHED(); 70 NOTREACHED();
72 return blink::WebPresentationConnectionCloseReason::Error; 71 return blink::WebPresentationConnectionCloseReason::Error;
73 } 72 }
74 } 73 }
75 74
76 } // namespace 75 } // namespace
77 76
78 namespace content { 77 namespace content {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 size_t length) { 158 size_t length) {
160 DCHECK(data); 159 DCHECK(data);
161 if (length > kMaxPresentationSessionMessageSize) { 160 if (length > kMaxPresentationSessionMessageSize) {
162 // TODO(crbug.com/459008): Same as in sendString(). 161 // TODO(crbug.com/459008): Same as in sendString().
163 LOG(WARNING) << "data size exceeded limit!"; 162 LOG(WARNING) << "data size exceeded limit!";
164 return; 163 return;
165 } 164 }
166 165
167 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( 166 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest(
168 presentationUrl, presentationId, 167 presentationUrl, presentationId,
169 mojom::PresentationMessageType::ARRAY_BUFFER, data, length))); 168 blink::mojom::PresentationMessageType::ARRAY_BUFFER, data, length)));
170 // Start processing request if only one in the queue. 169 // Start processing request if only one in the queue.
171 if (message_request_queue_.size() == 1) 170 if (message_request_queue_.size() == 1)
172 DoSendMessage(message_request_queue_.front().get()); 171 DoSendMessage(message_request_queue_.front().get());
173 } 172 }
174 173
175 void PresentationDispatcher::sendBlobData( 174 void PresentationDispatcher::sendBlobData(
176 const blink::WebString& presentationUrl, 175 const blink::WebString& presentationUrl,
177 const blink::WebString& presentationId, 176 const blink::WebString& presentationId,
178 const uint8_t* data, 177 const uint8_t* data,
179 size_t length) { 178 size_t length) {
180 DCHECK(data); 179 DCHECK(data);
181 if (length > kMaxPresentationSessionMessageSize) { 180 if (length > kMaxPresentationSessionMessageSize) {
182 // TODO(crbug.com/459008): Same as in sendString(). 181 // TODO(crbug.com/459008): Same as in sendString().
183 LOG(WARNING) << "data size exceeded limit!"; 182 LOG(WARNING) << "data size exceeded limit!";
184 return; 183 return;
185 } 184 }
186 185
187 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( 186 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest(
188 presentationUrl, presentationId, mojom::PresentationMessageType::BLOB, 187 presentationUrl, presentationId,
189 data, length))); 188 blink::mojom::PresentationMessageType::BLOB, data, length)));
190 // Start processing request if only one in the queue. 189 // Start processing request if only one in the queue.
191 if (message_request_queue_.size() == 1) 190 if (message_request_queue_.size() == 1)
192 DoSendMessage(message_request_queue_.front().get()); 191 DoSendMessage(message_request_queue_.front().get());
193 } 192 }
194 193
195 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { 194 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) {
196 ConnectToPresentationServiceIfNeeded(); 195 ConnectToPresentationServiceIfNeeded();
197 196
198 presentation_service_->SendSessionMessage( 197 presentation_service_->SendSessionMessage(
199 std::move(request->session_info), std::move(request->message), 198 std::move(request->session_info), std::move(request->message),
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 !iter.IsAtEnd(); iter.Advance()) { 350 !iter.IsAtEnd(); iter.Advance()) {
352 iter.GetCurrentValue()->onError(blink::WebPresentationError( 351 iter.GetCurrentValue()->onError(blink::WebPresentationError(
353 blink::WebPresentationError::ErrorTypeAvailabilityNotSupported, 352 blink::WebPresentationError::ErrorTypeAvailabilityNotSupported,
354 not_supported_error)); 353 not_supported_error));
355 } 354 }
356 status->availability_callbacks.Clear(); 355 status->availability_callbacks.Clear();
357 UpdateListeningState(status); 356 UpdateListeningState(status);
358 } 357 }
359 358
360 void PresentationDispatcher::OnDefaultSessionStarted( 359 void PresentationDispatcher::OnDefaultSessionStarted(
361 mojom::PresentationSessionInfoPtr session_info) { 360 blink::mojom::PresentationSessionInfoPtr session_info) {
362 if (!controller_) 361 if (!controller_)
363 return; 362 return;
364 363
365 if (!session_info.is_null()) { 364 if (!session_info.is_null()) {
366 presentation_service_->ListenForSessionMessages(session_info.Clone()); 365 presentation_service_->ListenForSessionMessages(session_info.Clone());
367 controller_->didStartDefaultSession( 366 controller_->didStartDefaultSession(
368 new PresentationConnectionClient(std::move(session_info))); 367 new PresentationConnectionClient(std::move(session_info)));
369 } 368 }
370 } 369 }
371 370
372 void PresentationDispatcher::OnSessionCreated( 371 void PresentationDispatcher::OnSessionCreated(
373 blink::WebPresentationConnectionClientCallbacks* callback, 372 blink::WebPresentationConnectionClientCallbacks* callback,
374 mojom::PresentationSessionInfoPtr session_info, 373 blink::mojom::PresentationSessionInfoPtr session_info,
375 mojom::PresentationErrorPtr error) { 374 blink::mojom::PresentationErrorPtr error) {
376 DCHECK(callback); 375 DCHECK(callback);
377 if (!error.is_null()) { 376 if (!error.is_null()) {
378 DCHECK(session_info.is_null()); 377 DCHECK(session_info.is_null());
379 callback->onError(blink::WebPresentationError( 378 callback->onError(blink::WebPresentationError(
380 GetWebPresentationErrorTypeFromMojo(error->error_type), 379 GetWebPresentationErrorTypeFromMojo(error->error_type),
381 blink::WebString::fromUTF8(error->message))); 380 blink::WebString::fromUTF8(error->message)));
382 return; 381 return;
383 } 382 }
384 383
385 DCHECK(!session_info.is_null()); 384 DCHECK(!session_info.is_null());
386 presentation_service_->ListenForSessionMessages(session_info.Clone()); 385 presentation_service_->ListenForSessionMessages(session_info.Clone());
387 callback->onSuccess(base::WrapUnique( 386 callback->onSuccess(base::WrapUnique(
388 new PresentationConnectionClient(std::move(session_info)))); 387 new PresentationConnectionClient(std::move(session_info))));
389 } 388 }
390 389
391 void PresentationDispatcher::OnConnectionStateChanged( 390 void PresentationDispatcher::OnConnectionStateChanged(
392 mojom::PresentationSessionInfoPtr connection, 391 blink::mojom::PresentationSessionInfoPtr connection,
393 mojom::PresentationConnectionState state) { 392 blink::mojom::PresentationConnectionState state) {
394 if (!controller_) 393 if (!controller_)
395 return; 394 return;
396 395
397 DCHECK(!connection.is_null()); 396 DCHECK(!connection.is_null());
398 controller_->didChangeSessionState( 397 controller_->didChangeSessionState(
399 new PresentationConnectionClient(std::move(connection)), 398 new PresentationConnectionClient(std::move(connection)),
400 GetWebPresentationConnectionStateFromMojo(state)); 399 GetWebPresentationConnectionStateFromMojo(state));
401 } 400 }
402 401
403 void PresentationDispatcher::OnConnectionClosed( 402 void PresentationDispatcher::OnConnectionClosed(
404 mojom::PresentationSessionInfoPtr connection, 403 blink::mojom::PresentationSessionInfoPtr connection,
405 mojom::PresentationConnectionCloseReason reason, 404 blink::mojom::PresentationConnectionCloseReason reason,
406 const mojo::String& message) { 405 const mojo::String& message) {
407 if (!controller_) 406 if (!controller_)
408 return; 407 return;
409 408
410 DCHECK(!connection.is_null()); 409 DCHECK(!connection.is_null());
411 controller_->didCloseConnection( 410 controller_->didCloseConnection(
412 new PresentationConnectionClient(std::move(connection)), 411 new PresentationConnectionClient(std::move(connection)),
413 GetWebPresentationConnectionCloseReasonFromMojo(reason), 412 GetWebPresentationConnectionCloseReasonFromMojo(reason),
414 blink::WebString::fromUTF8(message)); 413 blink::WebString::fromUTF8(message));
415 } 414 }
416 415
417 void PresentationDispatcher::OnSessionMessagesReceived( 416 void PresentationDispatcher::OnSessionMessagesReceived(
418 mojom::PresentationSessionInfoPtr session_info, 417 blink::mojom::PresentationSessionInfoPtr session_info,
419 mojo::Array<mojom::SessionMessagePtr> messages) { 418 mojo::Array<blink::mojom::SessionMessagePtr> messages) {
420 if (!controller_) 419 if (!controller_)
421 return; 420 return;
422 421
423 for (size_t i = 0; i < messages.size(); ++i) { 422 for (size_t i = 0; i < messages.size(); ++i) {
424 // Note: Passing batches of messages to the Blink layer would be more 423 // Note: Passing batches of messages to the Blink layer would be more
425 // efficient. 424 // efficient.
426 std::unique_ptr<PresentationConnectionClient> session_client( 425 std::unique_ptr<PresentationConnectionClient> session_client(
427 new PresentationConnectionClient(session_info->url, session_info->id)); 426 new PresentationConnectionClient(session_info->url, session_info->id));
428 switch (messages[i]->type) { 427 switch (messages[i]->type) {
429 case mojom::PresentationMessageType::TEXT: { 428 case blink::mojom::PresentationMessageType::TEXT: {
430 controller_->didReceiveSessionTextMessage( 429 controller_->didReceiveSessionTextMessage(
431 session_client.release(), 430 session_client.release(),
432 blink::WebString::fromUTF8(messages[i]->message)); 431 blink::WebString::fromUTF8(messages[i]->message));
433 break; 432 break;
434 } 433 }
435 case mojom::PresentationMessageType::ARRAY_BUFFER: 434 case blink::mojom::PresentationMessageType::ARRAY_BUFFER:
436 case mojom::PresentationMessageType::BLOB: { 435 case blink::mojom::PresentationMessageType::BLOB: {
437 controller_->didReceiveSessionBinaryMessage( 436 controller_->didReceiveSessionBinaryMessage(
438 session_client.release(), &(messages[i]->data.front()), 437 session_client.release(), &(messages[i]->data.front()),
439 messages[i]->data.size()); 438 messages[i]->data.size());
440 break; 439 break;
441 } 440 }
442 default: { 441 default: {
443 NOTREACHED(); 442 NOTREACHED();
444 break; 443 break;
445 } 444 }
446 } 445 }
(...skipping 21 matching lines...) Expand all
468 if (should_listen) { 467 if (should_listen) {
469 status->listening_state = ListeningState::WAITING; 468 status->listening_state = ListeningState::WAITING;
470 presentation_service_->ListenForScreenAvailability(status->url); 469 presentation_service_->ListenForScreenAvailability(status->url);
471 } else { 470 } else {
472 status->listening_state = ListeningState::INACTIVE; 471 status->listening_state = ListeningState::INACTIVE;
473 presentation_service_->StopListeningForScreenAvailability(status->url); 472 presentation_service_->StopListeningForScreenAvailability(status->url);
474 } 473 }
475 } 474 }
476 475
477 PresentationDispatcher::SendMessageRequest::SendMessageRequest( 476 PresentationDispatcher::SendMessageRequest::SendMessageRequest(
478 mojom::PresentationSessionInfoPtr session_info, 477 blink::mojom::PresentationSessionInfoPtr session_info,
479 mojom::SessionMessagePtr message) 478 blink::mojom::SessionMessagePtr message)
480 : session_info(std::move(session_info)), message(std::move(message)) {} 479 : session_info(std::move(session_info)), message(std::move(message)) {}
481 480
482 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} 481 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {}
483 482
484 // static 483 // static
485 PresentationDispatcher::SendMessageRequest* 484 PresentationDispatcher::SendMessageRequest*
486 PresentationDispatcher::CreateSendTextMessageRequest( 485 PresentationDispatcher::CreateSendTextMessageRequest(
487 const blink::WebString& presentationUrl, 486 const blink::WebString& presentationUrl,
488 const blink::WebString& presentationId, 487 const blink::WebString& presentationId,
489 const blink::WebString& message) { 488 const blink::WebString& message) {
490 mojom::PresentationSessionInfoPtr session_info = 489 blink::mojom::PresentationSessionInfoPtr session_info =
491 mojom::PresentationSessionInfo::New(); 490 blink::mojom::PresentationSessionInfo::New();
492 session_info->url = presentationUrl.utf8(); 491 session_info->url = presentationUrl.utf8();
493 session_info->id = presentationId.utf8(); 492 session_info->id = presentationId.utf8();
494 493
495 mojom::SessionMessagePtr session_message = mojom::SessionMessage::New(); 494 blink::mojom::SessionMessagePtr session_message =
496 session_message->type = mojom::PresentationMessageType::TEXT; 495 blink::mojom::SessionMessage::New();
496 session_message->type = blink::mojom::PresentationMessageType::TEXT;
497 session_message->message = message.utf8(); 497 session_message->message = message.utf8();
498 return new SendMessageRequest(std::move(session_info), 498 return new SendMessageRequest(std::move(session_info),
499 std::move(session_message)); 499 std::move(session_message));
500 } 500 }
501 501
502 // static 502 // static
503 PresentationDispatcher::SendMessageRequest* 503 PresentationDispatcher::SendMessageRequest*
504 PresentationDispatcher::CreateSendBinaryMessageRequest( 504 PresentationDispatcher::CreateSendBinaryMessageRequest(
505 const blink::WebString& presentationUrl, 505 const blink::WebString& presentationUrl,
506 const blink::WebString& presentationId, 506 const blink::WebString& presentationId,
507 mojom::PresentationMessageType type, 507 blink::mojom::PresentationMessageType type,
508 const uint8_t* data, 508 const uint8_t* data,
509 size_t length) { 509 size_t length) {
510 mojom::PresentationSessionInfoPtr session_info = 510 blink::mojom::PresentationSessionInfoPtr session_info =
511 mojom::PresentationSessionInfo::New(); 511 blink::mojom::PresentationSessionInfo::New();
512 session_info->url = presentationUrl.utf8(); 512 session_info->url = presentationUrl.utf8();
513 session_info->id = presentationId.utf8(); 513 session_info->id = presentationId.utf8();
514 514
515 mojom::SessionMessagePtr session_message = mojom::SessionMessage::New(); 515 blink::mojom::SessionMessagePtr session_message =
516 blink::mojom::SessionMessage::New();
516 session_message->type = type; 517 session_message->type = type;
517 std::vector<uint8_t> tmp_data_vector(data, data + length); 518 std::vector<uint8_t> tmp_data_vector(data, data + length);
518 session_message->data.Swap(&tmp_data_vector); 519 session_message->data.Swap(&tmp_data_vector);
519 return new SendMessageRequest(std::move(session_info), 520 return new SendMessageRequest(std::move(session_info),
520 std::move(session_message)); 521 std::move(session_message));
521 } 522 }
522 523
523 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( 524 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
524 const std::string& availability_url) 525 const std::string& availability_url)
525 : url(availability_url), 526 : url(availability_url),
526 last_known_availability(false), 527 last_known_availability(false),
527 listening_state(ListeningState::INACTIVE) {} 528 listening_state(ListeningState::INACTIVE) {}
528 529
529 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { 530 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() {
530 } 531 }
531 532
532 } // namespace content 533 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | third_party/WebKit/public/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698