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 <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "content/public/common/presentation_constants.h" | 13 #include "content/public/common/presentation_constants.h" |
14 #include "content/public/renderer/render_frame.h" | 14 #include "content/public/renderer/render_frame.h" |
15 #include "content/renderer/presentation/presentation_connection_client.h" | 15 #include "content/renderer/presentation/presentation_connection_client.h" |
16 #include "content/renderer/presentation/presentation_connection_proxy.h" | |
16 #include "services/service_manager/public/cpp/interface_provider.h" | 17 #include "services/service_manager/public/cpp/interface_provider.h" |
17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
18 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" | 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" |
21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" | 22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" |
22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" | 23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" |
23 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" | 24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nReceiver.h" |
24 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" | 25 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" |
25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 133 |
133 // The dispatcher owns the service so |this| will be valid when | 134 // The dispatcher owns the service so |this| will be valid when |
134 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 135 // OnSessionCreated() is called. |callback| needs to be alive and also needs |
135 // to be destroyed so we transfer its ownership to the mojo callback. | 136 // to be destroyed so we transfer its ownership to the mojo callback. |
136 presentation_service_->JoinSession( | 137 presentation_service_->JoinSession( |
137 urls, presentationId.utf8(), | 138 urls, presentationId.utf8(), |
138 base::Bind(&PresentationDispatcher::OnSessionCreated, | 139 base::Bind(&PresentationDispatcher::OnSessionCreated, |
139 base::Unretained(this), base::Owned(callback))); | 140 base::Unretained(this), base::Owned(callback))); |
140 } | 141 } |
141 | 142 |
142 void PresentationDispatcher::sendString(const blink::WebURL& presentationUrl, | 143 void PresentationDispatcher::sendString( |
143 const blink::WebString& presentationId, | 144 const blink::WebURL& presentationUrl, |
144 const blink::WebString& message) { | 145 const blink::WebString& presentationId, |
146 const blink::WebString& message, | |
147 const blink::WebPresentationConnectionProxy* connection_proxy) { | |
145 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { | 148 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { |
146 // TODO(crbug.com/459008): Limit the size of individual messages to 64k | 149 // TODO(crbug.com/459008): Limit the size of individual messages to 64k |
147 // for now. Consider throwing DOMException or splitting bigger messages | 150 // for now. Consider throwing DOMException or splitting bigger messages |
148 // into smaller chunks later. | 151 // into smaller chunks later. |
149 LOG(WARNING) << "message size exceeded limit!"; | 152 LOG(WARNING) << "message size exceeded limit!"; |
150 return; | 153 return; |
151 } | 154 } |
152 | 155 |
153 message_request_queue_.push(base::WrapUnique( | 156 message_request_queue_.push(base::WrapUnique( |
154 CreateSendTextMessageRequest(presentationUrl, presentationId, message))); | 157 CreateSendTextMessageRequest(presentationUrl, presentationId, message))); |
155 // Start processing request if only one in the queue. | 158 // Start processing request if only one in the queue. |
156 if (message_request_queue_.size() == 1) | 159 if (message_request_queue_.size() == 1) |
157 DoSendMessage(message_request_queue_.front().get()); | 160 DoSendMessage(message_request_queue_.front().get(), connection_proxy); |
158 } | 161 } |
159 | 162 |
160 void PresentationDispatcher::sendArrayBuffer( | 163 void PresentationDispatcher::sendArrayBuffer( |
161 const blink::WebURL& presentationUrl, | 164 const blink::WebURL& presentationUrl, |
162 const blink::WebString& presentationId, | 165 const blink::WebString& presentationId, |
163 const uint8_t* data, | 166 const uint8_t* data, |
164 size_t length) { | 167 size_t length, |
168 const blink::WebPresentationConnectionProxy* connection_proxy) { | |
165 DCHECK(data); | 169 DCHECK(data); |
166 if (length > kMaxPresentationSessionMessageSize) { | 170 if (length > kMaxPresentationSessionMessageSize) { |
167 // TODO(crbug.com/459008): Same as in sendString(). | 171 // TODO(crbug.com/459008): Same as in sendString(). |
168 LOG(WARNING) << "data size exceeded limit!"; | 172 LOG(WARNING) << "data size exceeded limit!"; |
169 return; | 173 return; |
170 } | 174 } |
171 | 175 |
172 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( | 176 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( |
173 presentationUrl, presentationId, | 177 presentationUrl, presentationId, |
174 blink::mojom::PresentationMessageType::ARRAY_BUFFER, data, length))); | 178 blink::mojom::PresentationMessageType::ARRAY_BUFFER, data, length))); |
175 // Start processing request if only one in the queue. | 179 // Start processing request if only one in the queue. |
176 if (message_request_queue_.size() == 1) | 180 if (message_request_queue_.size() == 1) |
177 DoSendMessage(message_request_queue_.front().get()); | 181 DoSendMessage(message_request_queue_.front().get(), connection_proxy); |
178 } | 182 } |
179 | 183 |
180 void PresentationDispatcher::sendBlobData( | 184 void PresentationDispatcher::sendBlobData( |
181 const blink::WebURL& presentationUrl, | 185 const blink::WebURL& presentationUrl, |
182 const blink::WebString& presentationId, | 186 const blink::WebString& presentationId, |
183 const uint8_t* data, | 187 const uint8_t* data, |
184 size_t length) { | 188 size_t length, |
189 const blink::WebPresentationConnectionProxy* connection_proxy) { | |
185 DCHECK(data); | 190 DCHECK(data); |
186 if (length > kMaxPresentationSessionMessageSize) { | 191 if (length > kMaxPresentationSessionMessageSize) { |
187 // TODO(crbug.com/459008): Same as in sendString(). | 192 // TODO(crbug.com/459008): Same as in sendString(). |
188 LOG(WARNING) << "data size exceeded limit!"; | 193 LOG(WARNING) << "data size exceeded limit!"; |
189 return; | 194 return; |
190 } | 195 } |
191 | 196 |
192 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( | 197 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( |
193 presentationUrl, presentationId, | 198 presentationUrl, presentationId, |
194 blink::mojom::PresentationMessageType::BLOB, data, length))); | 199 blink::mojom::PresentationMessageType::BLOB, data, length))); |
195 // Start processing request if only one in the queue. | 200 // Start processing request if only one in the queue. |
196 if (message_request_queue_.size() == 1) | 201 if (message_request_queue_.size() == 1) |
197 DoSendMessage(message_request_queue_.front().get()); | 202 DoSendMessage(message_request_queue_.front().get(), connection_proxy); |
198 } | 203 } |
199 | 204 |
200 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { | 205 void PresentationDispatcher::DoSendMessage( |
206 SendMessageRequest* request, | |
207 const blink::WebPresentationConnectionProxy* connection_proxy) { | |
201 ConnectToPresentationServiceIfNeeded(); | 208 ConnectToPresentationServiceIfNeeded(); |
202 | 209 |
203 presentation_service_->SendSessionMessage( | 210 presentation_service_->SendSessionMessage( |
204 std::move(request->session_info), std::move(request->message), | 211 std::move(request->session_info), std::move(request->message), |
205 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, | 212 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, |
206 base::Unretained(this))); | 213 base::Unretained(this), nullptr)); |
mark a. foltz
2016/12/02 22:44:00
It looks like connection_proxy is passed around to
zhaobin
2016/12/05 20:28:17
No, it is not used in this patch (proxy is used in
mark a. foltz
2016/12/05 22:07:29
Can you add a TODO here to set this with a followu
zhaobin
2016/12/08 02:41:10
Done.
| |
207 } | 214 } |
208 | 215 |
209 void PresentationDispatcher::HandleSendMessageRequests(bool success) { | 216 void PresentationDispatcher::HandleSendMessageRequests( |
217 const blink::WebPresentationConnectionProxy* connection_proxy, | |
218 bool success) { | |
210 // In normal cases, message_request_queue_ should not be empty at this point | 219 // In normal cases, message_request_queue_ should not be empty at this point |
211 // of time, but when DidCommitProvisionalLoad() is invoked before receiving | 220 // of time, but when DidCommitProvisionalLoad() is invoked before receiving |
212 // the callback for previous send mojo call, queue would have been emptied. | 221 // the callback for previous send mojo call, queue would have been emptied. |
213 if (message_request_queue_.empty()) | 222 if (message_request_queue_.empty()) |
214 return; | 223 return; |
215 | 224 |
216 if (!success) { | 225 if (!success) { |
217 // PresentationServiceImpl is informing that Frame has been detached or | 226 // PresentationServiceImpl is informing that Frame has been detached or |
218 // navigated away. Invalidate all pending requests. | 227 // navigated away. Invalidate all pending requests. |
219 MessageRequestQueue empty; | 228 MessageRequestQueue empty; |
220 std::swap(message_request_queue_, empty); | 229 std::swap(message_request_queue_, empty); |
221 return; | 230 return; |
222 } | 231 } |
223 | 232 |
224 message_request_queue_.pop(); | 233 message_request_queue_.pop(); |
225 if (!message_request_queue_.empty()) { | 234 if (!message_request_queue_.empty()) { |
226 DoSendMessage(message_request_queue_.front().get()); | 235 DoSendMessage(message_request_queue_.front().get(), connection_proxy); |
227 } | 236 } |
228 } | 237 } |
229 | 238 |
230 void PresentationDispatcher::closeSession( | 239 void PresentationDispatcher::closeSession( |
231 const blink::WebURL& presentationUrl, | 240 const blink::WebURL& presentationUrl, |
232 const blink::WebString& presentationId) { | 241 const blink::WebString& presentationId) { |
233 ConnectToPresentationServiceIfNeeded(); | 242 ConnectToPresentationServiceIfNeeded(); |
234 presentation_service_->CloseConnection(presentationUrl, | 243 presentation_service_->CloseConnection(presentationUrl, |
235 presentationId.utf8()); | 244 presentationId.utf8()); |
236 } | 245 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 void PresentationDispatcher::OnSessionMessagesReceived( | 448 void PresentationDispatcher::OnSessionMessagesReceived( |
440 blink::mojom::PresentationSessionInfoPtr session_info, | 449 blink::mojom::PresentationSessionInfoPtr session_info, |
441 std::vector<blink::mojom::SessionMessagePtr> messages) { | 450 std::vector<blink::mojom::SessionMessagePtr> messages) { |
442 if (!controller_) | 451 if (!controller_) |
443 return; | 452 return; |
444 | 453 |
445 for (size_t i = 0; i < messages.size(); ++i) { | 454 for (size_t i = 0; i < messages.size(); ++i) { |
446 // Note: Passing batches of messages to the Blink layer would be more | 455 // Note: Passing batches of messages to the Blink layer would be more |
447 // efficient. | 456 // efficient. |
448 std::unique_ptr<PresentationConnectionClient> session_client( | 457 std::unique_ptr<PresentationConnectionClient> session_client( |
449 new PresentationConnectionClient(session_info->url, session_info->id)); | 458 new PresentationConnectionClient(session_info.Clone())); |
450 switch (messages[i]->type) { | 459 switch (messages[i]->type) { |
451 case blink::mojom::PresentationMessageType::TEXT: { | 460 case blink::mojom::PresentationMessageType::TEXT: { |
452 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)? | 461 // TODO(mfoltz): Do we need to DCHECK(messages[i]->message)? |
453 controller_->didReceiveSessionTextMessage( | 462 controller_->didReceiveSessionTextMessage( |
454 session_client.release(), | 463 session_client.release(), |
455 blink::WebString::fromUTF8(messages[i]->message.value())); | 464 blink::WebString::fromUTF8(messages[i]->message.value())); |
456 break; | 465 break; |
457 } | 466 } |
458 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: | 467 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: |
459 case blink::mojom::PresentationMessageType::BLOB: { | 468 case blink::mojom::PresentationMessageType::BLOB: { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 556 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
548 const GURL& availability_url) | 557 const GURL& availability_url) |
549 : url(availability_url), | 558 : url(availability_url), |
550 last_known_availability(false), | 559 last_known_availability(false), |
551 listening_state(ListeningState::INACTIVE) {} | 560 listening_state(ListeningState::INACTIVE) {} |
552 | 561 |
553 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 562 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
554 } | 563 } |
555 | 564 |
556 } // namespace content | 565 } // namespace content |
OLD | NEW |