Chromium Code Reviews| 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/browser/presentation/presentation_service_impl.h" | 5 #include "content/browser/presentation/presentation_service_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/presentation/presentation_type_converters.h" | 10 #include "content/browser/presentation/presentation_type_converters.h" |
| 11 #include "content/public/browser/content_browser_client.h" | 11 #include "content/public/browser/content_browser_client.h" |
| 12 #include "content/public/browser/navigation_details.h" | 12 #include "content/public/browser/navigation_details.h" |
| 13 #include "content/public/browser/presentation_session_message.h" | |
| 13 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 17 #include "content/public/common/frame_navigate_params.h" | 18 #include "content/public/common/frame_navigate_params.h" |
| 18 | 19 |
| 20 namespace { | |
| 21 | |
| 22 presentation::SessionMessagePtr ToMojoSessionMessage( | |
|
mark a. foltz
2015/05/01 19:42:07
Add // documentation for this function.
Note that
haibinlu
2015/05/02 00:32:55
Done.
| |
| 23 content::PresentationSessionMessage* input) { | |
|
mark a. foltz
2015/05/01 19:42:07
const content::PresentationSessionMessage& for |in
haibinlu
2015/05/02 00:32:55
cosnt does not work with Swap
| |
| 24 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); | |
| 25 output->presentation_url = input->presentation_url; | |
| 26 output->presentation_id = input->presentation_id; | |
| 27 if (input->is_binary()) { | |
| 28 // binary data | |
| 29 output->type = presentation::PresentationMessageType:: | |
| 30 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
| 31 output->data.Swap(input->data.get()); | |
| 32 } else { | |
| 33 // string message | |
| 34 output->type = | |
| 35 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | |
| 36 output->message.Swap(input->message.get()); | |
| 37 } | |
| 38 return output.Pass(); | |
| 39 } | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 19 namespace content { | 43 namespace content { |
| 20 | 44 |
| 21 PresentationServiceImpl::PresentationServiceImpl( | 45 PresentationServiceImpl::PresentationServiceImpl( |
| 22 RenderFrameHost* render_frame_host, | 46 RenderFrameHost* render_frame_host, |
| 23 WebContents* web_contents, | 47 WebContents* web_contents, |
| 24 PresentationServiceDelegate* delegate) | 48 PresentationServiceDelegate* delegate) |
| 25 : WebContentsObserver(web_contents), | 49 : WebContentsObserver(web_contents), |
| 26 delegate_(delegate), | 50 delegate_(delegate), |
| 27 is_start_session_pending_(false), | 51 is_start_session_pending_(false), |
| 28 next_request_session_id_(0), | 52 next_request_session_id_(0), |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 content::RenderFrameHost* render_frame_host) const { | 352 content::RenderFrameHost* render_frame_host) const { |
| 329 if (!render_frame_host) | 353 if (!render_frame_host) |
| 330 return false; | 354 return false; |
| 331 | 355 |
| 332 return render_frame_host->GetProcess()->GetID() == render_process_id_ && | 356 return render_frame_host->GetProcess()->GetID() == render_process_id_ && |
| 333 render_frame_host->GetRoutingID() == render_frame_id_; | 357 render_frame_host->GetRoutingID() == render_frame_id_; |
| 334 } | 358 } |
| 335 | 359 |
| 336 void PresentationServiceImpl::ListenForSessionMessages( | 360 void PresentationServiceImpl::ListenForSessionMessages( |
| 337 const SessionMessagesCallback& callback) { | 361 const SessionMessagesCallback& callback) { |
| 338 NOTIMPLEMENTED(); | 362 DVLOG(2) << "ListenForSessionMessages"; |
| 363 if (!delegate_) { | |
| 364 callback.Run(mojo::Array<presentation::SessionMessagePtr>()); | |
| 365 return; | |
| 366 } | |
| 367 | |
| 368 if (on_session_messages_callback_.get()) { | |
|
mark a. foltz
2015/05/01 19:42:07
When could this happen? Does this mean that the c
haibinlu
2015/05/02 00:32:55
Done.
| |
| 369 callback.Run(mojo::Array<presentation::SessionMessagePtr>()); | |
| 370 return; | |
| 371 } | |
| 372 | |
| 373 on_session_messages_callback_.reset(new SessionMessagesCallback(callback)); | |
| 374 delegate_->ListenForSessionMessages( | |
| 375 render_process_id_, render_frame_id_, | |
| 376 base::Bind(&PresentationServiceImpl::OnSessionMessages, | |
| 377 weak_factory_.GetWeakPtr())); | |
| 378 } | |
| 379 | |
| 380 void PresentationServiceImpl::OnSessionMessages( | |
| 381 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) { | |
|
mark a. foltz
2015/05/01 19:42:07
I've usually seen std::vector<linked_ptr<Foo>> use
haibinlu
2015/05/02 00:32:55
Acknowledged.
| |
| 382 DCHECK(messages.get()); | |
|
mark a. foltz
2015/05/01 19:42:07
What if messages->size() == 0?
haibinlu
2015/05/02 00:32:55
Done.
| |
| 383 if (!on_session_messages_callback_.get()) { | |
| 384 // Reseted | |
|
mark a. foltz
2015/05/01 19:42:07
What was reset? The callback?
haibinlu
2015/05/02 00:32:55
Clarified the comments.
| |
| 385 return; | |
| 386 } | |
| 387 | |
| 388 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size()); | |
| 389 for (size_t i = 0; i < messages->size(); ++i) { | |
| 390 mojoMessages[i] = ToMojoSessionMessage((*messages)[i]); | |
| 391 } | |
| 392 | |
| 393 on_session_messages_callback_->Run(mojoMessages.Pass()); | |
| 339 } | 394 } |
| 340 | 395 |
| 341 void PresentationServiceImpl::DidNavigateAnyFrame( | 396 void PresentationServiceImpl::DidNavigateAnyFrame( |
| 342 content::RenderFrameHost* render_frame_host, | 397 content::RenderFrameHost* render_frame_host, |
| 343 const content::LoadCommittedDetails& details, | 398 const content::LoadCommittedDetails& details, |
| 344 const content::FrameNavigateParams& params) { | 399 const content::FrameNavigateParams& params) { |
| 345 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 400 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
| 346 if (!FrameMatches(render_frame_host)) | 401 if (!FrameMatches(render_frame_host)) |
| 347 return; | 402 return; |
| 348 | 403 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 DVLOG(2) << "PresentationServiceImpl::Reset"; | 436 DVLOG(2) << "PresentationServiceImpl::Reset"; |
| 382 if (delegate_) | 437 if (delegate_) |
| 383 delegate_->Reset(render_process_id_, render_frame_id_); | 438 delegate_->Reset(render_process_id_, render_frame_id_); |
| 384 | 439 |
| 385 default_presentation_url_.clear(); | 440 default_presentation_url_.clear(); |
| 386 default_presentation_id_.clear(); | 441 default_presentation_id_.clear(); |
| 387 availability_contexts_.clear(); | 442 availability_contexts_.clear(); |
| 388 queued_start_session_requests_.clear(); | 443 queued_start_session_requests_.clear(); |
| 389 FlushNewSessionCallbacks(); | 444 FlushNewSessionCallbacks(); |
| 390 default_session_start_context_.reset(); | 445 default_session_start_context_.reset(); |
| 446 if (on_session_messages_callback_.get()) { | |
| 447 on_session_messages_callback_->Run( | |
| 448 mojo::Array<presentation::SessionMessagePtr>()); | |
| 449 on_session_messages_callback_.reset(); | |
| 450 } | |
| 391 } | 451 } |
| 392 | 452 |
| 393 // static | 453 // static |
| 394 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( | 454 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( |
| 395 const NewSessionMojoCallback& callback) { | 455 const NewSessionMojoCallback& callback) { |
| 396 callback.Run( | 456 callback.Run( |
| 397 presentation::PresentationSessionInfoPtr(), | 457 presentation::PresentationSessionInfoPtr(), |
| 398 presentation::PresentationError::From( | 458 presentation::PresentationError::From( |
| 399 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | 459 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
| 400 } | 460 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 590 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| 531 ScopedVector<DefaultSessionMojoCallback> callbacks; | 591 ScopedVector<DefaultSessionMojoCallback> callbacks; |
| 532 callbacks.swap(callbacks_); | 592 callbacks.swap(callbacks_); |
| 533 for (const auto& callback : callbacks) | 593 for (const auto& callback : callbacks) |
| 534 callback->Run(presentation::PresentationSessionInfoPtr()); | 594 callback->Run(presentation::PresentationSessionInfoPtr()); |
| 535 session_.reset(); | 595 session_.reset(); |
| 536 } | 596 } |
| 537 | 597 |
| 538 } // namespace content | 598 } // namespace content |
| 539 | 599 |
| OLD | NEW |