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 <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 const blink::WebString& message, | 155 const blink::WebString& message, |
156 const blink::WebPresentationConnectionProxy* connection_proxy) { | 156 const blink::WebPresentationConnectionProxy* connection_proxy) { |
157 if (message.utf8().size() > kMaxPresentationConnectionMessageSize) { | 157 if (message.utf8().size() > kMaxPresentationConnectionMessageSize) { |
158 // TODO(crbug.com/459008): Limit the size of individual messages to 64k | 158 // TODO(crbug.com/459008): Limit the size of individual messages to 64k |
159 // for now. Consider throwing DOMException or splitting bigger messages | 159 // for now. Consider throwing DOMException or splitting bigger messages |
160 // into smaller chunks later. | 160 // into smaller chunks later. |
161 LOG(WARNING) << "message size exceeded limit!"; | 161 LOG(WARNING) << "message size exceeded limit!"; |
162 return; | 162 return; |
163 } | 163 } |
164 | 164 |
165 message_request_queue_.push(base::WrapUnique(CreateSendTextMessageRequest( | 165 message_request_queue_.push_back( |
166 presentationUrl, presentationId, message, connection_proxy))); | 166 base::WrapUnique(CreateSendTextMessageRequest( |
| 167 presentationUrl, presentationId, message, connection_proxy))); |
167 // Start processing request if only one in the queue. | 168 // Start processing request if only one in the queue. |
168 if (message_request_queue_.size() == 1) | 169 if (message_request_queue_.size() == 1) |
169 DoSendMessage(message_request_queue_.front().get()); | 170 DoSendMessage(message_request_queue_.front().get()); |
170 } | 171 } |
171 | 172 |
172 void PresentationDispatcher::sendArrayBuffer( | 173 void PresentationDispatcher::sendArrayBuffer( |
173 const blink::WebURL& presentationUrl, | 174 const blink::WebURL& presentationUrl, |
174 const blink::WebString& presentationId, | 175 const blink::WebString& presentationId, |
175 const uint8_t* data, | 176 const uint8_t* data, |
176 size_t length, | 177 size_t length, |
177 const blink::WebPresentationConnectionProxy* connection_proxy) { | 178 const blink::WebPresentationConnectionProxy* connection_proxy) { |
178 DCHECK(data); | 179 DCHECK(data); |
179 if (length > kMaxPresentationConnectionMessageSize) { | 180 if (length > kMaxPresentationConnectionMessageSize) { |
180 // TODO(crbug.com/459008): Same as in sendString(). | 181 // TODO(crbug.com/459008): Same as in sendString(). |
181 LOG(WARNING) << "data size exceeded limit!"; | 182 LOG(WARNING) << "data size exceeded limit!"; |
182 return; | 183 return; |
183 } | 184 } |
184 | 185 |
185 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( | 186 message_request_queue_.push_back( |
186 presentationUrl, presentationId, | 187 base::WrapUnique(CreateSendBinaryMessageRequest( |
187 blink::mojom::PresentationMessageType::BINARY, data, length, | 188 presentationUrl, presentationId, |
188 connection_proxy))); | 189 blink::mojom::PresentationMessageType::BINARY, data, length, |
| 190 connection_proxy))); |
189 // Start processing request if only one in the queue. | 191 // Start processing request if only one in the queue. |
190 if (message_request_queue_.size() == 1) | 192 if (message_request_queue_.size() == 1) |
191 DoSendMessage(message_request_queue_.front().get()); | 193 DoSendMessage(message_request_queue_.front().get()); |
192 } | 194 } |
193 | 195 |
194 void PresentationDispatcher::sendBlobData( | 196 void PresentationDispatcher::sendBlobData( |
195 const blink::WebURL& presentationUrl, | 197 const blink::WebURL& presentationUrl, |
196 const blink::WebString& presentationId, | 198 const blink::WebString& presentationId, |
197 const uint8_t* data, | 199 const uint8_t* data, |
198 size_t length, | 200 size_t length, |
199 const blink::WebPresentationConnectionProxy* connection_proxy) { | 201 const blink::WebPresentationConnectionProxy* connection_proxy) { |
200 DCHECK(data); | 202 DCHECK(data); |
201 if (length > kMaxPresentationConnectionMessageSize) { | 203 if (length > kMaxPresentationConnectionMessageSize) { |
202 // TODO(crbug.com/459008): Same as in sendString(). | 204 // TODO(crbug.com/459008): Same as in sendString(). |
203 LOG(WARNING) << "data size exceeded limit!"; | 205 LOG(WARNING) << "data size exceeded limit!"; |
204 return; | 206 return; |
205 } | 207 } |
206 | 208 |
207 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( | 209 message_request_queue_.push_back( |
208 presentationUrl, presentationId, | 210 base::WrapUnique(CreateSendBinaryMessageRequest( |
209 blink::mojom::PresentationMessageType::BINARY, data, length, | 211 presentationUrl, presentationId, |
210 connection_proxy))); | 212 blink::mojom::PresentationMessageType::BINARY, data, length, |
| 213 connection_proxy))); |
211 // Start processing request if only one in the queue. | 214 // Start processing request if only one in the queue. |
212 if (message_request_queue_.size() == 1) | 215 if (message_request_queue_.size() == 1) |
213 DoSendMessage(message_request_queue_.front().get()); | 216 DoSendMessage(message_request_queue_.front().get()); |
214 } | 217 } |
215 | 218 |
216 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { | 219 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { |
217 DCHECK(request->connection_proxy); | 220 DCHECK(request->connection_proxy); |
218 // TODO(crbug.com/684116): Remove static_cast after moving message queue logic | 221 // TODO(crbug.com/684116): Remove static_cast after moving message queue logic |
219 // from PresentationDispatcher to PresentationConnectionProxy. | 222 // from PresentationDispatcher to PresentationConnectionProxy. |
220 static_cast<const PresentationConnectionProxy*>(request->connection_proxy) | 223 static_cast<const PresentationConnectionProxy*>(request->connection_proxy) |
(...skipping 11 matching lines...) Expand all Loading... |
232 return; | 235 return; |
233 | 236 |
234 if (!success) { | 237 if (!success) { |
235 // PresentationServiceImpl is informing that Frame has been detached or | 238 // PresentationServiceImpl is informing that Frame has been detached or |
236 // navigated away. Invalidate all pending requests. | 239 // navigated away. Invalidate all pending requests. |
237 MessageRequestQueue empty; | 240 MessageRequestQueue empty; |
238 std::swap(message_request_queue_, empty); | 241 std::swap(message_request_queue_, empty); |
239 return; | 242 return; |
240 } | 243 } |
241 | 244 |
242 message_request_queue_.pop(); | 245 message_request_queue_.pop_front(); |
243 if (!message_request_queue_.empty()) { | 246 if (!message_request_queue_.empty()) { |
244 DoSendMessage(message_request_queue_.front().get()); | 247 DoSendMessage(message_request_queue_.front().get()); |
245 } | 248 } |
246 } | 249 } |
247 | 250 |
248 void PresentationDispatcher::SetControllerConnection( | 251 void PresentationDispatcher::SetControllerConnection( |
249 const PresentationSessionInfo& session_info, | 252 const PresentationSessionInfo& session_info, |
250 blink::WebPresentationConnection* connection) { | 253 blink::WebPresentationConnection* connection) { |
251 DCHECK(connection); | 254 DCHECK(connection); |
252 | 255 |
253 auto* controller_connection_proxy = new ControllerConnectionProxy(connection); | 256 auto* controller_connection_proxy = new ControllerConnectionProxy(connection); |
254 connection->bindProxy(base::WrapUnique(controller_connection_proxy)); | 257 connection->bindProxy(base::WrapUnique(controller_connection_proxy)); |
255 | 258 |
256 ConnectToPresentationServiceIfNeeded(); | 259 ConnectToPresentationServiceIfNeeded(); |
257 presentation_service_->SetPresentationConnection( | 260 presentation_service_->SetPresentationConnection( |
258 session_info, controller_connection_proxy->Bind(), | 261 session_info, controller_connection_proxy->Bind(), |
259 controller_connection_proxy->MakeRemoteRequest()); | 262 controller_connection_proxy->MakeRemoteRequest()); |
260 } | 263 } |
261 | 264 |
262 void PresentationDispatcher::closeSession( | 265 void PresentationDispatcher::closeSession( |
263 const blink::WebURL& presentationUrl, | 266 const blink::WebURL& presentationUrl, |
264 const blink::WebString& presentationId) { | 267 const blink::WebString& presentationId, |
| 268 const blink::WebPresentationConnectionProxy* connection_proxy) { |
| 269 message_request_queue_.erase( |
| 270 std::remove_if(message_request_queue_.begin(), |
| 271 message_request_queue_.end(), |
| 272 [&connection_proxy]( |
| 273 const std::unique_ptr<SendMessageRequest>& request) { |
| 274 return request->connection_proxy == connection_proxy; |
| 275 }), |
| 276 message_request_queue_.end()); |
| 277 |
| 278 connection_proxy->close(); |
| 279 |
265 ConnectToPresentationServiceIfNeeded(); | 280 ConnectToPresentationServiceIfNeeded(); |
266 presentation_service_->CloseConnection(presentationUrl, | 281 presentation_service_->CloseConnection(presentationUrl, |
267 presentationId.utf8()); | 282 presentationId.utf8()); |
268 } | 283 } |
269 | 284 |
270 void PresentationDispatcher::terminateSession( | 285 void PresentationDispatcher::terminateSession( |
271 const blink::WebURL& presentationUrl, | 286 const blink::WebURL& presentationUrl, |
272 const blink::WebString& presentationId) { | 287 const blink::WebString& presentationId) { |
273 ConnectToPresentationServiceIfNeeded(); | 288 ConnectToPresentationServiceIfNeeded(); |
274 presentation_service_->Terminate(presentationUrl, presentationId.utf8()); | 289 presentation_service_->Terminate(presentationUrl, presentationId.utf8()); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 | 792 |
778 PresentationDispatcher::ListeningStatus::ListeningStatus( | 793 PresentationDispatcher::ListeningStatus::ListeningStatus( |
779 const GURL& availability_url) | 794 const GURL& availability_url) |
780 : url(availability_url), | 795 : url(availability_url), |
781 last_known_availability(ScreenAvailability::UNKNOWN), | 796 last_known_availability(ScreenAvailability::UNKNOWN), |
782 listening_state(ListeningState::INACTIVE) {} | 797 listening_state(ListeningState::INACTIVE) {} |
783 | 798 |
784 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} | 799 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} |
785 | 800 |
786 } // namespace content | 801 } // namespace content |
OLD | NEW |