Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/media/router/receiver_presentation_service_delegate_imp l.h" | |
| 6 | |
| 7 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | |
| 8 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "content/public/browser/presentation_session_state_listener.h" | |
| 11 | |
| 12 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | |
| 13 media_router::ReceiverPresentationServiceDelegateImpl); | |
| 14 | |
| 15 using content::PresentationServiceDelegate; | |
| 16 using content::RenderFrameHost; | |
| 17 | |
| 18 namespace media_router { | |
| 19 | |
| 20 // static | |
| 21 ReceiverPresentationServiceDelegateImpl* | |
| 22 ReceiverPresentationServiceDelegateImpl::GetOrCreateForWebContents( | |
| 23 content::WebContents* web_contents) { | |
| 24 DCHECK(web_contents); | |
| 25 // CreateForWebContents does nothing if the delegate instance already exists. | |
| 26 ReceiverPresentationServiceDelegateImpl::CreateForWebContents(web_contents); | |
| 27 return ReceiverPresentationServiceDelegateImpl::FromWebContents(web_contents); | |
| 28 } | |
| 29 | |
| 30 ReceiverPresentationServiceDelegateImpl:: | |
| 31 ~ReceiverPresentationServiceDelegateImpl() { | |
| 32 for (auto& observer_pair : observers_) | |
| 33 observer_pair.second->OnDelegateDestroyed(); | |
| 34 } | |
| 35 | |
| 36 void ReceiverPresentationServiceDelegateImpl::AddObserver( | |
| 37 int render_process_id, | |
| 38 int render_frame_id, | |
| 39 content::PresentationServiceDelegate::Observer* observer) { | |
| 40 DCHECK(observer); | |
| 41 | |
| 42 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 43 DCHECK(!ContainsKey(observers_, rfh_id)); | |
| 44 observers_[rfh_id] = observer; | |
| 45 } | |
| 46 | |
| 47 void ReceiverPresentationServiceDelegateImpl::RemoveObserver( | |
| 48 int render_process_id, | |
| 49 int render_frame_id) { | |
| 50 observers_.erase(RenderFrameHostId(render_process_id, render_frame_id)); | |
| 51 } | |
| 52 | |
| 53 bool ReceiverPresentationServiceDelegateImpl::AddScreenAvailabilityListener( | |
|
miu
2015/09/27 00:22:08
There are a ton of "NOTIMPLEMENTED()" methods. Co
imcheng
2015/09/30 01:13:42
Ack. I think it's not worth the trouble since all
| |
| 54 int render_process_id, | |
| 55 int render_frame_id, | |
| 56 content::PresentationScreenAvailabilityListener* listener) { | |
| 57 NOTIMPLEMENTED(); | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 void ReceiverPresentationServiceDelegateImpl::RemoveScreenAvailabilityListener( | |
| 62 int render_process_id, | |
| 63 int render_frame_id, | |
| 64 content::PresentationScreenAvailabilityListener* listener) { | |
| 65 NOTIMPLEMENTED(); | |
| 66 } | |
| 67 | |
| 68 void ReceiverPresentationServiceDelegateImpl::Reset(int render_process_id, | |
| 69 int render_frame_id) { | |
| 70 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 71 | |
| 72 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 73 if (offscreen_presenter_context_ && | |
| 74 offscreen_presenter_context_->IsPresenterFrame(rfh_id)) | |
| 75 offscreen_presenter_context_.reset(); | |
| 76 } | |
| 77 | |
| 78 void ReceiverPresentationServiceDelegateImpl::SetDefaultPresentationUrl( | |
| 79 int render_process_id, | |
| 80 int render_frame_id, | |
| 81 const std::string& default_presentation_url) { | |
| 82 NOTIMPLEMENTED(); | |
| 83 } | |
| 84 | |
| 85 void ReceiverPresentationServiceDelegateImpl::StartSession( | |
| 86 int render_process_id, | |
| 87 int render_frame_id, | |
| 88 const std::string& presentation_url, | |
| 89 const PresentationSessionSuccessCallback& success_cb, | |
| 90 const PresentationSessionErrorCallback& error_cb) { | |
| 91 NOTIMPLEMENTED(); | |
| 92 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | |
| 93 "Not implemented")); | |
| 94 } | |
| 95 | |
| 96 void ReceiverPresentationServiceDelegateImpl::JoinSession( | |
| 97 int render_process_id, | |
| 98 int render_frame_id, | |
| 99 const std::string& presentation_url, | |
| 100 const std::string& presentation_id, | |
| 101 const PresentationSessionSuccessCallback& success_cb, | |
| 102 const PresentationSessionErrorCallback& error_cb) { | |
| 103 NOTIMPLEMENTED(); | |
| 104 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | |
| 105 "Not implemented")); | |
| 106 } | |
| 107 | |
| 108 void ReceiverPresentationServiceDelegateImpl::CloseSession( | |
| 109 int render_process_id, | |
| 110 int render_frame_id, | |
| 111 const std::string& presentation_id) { | |
| 112 NOTIMPLEMENTED(); | |
| 113 } | |
| 114 | |
| 115 void ReceiverPresentationServiceDelegateImpl::ListenForSessionMessages( | |
| 116 int render_process_id, | |
| 117 int render_frame_id, | |
| 118 const content::PresentationSessionInfo& session, | |
| 119 const content::PresentationSessionMessageCallback& message_cb) { | |
| 120 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 121 | |
| 122 if (!offscreen_presenter_context_) { | |
| 123 DVLOG(2) << __FUNCTION__ << ": no offscreen presenter context"; | |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 128 offscreen_presenter_context_->ListenForMessages(rfh_id, session, message_cb); | |
| 129 } | |
| 130 | |
| 131 void ReceiverPresentationServiceDelegateImpl::SendMessage( | |
| 132 int render_process_id, | |
| 133 int render_frame_id, | |
| 134 const content::PresentationSessionInfo& session, | |
| 135 scoped_ptr<content::PresentationSessionMessage> message, | |
| 136 const content::SendMessageCallback& send_message_cb) { | |
| 137 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 138 | |
| 139 if (!offscreen_presenter_context_) { | |
| 140 DVLOG(2) << __FUNCTION__ << ": no offscreen presenter context"; | |
| 141 send_message_cb.Run(false); | |
| 142 return; | |
| 143 } | |
| 144 | |
| 145 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 146 offscreen_presenter_context_->SendMessage(rfh_id, session, message.Pass(), | |
| 147 send_message_cb); | |
| 148 } | |
| 149 | |
| 150 bool ReceiverPresentationServiceDelegateImpl::ListenForSessionStateChange( | |
| 151 int render_process_id, | |
| 152 int render_frame_id, | |
| 153 content::PresentationSessionStateListener* listener) { | |
| 154 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 155 | |
| 156 if (!offscreen_presenter_context_) { | |
| 157 DVLOG(2) << __FUNCTION__ << ": no offscreen presenter context"; | |
| 158 return false; | |
| 159 } | |
| 160 | |
| 161 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 162 offscreen_presenter_context_->ListenForStateChanges(rfh_id, listener); | |
| 163 return true; | |
| 164 } | |
| 165 | |
| 166 void ReceiverPresentationServiceDelegateImpl::GetPresentationReceiverSession( | |
| 167 int render_process_id, | |
| 168 int render_frame_id, | |
| 169 const content::PresentationReceiverSessionAvailableCallback& | |
| 170 success_callback, | |
| 171 const base::Callback<void(const std::string&)>& error_callback) { | |
| 172 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 173 | |
| 174 if (!offscreen_presenter_context_) { | |
| 175 DVLOG(2) << __FUNCTION__ << ": no offscreen presenter context"; | |
| 176 error_callback.Run("No offscreen presenter context"); | |
| 177 return; | |
| 178 } | |
| 179 | |
| 180 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 181 offscreen_presenter_context_->GetPresentationReceiverSession( | |
| 182 rfh_id, success_callback, error_callback); | |
| 183 } | |
| 184 | |
| 185 std::vector<content::PresentationSessionInfo> | |
| 186 ReceiverPresentationServiceDelegateImpl::GetPresentationReceiverSessions( | |
| 187 int render_process_id, | |
| 188 int render_frame_id) { | |
| 189 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; | |
| 190 | |
| 191 if (!offscreen_presenter_context_) { | |
| 192 DVLOG(2) << __FUNCTION__ << ": no offscreen presenter context"; | |
| 193 return std::vector<content::PresentationSessionInfo>(); | |
| 194 } | |
| 195 | |
| 196 RenderFrameHostId rfh_id(render_process_id, render_frame_id); | |
| 197 return offscreen_presenter_context_->GetPresentationReceiverSessions(rfh_id); | |
| 198 } | |
| 199 | |
| 200 ReceiverPresentationServiceDelegateImpl:: | |
| 201 ReceiverPresentationServiceDelegateImpl(content::WebContents* web_contents) | |
| 202 : web_contents_(web_contents), | |
| 203 // Get the OffscreenPresentationManager keyed off the controller profile, | |
| 204 // since | |
| 205 // it is where the offscreen presentation is registered. | |
| 206 // Per OffscreenPresentationsOwner, the controller profile is the | |
| 207 // presenter | |
| 208 // tab's original profile. | |
| 209 offscreen_presenter_context_( | |
| 210 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | |
| 211 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | |
| 212 ->GetOriginalProfile()) | |
| 213 ->GetOffscreenPresenterContext(web_contents_)) { | |
| 214 DCHECK(web_contents_); | |
| 215 DCHECK(offscreen_presenter_context_); | |
| 216 } | |
| 217 | |
| 218 } // namespace media_router | |
| OLD | NEW |