Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 1084293004: [PresentationAPI] Added on-session-message handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 presentation_service_->ListenForSessionStateChange(base::Bind( 204 presentation_service_->ListenForSessionStateChange(base::Bind(
205 &PresentationDispatcher::OnSessionStateChange, 205 &PresentationDispatcher::OnSessionStateChange,
206 base::Unretained(this))); 206 base::Unretained(this)));
207 207
208 DCHECK(!session_info.is_null()); 208 DCHECK(!session_info.is_null());
209 controller_->didChangeSessionState( 209 controller_->didChangeSessionState(
210 new PresentationSessionClient(session_info.Pass()), 210 new PresentationSessionClient(session_info.Pass()),
211 GetWebPresentationSessionStateFromMojo(session_state)); 211 GetWebPresentationSessionStateFromMojo(session_state));
212 } 212 }
213 213
214 void PresentationDispatcher::OnSessionMessagesReceived(
215 mojo::Array<presentation::SessionMessagePtr> messages) {
216 if (!controller_)
217 return;
218
219 for (size_t i = 0; i < messages.size(); ++i) {
220 if (messages[i]->type ==
221 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT) {
222 controller_->didReceiveSessionTextMessage(
223 new PresentationSessionClient(messages[i]->presentation_url,
224 messages[i]->presentation_id),
225 blink::WebString::fromUTF8(messages[i]->message));
226 } else {
227 // TODO(haibinlu): handle binary message
228 }
229 }
230
231 presentation_service_->ListenForSessionMessages(
232 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived,
233 base::Unretained(this)));
234 }
235
214 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { 236 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
215 if (presentation_service_.get()) 237 if (presentation_service_.get())
216 return; 238 return;
217 239
218 render_frame()->GetServiceRegistry()->ConnectToRemoteService( 240 render_frame()->GetServiceRegistry()->ConnectToRemoteService(
219 &presentation_service_); 241 &presentation_service_);
220 // TODO(imcheng): Uncomment these once they are implemented on the browser 242 // TODO(imcheng): Uncomment these once they are implemented on the browser
221 // side. (crbug.com/459006) 243 // side. (crbug.com/459006)
222 /* 244 /*
223 presentation_service_->ListenForDefaultSessionStart(base::Bind( 245 presentation_service_->ListenForDefaultSessionStart(base::Bind(
224 &PresentationDispatcher::OnDefaultSessionStarted, 246 &PresentationDispatcher::OnDefaultSessionStarted,
225 base::Unretained(this))); 247 base::Unretained(this)));
226 presentation_service_->ListenForSessionStateChange(base::Bind( 248 presentation_service_->ListenForSessionStateChange(base::Bind(
227 &PresentationDispatcher::OnSessionStateChange, 249 &PresentationDispatcher::OnSessionStateChange,
228 base::Unretained(this))); 250 base::Unretained(this)));
251 presentation_service_->ListenForSessionMessages(
252 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived,
253 base::Unretained(this)));
229 */ 254 */
230 } 255 }
231 256
232 } // namespace content 257 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | content/renderer/presentation/presentation_session_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698