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 message_request_queue_.push(make_linked_ptr( | |
140 new MessageRequest( | |
141 presentationUrl.utf8(), | |
142 presentationId.utf8(), | |
143 message.utf8()))); | |
144 // Start processing request if only one in the queue. | |
145 if (message_request_queue_.size() == 1) { | |
146 DoSendStringMessage(presentationUrl.utf8(), | |
147 presentationId.utf8(), | |
148 message.utf8()); | |
149 } | |
150 } | |
151 | |
152 void PresentationDispatcher::sendArrayBuffer( | |
153 const blink::WebString& presentationUrl, | |
154 const blink::WebString& presentationId, | |
155 const char* data, | |
156 size_t length) { | |
157 // TODO(s.singapati): Handle ArrayBuffer data. | |
158 } | |
159 | |
160 void PresentationDispatcher::DoSendStringMessage( | |
161 const std::string& presentation_url, | |
162 const std::string& presentation_id, | |
163 const std::string& message) { | |
164 ConnectToPresentationServiceIfNeeded(); | |
165 presentation_service_->SendStringMessage( | |
166 presentation_url, | |
167 presentation_id, | |
168 message, | |
169 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, | |
170 base::Unretained(this))); | |
171 } | |
172 | |
173 void PresentationDispatcher::HandleSendMessageRequests() { | |
174 // In normal cases, message_request_queue_ should not be empty at this point | |
175 // of time, but when FrameWillClose() is invoked before receiving the | |
176 // callback for previous send mojo call, queue would have been emptied. | |
177 if (message_request_queue_.empty()) | |
178 return; | |
179 | |
180 message_request_queue_.pop(); | |
181 if (!message_request_queue_.empty()) { | |
182 const linked_ptr<MessageRequest>& request = message_request_queue_.front(); | |
183 DoSendStringMessage(request->presentation_url, | |
184 request->presentation_id, | |
185 request->message); | |
186 } | |
187 } | |
188 | |
135 void PresentationDispatcher::closeSession( | 189 void PresentationDispatcher::closeSession( |
136 const blink::WebString& presentationUrl, | 190 const blink::WebString& presentationUrl, |
137 const blink::WebString& presentationId) { | 191 const blink::WebString& presentationId) { |
138 ConnectToPresentationServiceIfNeeded(); | 192 ConnectToPresentationServiceIfNeeded(); |
139 | 193 |
140 presentation_service_->CloseSession( | 194 presentation_service_->CloseSession( |
141 presentationUrl.utf8(), | 195 presentationUrl.utf8(), |
142 presentationId.utf8()); | 196 presentationId.utf8()); |
143 } | 197 } |
144 | 198 |
145 void PresentationDispatcher::DidChangeDefaultPresentation() { | 199 void PresentationDispatcher::DidChangeDefaultPresentation() { |
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | 200 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); |
147 | 201 |
148 ConnectToPresentationServiceIfNeeded(); | 202 ConnectToPresentationServiceIfNeeded(); |
149 presentation_service_->SetDefaultPresentationURL( | 203 presentation_service_->SetDefaultPresentationURL( |
150 presentation_url.spec(), mojo::String()); | 204 presentation_url.spec(), mojo::String()); |
151 } | 205 } |
152 | 206 |
207 void PresentationDispatcher::FrameWillClose() { | |
imcheng
2015/04/14 21:29:13
How about overriding DidCommitProvisionalLoad to i
USE s.singapati at gmail.com
2015/04/15 16:09:08
I have tested that FrameWillClose() is always invo
| |
208 // Remove all pending send message requests. | |
209 MessageRequestQueue empty; | |
210 std::swap(message_request_queue_, empty); | |
211 } | |
212 | |
153 void PresentationDispatcher::OnScreenAvailabilityChanged( | 213 void PresentationDispatcher::OnScreenAvailabilityChanged( |
154 const std::string& presentation_url, bool available) { | 214 const std::string& presentation_url, bool available) { |
155 if (!controller_) | 215 if (!controller_) |
156 return; | 216 return; |
157 | 217 |
158 // Reset the callback to get the next event. | 218 // Reset the callback to get the next event. |
159 DoUpdateAvailableChangeWatched(presentation_url, | 219 DoUpdateAvailableChangeWatched(presentation_url, |
160 controller_->isAvailableChangeWatched()); | 220 controller_->isAvailableChangeWatched()); |
161 | 221 |
162 controller_->didChangeAvailability(available); | 222 controller_->didChangeAvailability(available); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 /* | 281 /* |
222 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 282 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
223 &PresentationDispatcher::OnDefaultSessionStarted, | 283 &PresentationDispatcher::OnDefaultSessionStarted, |
224 base::Unretained(this))); | 284 base::Unretained(this))); |
225 presentation_service_->ListenForSessionStateChange(base::Bind( | 285 presentation_service_->ListenForSessionStateChange(base::Bind( |
226 &PresentationDispatcher::OnSessionStateChange, | 286 &PresentationDispatcher::OnSessionStateChange, |
227 base::Unretained(this))); | 287 base::Unretained(this))); |
228 */ | 288 */ |
229 } | 289 } |
230 | 290 |
291 PresentationDispatcher::MessageRequest::MessageRequest( | |
292 const std::string& presentation_url, | |
293 const std::string& presentation_id, | |
294 const std::string& message) | |
295 : presentation_url(presentation_url), | |
296 presentation_id(presentation_id), | |
297 message(message) { | |
298 } | |
299 | |
300 PresentationDispatcher::MessageRequest::~MessageRequest() { | |
301 } | |
302 | |
231 } // namespace content | 303 } // namespace content |
OLD | NEW |