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

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

Issue 2949053002: [Presentation API] OffscreenPresentationManager should only interact with top level receiver frame (Closed)
Patch Set: add unit test Created 3 years, 5 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 controller_delegate_(controller_delegate), 52 controller_delegate_(controller_delegate),
53 receiver_delegate_(receiver_delegate), 53 receiver_delegate_(receiver_delegate),
54 start_presentation_request_id_(kInvalidRequestId), 54 start_presentation_request_id_(kInvalidRequestId),
55 weak_factory_(this) { 55 weak_factory_(this) {
56 DCHECK(render_frame_host); 56 DCHECK(render_frame_host);
57 DCHECK(web_contents); 57 DCHECK(web_contents);
58 CHECK(render_frame_host->IsRenderFrameLive()); 58 CHECK(render_frame_host->IsRenderFrameLive());
59 59
60 render_process_id_ = render_frame_host->GetProcess()->GetID(); 60 render_process_id_ = render_frame_host->GetProcess()->GetID();
61 render_frame_id_ = render_frame_host->GetRoutingID(); 61 render_frame_id_ = render_frame_host->GetRoutingID();
62 DVLOG(2) << "PresentationServiceImpl: " 62 is_main_frame_ = !render_frame_host->GetParent();
63 << render_process_id_ << ", " << render_frame_id_; 63
64 DVLOG(2) << "PresentationServiceImpl: " << render_process_id_ << ", "
65 << render_frame_id_ << " is main frame: " << is_main_frame_;
64 66
65 if (auto* delegate = GetPresentationServiceDelegate()) 67 if (auto* delegate = GetPresentationServiceDelegate())
66 delegate->AddObserver(render_process_id_, render_frame_id_, this); 68 delegate->AddObserver(render_process_id_, render_frame_id_, this);
67 } 69 }
68 70
69 PresentationServiceImpl::~PresentationServiceImpl() { 71 PresentationServiceImpl::~PresentationServiceImpl() {
70 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", " 72 DVLOG(2) << __FUNCTION__ << ": " << render_process_id_ << ", "
71 << render_frame_id_; 73 << render_frame_id_;
72 74
73 if (auto* delegate = GetPresentationServiceDelegate()) 75 if (auto* delegate = GetPresentationServiceDelegate())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>( 109 binding_.reset(new mojo::Binding<blink::mojom::PresentationService>(
108 this, std::move(request))); 110 this, std::move(request)));
109 } 111 }
110 112
111 void PresentationServiceImpl::SetClient( 113 void PresentationServiceImpl::SetClient(
112 blink::mojom::PresentationServiceClientPtr client) { 114 blink::mojom::PresentationServiceClientPtr client) {
113 DCHECK(!client_.get()); 115 DCHECK(!client_.get());
114 // TODO(imcheng): Set ErrorHandler to listen for errors. 116 // TODO(imcheng): Set ErrorHandler to listen for errors.
115 client_ = std::move(client); 117 client_ = std::move(client);
116 118
117 if (receiver_delegate_) { 119 if (receiver_delegate_ && is_main_frame_) {
118 receiver_delegate_->RegisterReceiverConnectionAvailableCallback( 120 receiver_delegate_->RegisterReceiverConnectionAvailableCallback(
119 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable, 121 base::Bind(&PresentationServiceImpl::OnReceiverConnectionAvailable,
120 weak_factory_.GetWeakPtr())); 122 weak_factory_.GetWeakPtr()));
121 } 123 }
122 } 124 }
123 125
124 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) { 126 void PresentationServiceImpl::ListenForScreenAvailability(const GURL& url) {
125 DVLOG(2) << "ListenForScreenAvailability " << url.spec(); 127 DVLOG(2) << "ListenForScreenAvailability " << url.spec();
126 if (!controller_delegate_) { 128 if (!controller_delegate_) {
127 client_->OnScreenAvailabilityUpdated( 129 client_->OnScreenAvailabilityUpdated(
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 LOG(ERROR) << "PresentationServiceImpl is being deleted in " 423 LOG(ERROR) << "PresentationServiceImpl is being deleted in "
422 << "WebContentsDestroyed()! This shouldn't happen since it " 424 << "WebContentsDestroyed()! This shouldn't happen since it "
423 << "should've been deleted during RenderFrameDeleted()."; 425 << "should've been deleted during RenderFrameDeleted().";
424 Reset(); 426 Reset();
425 delete this; 427 delete this;
426 } 428 }
427 429
428 void PresentationServiceImpl::Reset() { 430 void PresentationServiceImpl::Reset() {
429 DVLOG(2) << "PresentationServiceImpl::Reset"; 431 DVLOG(2) << "PresentationServiceImpl::Reset";
430 432
431 if (auto* delegate = GetPresentationServiceDelegate()) 433 if (controller_delegate_)
432 delegate->Reset(render_process_id_, render_frame_id_); 434 controller_delegate_->Reset(render_process_id_, render_frame_id_);
435
436 if (receiver_delegate_ && is_main_frame_)
437 receiver_delegate_->Reset(render_process_id_, render_frame_id_);
433 438
434 default_presentation_urls_.clear(); 439 default_presentation_urls_.clear();
435 440
436 screen_availability_listeners_.clear(); 441 screen_availability_listeners_.clear();
437 442
438 start_presentation_request_id_ = kInvalidRequestId; 443 start_presentation_request_id_ = kInvalidRequestId;
439 pending_start_presentation_cb_.reset(); 444 pending_start_presentation_cb_.reset();
440 445
441 pending_reconnect_presentation_cbs_.clear(); 446 pending_reconnect_presentation_cbs_.clear();
442 } 447 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 } 494 }
490 495
491 void PresentationServiceImpl::NewPresentationCallbackWrapper::Run( 496 void PresentationServiceImpl::NewPresentationCallbackWrapper::Run(
492 const base::Optional<PresentationInfo>& presentation_info, 497 const base::Optional<PresentationInfo>& presentation_info,
493 const base::Optional<PresentationError>& error) { 498 const base::Optional<PresentationError>& error) {
494 DCHECK(!callback_.is_null()); 499 DCHECK(!callback_.is_null());
495 std::move(callback_).Run(presentation_info, error); 500 std::move(callback_).Run(presentation_info, error);
496 } 501 }
497 502
498 } // namespace content 503 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698