OLD | NEW |
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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 GetWebPresentationSessionStateFromMojo(session_state)); | 368 GetWebPresentationSessionStateFromMojo(session_state)); |
369 } | 369 } |
370 | 370 |
371 void PresentationDispatcher::OnSessionMessagesReceived( | 371 void PresentationDispatcher::OnSessionMessagesReceived( |
372 mojo::Array<presentation::SessionMessagePtr> messages) { | 372 mojo::Array<presentation::SessionMessagePtr> messages) { |
373 // When messages is null, there is an error at presentation service side. | 373 // When messages is null, there is an error at presentation service side. |
374 if (!controller_ || messages.is_null()) | 374 if (!controller_ || messages.is_null()) |
375 return; | 375 return; |
376 | 376 |
377 for (size_t i = 0; i < messages.size(); ++i) { | 377 for (size_t i = 0; i < messages.size(); ++i) { |
378 if (messages[i]->type == | 378 // Note: Passing batches of messages to the Blink layer would be more |
379 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT) { | 379 // efficient. |
380 controller_->didReceiveSessionTextMessage( | 380 scoped_ptr<PresentationSessionClient> session_client( |
381 new PresentationSessionClient(messages[i]->presentation_url, | 381 new PresentationSessionClient(messages[i]->presentation_url, |
382 messages[i]->presentation_id), | 382 messages[i]->presentation_id)); |
383 blink::WebString::fromUTF8(messages[i]->message)); | 383 switch (messages[i]->type) { |
384 } else { | 384 case presentation::PresentationMessageType:: |
385 // TODO(haibinlu): handle binary message | 385 PRESENTATION_MESSAGE_TYPE_TEXT: { |
| 386 controller_->didReceiveSessionTextMessage( |
| 387 session_client.release(), |
| 388 blink::WebString::fromUTF8(messages[i]->message)); |
| 389 break; |
| 390 } |
| 391 case presentation::PresentationMessageType:: |
| 392 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: |
| 393 case presentation::PresentationMessageType:: |
| 394 PRESENTATION_MESSAGE_TYPE_BLOB: { |
| 395 controller_->didReceiveSessionBinaryMessage( |
| 396 session_client.release(), &(messages[i]->data.front()), |
| 397 messages[i]->data.size()); |
| 398 break; |
| 399 } |
| 400 default: { |
| 401 NOTREACHED(); |
| 402 break; |
| 403 } |
386 } | 404 } |
387 } | 405 } |
388 | 406 |
389 presentation_service_->ListenForSessionMessages( | 407 presentation_service_->ListenForSessionMessages( |
390 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 408 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
391 base::Unretained(this))); | 409 base::Unretained(this))); |
392 } | 410 } |
393 | 411 |
394 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 412 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
395 if (presentation_service_.get()) | 413 if (presentation_service_.get()) |
(...skipping 10 matching lines...) Expand all Loading... |
406 base::Unretained(this))); | 424 base::Unretained(this))); |
407 | 425 |
408 // TODO(imcheng): Uncomment this once it is implemented on the browser | 426 // TODO(imcheng): Uncomment this once it is implemented on the browser |
409 // side. (crbug.com/459006) | 427 // side. (crbug.com/459006) |
410 // presentation_service_->ListenForSessionStateChange(base::Bind( | 428 // presentation_service_->ListenForSessionStateChange(base::Bind( |
411 // &PresentationDispatcher::OnSessionStateChange, | 429 // &PresentationDispatcher::OnSessionStateChange, |
412 // base::Unretained(this))); | 430 // base::Unretained(this))); |
413 } | 431 } |
414 | 432 |
415 } // namespace content | 433 } // namespace content |
OLD | NEW |