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

Side by Side Diff: content/browser/presentation/presentation_service_impl.cc

Issue 1957143002: [OnionSoup] Move persentation_service.mojom from //content to //third_party/WebKit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 21 matching lines...) Expand all
32 32
33 int GetNextRequestSessionId() { 33 int GetNextRequestSessionId() {
34 static int next_request_session_id = 0; 34 static int next_request_session_id = 0;
35 return ++next_request_session_id; 35 return ++next_request_session_id;
36 } 36 }
37 37
38 // Converts a PresentationSessionMessage |input| to a SessionMessage. 38 // Converts a PresentationSessionMessage |input| to a SessionMessage.
39 // |input|: The message to convert. 39 // |input|: The message to convert.
40 // |pass_ownership|: If true, function may reuse strings or buffers from 40 // |pass_ownership|: If true, function may reuse strings or buffers from
41 // |input| without copying. |input| can be freely modified. 41 // |input| without copying. |input| can be freely modified.
42 mojom::SessionMessagePtr ToMojoSessionMessage( 42 blink::mojom::SessionMessagePtr ToMojoSessionMessage(
43 content::PresentationSessionMessage* input, 43 content::PresentationSessionMessage* input,
44 bool pass_ownership) { 44 bool pass_ownership) {
45 DCHECK(input); 45 DCHECK(input);
46 mojom::SessionMessagePtr output(mojom::SessionMessage::New()); 46 blink::mojom::SessionMessagePtr output(blink::mojom::SessionMessage::New());
47 if (input->is_binary()) { 47 if (input->is_binary()) {
48 // binary data 48 // binary data
49 DCHECK(input->data); 49 DCHECK(input->data);
50 output->type = mojom::PresentationMessageType::ARRAY_BUFFER; 50 output->type = blink::mojom::PresentationMessageType::ARRAY_BUFFER;
51 if (pass_ownership) { 51 if (pass_ownership) {
52 output->data.Swap(input->data.get()); 52 output->data.Swap(input->data.get());
53 } else { 53 } else {
54 output->data = mojo::Array<uint8_t>::From(*input->data); 54 output->data = mojo::Array<uint8_t>::From(*input->data);
55 } 55 }
56 } else { 56 } else {
57 // string message 57 // string message
58 output->type = mojom::PresentationMessageType::TEXT; 58 output->type = blink::mojom::PresentationMessageType::TEXT;
59 if (pass_ownership) { 59 if (pass_ownership) {
60 output->message.Swap(&input->message); 60 output->message.Swap(&input->message);
61 } else { 61 } else {
62 output->message = input->message; 62 output->message = input->message;
63 } 63 }
64 } 64 }
65 return output; 65 return output;
66 } 66 }
67 67
68 std::unique_ptr<PresentationSessionMessage> GetPresentationSessionMessage( 68 std::unique_ptr<PresentationSessionMessage> GetPresentationSessionMessage(
69 mojom::SessionMessagePtr input) { 69 blink::mojom::SessionMessagePtr input) {
70 DCHECK(!input.is_null()); 70 DCHECK(!input.is_null());
71 std::unique_ptr<content::PresentationSessionMessage> output; 71 std::unique_ptr<content::PresentationSessionMessage> output;
72 switch (input->type) { 72 switch (input->type) {
73 case mojom::PresentationMessageType::TEXT: { 73 case blink::mojom::PresentationMessageType::TEXT: {
74 DCHECK(!input->message.is_null()); 74 DCHECK(!input->message.is_null());
75 DCHECK(input->data.is_null()); 75 DCHECK(input->data.is_null());
76 // Return null PresentationSessionMessage if size exceeds. 76 // Return null PresentationSessionMessage if size exceeds.
77 if (input->message.size() > content::kMaxPresentationSessionMessageSize) 77 if (input->message.size() > content::kMaxPresentationSessionMessageSize)
78 return output; 78 return output;
79 79
80 output.reset( 80 output.reset(
81 new PresentationSessionMessage(PresentationMessageType::TEXT)); 81 new PresentationSessionMessage(PresentationMessageType::TEXT));
82 input->message.Swap(&output->message); 82 input->message.Swap(&output->message);
83 return output; 83 return output;
84 } 84 }
85 case mojom::PresentationMessageType::ARRAY_BUFFER: { 85 case blink::mojom::PresentationMessageType::ARRAY_BUFFER: {
86 DCHECK(!input->data.is_null()); 86 DCHECK(!input->data.is_null());
87 DCHECK(input->message.is_null()); 87 DCHECK(input->message.is_null());
88 if (input->data.size() > content::kMaxPresentationSessionMessageSize) 88 if (input->data.size() > content::kMaxPresentationSessionMessageSize)
89 return output; 89 return output;
90 90
91 output.reset(new PresentationSessionMessage( 91 output.reset(new PresentationSessionMessage(
92 PresentationMessageType::ARRAY_BUFFER)); 92 PresentationMessageType::ARRAY_BUFFER));
93 output->data.reset(new std::vector<uint8_t>); 93 output->data.reset(new std::vector<uint8_t>);
94 input->data.Swap(output->data.get()); 94 input->data.Swap(output->data.get());
95 return output; 95 return output;
96 } 96 }
97 case mojom::PresentationMessageType::BLOB: { 97 case blink::mojom::PresentationMessageType::BLOB: {
98 DCHECK(!input->data.is_null()); 98 DCHECK(!input->data.is_null());
99 DCHECK(input->message.is_null()); 99 DCHECK(input->message.is_null());
100 if (input->data.size() > content::kMaxPresentationSessionMessageSize) 100 if (input->data.size() > content::kMaxPresentationSessionMessageSize)
101 return output; 101 return output;
102 102
103 output.reset( 103 output.reset(
104 new PresentationSessionMessage(PresentationMessageType::BLOB)); 104 new PresentationSessionMessage(PresentationMessageType::BLOB));
105 output->data.reset(new std::vector<uint8_t>); 105 output->data.reset(new std::vector<uint8_t>);
106 input->data.Swap(output->data.get()); 106 input->data.Swap(output->data.get());
107 return output; 107 return output;
108 } 108 }
109 } 109 }
110 110
111 NOTREACHED() << "Invalid presentation message type " << input->type; 111 NOTREACHED() << "Invalid presentation message type " << input->type;
112 return output; 112 return output;
113 } 113 }
114 114
115 void InvokeNewSessionMojoCallbackWithError( 115 void InvokeNewSessionMojoCallbackWithError(
116 const NewSessionMojoCallback& callback) { 116 const NewSessionMojoCallback& callback) {
117 callback.Run(mojom::PresentationSessionInfoPtr(), 117 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
118 mojom::PresentationError::From(PresentationError( 118 blink::mojom::PresentationError::From(PresentationError(
119 PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 119 PRESENTATION_ERROR_UNKNOWN, "Internal error")));
120 } 120 }
121 121
122 } // namespace 122 } // namespace
123 123
124 PresentationServiceImpl::PresentationServiceImpl( 124 PresentationServiceImpl::PresentationServiceImpl(
125 RenderFrameHost* render_frame_host, 125 RenderFrameHost* render_frame_host,
126 WebContents* web_contents, 126 WebContents* web_contents,
127 PresentationServiceDelegate* delegate) 127 PresentationServiceDelegate* delegate)
128 : WebContentsObserver(web_contents), 128 : WebContentsObserver(web_contents),
(...skipping 13 matching lines...) Expand all
142 } 142 }
143 143
144 PresentationServiceImpl::~PresentationServiceImpl() { 144 PresentationServiceImpl::~PresentationServiceImpl() {
145 if (delegate_) 145 if (delegate_)
146 delegate_->RemoveObserver(render_process_id_, render_frame_id_); 146 delegate_->RemoveObserver(render_process_id_, render_frame_id_);
147 } 147 }
148 148
149 // static 149 // static
150 void PresentationServiceImpl::CreateMojoService( 150 void PresentationServiceImpl::CreateMojoService(
151 RenderFrameHost* render_frame_host, 151 RenderFrameHost* render_frame_host,
152 mojo::InterfaceRequest<mojom::PresentationService> request) { 152 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
153 DVLOG(2) << "CreateMojoService"; 153 DVLOG(2) << "CreateMojoService";
154 WebContents* web_contents = 154 WebContents* web_contents =
155 WebContents::FromRenderFrameHost(render_frame_host); 155 WebContents::FromRenderFrameHost(render_frame_host);
156 DCHECK(web_contents); 156 DCHECK(web_contents);
157 157
158 // This object will be deleted when the RenderFrameHost is about to be 158 // This object will be deleted when the RenderFrameHost is about to be
159 // deleted (RenderFrameDeleted). 159 // deleted (RenderFrameDeleted).
160 PresentationServiceImpl* impl = new PresentationServiceImpl( 160 PresentationServiceImpl* impl = new PresentationServiceImpl(
161 render_frame_host, 161 render_frame_host,
162 web_contents, 162 web_contents,
163 GetContentClient()->browser()->GetPresentationServiceDelegate( 163 GetContentClient()->browser()->GetPresentationServiceDelegate(
164 web_contents)); 164 web_contents));
165 impl->Bind(std::move(request)); 165 impl->Bind(std::move(request));
166 } 166 }
167 167
168 void PresentationServiceImpl::Bind( 168 void PresentationServiceImpl::Bind(
169 mojo::InterfaceRequest<mojom::PresentationService> request) { 169 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
170 binding_.reset( 170 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>(
171 new mojo::Binding<mojom::PresentationService>(this, std::move(request))); 171 this, std::move(request)));
172 } 172 }
173 173
174 void PresentationServiceImpl::SetClient( 174 void PresentationServiceImpl::SetClient(
175 mojom::PresentationServiceClientPtr client) { 175 blink::mojom::PresentationServiceClientPtr client) {
176 DCHECK(!client_.get()); 176 DCHECK(!client_.get());
177 // TODO(imcheng): Set ErrorHandler to listen for errors. 177 // TODO(imcheng): Set ErrorHandler to listen for errors.
178 client_ = std::move(client); 178 client_ = std::move(client);
179 } 179 }
180 180
181 void PresentationServiceImpl::ListenForScreenAvailability( 181 void PresentationServiceImpl::ListenForScreenAvailability(
182 const mojo::String& url) { 182 const mojo::String& url) {
183 DVLOG(2) << "ListenForScreenAvailability " << url; 183 DVLOG(2) << "ListenForScreenAvailability " << url;
184 if (!delegate_) { 184 if (!delegate_) {
185 client_->OnScreenAvailabilityUpdated(url, false); 185 client_->OnScreenAvailabilityUpdated(url, false);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 render_process_id_, render_frame_id_, listener_it->second.get()); 217 render_process_id_, render_frame_id_, listener_it->second.get());
218 screen_availability_listeners_.erase(listener_it); 218 screen_availability_listeners_.erase(listener_it);
219 } 219 }
220 220
221 void PresentationServiceImpl::StartSession( 221 void PresentationServiceImpl::StartSession(
222 const mojo::String& presentation_url, 222 const mojo::String& presentation_url,
223 const NewSessionMojoCallback& callback) { 223 const NewSessionMojoCallback& callback) {
224 DVLOG(2) << "StartSession"; 224 DVLOG(2) << "StartSession";
225 if (!delegate_) { 225 if (!delegate_) {
226 callback.Run( 226 callback.Run(
227 mojom::PresentationSessionInfoPtr(), 227 blink::mojom::PresentationSessionInfoPtr(),
228 mojom::PresentationError::From(PresentationError( 228 blink::mojom::PresentationError::From(PresentationError(
229 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found."))); 229 PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, "No screens found.")));
230 return; 230 return;
231 } 231 }
232 232
233 // There is a StartSession request in progress. To avoid queueing up 233 // There is a StartSession request in progress. To avoid queueing up
234 // requests, the incoming request is rejected. 234 // requests, the incoming request is rejected.
235 if (start_session_request_id_ != kInvalidRequestSessionId) { 235 if (start_session_request_id_ != kInvalidRequestSessionId) {
236 InvokeNewSessionMojoCallbackWithError(callback); 236 InvokeNewSessionMojoCallbackWithError(callback);
237 return; 237 return;
238 } 238 }
239 239
240 start_session_request_id_ = GetNextRequestSessionId(); 240 start_session_request_id_ = GetNextRequestSessionId();
241 pending_start_session_cb_.reset(new NewSessionMojoCallbackWrapper(callback)); 241 pending_start_session_cb_.reset(new NewSessionMojoCallbackWrapper(callback));
242 delegate_->StartSession( 242 delegate_->StartSession(
243 render_process_id_, render_frame_id_, presentation_url, 243 render_process_id_, render_frame_id_, presentation_url,
244 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded, 244 base::Bind(&PresentationServiceImpl::OnStartSessionSucceeded,
245 weak_factory_.GetWeakPtr(), start_session_request_id_), 245 weak_factory_.GetWeakPtr(), start_session_request_id_),
246 base::Bind(&PresentationServiceImpl::OnStartSessionError, 246 base::Bind(&PresentationServiceImpl::OnStartSessionError,
247 weak_factory_.GetWeakPtr(), start_session_request_id_)); 247 weak_factory_.GetWeakPtr(), start_session_request_id_));
248 } 248 }
249 249
250 void PresentationServiceImpl::JoinSession( 250 void PresentationServiceImpl::JoinSession(
251 const mojo::String& presentation_url, 251 const mojo::String& presentation_url,
252 const mojo::String& presentation_id, 252 const mojo::String& presentation_id,
253 const NewSessionMojoCallback& callback) { 253 const NewSessionMojoCallback& callback) {
254 DVLOG(2) << "JoinSession"; 254 DVLOG(2) << "JoinSession";
255 if (!delegate_) { 255 if (!delegate_) {
256 callback.Run(mojom::PresentationSessionInfoPtr(), 256 callback.Run(blink::mojom::PresentationSessionInfoPtr(),
257 mojom::PresentationError::From(PresentationError( 257 blink::mojom::PresentationError::From(PresentationError(
258 PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 258 PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
259 "Error joining route: No matching route"))); 259 "Error joining route: No matching route")));
260 return; 260 return;
261 } 261 }
262 262
263 int request_session_id = RegisterJoinSessionCallback(callback); 263 int request_session_id = RegisterJoinSessionCallback(callback);
264 if (request_session_id == kInvalidRequestSessionId) { 264 if (request_session_id == kInvalidRequestSessionId) {
265 InvokeNewSessionMojoCallbackWithError(callback); 265 InvokeNewSessionMojoCallbackWithError(callback);
266 return; 266 return;
267 } 267 }
(...skipping 30 matching lines...) Expand all
298 } 298 }
299 299
300 void PresentationServiceImpl::OnStartSessionSucceeded( 300 void PresentationServiceImpl::OnStartSessionSucceeded(
301 int request_session_id, 301 int request_session_id,
302 const PresentationSessionInfo& session_info) { 302 const PresentationSessionInfo& session_info) {
303 if (request_session_id != start_session_request_id_) 303 if (request_session_id != start_session_request_id_)
304 return; 304 return;
305 305
306 CHECK(pending_start_session_cb_.get()); 306 CHECK(pending_start_session_cb_.get());
307 pending_start_session_cb_->Run( 307 pending_start_session_cb_->Run(
308 mojom::PresentationSessionInfo::From(session_info), 308 blink::mojom::PresentationSessionInfo::From(session_info),
309 mojom::PresentationErrorPtr()); 309 blink::mojom::PresentationErrorPtr());
310 ListenForConnectionStateChange(session_info); 310 ListenForConnectionStateChange(session_info);
311 pending_start_session_cb_.reset(); 311 pending_start_session_cb_.reset();
312 start_session_request_id_ = kInvalidRequestSessionId; 312 start_session_request_id_ = kInvalidRequestSessionId;
313 } 313 }
314 314
315 void PresentationServiceImpl::OnStartSessionError( 315 void PresentationServiceImpl::OnStartSessionError(
316 int request_session_id, 316 int request_session_id,
317 const PresentationError& error) { 317 const PresentationError& error) {
318 if (request_session_id != start_session_request_id_) 318 if (request_session_id != start_session_request_id_)
319 return; 319 return;
320 320
321 CHECK(pending_start_session_cb_.get()); 321 CHECK(pending_start_session_cb_.get());
322 pending_start_session_cb_->Run(mojom::PresentationSessionInfoPtr(), 322 pending_start_session_cb_->Run(blink::mojom::PresentationSessionInfoPtr(),
323 mojom::PresentationError::From(error)); 323 blink::mojom::PresentationError::From(error));
324 pending_start_session_cb_.reset(); 324 pending_start_session_cb_.reset();
325 start_session_request_id_ = kInvalidRequestSessionId; 325 start_session_request_id_ = kInvalidRequestSessionId;
326 } 326 }
327 327
328 void PresentationServiceImpl::OnJoinSessionSucceeded( 328 void PresentationServiceImpl::OnJoinSessionSucceeded(
329 int request_session_id, 329 int request_session_id,
330 const PresentationSessionInfo& session_info) { 330 const PresentationSessionInfo& session_info) {
331 if (RunAndEraseJoinSessionMojoCallback( 331 if (RunAndEraseJoinSessionMojoCallback(
332 request_session_id, 332 request_session_id,
333 mojom::PresentationSessionInfo::From(session_info), 333 blink::mojom::PresentationSessionInfo::From(session_info),
334 mojom::PresentationErrorPtr())) { 334 blink::mojom::PresentationErrorPtr())) {
335 ListenForConnectionStateChange(session_info); 335 ListenForConnectionStateChange(session_info);
336 } 336 }
337 } 337 }
338 338
339 void PresentationServiceImpl::OnJoinSessionError( 339 void PresentationServiceImpl::OnJoinSessionError(
340 int request_session_id, 340 int request_session_id,
341 const PresentationError& error) { 341 const PresentationError& error) {
342 RunAndEraseJoinSessionMojoCallback(request_session_id, 342 RunAndEraseJoinSessionMojoCallback(
343 mojom::PresentationSessionInfoPtr(), 343 request_session_id, blink::mojom::PresentationSessionInfoPtr(),
344 mojom::PresentationError::From(error)); 344 blink::mojom::PresentationError::From(error));
345 } 345 }
346 346
347 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback( 347 bool PresentationServiceImpl::RunAndEraseJoinSessionMojoCallback(
348 int request_session_id, 348 int request_session_id,
349 mojom::PresentationSessionInfoPtr session, 349 blink::mojom::PresentationSessionInfoPtr session,
350 mojom::PresentationErrorPtr error) { 350 blink::mojom::PresentationErrorPtr error) {
351 auto it = pending_join_session_cbs_.find(request_session_id); 351 auto it = pending_join_session_cbs_.find(request_session_id);
352 if (it == pending_join_session_cbs_.end()) 352 if (it == pending_join_session_cbs_.end())
353 return false; 353 return false;
354 354
355 DCHECK(it->second.get()); 355 DCHECK(it->second.get());
356 it->second->Run(std::move(session), std::move(error)); 356 it->second->Run(std::move(session), std::move(error));
357 pending_join_session_cbs_.erase(it); 357 pending_join_session_cbs_.erase(it);
358 return true; 358 return true;
359 } 359 }
360 360
361 void PresentationServiceImpl::SetDefaultPresentationURL( 361 void PresentationServiceImpl::SetDefaultPresentationURL(
362 const mojo::String& url) { 362 const mojo::String& url) {
363 DVLOG(2) << "SetDefaultPresentationURL"; 363 DVLOG(2) << "SetDefaultPresentationURL";
364 if (!delegate_) 364 if (!delegate_)
365 return; 365 return;
366 366
367 const std::string& new_default_url = url.get(); 367 const std::string& new_default_url = url.get();
368 if (default_presentation_url_ == new_default_url) 368 if (default_presentation_url_ == new_default_url)
369 return; 369 return;
370 370
371 default_presentation_url_ = new_default_url; 371 default_presentation_url_ = new_default_url;
372 delegate_->SetDefaultPresentationUrl( 372 delegate_->SetDefaultPresentationUrl(
373 render_process_id_, render_frame_id_, new_default_url, 373 render_process_id_, render_frame_id_, new_default_url,
374 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 374 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
375 weak_factory_.GetWeakPtr())); 375 weak_factory_.GetWeakPtr()));
376 } 376 }
377 377
378 void PresentationServiceImpl::SendSessionMessage( 378 void PresentationServiceImpl::SendSessionMessage(
379 mojom::PresentationSessionInfoPtr session, 379 blink::mojom::PresentationSessionInfoPtr session,
380 mojom::SessionMessagePtr session_message, 380 blink::mojom::SessionMessagePtr session_message,
381 const SendMessageMojoCallback& callback) { 381 const SendMessageMojoCallback& callback) {
382 DVLOG(2) << "SendSessionMessage"; 382 DVLOG(2) << "SendSessionMessage";
383 DCHECK(!session_message.is_null()); 383 DCHECK(!session_message.is_null());
384 // send_message_callback_ should be null by now, otherwise resetting of 384 // send_message_callback_ should be null by now, otherwise resetting of
385 // send_message_callback_ with new callback will drop the old callback. 385 // send_message_callback_ with new callback will drop the old callback.
386 if (!delegate_ || send_message_callback_) { 386 if (!delegate_ || send_message_callback_) {
387 callback.Run(false); 387 callback.Run(false);
388 return; 388 return;
389 } 389 }
390 390
(...skipping 30 matching lines...) Expand all
421 if (delegate_) 421 if (delegate_)
422 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id); 422 delegate_->Terminate(render_process_id_, render_frame_id_, presentation_id);
423 } 423 }
424 424
425 void PresentationServiceImpl::OnConnectionStateChanged( 425 void PresentationServiceImpl::OnConnectionStateChanged(
426 const PresentationSessionInfo& connection, 426 const PresentationSessionInfo& connection,
427 const PresentationConnectionStateChangeInfo& info) { 427 const PresentationConnectionStateChangeInfo& info) {
428 DCHECK(client_.get()); 428 DCHECK(client_.get());
429 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) { 429 if (info.state == PRESENTATION_CONNECTION_STATE_CLOSED) {
430 client_->OnConnectionClosed( 430 client_->OnConnectionClosed(
431 mojom::PresentationSessionInfo::From(connection), 431 blink::mojom::PresentationSessionInfo::From(connection),
432 PresentationConnectionCloseReasonToMojo(info.close_reason), 432 content::PresentationConnectionCloseReasonToMojo(info.close_reason),
433 info.message); 433 info.message);
434 } else { 434 } else {
435 client_->OnConnectionStateChanged( 435 client_->OnConnectionStateChanged(
436 mojom::PresentationSessionInfo::From(connection), 436 blink::mojom::PresentationSessionInfo::From(connection),
437 PresentationConnectionStateToMojo(info.state)); 437 PresentationConnectionStateToMojo(info.state));
438 } 438 }
439 } 439 }
440 440
441 bool PresentationServiceImpl::FrameMatches( 441 bool PresentationServiceImpl::FrameMatches(
442 content::RenderFrameHost* render_frame_host) const { 442 content::RenderFrameHost* render_frame_host) const {
443 if (!render_frame_host) 443 if (!render_frame_host)
444 return false; 444 return false;
445 445
446 return render_frame_host->GetProcess()->GetID() == render_process_id_ && 446 return render_frame_host->GetProcess()->GetID() == render_process_id_ &&
447 render_frame_host->GetRoutingID() == render_frame_id_; 447 render_frame_host->GetRoutingID() == render_frame_id_;
448 } 448 }
449 449
450 void PresentationServiceImpl::ListenForSessionMessages( 450 void PresentationServiceImpl::ListenForSessionMessages(
451 mojom::PresentationSessionInfoPtr session) { 451 blink::mojom::PresentationSessionInfoPtr session) {
452 DVLOG(2) << "ListenForSessionMessages"; 452 DVLOG(2) << "ListenForSessionMessages";
453 if (!delegate_) 453 if (!delegate_)
454 return; 454 return;
455 455
456 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 456 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
457 delegate_->ListenForSessionMessages( 457 delegate_->ListenForSessionMessages(
458 render_process_id_, render_frame_id_, session_info, 458 render_process_id_, render_frame_id_, session_info,
459 base::Bind(&PresentationServiceImpl::OnSessionMessages, 459 base::Bind(&PresentationServiceImpl::OnSessionMessages,
460 weak_factory_.GetWeakPtr(), session_info)); 460 weak_factory_.GetWeakPtr(), session_info));
461 } 461 }
462 462
463 void PresentationServiceImpl::OnSessionMessages( 463 void PresentationServiceImpl::OnSessionMessages(
464 const PresentationSessionInfo& session, 464 const PresentationSessionInfo& session,
465 const ScopedVector<PresentationSessionMessage>& messages, 465 const ScopedVector<PresentationSessionMessage>& messages,
466 bool pass_ownership) { 466 bool pass_ownership) {
467 DCHECK(client_); 467 DCHECK(client_);
468 468
469 DVLOG(2) << "OnSessionMessages"; 469 DVLOG(2) << "OnSessionMessages";
470 mojo::Array<mojom::SessionMessagePtr> mojoMessages(messages.size()); 470 mojo::Array<blink::mojom::SessionMessagePtr> mojoMessages(messages.size());
471 for (size_t i = 0; i < messages.size(); ++i) 471 for (size_t i = 0; i < messages.size(); ++i)
472 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership); 472 mojoMessages[i] = ToMojoSessionMessage(messages[i], pass_ownership);
473 473
474 client_->OnSessionMessagesReceived( 474 client_->OnSessionMessagesReceived(
475 mojom::PresentationSessionInfo::From(session), std::move(mojoMessages)); 475 blink::mojom::PresentationSessionInfo::From(session),
476 std::move(mojoMessages));
476 } 477 }
477 478
478 void PresentationServiceImpl::DidNavigateAnyFrame( 479 void PresentationServiceImpl::DidNavigateAnyFrame(
479 content::RenderFrameHost* render_frame_host, 480 content::RenderFrameHost* render_frame_host,
480 const content::LoadCommittedDetails& details, 481 const content::LoadCommittedDetails& details,
481 const content::FrameNavigateParams& params) { 482 const content::FrameNavigateParams& params) {
482 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 483 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
483 if (!FrameMatches(render_frame_host)) 484 if (!FrameMatches(render_frame_host))
484 return; 485 return;
485 486
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 default_presentation_url_.clear(); 527 default_presentation_url_.clear();
527 528
528 screen_availability_listeners_.clear(); 529 screen_availability_listeners_.clear();
529 530
530 start_session_request_id_ = kInvalidRequestSessionId; 531 start_session_request_id_ = kInvalidRequestSessionId;
531 pending_start_session_cb_.reset(); 532 pending_start_session_cb_.reset();
532 533
533 pending_join_session_cbs_.clear(); 534 pending_join_session_cbs_.clear();
534 535
535 if (on_session_messages_callback_.get()) { 536 if (on_session_messages_callback_.get()) {
536 on_session_messages_callback_->Run(mojo::Array<mojom::SessionMessagePtr>()); 537 on_session_messages_callback_->Run(
538 mojo::Array<blink::mojom::SessionMessagePtr>());
537 on_session_messages_callback_.reset(); 539 on_session_messages_callback_.reset();
538 } 540 }
539 541
540 if (send_message_callback_) { 542 if (send_message_callback_) {
541 // Run the callback with false, indicating the renderer to stop sending 543 // Run the callback with false, indicating the renderer to stop sending
542 // the requests and invalidate all pending requests. 544 // the requests and invalidate all pending requests.
543 send_message_callback_->Run(false); 545 send_message_callback_->Run(false);
544 send_message_callback_.reset(); 546 send_message_callback_.reset();
545 } 547 }
546 } 548 }
547 549
548 void PresentationServiceImpl::OnDelegateDestroyed() { 550 void PresentationServiceImpl::OnDelegateDestroyed() {
549 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed"; 551 DVLOG(2) << "PresentationServiceImpl::OnDelegateDestroyed";
550 delegate_ = nullptr; 552 delegate_ = nullptr;
551 Reset(); 553 Reset();
552 } 554 }
553 555
554 void PresentationServiceImpl::OnDefaultPresentationStarted( 556 void PresentationServiceImpl::OnDefaultPresentationStarted(
555 const PresentationSessionInfo& connection) { 557 const PresentationSessionInfo& connection) {
556 DCHECK(client_.get()); 558 DCHECK(client_.get());
557 client_->OnDefaultSessionStarted( 559 client_->OnDefaultSessionStarted(
558 mojom::PresentationSessionInfo::From(connection)); 560 blink::mojom::PresentationSessionInfo::From(connection));
559 ListenForConnectionStateChange(connection); 561 ListenForConnectionStateChange(connection);
560 } 562 }
561 563
562 PresentationServiceImpl::ScreenAvailabilityListenerImpl 564 PresentationServiceImpl::ScreenAvailabilityListenerImpl
563 ::ScreenAvailabilityListenerImpl( 565 ::ScreenAvailabilityListenerImpl(
564 const std::string& availability_url, 566 const std::string& availability_url,
565 PresentationServiceImpl* service) 567 PresentationServiceImpl* service)
566 : availability_url_(availability_url), 568 : availability_url_(availability_url),
567 service_(service) { 569 service_(service) {
568 DCHECK(service_); 570 DCHECK(service_);
(...skipping 24 matching lines...) Expand all
593 : callback_(callback) { 595 : callback_(callback) {
594 } 596 }
595 597
596 PresentationServiceImpl::NewSessionMojoCallbackWrapper 598 PresentationServiceImpl::NewSessionMojoCallbackWrapper
597 ::~NewSessionMojoCallbackWrapper() { 599 ::~NewSessionMojoCallbackWrapper() {
598 if (!callback_.is_null()) 600 if (!callback_.is_null())
599 InvokeNewSessionMojoCallbackWithError(callback_); 601 InvokeNewSessionMojoCallbackWithError(callback_);
600 } 602 }
601 603
602 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run( 604 void PresentationServiceImpl::NewSessionMojoCallbackWrapper::Run(
603 mojom::PresentationSessionInfoPtr session, 605 blink::mojom::PresentationSessionInfoPtr session,
604 mojom::PresentationErrorPtr error) { 606 blink::mojom::PresentationErrorPtr error) {
605 DCHECK(!callback_.is_null()); 607 DCHECK(!callback_.is_null());
606 callback_.Run(std::move(session), std::move(error)); 608 callback_.Run(std::move(session), std::move(error));
607 callback_.reset(); 609 callback_.reset();
608 } 610 }
609 611
610 } // namespace content 612 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698