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/profiles/profile.h" |
| 8 #include "content/public/browser/render_frame_host.h" |
| 9 #include "content/public/browser/render_process_host.h" |
| 10 |
| 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 12 media_router::ReceiverPresentationServiceDelegateImpl); |
| 13 |
| 14 using content::PresentationServiceDelegate; |
| 15 using content::RenderFrameHost; |
| 16 |
| 17 namespace media_router { |
| 18 |
| 19 // static |
| 20 void ReceiverPresentationServiceDelegateImpl::CreateForWebContents( |
| 21 content::WebContents* web_contents, |
| 22 const std::string& presentation_id) { |
| 23 DCHECK(web_contents); |
| 24 |
| 25 if (FromWebContents(web_contents)) |
| 26 return; |
| 27 |
| 28 web_contents->SetUserData(UserDataKey(), |
| 29 new ReceiverPresentationServiceDelegateImpl( |
| 30 web_contents, presentation_id)); |
| 31 } |
| 32 |
| 33 ReceiverPresentationServiceDelegateImpl:: |
| 34 ~ReceiverPresentationServiceDelegateImpl() { |
| 35 for (auto& observer_pair : observers_) |
| 36 observer_pair.second->OnDelegateDestroyed(); |
| 37 } |
| 38 |
| 39 void ReceiverPresentationServiceDelegateImpl::AddObserver( |
| 40 int render_process_id, |
| 41 int render_frame_id, |
| 42 content::PresentationServiceDelegate::Observer* observer) { |
| 43 DCHECK(observer); |
| 44 |
| 45 RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 46 DCHECK(!base::ContainsKey(observers_, rfh_id)); |
| 47 observers_[rfh_id] = observer; |
| 48 } |
| 49 |
| 50 void ReceiverPresentationServiceDelegateImpl::RemoveObserver( |
| 51 int render_process_id, |
| 52 int render_frame_id) { |
| 53 observers_.erase(RenderFrameHostId(render_process_id, render_frame_id)); |
| 54 } |
| 55 |
| 56 bool ReceiverPresentationServiceDelegateImpl::AddScreenAvailabilityListener( |
| 57 int render_process_id, |
| 58 int render_frame_id, |
| 59 content::PresentationScreenAvailabilityListener* listener) { |
| 60 NOTIMPLEMENTED(); |
| 61 return false; |
| 62 } |
| 63 |
| 64 void ReceiverPresentationServiceDelegateImpl::RemoveScreenAvailabilityListener( |
| 65 int render_process_id, |
| 66 int render_frame_id, |
| 67 content::PresentationScreenAvailabilityListener* listener) { |
| 68 NOTIMPLEMENTED(); |
| 69 } |
| 70 |
| 71 void ReceiverPresentationServiceDelegateImpl::Reset(int render_process_id, |
| 72 int render_frame_id) { |
| 73 DVLOG(2) << __FUNCTION__ << render_process_id << ", " << render_frame_id; |
| 74 |
| 75 RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 76 if (rfh_id != current_frame_id_) { |
| 77 DVLOG(2) << __FUNCTION__ << ": not main frame"; |
| 78 return; |
| 79 } |
| 80 |
| 81 current_frame_id_ = RenderFrameHostId(); |
| 82 } |
| 83 |
| 84 void ReceiverPresentationServiceDelegateImpl::SetDefaultPresentationUrls( |
| 85 int render_process_id, |
| 86 int render_frame_id, |
| 87 const std::vector<std::string>& default_presentation_urls, |
| 88 const content::PresentationSessionStartedCallback& callback) { |
| 89 NOTIMPLEMENTED(); |
| 90 } |
| 91 |
| 92 void ReceiverPresentationServiceDelegateImpl::StartSession( |
| 93 int render_process_id, |
| 94 int render_frame_id, |
| 95 const std::vector<std::string>& presentation_urls, |
| 96 const content::PresentationSessionStartedCallback& success_cb, |
| 97 const content::PresentationSessionErrorCallback& error_cb) { |
| 98 NOTIMPLEMENTED(); |
| 99 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 100 "Not implemented")); |
| 101 } |
| 102 |
| 103 void ReceiverPresentationServiceDelegateImpl::JoinSession( |
| 104 int render_process_id, |
| 105 int render_frame_id, |
| 106 const std::vector<std::string>& presentation_urls, |
| 107 const std::string& presentation_id, |
| 108 const content::PresentationSessionStartedCallback& success_cb, |
| 109 const content::PresentationSessionErrorCallback& error_cb) { |
| 110 NOTIMPLEMENTED(); |
| 111 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 112 "Not implemented")); |
| 113 } |
| 114 |
| 115 void ReceiverPresentationServiceDelegateImpl::CloseConnection( |
| 116 int render_process_id, |
| 117 int render_frame_id, |
| 118 const std::string& presentation_id) { |
| 119 NOTIMPLEMENTED(); |
| 120 } |
| 121 |
| 122 void ReceiverPresentationServiceDelegateImpl::Terminate( |
| 123 int render_process_id, |
| 124 int render_frame_id, |
| 125 const std::string& presentation_id) { |
| 126 NOTIMPLEMENTED(); |
| 127 } |
| 128 |
| 129 void ReceiverPresentationServiceDelegateImpl::ListenForSessionMessages( |
| 130 int render_process_id, |
| 131 int render_frame_id, |
| 132 const content::PresentationSessionInfo& session_info, |
| 133 const content::PresentationSessionMessageCallback& message_cb) { |
| 134 NOTIMPLEMENTED(); |
| 135 } |
| 136 |
| 137 void ReceiverPresentationServiceDelegateImpl::SendMessage( |
| 138 int render_process_id, |
| 139 int render_frame_id, |
| 140 const content::PresentationSessionInfo& session_info, |
| 141 std::unique_ptr<content::PresentationSessionMessage> message, |
| 142 const SendMessageCallback& send_message_cb) { |
| 143 NOTIMPLEMENTED(); |
| 144 } |
| 145 |
| 146 void ReceiverPresentationServiceDelegateImpl::ListenForConnectionStateChange( |
| 147 int render_process_id, |
| 148 int render_frame_id, |
| 149 const content::PresentationSessionInfo& connection, |
| 150 const content::PresentationConnectionStateChangedCallback& |
| 151 state_changed_cb) { |
| 152 NOTIMPLEMENTED(); |
| 153 } |
| 154 |
| 155 ReceiverPresentationServiceDelegateImpl:: |
| 156 ReceiverPresentationServiceDelegateImpl(content::WebContents* web_contents, |
| 157 const std::string& presentation_id) |
| 158 : web_contents_(web_contents), |
| 159 presentation_id_(presentation_id), |
| 160 offscreen_presentation_manager_( |
| 161 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( |
| 162 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 163 ->GetOriginalProfile())) { |
| 164 DCHECK(web_contents_); |
| 165 DCHECK(!presentation_id.empty()); |
| 166 DCHECK(offscreen_presentation_manager_); |
| 167 DCHECK(web_contents_->GetBrowserContext()->IsOffTheRecord()); |
| 168 } |
| 169 |
| 170 void ReceiverPresentationServiceDelegateImpl:: |
| 171 RegisterOffscreenPresentationReceiver( |
| 172 content::OffscreenPresentationClient* client) { |
| 173 offscreen_presentation_manager_->RegisterOffscreenPresentationReceiver( |
| 174 presentation_id_, client); |
| 175 } |
| 176 |
| 177 void ReceiverPresentationServiceDelegateImpl:: |
| 178 UnregisterOffscreenPresentationReceiver( |
| 179 content::OffscreenPresentationClient* client) { |
| 180 offscreen_presentation_manager_->UnregisterOffscreenPresentationReceiver( |
| 181 presentation_id_); |
| 182 } |
| 183 |
| 184 } // namespace media_router |
OLD | NEW |