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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "content/public/common/presentation_connection_message.h" | 16 #include "content/public/common/presentation_connection_message.h" |
17 #include "content/public/renderer/render_frame.h" | 17 #include "content/public/renderer/render_frame.h" |
18 #include "content/renderer/presentation/presentation_connection_proxy.h" | 18 #include "content/renderer/presentation/presentation_connection_proxy.h" |
19 #include "services/service_manager/public/cpp/interface_provider.h" | 19 #include "services/service_manager/public/cpp/interface_provider.h" |
20 #include "third_party/WebKit/public/platform/WebString.h" | 20 #include "third_party/WebKit/public/platform/WebString.h" |
21 #include "third_party/WebKit/public/platform/WebURL.h" | 21 #include "third_party/WebKit/public/platform/WebURL.h" |
22 #include "third_party/WebKit/public/platform/WebVector.h" | 22 #include "third_party/WebKit/public/platform/WebVector.h" |
23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" | 23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nAvailabilityObserver.h" |
24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" | 24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnection.h" |
25 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnectionCallbacks.h" | 25 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nConnectionCallbacks.h" |
26 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" | 26 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nController.h" |
27 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nError.h" | 27 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nError.h" |
| 28 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nInfo.h" |
28 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nReceiver.h" | 29 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nReceiver.h" |
29 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nSessionInfo.h" | |
30 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | 30 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
31 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 | 33 |
34 namespace content { | 34 namespace content { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 blink::WebPresentationError::ErrorType GetWebPresentationErrorType( | 38 blink::WebPresentationError::ErrorType GetWebPresentationErrorType( |
39 PresentationErrorType errorType) { | 39 PresentationErrorType errorType) { |
40 switch (errorType) { | 40 switch (errorType) { |
41 case PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS: | 41 case PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS: |
42 return blink::WebPresentationError::ErrorTypeNoAvailableScreens; | 42 return blink::WebPresentationError::ErrorTypeNoAvailableScreens; |
43 case PresentationErrorType::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED: | 43 case PresentationErrorType:: |
44 return blink::WebPresentationError::ErrorTypeSessionRequestCancelled; | 44 PRESENTATION_ERROR_PRESENTATION_REQUEST_CANCELLED: |
| 45 return blink::WebPresentationError::ErrorTypePresentationRequestCancelled; |
45 case PresentationErrorType::PRESENTATION_ERROR_NO_PRESENTATION_FOUND: | 46 case PresentationErrorType::PRESENTATION_ERROR_NO_PRESENTATION_FOUND: |
46 return blink::WebPresentationError::ErrorTypeNoPresentationFound; | 47 return blink::WebPresentationError::ErrorTypeNoPresentationFound; |
47 case PresentationErrorType::PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS: | 48 case PresentationErrorType::PRESENTATION_ERROR_PREVIOUS_START_IN_PROGRESS: |
48 return blink::WebPresentationError::ErrorTypePreviousStartInProgress; | 49 return blink::WebPresentationError::ErrorTypePreviousStartInProgress; |
49 case PresentationErrorType::PRESENTATION_ERROR_UNKNOWN: | 50 case PresentationErrorType::PRESENTATION_ERROR_UNKNOWN: |
50 default: | 51 default: |
51 return blink::WebPresentationError::ErrorTypeUnknown; | 52 return blink::WebPresentationError::ErrorTypeUnknown; |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 blink::WebPresentationConnectionState GetWebPresentationConnectionState( | 56 blink::WebPresentationConnectionState GetWebPresentationConnectionState( |
56 PresentationConnectionState sessionState) { | 57 PresentationConnectionState connectionState) { |
57 switch (sessionState) { | 58 switch (connectionState) { |
58 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CONNECTING: | 59 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CONNECTING: |
59 return blink::WebPresentationConnectionState::Connecting; | 60 return blink::WebPresentationConnectionState::Connecting; |
60 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CONNECTED: | 61 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CONNECTED: |
61 return blink::WebPresentationConnectionState::Connected; | 62 return blink::WebPresentationConnectionState::Connected; |
62 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED: | 63 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_CLOSED: |
63 return blink::WebPresentationConnectionState::Closed; | 64 return blink::WebPresentationConnectionState::Closed; |
64 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_TERMINATED: | 65 case PresentationConnectionState::PRESENTATION_CONNECTION_STATE_TERMINATED: |
65 return blink::WebPresentationConnectionState::Terminated; | 66 return blink::WebPresentationConnectionState::Terminated; |
66 default: | 67 default: |
67 NOTREACHED(); | 68 NOTREACHED(); |
(...skipping 14 matching lines...) Expand all Loading... |
82 case PresentationConnectionCloseReason:: | 83 case PresentationConnectionCloseReason:: |
83 PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY: | 84 PRESENTATION_CONNECTION_CLOSE_REASON_WENT_AWAY: |
84 return blink::WebPresentationConnectionCloseReason::WentAway; | 85 return blink::WebPresentationConnectionCloseReason::WentAway; |
85 default: | 86 default: |
86 NOTREACHED(); | 87 NOTREACHED(); |
87 return blink::WebPresentationConnectionCloseReason::Error; | 88 return blink::WebPresentationConnectionCloseReason::Error; |
88 } | 89 } |
89 } | 90 } |
90 } // namespace | 91 } // namespace |
91 | 92 |
| 93 // TODO(mfoltz): Reorder definitions to match presentation_dispatcher.h. |
| 94 |
92 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 95 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
93 : RenderFrameObserver(render_frame), | 96 : RenderFrameObserver(render_frame), |
94 controller_(nullptr), | 97 controller_(nullptr), |
95 receiver_(nullptr), | 98 receiver_(nullptr), |
96 binding_(this) {} | 99 binding_(this) {} |
97 | 100 |
98 PresentationDispatcher::~PresentationDispatcher() { | 101 PresentationDispatcher::~PresentationDispatcher() { |
99 // Controller should be destroyed before the dispatcher when frame is | 102 // Controller should be destroyed before the dispatcher when frame is |
100 // destroyed. | 103 // destroyed. |
101 DCHECK(!controller_); | 104 DCHECK(!controller_); |
102 } | 105 } |
103 | 106 |
104 void PresentationDispatcher::setController( | 107 void PresentationDispatcher::setController( |
105 blink::WebPresentationController* controller) { | 108 blink::WebPresentationController* controller) { |
106 // There shouldn't be any swapping from one non-null controller to another. | 109 // There shouldn't be any swapping from one non-null controller to another. |
107 DCHECK(controller != controller_ && (!controller || !controller_)); | 110 DCHECK(controller != controller_ && (!controller || !controller_)); |
108 controller_ = controller; | 111 controller_ = controller; |
109 // The controller is set to null when the frame is about to be detached. | 112 // The controller is set to null when the frame is about to be detached. |
110 // Nothing is listening for screen availability anymore but the Mojo service | 113 // Nothing is listening for screen availability anymore but the Mojo service |
111 // will know about the frame being detached anyway. | 114 // will know about the frame being detached anyway. |
112 } | 115 } |
113 | 116 |
114 void PresentationDispatcher::startSession( | 117 void PresentationDispatcher::startPresentation( |
115 const blink::WebVector<blink::WebURL>& presentationUrls, | 118 const blink::WebVector<blink::WebURL>& presentationUrls, |
116 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback) { | 119 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback) { |
117 DCHECK(callback); | 120 DCHECK(callback); |
118 ConnectToPresentationServiceIfNeeded(); | 121 ConnectToPresentationServiceIfNeeded(); |
119 | 122 |
120 std::vector<GURL> urls; | 123 std::vector<GURL> urls; |
121 for (const auto& url : presentationUrls) | 124 for (const auto& url : presentationUrls) |
122 urls.push_back(url); | 125 urls.push_back(url); |
123 | 126 |
124 // The dispatcher owns the service so |this| will be valid when | 127 // The dispatcher owns the service so |this| will be valid when |
125 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 128 // OnConnectionCreated() is called. |callback| needs to be alive and also |
126 // to be destroyed so we transfer its ownership to the mojo callback. | 129 // needs to be destroyed so we transfer its ownership to the mojo callback. |
127 presentation_service_->StartSession( | 130 presentation_service_->StartPresentation( |
128 urls, base::Bind(&PresentationDispatcher::OnSessionCreated, | 131 urls, base::Bind(&PresentationDispatcher::OnConnectionCreated, |
129 base::Unretained(this), base::Passed(&callback))); | 132 base::Unretained(this), base::Passed(&callback))); |
130 } | 133 } |
131 | 134 |
132 void PresentationDispatcher::joinSession( | 135 void PresentationDispatcher::reconnectPresentation( |
133 const blink::WebVector<blink::WebURL>& presentationUrls, | 136 const blink::WebVector<blink::WebURL>& presentationUrls, |
134 const blink::WebString& presentationId, | 137 const blink::WebString& presentationId, |
135 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback) { | 138 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback) { |
136 DCHECK(callback); | 139 DCHECK(callback); |
137 ConnectToPresentationServiceIfNeeded(); | 140 ConnectToPresentationServiceIfNeeded(); |
138 | 141 |
139 std::vector<GURL> urls; | 142 std::vector<GURL> urls; |
140 for (const auto& url : presentationUrls) | 143 for (const auto& url : presentationUrls) |
141 urls.push_back(url); | 144 urls.push_back(url); |
142 | 145 |
143 // The dispatcher owns the service so |this| will be valid when | 146 // The dispatcher owns the service so |this| will be valid when |
144 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 147 // OnConnectionCreated() is called. |callback| needs to be alive and also |
145 // to be destroyed so we transfer its ownership to the mojo callback. | 148 // needs to be destroyed so we transfer its ownership to the mojo callback. |
146 presentation_service_->JoinSession( | 149 presentation_service_->ReconnectPresentation( |
147 urls, presentationId.utf8(), | 150 urls, presentationId.utf8(), |
148 base::Bind(&PresentationDispatcher::OnSessionCreated, | 151 base::Bind(&PresentationDispatcher::OnConnectionCreated, |
149 base::Unretained(this), base::Passed(&callback))); | 152 base::Unretained(this), base::Passed(&callback))); |
150 } | 153 } |
151 | 154 |
152 void PresentationDispatcher::sendString( | 155 void PresentationDispatcher::sendString( |
153 const blink::WebURL& presentationUrl, | 156 const blink::WebURL& presentationUrl, |
154 const blink::WebString& presentationId, | 157 const blink::WebString& presentationId, |
155 const blink::WebString& message, | 158 const blink::WebString& message, |
156 const blink::WebPresentationConnectionProxy* connection_proxy) { | 159 const blink::WebPresentationConnectionProxy* connection_proxy) { |
157 if (message.utf8().size() > kMaxPresentationConnectionMessageSize) { | 160 if (message.utf8().size() > kMaxPresentationConnectionMessageSize) { |
158 // TODO(crbug.com/459008): Limit the size of individual messages to 64k | 161 // TODO(crbug.com/459008): Limit the size of individual messages to 64k |
159 // for now. Consider throwing DOMException or splitting bigger messages | 162 // for now. Consider throwing DOMException or splitting bigger messages |
160 // into smaller chunks later. | 163 // into smaller chunks later. |
161 LOG(WARNING) << "message size exceeded limit!"; | 164 LOG(WARNING) << "message size exceeded limit!"; |
162 return; | 165 return; |
163 } | 166 } |
164 | 167 |
165 message_request_queue_.push_back(CreateSendTextMessageRequest( | 168 message_request_queue_.push_back(CreateSendTextMessageRequest( |
166 presentationUrl, presentationId, message, connection_proxy)); | 169 presentationUrl, presentationId, message, connection_proxy)); |
167 // Start processing request if only one in the queue. | 170 // Start processing request if only one in the queue. |
168 if (message_request_queue_.size() == 1) | 171 if (message_request_queue_.size() == 1) |
169 DoSendMessage(message_request_queue_.front().get()); | 172 DoSendMessage(message_request_queue_.front().get()); |
170 } | 173 } |
171 | 174 |
| 175 void PresentationDispatcher::terminatePresentation( |
| 176 const blink::WebURL& presentationUrl, |
| 177 const blink::WebString& presentationId) { |
| 178 if (receiver_) { |
| 179 receiver_->terminateConnection(); |
| 180 return; |
| 181 } |
| 182 |
| 183 ConnectToPresentationServiceIfNeeded(); |
| 184 presentation_service_->Terminate(presentationUrl, presentationId.utf8()); |
| 185 } |
| 186 |
172 void PresentationDispatcher::sendArrayBuffer( | 187 void PresentationDispatcher::sendArrayBuffer( |
173 const blink::WebURL& presentationUrl, | 188 const blink::WebURL& presentationUrl, |
174 const blink::WebString& presentationId, | 189 const blink::WebString& presentationId, |
175 const uint8_t* data, | 190 const uint8_t* data, |
176 size_t length, | 191 size_t length, |
177 const blink::WebPresentationConnectionProxy* connection_proxy) { | 192 const blink::WebPresentationConnectionProxy* connection_proxy) { |
178 DCHECK(data); | 193 DCHECK(data); |
179 if (length > kMaxPresentationConnectionMessageSize) { | 194 if (length > kMaxPresentationConnectionMessageSize) { |
180 // TODO(crbug.com/459008): Same as in sendString(). | 195 // TODO(crbug.com/459008): Same as in sendString(). |
181 LOG(WARNING) << "data size exceeded limit!"; | 196 LOG(WARNING) << "data size exceeded limit!"; |
(...skipping 20 matching lines...) Expand all Loading... |
202 return; | 217 return; |
203 } | 218 } |
204 | 219 |
205 message_request_queue_.push_back(CreateSendBinaryMessageRequest( | 220 message_request_queue_.push_back(CreateSendBinaryMessageRequest( |
206 presentationUrl, presentationId, data, length, connection_proxy)); | 221 presentationUrl, presentationId, data, length, connection_proxy)); |
207 // Start processing request if only one in the queue. | 222 // Start processing request if only one in the queue. |
208 if (message_request_queue_.size() == 1) | 223 if (message_request_queue_.size() == 1) |
209 DoSendMessage(message_request_queue_.front().get()); | 224 DoSendMessage(message_request_queue_.front().get()); |
210 } | 225 } |
211 | 226 |
| 227 void PresentationDispatcher::closeConnection( |
| 228 const blink::WebURL& presentationUrl, |
| 229 const blink::WebString& presentationId, |
| 230 const blink::WebPresentationConnectionProxy* connection_proxy) { |
| 231 message_request_queue_.erase( |
| 232 std::remove_if(message_request_queue_.begin(), |
| 233 message_request_queue_.end(), |
| 234 [&connection_proxy]( |
| 235 const std::unique_ptr<SendMessageRequest>& request) { |
| 236 return request->connection_proxy == connection_proxy; |
| 237 }), |
| 238 message_request_queue_.end()); |
| 239 |
| 240 connection_proxy->close(); |
| 241 |
| 242 ConnectToPresentationServiceIfNeeded(); |
| 243 presentation_service_->CloseConnection(presentationUrl, |
| 244 presentationId.utf8()); |
| 245 } |
| 246 |
212 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { | 247 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { |
213 DCHECK(request->connection_proxy); | 248 DCHECK(request->connection_proxy); |
214 // TODO(crbug.com/684116): Remove static_cast after moving message queue logic | 249 // TODO(crbug.com/684116): Remove static_cast after moving message queue logic |
215 // from PresentationDispatcher to PresentationConnectionProxy. | 250 // from PresentationDispatcher to PresentationConnectionProxy. |
216 static_cast<const PresentationConnectionProxy*>(request->connection_proxy) | 251 static_cast<const PresentationConnectionProxy*>(request->connection_proxy) |
217 ->SendConnectionMessage( | 252 ->SendConnectionMessage( |
218 std::move(request->message), | 253 std::move(request->message), |
219 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, | 254 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, |
220 base::Unretained(this))); | 255 base::Unretained(this))); |
221 } | 256 } |
(...skipping 13 matching lines...) Expand all Loading... |
235 return; | 270 return; |
236 } | 271 } |
237 | 272 |
238 message_request_queue_.pop_front(); | 273 message_request_queue_.pop_front(); |
239 if (!message_request_queue_.empty()) { | 274 if (!message_request_queue_.empty()) { |
240 DoSendMessage(message_request_queue_.front().get()); | 275 DoSendMessage(message_request_queue_.front().get()); |
241 } | 276 } |
242 } | 277 } |
243 | 278 |
244 void PresentationDispatcher::SetControllerConnection( | 279 void PresentationDispatcher::SetControllerConnection( |
245 const PresentationSessionInfo& session_info, | 280 const PresentationInfo& presentation_info, |
246 blink::WebPresentationConnection* connection) { | 281 blink::WebPresentationConnection* connection) { |
247 DCHECK(connection); | 282 DCHECK(connection); |
248 | 283 |
249 auto* controller_connection_proxy = new ControllerConnectionProxy(connection); | 284 auto* controller_connection_proxy = new ControllerConnectionProxy(connection); |
250 connection->bindProxy(base::WrapUnique(controller_connection_proxy)); | 285 connection->bindProxy(base::WrapUnique(controller_connection_proxy)); |
251 | 286 |
252 ConnectToPresentationServiceIfNeeded(); | 287 ConnectToPresentationServiceIfNeeded(); |
253 presentation_service_->SetPresentationConnection( | 288 presentation_service_->SetPresentationConnection( |
254 session_info, controller_connection_proxy->Bind(), | 289 presentation_info, controller_connection_proxy->Bind(), |
255 controller_connection_proxy->MakeRemoteRequest()); | 290 controller_connection_proxy->MakeRemoteRequest()); |
256 } | 291 } |
257 | 292 |
258 void PresentationDispatcher::closeSession( | |
259 const blink::WebURL& presentationUrl, | |
260 const blink::WebString& presentationId, | |
261 const blink::WebPresentationConnectionProxy* connection_proxy) { | |
262 message_request_queue_.erase( | |
263 std::remove_if(message_request_queue_.begin(), | |
264 message_request_queue_.end(), | |
265 [&connection_proxy]( | |
266 const std::unique_ptr<SendMessageRequest>& request) { | |
267 return request->connection_proxy == connection_proxy; | |
268 }), | |
269 message_request_queue_.end()); | |
270 | |
271 connection_proxy->close(); | |
272 | |
273 ConnectToPresentationServiceIfNeeded(); | |
274 presentation_service_->CloseConnection(presentationUrl, | |
275 presentationId.utf8()); | |
276 } | |
277 | |
278 void PresentationDispatcher::terminateConnection( | |
279 const blink::WebURL& presentationUrl, | |
280 const blink::WebString& presentationId) { | |
281 if (receiver_) { | |
282 receiver_->terminateConnection(); | |
283 return; | |
284 } | |
285 | |
286 ConnectToPresentationServiceIfNeeded(); | |
287 presentation_service_->Terminate(presentationUrl, presentationId.utf8()); | |
288 } | |
289 | |
290 void PresentationDispatcher::getAvailability( | 293 void PresentationDispatcher::getAvailability( |
291 const blink::WebVector<blink::WebURL>& availabilityUrls, | 294 const blink::WebVector<blink::WebURL>& availabilityUrls, |
292 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callback) { | 295 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callback) { |
293 DCHECK(!availabilityUrls.isEmpty()); | 296 DCHECK(!availabilityUrls.isEmpty()); |
294 | 297 |
295 std::vector<GURL> urls; | 298 std::vector<GURL> urls; |
296 for (const auto& availability_url : availabilityUrls) | 299 for (const auto& availability_url : availabilityUrls) |
297 urls.push_back(availability_url); | 300 urls.push_back(availability_url); |
298 | 301 |
299 auto screen_availability = GetScreenAvailability(urls); | 302 auto screen_availability = GetScreenAvailability(urls); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 401 } |
399 | 402 |
400 void PresentationDispatcher::OnDestruct() { | 403 void PresentationDispatcher::OnDestruct() { |
401 delete this; | 404 delete this; |
402 } | 405 } |
403 | 406 |
404 void PresentationDispatcher::WidgetWillClose() { | 407 void PresentationDispatcher::WidgetWillClose() { |
405 if (!receiver_) | 408 if (!receiver_) |
406 return; | 409 return; |
407 | 410 |
408 receiver_->didChangeSessionState( | 411 receiver_->didChangeConnectionState( |
409 blink::WebPresentationConnectionState::Terminated); | 412 blink::WebPresentationConnectionState::Terminated); |
410 } | 413 } |
411 | 414 |
412 void PresentationDispatcher::OnScreenAvailabilityUpdated(const GURL& url, | 415 void PresentationDispatcher::OnScreenAvailabilityUpdated(const GURL& url, |
413 bool available) { | 416 bool available) { |
414 auto* listening_status = GetListeningStatus(url); | 417 auto* listening_status = GetListeningStatus(url); |
415 if (!listening_status) | 418 if (!listening_status) |
416 return; | 419 return; |
417 | 420 |
418 if (listening_status->listening_state == ListeningState::WAITING) | 421 if (listening_status->listening_state == ListeningState::WAITING) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 if (listening_status->last_known_availability == | 469 if (listening_status->last_known_availability == |
467 ScreenAvailability::UNSUPPORTED) { | 470 ScreenAvailability::UNSUPPORTED) { |
468 return; | 471 return; |
469 } | 472 } |
470 | 473 |
471 listening_status->last_known_availability = ScreenAvailability::UNSUPPORTED; | 474 listening_status->last_known_availability = ScreenAvailability::UNSUPPORTED; |
472 | 475 |
473 const blink::WebString& not_supported_error = blink::WebString::fromUTF8( | 476 const blink::WebString& not_supported_error = blink::WebString::fromUTF8( |
474 "getAvailability() isn't supported at the moment. It can be due to " | 477 "getAvailability() isn't supported at the moment. It can be due to " |
475 "a permanent or temporary system limitation. It is recommended to " | 478 "a permanent or temporary system limitation. It is recommended to " |
476 "try to blindly start a session in that case."); | 479 "try to blindly start a presentation in that case."); |
477 | 480 |
478 std::set<AvailabilityListener*> modified_listeners; | 481 std::set<AvailabilityListener*> modified_listeners; |
479 for (auto& listener : availability_set_) { | 482 for (auto& listener : availability_set_) { |
480 if (!base::ContainsValue(listener->urls, url)) | 483 if (!base::ContainsValue(listener->urls, url)) |
481 continue; | 484 continue; |
482 | 485 |
483 // ScreenAvailabilityNotSupported should be a browser side setting, which | 486 // ScreenAvailabilityNotSupported should be a browser side setting, which |
484 // means all urls in PresentationAvailability should report NotSupported. | 487 // means all urls in PresentationAvailability should report NotSupported. |
485 // It is not possible to change listening status from Available or | 488 // It is not possible to change listening status from Available or |
486 // Unavailable to NotSupported. No need to update observer. | 489 // Unavailable to NotSupported. No need to update observer. |
(...skipping 12 matching lines...) Expand all Loading... |
499 for (const auto& availability_url : listener->urls) | 502 for (const auto& availability_url : listener->urls) |
500 MaybeStopListeningToURL(availability_url); | 503 MaybeStopListeningToURL(availability_url); |
501 | 504 |
502 modified_listeners.insert(listener.get()); | 505 modified_listeners.insert(listener.get()); |
503 } | 506 } |
504 | 507 |
505 for (auto* listener : modified_listeners) | 508 for (auto* listener : modified_listeners) |
506 TryRemoveAvailabilityListener(listener); | 509 TryRemoveAvailabilityListener(listener); |
507 } | 510 } |
508 | 511 |
509 void PresentationDispatcher::OnDefaultSessionStarted( | 512 void PresentationDispatcher::OnDefaultPresentationStarted( |
510 const PresentationSessionInfo& session_info) { | 513 const PresentationInfo& presentation_info) { |
511 if (!controller_) | 514 if (!controller_) |
512 return; | 515 return; |
513 | 516 |
514 auto* connection = | 517 auto* connection = |
515 controller_->didStartDefaultSession(blink::WebPresentationSessionInfo( | 518 controller_->didStartDefaultPresentation(blink::WebPresentationInfo( |
516 session_info.presentation_url, | 519 presentation_info.presentation_url, |
517 blink::WebString::fromUTF8(session_info.presentation_id))); | 520 blink::WebString::fromUTF8(presentation_info.presentation_id))); |
518 | 521 |
519 if (connection) { | 522 if (connection) { |
520 SetControllerConnection(session_info, connection); | 523 SetControllerConnection(presentation_info, connection); |
521 // Change blink connection state to 'connected' before listening to | 524 // Change blink connection state to 'connected' before listening to |
522 // connection message. Remove ListenForConnectionMessage() after | 525 // connection message. Remove ListenForConnectionMessage() after |
523 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send | 526 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send |
524 // message from route to blink connection. | 527 // message from route to blink connection. |
525 presentation_service_->ListenForConnectionMessages(session_info); | 528 presentation_service_->ListenForConnectionMessages(presentation_info); |
526 } | 529 } |
527 } | 530 } |
528 | 531 |
529 void PresentationDispatcher::OnSessionCreated( | 532 void PresentationDispatcher::OnConnectionCreated( |
530 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, | 533 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, |
531 const base::Optional<PresentationSessionInfo>& session_info, | 534 const base::Optional<PresentationInfo>& presentation_info, |
532 const base::Optional<PresentationError>& error) { | 535 const base::Optional<PresentationError>& error) { |
533 DCHECK(callback); | 536 DCHECK(callback); |
534 if (error) { | 537 if (error) { |
535 DCHECK(!session_info); | 538 DCHECK(!presentation_info); |
536 callback->onError(blink::WebPresentationError( | 539 callback->onError(blink::WebPresentationError( |
537 GetWebPresentationErrorType(error->error_type), | 540 GetWebPresentationErrorType(error->error_type), |
538 blink::WebString::fromUTF8(error->message))); | 541 blink::WebString::fromUTF8(error->message))); |
539 return; | 542 return; |
540 } | 543 } |
541 | 544 |
542 DCHECK(session_info); | 545 DCHECK(presentation_info); |
543 callback->onSuccess(blink::WebPresentationSessionInfo( | 546 callback->onSuccess(blink::WebPresentationInfo( |
544 session_info->presentation_url, | 547 presentation_info->presentation_url, |
545 blink::WebString::fromUTF8(session_info->presentation_id))); | 548 blink::WebString::fromUTF8(presentation_info->presentation_id))); |
546 // Change blink connection state to 'connected' before listening to | 549 // Change blink connection state to 'connected' before listening to |
547 // connection message. Remove ListenForConnectionMessage() after | 550 // connection message. Remove ListenForConnectionMessage() after |
548 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send | 551 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send |
549 // message from route to blink connection. | 552 // message from route to blink connection. |
550 SetControllerConnection(session_info.value(), callback->getConnection()); | 553 SetControllerConnection(presentation_info.value(), callback->getConnection()); |
551 presentation_service_->ListenForConnectionMessages(session_info.value()); | 554 presentation_service_->ListenForConnectionMessages(presentation_info.value()); |
552 } | 555 } |
553 | 556 |
554 void PresentationDispatcher::OnReceiverConnectionAvailable( | 557 void PresentationDispatcher::OnReceiverConnectionAvailable( |
555 const PresentationSessionInfo& session_info, | 558 const PresentationInfo& presentation_info, |
556 blink::mojom::PresentationConnectionPtr controller_connection_ptr, | 559 blink::mojom::PresentationConnectionPtr controller_connection_ptr, |
557 blink::mojom::PresentationConnectionRequest receiver_connection_request) { | 560 blink::mojom::PresentationConnectionRequest receiver_connection_request) { |
558 DCHECK(receiver_); | 561 DCHECK(receiver_); |
559 | 562 |
560 // Bind receiver_connection_proxy with PresentationConnection in receiver | 563 // Bind receiver_connection_proxy with PresentationConnection in receiver |
561 // page. | 564 // page. |
562 auto* connection = receiver_->onReceiverConnectionAvailable( | 565 auto* connection = |
563 blink::WebPresentationSessionInfo( | 566 receiver_->onReceiverConnectionAvailable(blink::WebPresentationInfo( |
564 session_info.presentation_url, | 567 presentation_info.presentation_url, |
565 blink::WebString::fromUTF8(session_info.presentation_id))); | 568 blink::WebString::fromUTF8(presentation_info.presentation_id))); |
566 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection); | 569 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection); |
567 connection->bindProxy(base::WrapUnique(receiver_connection_proxy)); | 570 connection->bindProxy(base::WrapUnique(receiver_connection_proxy)); |
568 | 571 |
569 receiver_connection_proxy->Bind(std::move(receiver_connection_request)); | 572 receiver_connection_proxy->Bind(std::move(receiver_connection_request)); |
570 receiver_connection_proxy->BindControllerConnection( | 573 receiver_connection_proxy->BindControllerConnection( |
571 std::move(controller_connection_ptr)); | 574 std::move(controller_connection_ptr)); |
572 } | 575 } |
573 | 576 |
574 void PresentationDispatcher::OnConnectionStateChanged( | 577 void PresentationDispatcher::OnConnectionStateChanged( |
575 const PresentationSessionInfo& session_info, | 578 const PresentationInfo& presentation_info, |
576 PresentationConnectionState state) { | 579 PresentationConnectionState state) { |
577 if (!controller_) | 580 if (!controller_) |
578 return; | 581 return; |
579 | 582 |
580 controller_->didChangeSessionState( | 583 controller_->didChangeConnectionState( |
581 blink::WebPresentationSessionInfo( | 584 blink::WebPresentationInfo( |
582 session_info.presentation_url, | 585 presentation_info.presentation_url, |
583 blink::WebString::fromUTF8(session_info.presentation_id)), | 586 blink::WebString::fromUTF8(presentation_info.presentation_id)), |
584 GetWebPresentationConnectionState(state)); | 587 GetWebPresentationConnectionState(state)); |
585 } | 588 } |
586 | 589 |
587 void PresentationDispatcher::OnConnectionClosed( | 590 void PresentationDispatcher::OnConnectionClosed( |
588 const PresentationSessionInfo& session_info, | 591 const PresentationInfo& presentation_info, |
589 PresentationConnectionCloseReason reason, | 592 PresentationConnectionCloseReason reason, |
590 const std::string& message) { | 593 const std::string& message) { |
591 if (!controller_) | 594 if (!controller_) |
592 return; | 595 return; |
593 | 596 |
594 controller_->didCloseConnection( | 597 controller_->didCloseConnection( |
595 blink::WebPresentationSessionInfo( | 598 blink::WebPresentationInfo( |
596 session_info.presentation_url, | 599 presentation_info.presentation_url, |
597 blink::WebString::fromUTF8(session_info.presentation_id)), | 600 blink::WebString::fromUTF8(presentation_info.presentation_id)), |
598 GetWebPresentationConnectionCloseReason(reason), | 601 GetWebPresentationConnectionCloseReason(reason), |
599 blink::WebString::fromUTF8(message)); | 602 blink::WebString::fromUTF8(message)); |
600 } | 603 } |
601 | 604 |
602 void PresentationDispatcher::OnConnectionMessagesReceived( | 605 void PresentationDispatcher::OnConnectionMessagesReceived( |
603 const PresentationSessionInfo& session_info, | 606 const PresentationInfo& presentation_info, |
604 std::vector<PresentationConnectionMessage> messages) { | 607 std::vector<PresentationConnectionMessage> messages) { |
605 if (!controller_) | 608 if (!controller_) |
606 return; | 609 return; |
607 | 610 |
608 for (size_t i = 0; i < messages.size(); ++i) { | 611 for (size_t i = 0; i < messages.size(); ++i) { |
609 // Note: Passing batches of messages to the Blink layer would be more | 612 // Note: Passing batches of messages to the Blink layer would be more |
610 // efficient. | 613 // efficient. |
611 auto web_session_info = blink::WebPresentationSessionInfo( | 614 auto web_presentation_info = blink::WebPresentationInfo( |
612 session_info.presentation_url, | 615 presentation_info.presentation_url, |
613 blink::WebString::fromUTF8(session_info.presentation_id)); | 616 blink::WebString::fromUTF8(presentation_info.presentation_id)); |
614 | 617 |
615 if (messages[i].is_binary()) { | 618 if (messages[i].is_binary()) { |
616 controller_->didReceiveSessionBinaryMessage(web_session_info, | 619 controller_->didReceiveConnectionBinaryMessage( |
617 &(messages[i].data->front()), | 620 web_presentation_info, &(messages[i].data->front()), |
618 messages[i].data->size()); | 621 messages[i].data->size()); |
619 } else { | 622 } else { |
620 DCHECK(messages[i].message); | 623 DCHECK(messages[i].message); |
621 controller_->didReceiveSessionTextMessage( | 624 controller_->didReceiveConnectionTextMessage( |
622 web_session_info, blink::WebString::fromUTF8(*messages[i].message)); | 625 web_presentation_info, |
| 626 blink::WebString::fromUTF8(*messages[i].message)); |
623 } | 627 } |
624 } | 628 } |
625 } | 629 } |
626 | 630 |
627 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 631 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
628 if (presentation_service_.get()) | 632 if (presentation_service_.get()) |
629 return; | 633 return; |
630 | 634 |
631 render_frame()->GetRemoteInterfaces()->GetInterface(&presentation_service_); | 635 render_frame()->GetRemoteInterfaces()->GetInterface(&presentation_service_); |
632 presentation_service_->SetClient(binding_.CreateInterfacePtrAndBind()); | 636 presentation_service_->SetClient(binding_.CreateInterfacePtrAndBind()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 auto screen_availability = | 729 auto screen_availability = |
726 status ? status->last_known_availability : ScreenAvailability::UNKNOWN; | 730 status ? status->last_known_availability : ScreenAvailability::UNKNOWN; |
727 current_availability = | 731 current_availability = |
728 std::max(current_availability, static_cast<int>(screen_availability)); | 732 std::max(current_availability, static_cast<int>(screen_availability)); |
729 } | 733 } |
730 | 734 |
731 return static_cast<ScreenAvailability>(current_availability); | 735 return static_cast<ScreenAvailability>(current_availability); |
732 } | 736 } |
733 | 737 |
734 PresentationDispatcher::SendMessageRequest::SendMessageRequest( | 738 PresentationDispatcher::SendMessageRequest::SendMessageRequest( |
735 const PresentationSessionInfo& session_info, | 739 const PresentationInfo& presentation_info, |
736 PresentationConnectionMessage connection_message, | 740 PresentationConnectionMessage connection_message, |
737 const blink::WebPresentationConnectionProxy* connection_proxy) | 741 const blink::WebPresentationConnectionProxy* connection_proxy) |
738 : session_info(session_info), | 742 : presentation_info(presentation_info), |
739 message(std::move(connection_message)), | 743 message(std::move(connection_message)), |
740 connection_proxy(connection_proxy) {} | 744 connection_proxy(connection_proxy) {} |
741 | 745 |
742 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} | 746 PresentationDispatcher::SendMessageRequest::~SendMessageRequest() {} |
743 | 747 |
744 // static | 748 // static |
745 std::unique_ptr<PresentationDispatcher::SendMessageRequest> | 749 std::unique_ptr<PresentationDispatcher::SendMessageRequest> |
746 PresentationDispatcher::CreateSendTextMessageRequest( | 750 PresentationDispatcher::CreateSendTextMessageRequest( |
747 const blink::WebURL& presentationUrl, | 751 const blink::WebURL& presentationUrl, |
748 const blink::WebString& presentationId, | 752 const blink::WebString& presentationId, |
749 const blink::WebString& message, | 753 const blink::WebString& message, |
750 const blink::WebPresentationConnectionProxy* connection_proxy) { | 754 const blink::WebPresentationConnectionProxy* connection_proxy) { |
751 PresentationSessionInfo session_info(GURL(presentationUrl), | 755 PresentationInfo presentation_info(GURL(presentationUrl), |
752 presentationId.utf8()); | 756 presentationId.utf8()); |
753 | 757 |
754 return base::MakeUnique<SendMessageRequest>( | 758 return base::MakeUnique<SendMessageRequest>( |
755 session_info, PresentationConnectionMessage(message.utf8()), | 759 presentation_info, PresentationConnectionMessage(message.utf8()), |
756 connection_proxy); | 760 connection_proxy); |
757 } | 761 } |
758 | 762 |
759 // static | 763 // static |
760 std::unique_ptr<PresentationDispatcher::SendMessageRequest> | 764 std::unique_ptr<PresentationDispatcher::SendMessageRequest> |
761 PresentationDispatcher::CreateSendBinaryMessageRequest( | 765 PresentationDispatcher::CreateSendBinaryMessageRequest( |
762 const blink::WebURL& presentationUrl, | 766 const blink::WebURL& presentationUrl, |
763 const blink::WebString& presentationId, | 767 const blink::WebString& presentationId, |
764 const uint8_t* data, | 768 const uint8_t* data, |
765 size_t length, | 769 size_t length, |
766 const blink::WebPresentationConnectionProxy* connection_proxy) { | 770 const blink::WebPresentationConnectionProxy* connection_proxy) { |
767 PresentationSessionInfo session_info(GURL(presentationUrl), | 771 PresentationInfo presentation_info(GURL(presentationUrl), |
768 presentationId.utf8()); | 772 presentationId.utf8()); |
769 return base::MakeUnique<SendMessageRequest>( | 773 return base::MakeUnique<SendMessageRequest>( |
770 session_info, | 774 presentation_info, |
771 PresentationConnectionMessage(std::vector<uint8_t>(data, data + length)), | 775 PresentationConnectionMessage(std::vector<uint8_t>(data, data + length)), |
772 connection_proxy); | 776 connection_proxy); |
773 } | 777 } |
774 | 778 |
775 PresentationDispatcher::AvailabilityListener::AvailabilityListener( | 779 PresentationDispatcher::AvailabilityListener::AvailabilityListener( |
776 const std::vector<GURL>& availability_urls) | 780 const std::vector<GURL>& availability_urls) |
777 : urls(availability_urls) {} | 781 : urls(availability_urls) {} |
778 | 782 |
779 PresentationDispatcher::AvailabilityListener::~AvailabilityListener() {} | 783 PresentationDispatcher::AvailabilityListener::~AvailabilityListener() {} |
780 | 784 |
781 PresentationDispatcher::ListeningStatus::ListeningStatus( | 785 PresentationDispatcher::ListeningStatus::ListeningStatus( |
782 const GURL& availability_url) | 786 const GURL& availability_url) |
783 : url(availability_url), | 787 : url(availability_url), |
784 last_known_availability(ScreenAvailability::UNKNOWN), | 788 last_known_availability(ScreenAvailability::UNKNOWN), |
785 listening_state(ListeningState::INACTIVE) {} | 789 listening_state(ListeningState::INACTIVE) {} |
786 | 790 |
787 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} | 791 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} |
788 | 792 |
789 } // namespace content | 793 } // namespace content |
OLD | NEW |