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

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

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: resolve code review comments from Mark Created 4 years, 2 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 <utility> 10 #include <utility>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 render_process_id_ = render_frame_host->GetProcess()->GetID(); 138 render_process_id_ = render_frame_host->GetProcess()->GetID();
139 render_frame_id_ = render_frame_host->GetRoutingID(); 139 render_frame_id_ = render_frame_host->GetRoutingID();
140 DVLOG(2) << "PresentationServiceImpl: " 140 DVLOG(2) << "PresentationServiceImpl: "
141 << render_process_id_ << ", " << render_frame_id_; 141 << render_process_id_ << ", " << render_frame_id_;
142 if (delegate_) 142 if (delegate_)
143 delegate_->AddObserver(render_process_id_, render_frame_id_, this); 143 delegate_->AddObserver(render_process_id_, render_frame_id_, this);
144 } 144 }
145 145
146 PresentationServiceImpl::~PresentationServiceImpl() { 146 PresentationServiceImpl::~PresentationServiceImpl() {
147 DVLOG(2) << "~PresentationServiceImpl: " << render_process_id_ << ", "
mark a. foltz 2016/10/08 00:33:42 __FUNCTION__ as is done elsewhere in this patch?
zhaobin 2016/10/12 02:27:33 Done.
148 << render_frame_id_;
147 if (delegate_) 149 if (delegate_)
148 delegate_->RemoveObserver(render_process_id_, render_frame_id_); 150 delegate_->RemoveObserver(render_process_id_, render_frame_id_);
149 } 151 }
150 152
151 // static 153 // static
152 void PresentationServiceImpl::CreateMojoService( 154 void PresentationServiceImpl::CreateMojoService(
153 RenderFrameHost* render_frame_host, 155 RenderFrameHost* render_frame_host,
154 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 156 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
155 DVLOG(2) << "CreateMojoService"; 157 DVLOG(2) << "CreateMojoService";
156 WebContents* web_contents = 158 WebContents* web_contents =
(...skipping 14 matching lines...) Expand all
171 mojo::InterfaceRequest<blink::mojom::PresentationService> request) { 173 mojo::InterfaceRequest<blink::mojom::PresentationService> request) {
172 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( 174 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>(
173 this, std::move(request))); 175 this, std::move(request)));
174 } 176 }
175 177
176 void PresentationServiceImpl::SetClient( 178 void PresentationServiceImpl::SetClient(
177 blink::mojom::PresentationServiceClientPtr client) { 179 blink::mojom::PresentationServiceClientPtr client) {
178 DCHECK(!client_.get()); 180 DCHECK(!client_.get());
179 // TODO(imcheng): Set ErrorHandler to listen for errors. 181 // TODO(imcheng): Set ErrorHandler to listen for errors.
180 client_ = std::move(client); 182 client_ = std::move(client);
183
184 if (delegate_) {
185 delegate_->RegisterReceiverAvailableCallback(
186 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
187 weak_factory_.GetWeakPtr()));
188 }
181 } 189 }
182 190
183 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { 191 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
184 DVLOG(2) << "ListenForScreenAvailability " << url; 192 DVLOG(2) << "ListenForScreenAvailability " << url;
185 if (!delegate_) { 193 if (!delegate_) {
186 client_->OnScreenAvailabilityUpdated(url, false); 194 client_->OnScreenAvailabilityUpdated(url, false);
187 return; 195 return;
188 } 196 }
189 197
190 if (screen_availability_listeners_.count(url.spec())) 198 if (screen_availability_listeners_.count(url.spec()))
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 delegate_->SetDefaultPresentationUrls( 394 delegate_->SetDefaultPresentationUrls(
387 render_process_id_, render_frame_id_, presentation_urls_for_delegate, 395 render_process_id_, render_frame_id_, presentation_urls_for_delegate,
388 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted, 396 base::Bind(&PresentationServiceImpl::OnDefaultPresentationStarted,
389 weak_factory_.GetWeakPtr())); 397 weak_factory_.GetWeakPtr()));
390 } 398 }
391 399
392 void PresentationServiceImpl::SendSessionMessage( 400 void PresentationServiceImpl::SendSessionMessage(
393 blink::mojom::PresentationSessionInfoPtr session, 401 blink::mojom::PresentationSessionInfoPtr session,
394 blink::mojom::SessionMessagePtr session_message, 402 blink::mojom::SessionMessagePtr session_message,
395 const SendSessionMessageCallback& callback) { 403 const SendSessionMessageCallback& callback) {
396 DVLOG(2) << "SendSessionMessage"; 404 DVLOG(2) << "SendSessionMessage"
405 << " [url]: " << session->url << ", [id]: " << session->id
406 << ", [process id]: " << render_process_id_
407 << ", [render frame id]: " << render_frame_id_;
397 DCHECK(!session_message.is_null()); 408 DCHECK(!session_message.is_null());
398 // send_message_callback_ should be null by now, otherwise resetting of 409 // send_message_callback_ should be null by now, otherwise resetting of
399 // send_message_callback_ with new callback will drop the old callback. 410 // send_message_callback_ with new callback will drop the old callback.
400 if (!delegate_ || send_message_callback_) { 411 if (!delegate_ || send_message_callback_) {
401 callback.Run(false); 412 callback.Run(false);
402 return; 413 return;
403 } 414 }
404 415
405 send_message_callback_.reset(new SendSessionMessageCallback(callback)); 416 send_message_callback_.reset(new SendSessionMessageCallback(callback));
406 delegate_->SendMessage( 417 delegate_->SendMessage(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (!delegate_) 478 if (!delegate_)
468 return; 479 return;
469 480
470 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>()); 481 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
471 delegate_->ListenForSessionMessages( 482 delegate_->ListenForSessionMessages(
472 render_process_id_, render_frame_id_, session_info, 483 render_process_id_, render_frame_id_, session_info,
473 base::Bind(&PresentationServiceImpl::OnSessionMessages, 484 base::Bind(&PresentationServiceImpl::OnSessionMessages,
474 weak_factory_.GetWeakPtr(), session_info)); 485 weak_factory_.GetWeakPtr(), session_info));
475 } 486 }
476 487
488 void PresentationServiceImpl::SetPresentationConnection(
489 blink::mojom::PresentationSessionInfoPtr session,
490 blink::mojom::PresentationConnectionPtr connection) {
491 DVLOG(2) << "SetPresentationConnection";
492
493 if (!delegate_)
494 return;
495
496 PresentationSessionInfo session_info(session.To<PresentationSessionInfo>());
497 delegate_->RegisterOffscreenPresentationConnection(
498 render_process_id_, render_frame_id_, session_info,
499 std::move(connection));
500 }
501
477 void PresentationServiceImpl::OnSessionMessages( 502 void PresentationServiceImpl::OnSessionMessages(
478 const PresentationSessionInfo& session, 503 const PresentationSessionInfo& session,
479 const ScopedVector<PresentationSessionMessage>& messages, 504 const ScopedVector<PresentationSessionMessage>& messages,
480 bool pass_ownership) { 505 bool pass_ownership) {
481 DCHECK(client_); 506 DCHECK(client_);
482 507 DVLOG(2) << "OnSessionMessages"
483 DVLOG(2) << "OnSessionMessages"; 508 << " [url]: " << session.presentation_url
509 << ", [id]: " << session.presentation_id
510 << ", [process id]: " << render_process_id_
511 << ", [render frame id]: " << render_frame_id_;
484 std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size()); 512 std::vector<blink::mojom::SessionMessagePtr> mojo_messages(messages.size());
485 std::transform(messages.begin(), messages.end(), mojo_messages.begin(), 513 std::transform(messages.begin(), messages.end(), mojo_messages.begin(),
486 [pass_ownership](PresentationSessionMessage* message) { 514 [pass_ownership](PresentationSessionMessage* message) {
487 return ToMojoSessionMessage(message, pass_ownership); 515 return ToMojoSessionMessage(message, pass_ownership);
488 }); 516 });
489 517
490 client_->OnSessionMessagesReceived( 518 client_->OnSessionMessagesReceived(
491 blink::mojom::PresentationSessionInfo::From(session), 519 blink::mojom::PresentationSessionInfo::From(session),
492 std::move(mojo_messages)); 520 std::move(mojo_messages));
493 } 521 }
494 522
523 void PresentationServiceImpl::OnReceiverConnectionAvailable(
524 const content::PresentationSessionInfo& session_info,
525 PresentationConnectionPtr&& controller) {
526 DVLOG(2) << "PresentationServiceImpl::OnReceiverConnectionAvailable";
527 DVLOG(2) << "controller: " << controller;
528
529 client_->OnReceiverConnectionAvailable(
530 blink::mojom::PresentationSessionInfo::From(session_info),
531 std::move(controller));
532 }
533
495 void PresentationServiceImpl::DidNavigateAnyFrame( 534 void PresentationServiceImpl::DidNavigateAnyFrame(
496 content::RenderFrameHost* render_frame_host, 535 content::RenderFrameHost* render_frame_host,
497 const content::LoadCommittedDetails& details, 536 const content::LoadCommittedDetails& details,
498 const content::FrameNavigateParams& params) { 537 const content::FrameNavigateParams& params) {
499 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame"; 538 DVLOG(2) << "PresentationServiceImpl::DidNavigateAnyFrame";
500 if (!FrameMatches(render_frame_host)) 539 if (!FrameMatches(render_frame_host))
501 return; 540 return;
502 541
503 std::string prev_url_host = details.previous_url.host(); 542 std::string prev_url_host = details.previous_url.host();
504 std::string curr_url_host = params.url.host(); 543 std::string curr_url_host = params.url.host();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 659
621 void PresentationServiceImpl::NewSessionCallbackWrapper::Run( 660 void PresentationServiceImpl::NewSessionCallbackWrapper::Run(
622 blink::mojom::PresentationSessionInfoPtr session, 661 blink::mojom::PresentationSessionInfoPtr session,
623 blink::mojom::PresentationErrorPtr error) { 662 blink::mojom::PresentationErrorPtr error) {
624 DCHECK(!callback_.is_null()); 663 DCHECK(!callback_.is_null());
625 callback_.Run(std::move(session), std::move(error)); 664 callback_.Run(std::move(session), std::move(error));
626 callback_.Reset(); 665 callback_.Reset();
627 } 666 }
628 667
629 } // namespace content 668 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698