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 "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/presentation/presentation_service.mojom.h" | 8 #include "content/common/presentation/presentation_service.mojom.h" |
9 #include "content/public/common/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 125 // OnSessionCreated() is called. |callback| needs to be alive and also needs |
126 // to be destroyed so we transfer its ownership to the mojo callback. | 126 // to be destroyed so we transfer its ownership to the mojo callback. |
127 presentation_service_->JoinSession( | 127 presentation_service_->JoinSession( |
128 presentationUrl.utf8(), | 128 presentationUrl.utf8(), |
129 presentationId.utf8(), | 129 presentationId.utf8(), |
130 base::Bind(&PresentationDispatcher::OnSessionCreated, | 130 base::Bind(&PresentationDispatcher::OnSessionCreated, |
131 base::Unretained(this), | 131 base::Unretained(this), |
132 base::Owned(callback))); | 132 base::Owned(callback))); |
133 } | 133 } |
134 | 134 |
135 void PresentationDispatcher::sendString( | |
136 const blink::WebString& presentationUrl, | |
137 const blink::WebString& presentationId, | |
138 const blink::WebString& message) { | |
139 presentation::SessionMessage* session_message = | |
whywhat
2015/04/30 15:50:58
We probably should limit the size of the message (
USE s.singapati at gmail.com
2015/05/01 10:30:25
Is it ok to DCHECK the size or just return if size
whywhat
2015/05/01 14:09:08
DCHECK surely won't work since a website is not re
USE s.singapati at gmail.com
2015/05/04 16:40:28
Done.
| |
140 new presentation::SessionMessage(); | |
141 session_message->presentation_url = presentationUrl.utf8(); | |
142 session_message->presentation_id = presentationId.utf8(); | |
143 session_message->type = presentation::PresentationMessageType:: | |
144 PRESENTATION_MESSAGE_TYPE_TEXT; | |
145 session_message->message = message.utf8(); | |
146 | |
147 message_request_queue_.push(make_linked_ptr(session_message)); | |
148 // Start processing request if only one in the queue. | |
149 if (message_request_queue_.size() == 1) { | |
150 const linked_ptr<presentation::SessionMessage>& request = | |
151 message_request_queue_.front(); | |
152 DoSendMessage(*request); | |
153 } | |
154 } | |
155 | |
156 void PresentationDispatcher::sendArrayBuffer( | |
157 const blink::WebString& presentationUrl, | |
158 const blink::WebString& presentationId, | |
159 const uint8* data, | |
160 size_t length) { | |
161 DCHECK(data); | |
whywhat
2015/04/30 15:50:58
Ditto
USE s.singapati at gmail.com
2015/05/04 16:40:28
Done.
| |
162 const std::vector<uint8> vector(data, data + length); | |
163 presentation::SessionMessage* session_message = | |
164 new presentation::SessionMessage(); | |
165 session_message->presentation_url = presentationUrl.utf8(); | |
166 session_message->presentation_id = presentationId.utf8(); | |
167 session_message->type = presentation::PresentationMessageType:: | |
168 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
169 session_message->data = mojo::Array<uint8>::From(vector); | |
170 | |
171 message_request_queue_.push(make_linked_ptr(session_message)); | |
172 // Start processing request if only one in the queue. | |
173 if (message_request_queue_.size() == 1) { | |
174 const linked_ptr<presentation::SessionMessage>& request = | |
175 message_request_queue_.front(); | |
176 DoSendMessage(*request); | |
177 } | |
178 } | |
179 | |
180 void PresentationDispatcher::DoSendMessage( | |
181 const presentation::SessionMessage& session_message) { | |
182 ConnectToPresentationServiceIfNeeded(); | |
183 | |
184 presentation::SessionMessagePtr message_request( | |
185 presentation::SessionMessage::New()); | |
186 message_request->presentation_url = session_message.presentation_url; | |
187 message_request->presentation_id = session_message.presentation_id; | |
188 message_request->type = session_message.type; | |
189 message_request->message = session_message.message; | |
190 message_request->data = mojo::Array<uint8>::From( | |
191 session_message.data.storage()); | |
192 | |
193 presentation_service_->SendMessage( | |
194 message_request.Pass(), | |
195 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, | |
196 base::Unretained(this))); | |
197 } | |
198 | |
199 void PresentationDispatcher::HandleSendMessageRequests(bool success) { | |
200 // In normal cases, message_request_queue_ should not be empty at this point | |
201 // of time, but when DidCommitProvisionalLoad() is invoked before receiving | |
202 // the callback for previous send mojo call, queue would have been emptied. | |
203 if (message_request_queue_.empty()) | |
204 return; | |
205 | |
206 if (!success) { | |
207 // PresentationServiceImpl is informing that Frame has been detached or | |
208 // navigated away. Invalidate all pending requests. | |
209 MessageRequestQueue empty; | |
210 std::swap(message_request_queue_, empty); | |
211 return; | |
212 } | |
213 | |
214 message_request_queue_.pop(); | |
215 if (!message_request_queue_.empty()) { | |
216 const linked_ptr<presentation::SessionMessage>& request = | |
217 message_request_queue_.front(); | |
218 DoSendMessage(*request); | |
219 } | |
220 } | |
221 | |
135 void PresentationDispatcher::closeSession( | 222 void PresentationDispatcher::closeSession( |
136 const blink::WebString& presentationUrl, | 223 const blink::WebString& presentationUrl, |
137 const blink::WebString& presentationId) { | 224 const blink::WebString& presentationId) { |
138 ConnectToPresentationServiceIfNeeded(); | 225 ConnectToPresentationServiceIfNeeded(); |
139 | 226 |
140 presentation_service_->CloseSession( | 227 presentation_service_->CloseSession( |
141 presentationUrl.utf8(), | 228 presentationUrl.utf8(), |
142 presentationId.utf8()); | 229 presentationId.utf8()); |
143 } | 230 } |
144 | 231 |
145 void PresentationDispatcher::DidChangeDefaultPresentation() { | 232 void PresentationDispatcher::DidChangeDefaultPresentation() { |
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | 233 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); |
147 | 234 |
148 ConnectToPresentationServiceIfNeeded(); | 235 ConnectToPresentationServiceIfNeeded(); |
149 presentation_service_->SetDefaultPresentationURL( | 236 presentation_service_->SetDefaultPresentationURL( |
150 presentation_url.spec(), mojo::String()); | 237 presentation_url.spec(), mojo::String()); |
151 } | 238 } |
152 | 239 |
240 void PresentationDispatcher::DidCommitProvisionalLoad( | |
241 bool is_new_navigation, | |
242 bool is_same_page_navigation) { | |
243 blink::WebFrame* frame = render_frame()->GetWebFrame(); | |
244 // If not top-level navigation. | |
245 if (frame->parent() || is_same_page_navigation) | |
246 return; | |
247 | |
248 // Remove all pending send message requests. | |
249 MessageRequestQueue empty; | |
250 std::swap(message_request_queue_, empty); | |
251 } | |
252 | |
153 void PresentationDispatcher::OnScreenAvailabilityChanged( | 253 void PresentationDispatcher::OnScreenAvailabilityChanged( |
154 const std::string& presentation_url, bool available) { | 254 const std::string& presentation_url, bool available) { |
155 if (!controller_) | 255 if (!controller_) |
156 return; | 256 return; |
157 | 257 |
158 // Reset the callback to get the next event. | 258 // Reset the callback to get the next event. |
159 DoUpdateAvailableChangeWatched(presentation_url, | 259 DoUpdateAvailableChangeWatched(presentation_url, |
160 controller_->isAvailableChangeWatched()); | 260 controller_->isAvailableChangeWatched()); |
161 | 261 |
162 controller_->didChangeAvailability(available); | 262 controller_->didChangeAvailability(available); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 323 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
224 &PresentationDispatcher::OnDefaultSessionStarted, | 324 &PresentationDispatcher::OnDefaultSessionStarted, |
225 base::Unretained(this))); | 325 base::Unretained(this))); |
226 presentation_service_->ListenForSessionStateChange(base::Bind( | 326 presentation_service_->ListenForSessionStateChange(base::Bind( |
227 &PresentationDispatcher::OnSessionStateChange, | 327 &PresentationDispatcher::OnSessionStateChange, |
228 base::Unretained(this))); | 328 base::Unretained(this))); |
229 */ | 329 */ |
230 } | 330 } |
231 | 331 |
232 } // namespace content | 332 } // namespace content |
OLD | NEW |