| 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 case presentation::PRESENTATION_CONNECTION_STATE_CONNECTED: | 45 case presentation::PresentationConnectionState::CONNECTED: |
| 46 return blink::WebPresentationConnectionState::Connected; | 46 return blink::WebPresentationConnectionState::Connected; |
| 47 case presentation::PRESENTATION_CONNECTION_STATE_CLOSED: | 47 case presentation::PresentationConnectionState::CLOSED: |
| 48 return blink::WebPresentationConnectionState::Closed; | 48 return blink::WebPresentationConnectionState::Closed; |
| 49 case presentation::PRESENTATION_CONNECTION_STATE_TERMINATED: | 49 case presentation::PresentationConnectionState::TERMINATED: |
| 50 return blink::WebPresentationConnectionState::Terminated; | 50 return blink::WebPresentationConnectionState::Terminated; |
| 51 } | 51 } |
| 52 | 52 |
| 53 NOTREACHED(); | 53 NOTREACHED(); |
| 54 return blink::WebPresentationConnectionState::Terminated; | 54 return blink::WebPresentationConnectionState::Terminated; |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 namespace content { | 59 namespace content { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 const blink::WebString& presentationId, | 138 const blink::WebString& presentationId, |
| 139 const uint8_t* data, | 139 const uint8_t* data, |
| 140 size_t length) { | 140 size_t length) { |
| 141 DCHECK(data); | 141 DCHECK(data); |
| 142 if (length > kMaxPresentationSessionMessageSize) { | 142 if (length > kMaxPresentationSessionMessageSize) { |
| 143 // TODO(crbug.com/459008): Same as in sendString(). | 143 // TODO(crbug.com/459008): Same as in sendString(). |
| 144 LOG(WARNING) << "data size exceeded limit!"; | 144 LOG(WARNING) << "data size exceeded limit!"; |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 message_request_queue_.push(make_scoped_ptr( | 148 message_request_queue_.push(make_scoped_ptr(CreateSendBinaryMessageRequest( |
| 149 CreateSendBinaryMessageRequest(presentationUrl, presentationId, | 149 presentationUrl, presentationId, |
| 150 presentation::PresentationMessageType:: | 150 presentation::PresentationMessageType::ARRAY_BUFFER, data, length))); |
| 151 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER, | |
| 152 data, length))); | |
| 153 // Start processing request if only one in the queue. | 151 // Start processing request if only one in the queue. |
| 154 if (message_request_queue_.size() == 1) | 152 if (message_request_queue_.size() == 1) |
| 155 DoSendMessage(message_request_queue_.front().get()); | 153 DoSendMessage(message_request_queue_.front().get()); |
| 156 } | 154 } |
| 157 | 155 |
| 158 void PresentationDispatcher::sendBlobData( | 156 void PresentationDispatcher::sendBlobData( |
| 159 const blink::WebString& presentationUrl, | 157 const blink::WebString& presentationUrl, |
| 160 const blink::WebString& presentationId, | 158 const blink::WebString& presentationId, |
| 161 const uint8_t* data, | 159 const uint8_t* data, |
| 162 size_t length) { | 160 size_t length) { |
| 163 DCHECK(data); | 161 DCHECK(data); |
| 164 if (length > kMaxPresentationSessionMessageSize) { | 162 if (length > kMaxPresentationSessionMessageSize) { |
| 165 // TODO(crbug.com/459008): Same as in sendString(). | 163 // TODO(crbug.com/459008): Same as in sendString(). |
| 166 LOG(WARNING) << "data size exceeded limit!"; | 164 LOG(WARNING) << "data size exceeded limit!"; |
| 167 return; | 165 return; |
| 168 } | 166 } |
| 169 | 167 |
| 170 message_request_queue_.push(make_scoped_ptr(CreateSendBinaryMessageRequest( | 168 message_request_queue_.push(make_scoped_ptr(CreateSendBinaryMessageRequest( |
| 171 presentationUrl, presentationId, | 169 presentationUrl, presentationId, |
| 172 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB, | 170 presentation::PresentationMessageType::BLOB, data, length))); |
| 173 data, length))); | |
| 174 // Start processing request if only one in the queue. | 171 // Start processing request if only one in the queue. |
| 175 if (message_request_queue_.size() == 1) | 172 if (message_request_queue_.size() == 1) |
| 176 DoSendMessage(message_request_queue_.front().get()); | 173 DoSendMessage(message_request_queue_.front().get()); |
| 177 } | 174 } |
| 178 | 175 |
| 179 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { | 176 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { |
| 180 ConnectToPresentationServiceIfNeeded(); | 177 ConnectToPresentationServiceIfNeeded(); |
| 181 | 178 |
| 182 presentation_service_->SendSessionMessage( | 179 presentation_service_->SendSessionMessage( |
| 183 std::move(request->session_info), std::move(request->message), | 180 std::move(request->session_info), std::move(request->message), |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 mojo::Array<presentation::SessionMessagePtr> messages) { | 386 mojo::Array<presentation::SessionMessagePtr> messages) { |
| 390 if (!controller_) | 387 if (!controller_) |
| 391 return; | 388 return; |
| 392 | 389 |
| 393 for (size_t i = 0; i < messages.size(); ++i) { | 390 for (size_t i = 0; i < messages.size(); ++i) { |
| 394 // Note: Passing batches of messages to the Blink layer would be more | 391 // Note: Passing batches of messages to the Blink layer would be more |
| 395 // efficient. | 392 // efficient. |
| 396 scoped_ptr<PresentationConnectionClient> session_client( | 393 scoped_ptr<PresentationConnectionClient> session_client( |
| 397 new PresentationConnectionClient(session_info->url, session_info->id)); | 394 new PresentationConnectionClient(session_info->url, session_info->id)); |
| 398 switch (messages[i]->type) { | 395 switch (messages[i]->type) { |
| 399 case presentation::PresentationMessageType:: | 396 case presentation::PresentationMessageType::TEXT: { |
| 400 PRESENTATION_MESSAGE_TYPE_TEXT: { | |
| 401 controller_->didReceiveSessionTextMessage( | 397 controller_->didReceiveSessionTextMessage( |
| 402 session_client.release(), | 398 session_client.release(), |
| 403 blink::WebString::fromUTF8(messages[i]->message)); | 399 blink::WebString::fromUTF8(messages[i]->message)); |
| 404 break; | 400 break; |
| 405 } | 401 } |
| 406 case presentation::PresentationMessageType:: | 402 case presentation::PresentationMessageType::ARRAY_BUFFER: |
| 407 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: | 403 case presentation::PresentationMessageType::BLOB: { |
| 408 case presentation::PresentationMessageType:: | |
| 409 PRESENTATION_MESSAGE_TYPE_BLOB: { | |
| 410 controller_->didReceiveSessionBinaryMessage( | 404 controller_->didReceiveSessionBinaryMessage( |
| 411 session_client.release(), &(messages[i]->data.front()), | 405 session_client.release(), &(messages[i]->data.front()), |
| 412 messages[i]->data.size()); | 406 messages[i]->data.size()); |
| 413 break; | 407 break; |
| 414 } | 408 } |
| 415 default: { | 409 default: { |
| 416 NOTREACHED(); | 410 NOTREACHED(); |
| 417 break; | 411 break; |
| 418 } | 412 } |
| 419 } | 413 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 const blink::WebString& presentationUrl, | 456 const blink::WebString& presentationUrl, |
| 463 const blink::WebString& presentationId, | 457 const blink::WebString& presentationId, |
| 464 const blink::WebString& message) { | 458 const blink::WebString& message) { |
| 465 presentation::PresentationSessionInfoPtr session_info = | 459 presentation::PresentationSessionInfoPtr session_info = |
| 466 presentation::PresentationSessionInfo::New(); | 460 presentation::PresentationSessionInfo::New(); |
| 467 session_info->url = presentationUrl.utf8(); | 461 session_info->url = presentationUrl.utf8(); |
| 468 session_info->id = presentationId.utf8(); | 462 session_info->id = presentationId.utf8(); |
| 469 | 463 |
| 470 presentation::SessionMessagePtr session_message = | 464 presentation::SessionMessagePtr session_message = |
| 471 presentation::SessionMessage::New(); | 465 presentation::SessionMessage::New(); |
| 472 session_message->type = | 466 session_message->type = presentation::PresentationMessageType::TEXT; |
| 473 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | |
| 474 session_message->message = message.utf8(); | 467 session_message->message = message.utf8(); |
| 475 return new SendMessageRequest(std::move(session_info), | 468 return new SendMessageRequest(std::move(session_info), |
| 476 std::move(session_message)); | 469 std::move(session_message)); |
| 477 } | 470 } |
| 478 | 471 |
| 479 // static | 472 // static |
| 480 PresentationDispatcher::SendMessageRequest* | 473 PresentationDispatcher::SendMessageRequest* |
| 481 PresentationDispatcher::CreateSendBinaryMessageRequest( | 474 PresentationDispatcher::CreateSendBinaryMessageRequest( |
| 482 const blink::WebString& presentationUrl, | 475 const blink::WebString& presentationUrl, |
| 483 const blink::WebString& presentationId, | 476 const blink::WebString& presentationId, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 501 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 494 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 502 const std::string& availability_url) | 495 const std::string& availability_url) |
| 503 : url(availability_url), | 496 : url(availability_url), |
| 504 last_known_availability(false), | 497 last_known_availability(false), |
| 505 listening_state(ListeningState::INACTIVE) {} | 498 listening_state(ListeningState::INACTIVE) {} |
| 506 | 499 |
| 507 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 500 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 508 } | 501 } |
| 509 | 502 |
| 510 } // namespace content | 503 } // namespace content |
| OLD | NEW |