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 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 PresentationServiceImpl::PresentationServiceImpl( | 22 PresentationServiceImpl::PresentationServiceImpl( |
| 22 RenderFrameHost* render_frame_host, | 23 RenderFrameHost* render_frame_host, |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 content::RenderFrameHost* render_frame_host) const { | 329 content::RenderFrameHost* render_frame_host) const { |
| 329 if (!render_frame_host) | 330 if (!render_frame_host) |
| 330 return false; | 331 return false; |
| 331 | 332 |
| 332 return render_frame_host->GetProcess()->GetID() == render_process_id_ && | 333 return render_frame_host->GetProcess()->GetID() == render_process_id_ && |
| 333 render_frame_host->GetRoutingID() == render_frame_id_; | 334 render_frame_host->GetRoutingID() == render_frame_id_; |
| 334 } | 335 } |
| 335 | 336 |
| 336 void PresentationServiceImpl::ListenForSessionMessages( | 337 void PresentationServiceImpl::ListenForSessionMessages( |
| 337 const SessionMessagesCallback& callback) { | 338 const SessionMessagesCallback& callback) { |
| 338 NOTIMPLEMENTED(); | 339 DVLOG(2) << "ListenForSessionMessages"; |
| 340 if (!delegate_) { | |
| 341 callback.Run(mojo::Array<presentation::SessionMessagePtr>()); | |
| 342 return; | |
| 343 } | |
| 344 | |
| 345 if (on_session_messages_.get()) { | |
| 346 callback.Run(mojo::Array<presentation::SessionMessagePtr>()); | |
| 347 return; | |
| 348 } | |
| 349 | |
| 350 on_session_messages_.reset(new SessionMessagesCallback(callback)); | |
| 351 delegate_->ListenForSessionMessages( | |
| 352 render_process_id_, render_frame_id_, | |
| 353 base::Bind(&PresentationServiceImpl::OnSessionMessages, | |
| 354 weak_factory_.GetWeakPtr())); | |
| 355 } | |
| 356 | |
| 357 void PresentationServiceImpl::OnSessionMessages( | |
| 358 scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) { | |
| 359 if (!on_session_messages_.get()) { | |
| 360 // Reseted | |
| 361 return; | |
| 362 } | |
| 363 | |
| 364 mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size()); | |
| 365 for (size_t i = 0; i < messages->size(); ++i) | |
| 366 mojoMessages[i] = | |
|
whywhat
2015/05/01 15:26:12
nits: this needs to be in curly braces {}
haibinlu
2015/05/01 19:03:20
Done.
| |
| 367 PresentationServiceImpl::ToMojoSessionMessage((*messages)[i]); | |
| 368 | |
| 369 on_session_messages_->Run(mojoMessages.Pass()); | |
| 370 } | |
| 371 | |
| 372 // static | |
| 373 presentation::SessionMessagePtr PresentationServiceImpl::ToMojoSessionMessage( | |
| 374 PresentationSessionMessage* input) { | |
| 375 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); | |
| 376 output->presentation_url = input->presentation_url; | |
| 377 output->presentation_id = input->presentation_id; | |
| 378 if (input->message->size() == 0) { | |
|
whywhat
2015/05/01 15:26:12
nit: could be if (input->message->empty()) {
haibinlu
2015/05/01 19:03:20
Done.
| |
| 379 // binary data | |
| 380 output->type = presentation::PresentationMessageType:: | |
| 381 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; | |
| 382 output->data.Swap(input->data.get()); | |
| 383 } else { | |
| 384 // string message | |
| 385 output->type = | |
| 386 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; | |
| 387 output->message.Swap(input->message.get()); | |
| 388 } | |
| 389 return output.Pass(); | |
| 339 } | 390 } |
| 340 | 391 |
| 341 void PresentationServiceImpl::DidNavigateAnyFrame( | 392 void PresentationServiceImpl::DidNavigateAnyFrame( |
| 342 content::RenderFrameHost* render_frame_host, | 393 content::RenderFrameHost* render_frame_host, |
| 343 const content::LoadCommittedDetails& details, | 394 const content::LoadCommittedDetails& details, |
| 344 const content::FrameNavigateParams& params) { | 395 const content::FrameNavigateParams& params) { |
| 345 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; | 396 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; |
| 346 if (!FrameMatches(render_frame_host)) | 397 if (!FrameMatches(render_frame_host)) |
| 347 return; | 398 return; |
| 348 | 399 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 DVLOG(2) << "PresentationServiceImpl::Reset"; | 432 DVLOG(2) << "PresentationServiceImpl::Reset"; |
| 382 if (delegate_) | 433 if (delegate_) |
| 383 delegate_->Reset(render_process_id_, render_frame_id_); | 434 delegate_->Reset(render_process_id_, render_frame_id_); |
| 384 | 435 |
| 385 default_presentation_url_.clear(); | 436 default_presentation_url_.clear(); |
| 386 default_presentation_id_.clear(); | 437 default_presentation_id_.clear(); |
| 387 availability_contexts_.clear(); | 438 availability_contexts_.clear(); |
| 388 queued_start_session_requests_.clear(); | 439 queued_start_session_requests_.clear(); |
| 389 FlushNewSessionCallbacks(); | 440 FlushNewSessionCallbacks(); |
| 390 default_session_start_context_.reset(); | 441 default_session_start_context_.reset(); |
| 442 if (on_session_messages_.get()) { | |
| 443 on_session_messages_->Run(mojo::Array<presentation::SessionMessagePtr>()); | |
| 444 on_session_messages_.reset(); | |
| 445 } | |
| 391 } | 446 } |
| 392 | 447 |
| 393 // static | 448 // static |
| 394 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( | 449 void PresentationServiceImpl::InvokeNewSessionMojoCallbackWithError( |
| 395 const NewSessionMojoCallback& callback) { | 450 const NewSessionMojoCallback& callback) { |
| 396 callback.Run( | 451 callback.Run( |
| 397 presentation::PresentationSessionInfoPtr(), | 452 presentation::PresentationSessionInfoPtr(), |
| 398 presentation::PresentationError::From( | 453 presentation::PresentationError::From( |
| 399 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); | 454 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); |
| 400 } | 455 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { | 585 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { |
| 531 ScopedVector<DefaultSessionMojoCallback> callbacks; | 586 ScopedVector<DefaultSessionMojoCallback> callbacks; |
| 532 callbacks.swap(callbacks_); | 587 callbacks.swap(callbacks_); |
| 533 for (const auto& callback : callbacks) | 588 for (const auto& callback : callbacks) |
| 534 callback->Run(presentation::PresentationSessionInfoPtr()); | 589 callback->Run(presentation::PresentationSessionInfoPtr()); |
| 535 session_.reset(); | 590 session_.reset(); |
| 536 } | 591 } |
| 537 | 592 |
| 538 } // namespace content | 593 } // namespace content |
| 539 | 594 |
| OLD | NEW |