| 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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/common/presentation/presentation_service.mojom.h" | 12 #include "content/common/presentation/presentation_service.mojom.h" |
| 13 #include "content/public/common/presentation_constants.h" | 13 #include "content/public/common/presentation_constants.h" |
| 14 #include "content/public/common/service_registry.h" | 14 #include "content/public/common/service_registry.h" |
| 15 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/renderer/presentation/presentation_connection_client.h" | 16 #include "content/renderer/presentation/presentation_connection_client.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
| 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" | 19 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" |
| 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" | 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
| 21 #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/web/WebLocalFrame.h" | 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( | 27 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( |
| 28 presentation::PresentationErrorType mojoErrorType) { | 28 presentation::PresentationErrorType mojoErrorType) { |
| 29 switch (mojoErrorType) { | 29 switch (mojoErrorType) { |
| 30 case presentation::PRESENTATION_ERROR_TYPE_NO_AVAILABLE_SCREENS: | 30 case presentation::PresentationErrorType::NO_AVAILABLE_SCREENS: |
| 31 return blink::WebPresentationError::ErrorTypeNoAvailableScreens; | 31 return blink::WebPresentationError::ErrorTypeNoAvailableScreens; |
| 32 case presentation::PRESENTATION_ERROR_TYPE_SESSION_REQUEST_CANCELLED: | 32 case presentation::PresentationErrorType::SESSION_REQUEST_CANCELLED: |
| 33 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; | 33 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; |
| 34 case presentation::PRESENTATION_ERROR_TYPE_NO_PRESENTATION_FOUND: | 34 case presentation::PresentationErrorType::NO_PRESENTATION_FOUND: |
| 35 return blink::WebPresentationError::ErrorTypeNoPresentationFound; | 35 return blink::WebPresentationError::ErrorTypeNoPresentationFound; |
| 36 case presentation::PRESENTATION_ERROR_TYPE_UNKNOWN: | 36 case presentation::PresentationErrorType::UNKNOWN: |
| 37 default: | 37 default: |
| 38 return blink::WebPresentationError::ErrorTypeUnknown; | 38 return blink::WebPresentationError::ErrorTypeUnknown; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 blink::WebPresentationConnectionState GetWebPresentationConnectionStateFromMojo( | 42 blink::WebPresentationConnectionState GetWebPresentationConnectionStateFromMojo( |
| 43 presentation::PresentationConnectionState mojoSessionState) { | 43 presentation::PresentationConnectionState mojoSessionState) { |
| 44 switch (mojoSessionState) { | 44 switch (mojoSessionState) { |
| 45 // TODO(imcheng): Add Connecting state to Blink (crbug.com/575351). | 45 // TODO(imcheng): Add Connecting state to Blink (crbug.com/575351). |
| 46 case presentation::PRESENTATION_CONNECTION_STATE_CONNECTED: | 46 case presentation::PresentationConnectionState::CONNECTED: |
| 47 return blink::WebPresentationConnectionState::Connected; | 47 return blink::WebPresentationConnectionState::Connected; |
| 48 case presentation::PRESENTATION_CONNECTION_STATE_CLOSED: | 48 case presentation::PresentationConnectionState::CLOSED: |
| 49 return blink::WebPresentationConnectionState::Closed; | 49 return blink::WebPresentationConnectionState::Closed; |
| 50 case presentation::PRESENTATION_CONNECTION_STATE_TERMINATED: | 50 case presentation::PresentationConnectionState::TERMINATED: |
| 51 return blink::WebPresentationConnectionState::Terminated; | 51 return blink::WebPresentationConnectionState::Terminated; |
| 52 default: | 52 default: |
| 53 NOTREACHED(); | 53 NOTREACHED(); |
| 54 return blink::WebPresentationConnectionState::Terminated; | 54 return blink::WebPresentationConnectionState::Terminated; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 namespace content { | 60 namespace content { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 const blink::WebString& presentationId, | 139 const blink::WebString& presentationId, |
| 140 const uint8_t* data, | 140 const uint8_t* data, |
| 141 size_t length) { | 141 size_t length) { |
| 142 DCHECK(data); | 142 DCHECK(data); |
| 143 if (length > kMaxPresentationSessionMessageSize) { | 143 if (length > kMaxPresentationSessionMessageSize) { |
| 144 // TODO(crbug.com/459008): Same as in sendString(). | 144 // TODO(crbug.com/459008): Same as in sendString(). |
| 145 LOG(WARNING) << "data size exceeded limit!"; | 145 LOG(WARNING) << "data size exceeded limit!"; |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 | 148 |
| 149 message_request_queue_.push(make_scoped_ptr( | 149 message_request_queue_.push(make_scoped_ptr(CreateSendBinaryMessageRequest( |
| 150 CreateSendBinaryMessageRequest(presentationUrl, presentationId, | 150 presentationUrl, presentationId, |
| 151 presentation::PresentationMessageType:: | 151 presentation::PresentationMessageType::ARRAY_BUFFER, data, length))); |
| 152 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER, | |
| 153 data, length))); | |
| 154 // Start processing request if only one in the queue. | 152 // Start processing request if only one in the queue. |
| 155 if (message_request_queue_.size() == 1) | 153 if (message_request_queue_.size() == 1) |
| 156 DoSendMessage(message_request_queue_.front().get()); | 154 DoSendMessage(message_request_queue_.front().get()); |
| 157 } | 155 } |
| 158 | 156 |
| 159 void PresentationDispatcher::sendBlobData( | 157 void PresentationDispatcher::sendBlobData( |
| 160 const blink::WebString& presentationUrl, | 158 const blink::WebString& presentationUrl, |
| 161 const blink::WebString& presentationId, | 159 const blink::WebString& presentationId, |
| 162 const uint8_t* data, | 160 const uint8_t* data, |
| 163 size_t length) { | 161 size_t length) { |
| 164 DCHECK(data); | 162 DCHECK(data); |
| 165 if (length > kMaxPresentationSessionMessageSize) { | 163 if (length > kMaxPresentationSessionMessageSize) { |
| 166 // TODO(crbug.com/459008): Same as in sendString(). | 164 // TODO(crbug.com/459008): Same as in sendString(). |
| 167 LOG(WARNING) << "data size exceeded limit!"; | 165 LOG(WARNING) << "data size exceeded limit!"; |
| 168 return; | 166 return; |
| 169 } | 167 } |
| 170 | 168 |
| 171 message_request_queue_.push(make_scoped_ptr(CreateSendBinaryMessageRequest( | 169 message_request_queue_.push(make_scoped_ptr(CreateSendBinaryMessageRequest( |
| 172 presentationUrl, presentationId, | 170 presentationUrl, presentationId, |
| 173 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB, | 171 presentation::PresentationMessageType::BLOB, data, length))); |
| 174 data, length))); | |
| 175 // Start processing request if only one in the queue. | 172 // Start processing request if only one in the queue. |
| 176 if (message_request_queue_.size() == 1) | 173 if (message_request_queue_.size() == 1) |
| 177 DoSendMessage(message_request_queue_.front().get()); | 174 DoSendMessage(message_request_queue_.front().get()); |
| 178 } | 175 } |
| 179 | 176 |
| 180 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { | 177 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { |
| 181 ConnectToPresentationServiceIfNeeded(); | 178 ConnectToPresentationServiceIfNeeded(); |
| 182 | 179 |
| 183 presentation_service_->SendSessionMessage( | 180 presentation_service_->SendSessionMessage( |
| 184 std::move(request->session_info), std::move(request->message), | 181 std::move(request->session_info), std::move(request->message), |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 mojo::Array<presentation::SessionMessagePtr> messages) { | 387 mojo::Array<presentation::SessionMessagePtr> messages) { |
| 391 if (!controller_) | 388 if (!controller_) |
| 392 return; | 389 return; |
| 393 | 390 |
| 394 for (size_t i = 0; i < messages.size(); ++i) { | 391 for (size_t i = 0; i < messages.size(); ++i) { |
| 395 // Note: Passing batches of messages to the Blink layer would be more | 392 // Note: Passing batches of messages to the Blink layer would be more |
| 396 // efficient. | 393 // efficient. |
| 397 scoped_ptr<PresentationConnectionClient> session_client( | 394 scoped_ptr<PresentationConnectionClient> session_client( |
| 398 new PresentationConnectionClient(session_info->url, session_info->id)); | 395 new PresentationConnectionClient(session_info->url, session_info->id)); |
| 399 switch (messages[i]->type) { | 396 switch (messages[i]->type) { |
| 400 case presentation::PresentationMessageType:: | 397 case presentation::PresentationMessageType::TEXT: { |
| 401 PRESENTATION_MESSAGE_TYPE_TEXT: { | |
| 402 controller_->didReceiveSessionTextMessage( | 398 controller_->didReceiveSessionTextMessage( |
| 403 session_client.release(), | 399 session_client.release(), |
| 404 blink::WebString::fromUTF8(messages[i]->message)); | 400 blink::WebString::fromUTF8(messages[i]->message)); |
| 405 break; | 401 break; |
| 406 } | 402 } |
| 407 case presentation::PresentationMessageType:: | 403 case presentation::PresentationMessageType::ARRAY_BUFFER: |
| 408 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: | 404 case presentation::PresentationMessageType::BLOB: { |
| 409 case presentation::PresentationMessageType:: | |
| 410 PRESENTATION_MESSAGE_TYPE_BLOB: { | |
| 411 controller_->didReceiveSessionBinaryMessage( | 405 controller_->didReceiveSessionBinaryMessage( |
| 412 session_client.release(), &(messages[i]->data.front()), | 406 session_client.release(), &(messages[i]->data.front()), |
| 413 messages[i]->data.size()); | 407 messages[i]->data.size()); |
| 414 break; | 408 break; |
| 415 } | 409 } |
| 416 default: { | 410 default: { |
| 417 NOTREACHED(); | 411 NOTREACHED(); |
| 418 break; | 412 break; |
| 419 } | 413 } |
| 420 } | 414 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 const blink::WebString& presentationUrl, | 457 const blink::WebString& presentationUrl, |
| 464 const blink::WebString& presentationId, | 458 const blink::WebString& presentationId, |
| 465 const blink::WebString& message) { | 459 const blink::WebString& message) { |
| 466 presentation::PresentationSessionInfoPtr session_info = | 460 presentation::PresentationSessionInfoPtr session_info = |
| 467 presentation::PresentationSessionInfo::New(); | 461 presentation::PresentationSessionInfo::New(); |
| 468 session_info->url = presentationUrl.utf8(); | 462 session_info->url = presentationUrl.utf8(); |
| 469 session_info->id = presentationId.utf8(); | 463 session_info->id = presentationId.utf8(); |
| 470 | 464 |
| 471 presentation::SessionMessagePtr session_message = | 465 presentation::SessionMessagePtr session_message = |
| 472 presentation::SessionMessage::New(); | 466 presentation::SessionMessage::New(); |
| 473 session_message->type = | 467 session_message->type = presentation::PresentationMessageType::TEXT; |
| 474 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | |
| 475 session_message->message = message.utf8(); | 468 session_message->message = message.utf8(); |
| 476 return new SendMessageRequest(std::move(session_info), | 469 return new SendMessageRequest(std::move(session_info), |
| 477 std::move(session_message)); | 470 std::move(session_message)); |
| 478 } | 471 } |
| 479 | 472 |
| 480 // static | 473 // static |
| 481 PresentationDispatcher::SendMessageRequest* | 474 PresentationDispatcher::SendMessageRequest* |
| 482 PresentationDispatcher::CreateSendBinaryMessageRequest( | 475 PresentationDispatcher::CreateSendBinaryMessageRequest( |
| 483 const blink::WebString& presentationUrl, | 476 const blink::WebString& presentationUrl, |
| 484 const blink::WebString& presentationId, | 477 const blink::WebString& presentationId, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 502 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 495 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 503 const std::string& availability_url) | 496 const std::string& availability_url) |
| 504 : url(availability_url), | 497 : url(availability_url), |
| 505 last_known_availability(false), | 498 last_known_availability(false), |
| 506 listening_state(ListeningState::INACTIVE) {} | 499 listening_state(ListeningState::INACTIVE) {} |
| 507 | 500 |
| 508 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 501 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 509 } | 502 } |
| 510 | 503 |
| 511 } // namespace content | 504 } // namespace content |
| OLD | NEW |