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

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