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 "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
10 #include "base/containers/scoped_ptr_map.h" | 10 #include "base/containers/scoped_ptr_map.h" |
11 #include "base/containers/small_map.h" | 11 #include "base/containers/small_map.h" |
12 #include "base/guid.h" | |
13 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
15 #include "chrome/browser/media/router/create_presentation_session_request.h" | 14 #include "chrome/browser/media/router/create_presentation_session_request.h" |
16 #include "chrome/browser/media/router/media_route.h" | 15 #include "chrome/browser/media/router/media_route.h" |
17 #include "chrome/browser/media/router/media_router.h" | 16 #include "chrome/browser/media/router/media_router.h" |
18 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
19 #include "chrome/browser/media/router/media_router_factory.h" | 18 #include "chrome/browser/media/router/media_router_factory.h" |
20 #include "chrome/browser/media/router/media_sink.h" | 19 #include "chrome/browser/media/router/media_sink.h" |
21 #include "chrome/browser/media/router/media_source_helper.h" | 20 #include "chrome/browser/media/router/media_source_helper.h" |
21 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | |
22 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | |
22 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 23 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
23 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 24 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
24 #include "chrome/browser/media/router/presentation_session_state_observer.h" | 25 #include "chrome/browser/media/router/presentation_session_state_observer.h" |
25 #include "chrome/browser/sessions/session_tab_helper.h" | 26 #include "chrome/browser/sessions/session_tab_helper.h" |
26 #include "content/public/browser/presentation_screen_availability_listener.h" | 27 #include "content/public/browser/presentation_screen_availability_listener.h" |
27 #include "content/public/browser/presentation_session.h" | 28 #include "content/public/browser/presentation_session.h" |
28 #include "content/public/browser/presentation_session_state_listener.h" | 29 #include "content/public/browser/presentation_session_state_listener.h" |
29 #include "content/public/browser/render_frame_host.h" | 30 #include "content/public/browser/render_frame_host.h" |
30 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
31 | 32 |
32 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 33 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
33 media_router::PresentationServiceDelegateImpl); | 34 media_router::PresentationServiceDelegateImpl); |
34 | 35 |
35 using content::RenderFrameHost; | 36 using content::RenderFrameHost; |
36 | 37 |
37 namespace media_router { | 38 namespace media_router { |
38 | 39 |
40 using OffscreenPresentationSession = | |
41 OffscreenPresentationManager::OffscreenPresentationSession; | |
42 | |
39 namespace { | 43 namespace { |
40 | 44 |
41 using DelegateObserver = content::PresentationServiceDelegate::Observer; | 45 using DelegateObserver = content::PresentationServiceDelegate::Observer; |
42 using PresentationSessionErrorCallback = | 46 using PresentationSessionErrorCallback = |
43 content::PresentationServiceDelegate::PresentationSessionErrorCallback; | 47 content::PresentationServiceDelegate::PresentationSessionErrorCallback; |
44 using PresentationSessionSuccessCallback = | 48 using PresentationSessionSuccessCallback = |
45 content::PresentationServiceDelegate::PresentationSessionSuccessCallback; | 49 content::PresentationServiceDelegate::PresentationSessionSuccessCallback; |
46 | 50 |
47 using RenderFrameHostId = std::pair<int, int>; | |
48 | |
49 // Returns the unique identifier for the supplied RenderFrameHost. | 51 // Returns the unique identifier for the supplied RenderFrameHost. |
50 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { | 52 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { |
51 int render_process_id = render_frame_host->GetProcess()->GetID(); | 53 int render_process_id = render_frame_host->GetProcess()->GetID(); |
52 int render_frame_id = render_frame_host->GetRoutingID(); | 54 int render_frame_id = render_frame_host->GetRoutingID(); |
53 return RenderFrameHostId(render_process_id, render_frame_id); | 55 return RenderFrameHostId(render_process_id, render_frame_id); |
54 } | 56 } |
55 | 57 |
56 // Gets the last committed URL for the render frame specified by | 58 // Gets the last committed URL for the render frame specified by |
57 // |render_frame_host_id|. | 59 // |render_frame_host_id|. |
58 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { | 60 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { |
59 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( | 61 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( |
60 render_frame_host_id.first, render_frame_host_id.second); | 62 render_frame_host_id.first, render_frame_host_id.second); |
61 DCHECK(render_frame_host); | 63 DCHECK(render_frame_host); |
62 return render_frame_host->GetLastCommittedURL(); | 64 return render_frame_host->GetLastCommittedURL(); |
63 } | 65 } |
64 | 66 |
65 } // namespace | 67 } // namespace |
66 | 68 |
67 // Used by PresentationServiceDelegateImpl to manage | 69 // Used by PresentationServiceDelegateImpl to manage |
68 // listeners and default presentation info in a render frame. | 70 // listeners and default presentation info in a render frame. |
69 // Its lifetime: | 71 // Its lifetime: |
70 // * PresentationFrameManager AddDelegateObserver | 72 // * PresentationFrameManager AddDelegateObserver |
71 // * Reset 0+ times. | 73 // * Reset 0+ times. |
72 // * PresentationFrameManager.RemoveDelegateObserver. | 74 // * PresentationFrameManager.RemoveDelegateObserver. |
73 class PresentationFrame { | 75 class PresentationFrame { |
74 public: | 76 public: |
75 PresentationFrame(content::WebContents* web_contents, MediaRouter* router); | 77 PresentationFrame(content::WebContents* web_contents, |
78 const RenderFrameHostId& render_frame_host_id, | |
79 MediaRouter* router); | |
76 ~PresentationFrame(); | 80 ~PresentationFrame(); |
77 | 81 |
78 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 82 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
79 bool SetScreenAvailabilityListener( | 83 bool SetScreenAvailabilityListener( |
80 content::PresentationScreenAvailabilityListener* listener); | 84 content::PresentationScreenAvailabilityListener* listener); |
81 bool RemoveScreenAvailabilityListener( | 85 bool RemoveScreenAvailabilityListener( |
82 content::PresentationScreenAvailabilityListener* listener); | 86 content::PresentationScreenAvailabilityListener* listener); |
83 bool HasScreenAvailabilityListenerForTest( | 87 bool HasScreenAvailabilityListenerForTest( |
84 const MediaSource::Id& source_id) const; | 88 const MediaSource::Id& source_id) const; |
85 std::string GetDefaultPresentationId() const; | 89 std::string GetDefaultPresentationId() const; |
90 void SendMessage(const content::PresentationSessionInfo& session, | |
91 scoped_ptr<content::PresentationSessionMessage> message, | |
92 const content::SendMessageCallback send_message_cb); | |
86 bool ListenForSessionStateChange( | 93 bool ListenForSessionStateChange( |
87 content::PresentationSessionStateListener* listener); | 94 content::PresentationSessionStateListener* listener); |
88 void ListenForSessionMessages( | 95 void ListenForSessionMessages( |
89 const content::PresentationSessionInfo& session, | 96 const content::PresentationSessionInfo& session, |
90 const content::PresentationSessionMessageCallback& message_cb); | 97 const content::PresentationSessionMessageCallback& message_cb); |
91 void Reset(); | 98 void Reset(); |
92 | 99 |
93 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 100 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
94 const std::vector<MediaRoute::Id> GetRouteIds() const; | |
95 void OnPresentationSessionClosed(const std::string& presentation_id); | 101 void OnPresentationSessionClosed(const std::string& presentation_id); |
96 | 102 |
97 void OnPresentationSessionStarted( | 103 void OnPresentationSessionStarted( |
98 bool is_default_presentation, | 104 bool is_default_presentation, |
99 const content::PresentationSessionInfo& session, | 105 const content::PresentationSessionInfo& session, |
100 const MediaRoute::Id& route_id); | 106 const MediaRoute& route); |
101 void OnPresentationServiceDelegateDestroyed() const; | 107 void OnPresentationServiceDelegateDestroyed() const; |
102 | 108 |
103 void set_delegate_observer(DelegateObserver* observer) { | 109 void set_delegate_observer(DelegateObserver* observer) { |
104 delegate_observer_ = observer; | 110 delegate_observer_ = observer; |
105 } | 111 } |
106 | 112 |
107 void set_default_presentation_url(const std::string& url) { | 113 void set_default_presentation_url(const std::string& url) { |
108 default_presentation_url_ = url; | 114 default_presentation_url_ = url; |
109 } | 115 } |
110 | 116 |
111 private: | 117 private: |
112 MediaSource GetMediaSourceFromListener( | 118 MediaSource GetMediaSourceFromListener( |
113 content::PresentationScreenAvailabilityListener* listener) const; | 119 content::PresentationScreenAvailabilityListener* listener) const; |
120 OffscreenPresentationSession* FindOffscreenSession( | |
mark a. foltz
2015/10/01 06:25:28
Can you document this method? Which session is re
imcheng
2015/10/06 00:59:14
Done.
| |
121 const std::string& presentation_id) const; | |
122 | |
114 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 123 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
115 presentation_id_to_route_id_; | 124 presentation_id_to_route_id_; |
116 std::string default_presentation_url_; | 125 std::string default_presentation_url_; |
117 scoped_ptr<PresentationMediaSinksObserver> sinks_observer_; | 126 scoped_ptr<PresentationMediaSinksObserver> sinks_observer_; |
118 | 127 |
128 // Controller objects for offscreen presentations. Note that offscreen | |
129 // presentations are manipulated with these objects instead of the observers | |
130 // and MediaRouter objects below. | |
131 // Maps from presentation ID to the corresponding OffscreenController within | |
132 // this frame. | |
133 base::ScopedPtrMap<std::string, scoped_ptr<OffscreenPresentationSession>> | |
134 offscreen_presentation_sessions_; | |
135 | |
136 // For non-offscreen presentations. | |
119 // Maps from presentation ID to the corresponding presentation session's | 137 // Maps from presentation ID to the corresponding presentation session's |
120 // state change observer within this frame. | 138 // state change observer within this frame. |
121 base::ScopedPtrMap<std::string, scoped_ptr<PresentationSessionStateObserver>> | 139 base::ScopedPtrMap<std::string, scoped_ptr<PresentationSessionStateObserver>> |
122 session_state_observers_; | 140 session_state_observers_; |
123 ScopedVector<PresentationSessionMessagesObserver> session_messages_observers_; | 141 ScopedVector<PresentationSessionMessagesObserver> session_messages_observers_; |
124 | 142 |
125 // References to the owning WebContents, and the corresponding MediaRouter. | 143 // References to the owning WebContents. |
126 const content::WebContents* web_contents_; | 144 const content::WebContents* const web_contents_; |
127 MediaRouter* router_; | 145 |
146 // ID of owning RenderFrameHost. | |
147 const RenderFrameHostId render_frame_host_id_; | |
148 | |
149 // References to MediaRouter / OffscreenPresentationManager owned by | |
150 // the associated BrowserContext. | |
mark a. foltz
2015/10/01 06:25:28
I'm assuming that the BC outlives this object; can
imcheng
2015/10/06 00:59:14
Done.
| |
151 MediaRouter* const router_; | |
152 OffscreenPresentationManager* const offscreen_presentation_manager_; | |
128 | 153 |
129 DelegateObserver* delegate_observer_; | 154 DelegateObserver* delegate_observer_; |
130 }; | 155 }; |
131 | 156 |
132 PresentationFrame::PresentationFrame(content::WebContents* web_contents, | 157 PresentationFrame::PresentationFrame( |
133 MediaRouter* router) | 158 content::WebContents* web_contents, |
159 const RenderFrameHostId& render_frame_host_id, | |
160 MediaRouter* router) | |
134 : web_contents_(web_contents), | 161 : web_contents_(web_contents), |
162 render_frame_host_id_(render_frame_host_id), | |
135 router_(router), | 163 router_(router), |
164 offscreen_presentation_manager_( | |
165 OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | |
mark a. foltz
2015/10/01 06:25:28
Do we need to look this up for every presentation
imcheng
2015/10/06 00:59:15
We don't need to look it up for every frame. Howev
| |
166 web_contents_->GetBrowserContext())), | |
136 delegate_observer_(nullptr) { | 167 delegate_observer_(nullptr) { |
137 DCHECK(web_contents_); | 168 DCHECK(web_contents_); |
138 DCHECK(router_); | 169 DCHECK(router_); |
170 DCHECK(offscreen_presentation_manager_); | |
139 } | 171 } |
140 | 172 |
141 PresentationFrame::~PresentationFrame() { | 173 PresentationFrame::~PresentationFrame() { |
142 } | 174 } |
143 | 175 |
144 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const { | 176 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const { |
145 if (delegate_observer_) | 177 if (delegate_observer_) |
146 delegate_observer_->OnDelegateDestroyed(); | 178 delegate_observer_->OnDelegateDestroyed(); |
147 } | 179 } |
148 | 180 |
149 void PresentationFrame::OnPresentationSessionStarted( | 181 void PresentationFrame::OnPresentationSessionStarted( |
150 bool is_default_presentation, | 182 bool is_default_presentation, |
151 const content::PresentationSessionInfo& session, | 183 const content::PresentationSessionInfo& session, |
152 const MediaRoute::Id& route_id) { | 184 const MediaRoute& route) { |
153 presentation_id_to_route_id_[session.presentation_id] = route_id; | 185 const std::string& presentation_id = session.presentation_id; |
186 presentation_id_to_route_id_[presentation_id] = route.media_route_id(); | |
154 if (is_default_presentation && delegate_observer_) | 187 if (is_default_presentation && delegate_observer_) |
155 delegate_observer_->OnDefaultPresentationStarted(session); | 188 delegate_observer_->OnDefaultPresentationStarted(session); |
189 if (route.is_offscreen_presentation()) { | |
190 DCHECK(!ContainsKey(offscreen_presentation_sessions_, presentation_id)); | |
191 scoped_ptr<OffscreenPresentationSession> offscreen_session = | |
192 offscreen_presentation_manager_->CreateOffscreenPresentationConnection( | |
193 presentation_id, render_frame_host_id_); | |
194 | |
195 // If |offscreen_session| is nullptr, then the receiver is most likely | |
196 // already gone, so the route will die soon. This should happen very rarely | |
197 // since the receiver has to unregister itself between when offscreen | |
198 // presentation was created and when the resulting route arrived at MR. | |
199 if (!offscreen_session) { | |
200 // TODO(imcheng): we should probably reject the route request in this | |
201 // case. crbug.com/513859 | |
202 LOG(ERROR) << "CreateOffscreenPresentationConnection returned nullptr."; | |
203 } else { | |
204 offscreen_presentation_sessions_.insert(presentation_id, | |
205 offscreen_session.Pass()); | |
206 } | |
207 } | |
156 } | 208 } |
157 | 209 |
158 void PresentationFrame::OnPresentationSessionClosed( | 210 void PresentationFrame::OnPresentationSessionClosed( |
159 const std::string& presentation_id) { | 211 const std::string& presentation_id) { |
160 auto it = presentation_id_to_route_id_.find(presentation_id); | 212 auto it = presentation_id_to_route_id_.find(presentation_id); |
161 if (it != presentation_id_to_route_id_.end()) { | 213 if (it != presentation_id_to_route_id_.end()) { |
162 presentation_id_to_route_id_.erase(it); | 214 presentation_id_to_route_id_.erase(it); |
163 } | 215 } |
164 // TODO(imcheng): Notify PresentationSessionStateObserver? | 216 // TODO(imcheng): Notify PresentationSessionStateObserver? |
165 } | 217 } |
166 | 218 |
167 const MediaRoute::Id PresentationFrame::GetRouteId( | 219 const MediaRoute::Id PresentationFrame::GetRouteId( |
168 const std::string& presentation_id) const { | 220 const std::string& presentation_id) const { |
169 auto it = presentation_id_to_route_id_.find(presentation_id); | 221 auto it = presentation_id_to_route_id_.find(presentation_id); |
170 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 222 return it != presentation_id_to_route_id_.end() ? it->second : ""; |
171 } | 223 } |
172 | 224 |
173 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { | |
174 std::vector<MediaRoute::Id> route_ids; | |
175 for (const auto& e : presentation_id_to_route_id_) | |
176 route_ids.push_back(e.second); | |
177 return route_ids; | |
178 } | |
179 | |
180 bool PresentationFrame::SetScreenAvailabilityListener( | 225 bool PresentationFrame::SetScreenAvailabilityListener( |
181 content::PresentationScreenAvailabilityListener* listener) { | 226 content::PresentationScreenAvailabilityListener* listener) { |
182 if (sinks_observer_ && sinks_observer_->listener() == listener) { | 227 if (sinks_observer_ && sinks_observer_->listener() == listener) { |
183 return false; | 228 return false; |
184 } | 229 } |
185 MediaSource source(GetMediaSourceFromListener(listener)); | 230 MediaSource source(GetMediaSourceFromListener(listener)); |
186 sinks_observer_.reset( | 231 sinks_observer_.reset( |
187 new PresentationMediaSinksObserver(router_, listener, source)); | 232 new PresentationMediaSinksObserver(router_, listener, source)); |
188 return true; | 233 return true; |
189 } | 234 } |
(...skipping 11 matching lines...) Expand all Loading... | |
201 const MediaSource::Id& source_id) const { | 246 const MediaSource::Id& source_id) const { |
202 return sinks_observer_ && sinks_observer_->source().id() == source_id; | 247 return sinks_observer_ && sinks_observer_->source().id() == source_id; |
203 } | 248 } |
204 | 249 |
205 void PresentationFrame::Reset() { | 250 void PresentationFrame::Reset() { |
206 for (const auto& pid_route_id : presentation_id_to_route_id_) | 251 for (const auto& pid_route_id : presentation_id_to_route_id_) |
207 router_->OnPresentationSessionDetached(pid_route_id.second); | 252 router_->OnPresentationSessionDetached(pid_route_id.second); |
208 | 253 |
209 presentation_id_to_route_id_.clear(); | 254 presentation_id_to_route_id_.clear(); |
210 sinks_observer_.reset(); | 255 sinks_observer_.reset(); |
256 offscreen_presentation_sessions_.clear(); | |
257 session_state_observers_.clear(); | |
211 default_presentation_url_.clear(); | 258 default_presentation_url_.clear(); |
212 session_state_observers_.clear(); | 259 session_state_observers_.clear(); |
213 session_messages_observers_.clear(); | 260 session_messages_observers_.clear(); |
214 } | 261 } |
215 | 262 |
216 void PresentationFrame::ListenForSessionStateChange( | 263 void PresentationFrame::SendMessage( |
264 const content::PresentationSessionInfo& session, | |
265 scoped_ptr<content::PresentationSessionMessage> message, | |
266 const content::SendMessageCallback send_message_cb) { | |
267 auto it = presentation_id_to_route_id_.find(session.presentation_id); | |
268 if (it == presentation_id_to_route_id_.end()) { | |
269 DVLOG(2) << "ListenForSessionMessages: no route for " | |
270 << session.presentation_id; | |
271 return; | |
272 } | |
273 | |
274 OffscreenPresentationSession* offscreen_session = | |
275 FindOffscreenSession(session.presentation_id); | |
276 if (offscreen_session) { | |
277 offscreen_session->SendMessage(message.Pass(), send_message_cb); | |
278 } else { | |
279 if (message->is_binary()) { | |
280 router_->SendRouteBinaryMessage(it->second, message->data.Pass(), | |
281 send_message_cb); | |
282 } else { | |
283 router_->SendRouteMessage(it->second, message->message, send_message_cb); | |
284 } | |
285 } | |
286 } | |
287 | |
288 OffscreenPresentationSession* PresentationFrame::FindOffscreenSession( | |
289 const std::string& presentation_id) const { | |
290 auto offscreen_session_it = | |
291 offscreen_presentation_sessions_.find(presentation_id); | |
292 return offscreen_session_it != offscreen_presentation_sessions_.end() | |
293 ? offscreen_session_it->second | |
294 : nullptr; | |
295 } | |
296 | |
297 bool PresentationFrame::ListenForSessionStateChange( | |
217 content::PresentationSessionStateListener* listener) { | 298 content::PresentationSessionStateListener* listener) { |
218 std::string presentation_id(listener->GetSessionInfo().presentation_id); | 299 std::string presentation_id(listener->GetSessionInfo().presentation_id); |
219 auto it = presentation_id_to_route_id_.find(presentation_id); | 300 auto it = presentation_id_to_route_id_.find(presentation_id); |
220 if (it == presentation_id_to_route_id_.end()) { | 301 if (it == presentation_id_to_route_id_.end()) { |
221 DVLOG(2) << "ListenForSessionStateChange: no route for " << presentation_id; | 302 DVLOG(2) << "ListenForSessionStateChange: no route for " << presentation_id; |
222 return false; | 303 return false; |
223 } | 304 } |
224 | 305 |
225 if (ContainsKey(session_state_observers_, presentation_id)) { | 306 OffscreenPresentationSession* offscreen_session = |
226 DVLOG(2) << "ListenForSessionStateChange: already contains a state " | 307 FindOffscreenSession(presentation_id); |
227 << "observer for session " << presentation_id; | 308 if (offscreen_session) { |
228 return false; | 309 offscreen_session->ListenForStateChanges(listener); |
310 return true; | |
311 } else { | |
312 if (ContainsKey(session_state_observers_, presentation_id)) { | |
313 DVLOG(2) << "ListenForSessionStateChange: already contains a state " | |
314 << "observer for session " << presentation_id; | |
315 return false; | |
316 } | |
317 | |
318 session_state_observers_.insert( | |
319 presentation_id, make_scoped_ptr(new PresentationSessionStateObserver( | |
320 listener, it->second, router_))); | |
321 return true; | |
229 } | 322 } |
230 | |
231 session_state_observers_.insert( | |
232 presentation_id, make_scoped_ptr(new PresentationSessionStateObserver( | |
233 listener, it->second, router_))); | |
234 return true; | |
235 } | 323 } |
236 | 324 |
237 void PresentationFrame::ListenForSessionMessages( | 325 void PresentationFrame::ListenForSessionMessages( |
238 const content::PresentationSessionInfo& session, | 326 const content::PresentationSessionInfo& session, |
239 const content::PresentationSessionMessageCallback& message_cb) { | 327 const content::PresentationSessionMessageCallback& message_cb) { |
240 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 328 auto it = presentation_id_to_route_id_.find(session.presentation_id); |
241 if (it == presentation_id_to_route_id_.end()) { | 329 if (it == presentation_id_to_route_id_.end()) { |
242 DVLOG(2) << "ListenForSessionMessages: no route for " | 330 DVLOG(2) << "ListenForSessionMessages: no route for " |
243 << session.presentation_id; | 331 << session.presentation_id; |
244 return; | 332 return; |
245 } | 333 } |
246 | 334 |
247 session_messages_observers_.push_back( | 335 OffscreenPresentationSession* offscreen_session = |
248 new PresentationSessionMessagesObserver(message_cb, it->second, router_)); | 336 FindOffscreenSession(session.presentation_id); |
337 if (offscreen_session) { | |
338 offscreen_session->ListenForMessages(message_cb); | |
339 } else { | |
340 session_messages_observers_.push_back( | |
341 new PresentationSessionMessagesObserver(message_cb, it->second, | |
342 router_)); | |
343 } | |
249 } | 344 } |
250 | 345 |
251 MediaSource PresentationFrame::GetMediaSourceFromListener( | 346 MediaSource PresentationFrame::GetMediaSourceFromListener( |
252 content::PresentationScreenAvailabilityListener* listener) const { | 347 content::PresentationScreenAvailabilityListener* listener) const { |
253 // If the default presentation URL is empty then fall back to tab mirroring. | 348 // If the default presentation URL is empty then fall back to tab mirroring. |
254 std::string availability_url(listener->GetAvailabilityUrl()); | 349 std::string availability_url(listener->GetAvailabilityUrl()); |
255 return availability_url.empty() | 350 return availability_url.empty() |
256 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 351 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
257 : MediaSourceForPresentationUrl(availability_url); | 352 : MediaSourceForPresentationUrl(availability_url); |
258 } | 353 } |
259 | 354 |
260 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. | 355 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. |
261 class PresentationFrameManager { | 356 class PresentationFrameManager { |
262 public: | 357 public: |
263 PresentationFrameManager(content::WebContents* web_contents, | 358 PresentationFrameManager(content::WebContents* web_contents, |
264 MediaRouter* router); | 359 MediaRouter* router); |
265 ~PresentationFrameManager(); | 360 ~PresentationFrameManager(); |
266 | 361 |
267 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 362 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
268 bool SetScreenAvailabilityListener( | 363 bool SetScreenAvailabilityListener( |
269 const RenderFrameHostId& render_frame_host_id, | 364 const RenderFrameHostId& render_frame_host_id, |
270 content::PresentationScreenAvailabilityListener* listener); | 365 content::PresentationScreenAvailabilityListener* listener); |
271 bool RemoveScreenAvailabilityListener( | 366 bool RemoveScreenAvailabilityListener( |
272 const RenderFrameHostId& render_frame_host_id, | 367 const RenderFrameHostId& render_frame_host_id, |
273 content::PresentationScreenAvailabilityListener* listener); | 368 content::PresentationScreenAvailabilityListener* listener); |
274 void SetDefaultPresentationUrl(const RenderFrameHostId& render_frame_host_id, | 369 void SetDefaultPresentationUrl(const RenderFrameHostId& render_frame_host_id, |
275 const std::string& default_presentation_url); | 370 const std::string& default_presentation_url); |
371 void SendMessage(const RenderFrameHostId& render_frame_host_id, | |
372 const content::PresentationSessionInfo& session, | |
373 scoped_ptr<content::PresentationSessionMessage> message, | |
374 const content::SendMessageCallback send_message_cb); | |
276 bool ListenForSessionStateChange( | 375 bool ListenForSessionStateChange( |
277 const RenderFrameHostId& render_frame_host_id, | 376 const RenderFrameHostId& render_frame_host_id, |
278 content::PresentationSessionStateListener* listener); | 377 content::PresentationSessionStateListener* listener); |
279 void ListenForSessionMessages( | 378 void ListenForSessionMessages( |
280 const RenderFrameHostId& render_frame_host_id, | 379 const RenderFrameHostId& render_frame_host_id, |
281 const content::PresentationSessionInfo& session, | 380 const content::PresentationSessionInfo& session, |
282 const content::PresentationSessionMessageCallback& message_cb); | 381 const content::PresentationSessionMessageCallback& message_cb); |
283 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, | 382 void AddDelegateObserver(const RenderFrameHostId& render_frame_host_id, |
284 DelegateObserver* observer); | 383 DelegateObserver* observer); |
285 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); | 384 void RemoveDelegateObserver(const RenderFrameHostId& render_frame_host_id); |
286 void Reset(const RenderFrameHostId& render_frame_host_id); | 385 void Reset(const RenderFrameHostId& render_frame_host_id); |
287 bool HasScreenAvailabilityListenerForTest( | 386 bool HasScreenAvailabilityListenerForTest( |
288 const RenderFrameHostId& render_frame_host_id, | 387 const RenderFrameHostId& render_frame_host_id, |
289 const MediaSource::Id& source_id) const; | 388 const MediaSource::Id& source_id) const; |
290 void SetMediaRouterForTest(MediaRouter* router); | 389 void SetMediaRouterForTest(MediaRouter* router); |
291 | 390 |
292 void OnPresentationSessionStarted( | 391 void OnPresentationSessionStarted( |
293 const RenderFrameHostId& render_frame_host_id, | 392 const RenderFrameHostId& render_frame_host_id, |
294 bool is_default_presentation, | 393 bool is_default_presentation, |
295 const content::PresentationSessionInfo& session, | 394 const content::PresentationSessionInfo& session, |
296 const MediaRoute::Id& route_id); | 395 const MediaRoute& route); |
297 | 396 |
298 void OnPresentationSessionClosed( | 397 void OnPresentationSessionClosed( |
299 const RenderFrameHostId& render_frame_host_id, | 398 const RenderFrameHostId& render_frame_host_id, |
300 const std::string& presentation_id); | 399 const std::string& presentation_id); |
301 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 400 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
302 const std::string& presentation_id) const; | 401 const std::string& presentation_id) const; |
303 const std::vector<MediaRoute::Id> GetRouteIds( | |
304 const RenderFrameHostId& render_frame_host_id) const; | |
305 | 402 |
306 private: | 403 private: |
307 PresentationFrame* GetOrAddPresentationFrame( | 404 PresentationFrame* GetOrAddPresentationFrame( |
308 const RenderFrameHostId& render_frame_host_id); | 405 const RenderFrameHostId& render_frame_host_id); |
309 | 406 |
310 // Maps a frame identifier to a PresentationFrame object for frames | 407 // Maps a frame identifier to a PresentationFrame object for frames |
311 // that are using presentation API. | 408 // that are using presentation API. |
312 base::ScopedPtrHashMap<RenderFrameHostId, scoped_ptr<PresentationFrame>> | 409 base::ScopedPtrHashMap<RenderFrameHostId, scoped_ptr<PresentationFrame>> |
313 presentation_frames_; | 410 presentation_frames_; |
314 | 411 |
315 // References to the owning WebContents, and the corresponding MediaRouter. | 412 // References to the owning WebContents, and the corresponding MediaRouter. |
413 content::WebContents* const web_contents_; | |
316 MediaRouter* router_; | 414 MediaRouter* router_; |
317 content::WebContents* web_contents_; | |
318 }; | 415 }; |
319 | 416 |
320 PresentationFrameManager::PresentationFrameManager( | 417 PresentationFrameManager::PresentationFrameManager( |
321 content::WebContents* web_contents, | 418 content::WebContents* web_contents, |
322 MediaRouter* router) | 419 MediaRouter* router) |
323 : router_(router), web_contents_(web_contents) { | 420 : web_contents_(web_contents), router_(router) { |
324 DCHECK(web_contents_); | 421 DCHECK(web_contents_); |
325 DCHECK(router_); | 422 DCHECK(router_); |
326 } | 423 } |
327 | 424 |
328 PresentationFrameManager::~PresentationFrameManager() { | 425 PresentationFrameManager::~PresentationFrameManager() { |
329 for (auto& frame : presentation_frames_) | 426 for (auto& frame : presentation_frames_) |
330 frame.second->OnPresentationServiceDelegateDestroyed(); | 427 frame.second->OnPresentationServiceDelegateDestroyed(); |
331 } | 428 } |
332 | 429 |
333 void PresentationFrameManager::OnPresentationSessionStarted( | 430 void PresentationFrameManager::OnPresentationSessionStarted( |
334 const RenderFrameHostId& render_frame_host_id, | 431 const RenderFrameHostId& render_frame_host_id, |
335 bool is_default_presentation, | 432 bool is_default_presentation, |
336 const content::PresentationSessionInfo& session, | 433 const content::PresentationSessionInfo& session, |
337 const MediaRoute::Id& route_id) { | 434 const MediaRoute& route) { |
338 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 435 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
339 if (presentation_frame) | 436 if (presentation_frame) { |
340 presentation_frame->OnPresentationSessionStarted(is_default_presentation, | 437 presentation_frame->OnPresentationSessionStarted(is_default_presentation, |
341 session, route_id); | 438 session, route); |
439 } | |
342 } | 440 } |
343 | 441 |
344 void PresentationFrameManager::OnPresentationSessionClosed( | 442 void PresentationFrameManager::OnPresentationSessionClosed( |
345 const RenderFrameHostId& render_frame_host_id, | 443 const RenderFrameHostId& render_frame_host_id, |
346 const std::string& presentation_id) { | 444 const std::string& presentation_id) { |
347 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 445 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
348 if (presentation_frame) | 446 if (presentation_frame) |
349 presentation_frame->OnPresentationSessionClosed(presentation_id); | 447 presentation_frame->OnPresentationSessionClosed(presentation_id); |
350 } | 448 } |
351 | 449 |
352 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 450 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
353 const RenderFrameHostId& render_frame_host_id, | 451 const RenderFrameHostId& render_frame_host_id, |
354 const std::string& presentation_id) const { | 452 const std::string& presentation_id) const { |
355 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 453 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
356 return presentation_frame ? presentation_frame->GetRouteId(presentation_id) | 454 return presentation_frame ? presentation_frame->GetRouteId(presentation_id) |
357 : ""; | 455 : ""; |
358 } | 456 } |
359 | 457 |
360 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | |
361 const RenderFrameHostId& render_frame_host_id) const { | |
362 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | |
363 return presentation_frame ? presentation_frame->GetRouteIds() | |
364 : std::vector<MediaRoute::Id>(); | |
365 } | |
366 | |
367 bool PresentationFrameManager::SetScreenAvailabilityListener( | 458 bool PresentationFrameManager::SetScreenAvailabilityListener( |
368 const RenderFrameHostId& render_frame_host_id, | 459 const RenderFrameHostId& render_frame_host_id, |
369 content::PresentationScreenAvailabilityListener* listener) { | 460 content::PresentationScreenAvailabilityListener* listener) { |
370 DCHECK(listener); | 461 DCHECK(listener); |
371 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 462 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
372 return presentation_frame->SetScreenAvailabilityListener(listener); | 463 return presentation_frame->SetScreenAvailabilityListener(listener); |
373 } | 464 } |
374 | 465 |
375 bool PresentationFrameManager::RemoveScreenAvailabilityListener( | 466 bool PresentationFrameManager::RemoveScreenAvailabilityListener( |
376 const RenderFrameHostId& render_frame_host_id, | 467 const RenderFrameHostId& render_frame_host_id, |
(...skipping 12 matching lines...) Expand all Loading... | |
389 presentation_frame->HasScreenAvailabilityListenerForTest(source_id); | 480 presentation_frame->HasScreenAvailabilityListenerForTest(source_id); |
390 } | 481 } |
391 | 482 |
392 void PresentationFrameManager::SetDefaultPresentationUrl( | 483 void PresentationFrameManager::SetDefaultPresentationUrl( |
393 const RenderFrameHostId& render_frame_host_id, | 484 const RenderFrameHostId& render_frame_host_id, |
394 const std::string& default_presentation_url) { | 485 const std::string& default_presentation_url) { |
395 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 486 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
396 presentation_frame->set_default_presentation_url(default_presentation_url); | 487 presentation_frame->set_default_presentation_url(default_presentation_url); |
397 } | 488 } |
398 | 489 |
399 void PresentationFrameManager::ListenForSessionStateChange( | 490 void PresentationFrameManager::SendMessage( |
491 const RenderFrameHostId& render_frame_host_id, | |
492 const content::PresentationSessionInfo& session, | |
493 scoped_ptr<content::PresentationSessionMessage> message, | |
494 const content::SendMessageCallback send_message_cb) { | |
495 PresentationFrame* presentation_frame = | |
496 presentation_frames_.get(render_frame_host_id); | |
497 if (!presentation_frame) { | |
498 DVLOG(2) << "SendMessage: PresentationFrame does not exist " | |
499 << "for: (" << render_frame_host_id.first << ", " | |
500 << render_frame_host_id.second << ")"; | |
501 send_message_cb.Run(false); | |
502 return; | |
503 } | |
504 | |
505 presentation_frame->SendMessage(session, message.Pass(), send_message_cb); | |
506 } | |
507 | |
508 bool PresentationFrameManager::ListenForSessionStateChange( | |
400 const RenderFrameHostId& render_frame_host_id, | 509 const RenderFrameHostId& render_frame_host_id, |
401 content::PresentationSessionStateListener* listener) { | 510 content::PresentationSessionStateListener* listener) { |
402 PresentationFrame* presentation_frame = | 511 PresentationFrame* presentation_frame = |
403 GetOrAddPresentationFrame(render_frame_host_id); | 512 GetOrAddPresentationFrame(render_frame_host_id); |
404 return presentation_frame->ListenForSessionStateChange(listener); | 513 return presentation_frame->ListenForSessionStateChange(listener); |
405 } | 514 } |
406 | 515 |
407 void PresentationFrameManager::ListenForSessionMessages( | 516 void PresentationFrameManager::ListenForSessionMessages( |
408 const RenderFrameHostId& render_frame_host_id, | 517 const RenderFrameHostId& render_frame_host_id, |
409 const content::PresentationSessionInfo& session, | 518 const content::PresentationSessionInfo& session, |
(...skipping 30 matching lines...) Expand all Loading... | |
440 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 549 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
441 if (presentation_frame) | 550 if (presentation_frame) |
442 presentation_frame->Reset(); | 551 presentation_frame->Reset(); |
443 } | 552 } |
444 | 553 |
445 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( | 554 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( |
446 const RenderFrameHostId& render_frame_host_id) { | 555 const RenderFrameHostId& render_frame_host_id) { |
447 if (!presentation_frames_.contains(render_frame_host_id)) { | 556 if (!presentation_frames_.contains(render_frame_host_id)) { |
448 presentation_frames_.add( | 557 presentation_frames_.add( |
449 render_frame_host_id, | 558 render_frame_host_id, |
450 scoped_ptr<PresentationFrame>( | 559 scoped_ptr<PresentationFrame>(new PresentationFrame( |
451 new PresentationFrame(web_contents_, router_))); | 560 web_contents_, render_frame_host_id, router_))); |
452 } | 561 } |
453 return presentation_frames_.get(render_frame_host_id); | 562 return presentation_frames_.get(render_frame_host_id); |
454 } | 563 } |
455 | 564 |
456 void PresentationFrameManager::SetMediaRouterForTest(MediaRouter* router) { | 565 void PresentationFrameManager::SetMediaRouterForTest(MediaRouter* router) { |
457 router_ = router; | 566 router_ = router; |
458 } | 567 } |
459 | 568 |
460 PresentationServiceDelegateImpl* | 569 PresentationServiceDelegateImpl* |
461 PresentationServiceDelegateImpl::GetOrCreateForWebContents( | 570 PresentationServiceDelegateImpl::GetOrCreateForWebContents( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 const MediaRoute* route, | 680 const MediaRoute* route, |
572 const std::string& presentation_id, | 681 const std::string& presentation_id, |
573 const std::string& error_text) { | 682 const std::string& error_text) { |
574 if (!route) { | 683 if (!route) { |
575 error_cb.Run(content::PresentationError( | 684 error_cb.Run(content::PresentationError( |
576 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text)); | 685 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text)); |
577 } else { | 686 } else { |
578 DVLOG(1) << "OnJoinRouteResponse: " | 687 DVLOG(1) << "OnJoinRouteResponse: " |
579 << "route_id: " << route->media_route_id() | 688 << "route_id: " << route->media_route_id() |
580 << ", presentation URL: " << session.presentation_url | 689 << ", presentation URL: " << session.presentation_url |
581 << ", presentation ID: " << session.presentation_id; | 690 << ", presentation ID: " << session.presentation_id |
691 << ", offscreen? " << route->is_offscreen_presentation(); | |
582 DCHECK_EQ(session.presentation_id, presentation_id); | 692 DCHECK_EQ(session.presentation_id, presentation_id); |
583 frame_manager_->OnPresentationSessionStarted( | 693 RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
584 RenderFrameHostId(render_process_id, render_frame_id), false, session, | 694 frame_manager_->OnPresentationSessionStarted(rfh_id, false, session, |
585 route->media_route_id()); | 695 *route); |
586 success_cb.Run(session); | 696 success_cb.Run(session); |
587 } | 697 } |
588 } | 698 } |
589 | 699 |
590 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( | 700 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( |
591 int render_process_id, | 701 int render_process_id, |
592 int render_frame_id, | 702 int render_frame_id, |
593 const PresentationSessionSuccessCallback& success_cb, | 703 const PresentationSessionSuccessCallback& success_cb, |
594 const content::PresentationSessionInfo& new_session, | 704 const content::PresentationSessionInfo& new_session, |
595 const MediaRoute::Id& route_id) { | 705 const MediaRoute& route) { |
706 const MediaRoute::Id& route_id = route.media_route_id(); | |
596 DVLOG(1) << "OnStartSessionSucceeded: " | 707 DVLOG(1) << "OnStartSessionSucceeded: " |
597 << "route_id: " << route_id | 708 << "route_id: " << route_id |
598 << ", presentation URL: " << new_session.presentation_url | 709 << ", presentation URL: " << new_session.presentation_url |
599 << ", presentation ID: " << new_session.presentation_id; | 710 << ", presentation ID: " << new_session.presentation_id; |
600 frame_manager_->OnPresentationSessionStarted( | 711 RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
601 RenderFrameHostId(render_process_id, render_frame_id), false, new_session, | 712 frame_manager_->OnPresentationSessionStarted(rfh_id, false, new_session, |
602 route_id); | 713 route); |
603 success_cb.Run(new_session); | 714 success_cb.Run(new_session); |
604 } | 715 } |
605 | 716 |
606 void PresentationServiceDelegateImpl::StartSession( | 717 void PresentationServiceDelegateImpl::StartSession( |
607 int render_process_id, | 718 int render_process_id, |
608 int render_frame_id, | 719 int render_frame_id, |
609 const std::string& presentation_url, | 720 const std::string& presentation_url, |
610 const PresentationSessionSuccessCallback& success_cb, | 721 const PresentationSessionSuccessCallback& success_cb, |
611 const PresentationSessionErrorCallback& error_cb) { | 722 const PresentationSessionErrorCallback& error_cb) { |
612 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { | 723 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 return; | 776 return; |
666 } | 777 } |
667 router_->CloseRoute(route_id); | 778 router_->CloseRoute(route_id); |
668 } | 779 } |
669 | 780 |
670 void PresentationServiceDelegateImpl::ListenForSessionMessages( | 781 void PresentationServiceDelegateImpl::ListenForSessionMessages( |
671 int render_process_id, | 782 int render_process_id, |
672 int render_frame_id, | 783 int render_frame_id, |
673 const content::PresentationSessionInfo& session, | 784 const content::PresentationSessionInfo& session, |
674 const content::PresentationSessionMessageCallback& message_cb) { | 785 const content::PresentationSessionMessageCallback& message_cb) { |
675 frame_manager_->ListenForSessionMessages( | 786 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
676 RenderFrameHostId(render_process_id, render_frame_id), session, | 787 frame_manager_->ListenForSessionMessages(render_frame_host_id, session, |
677 message_cb); | 788 message_cb); |
678 } | 789 } |
679 | 790 |
680 void PresentationServiceDelegateImpl::SendMessage( | 791 void PresentationServiceDelegateImpl::SendMessage( |
681 int render_process_id, | 792 int render_process_id, |
682 int render_frame_id, | 793 int render_frame_id, |
683 const content::PresentationSessionInfo& session, | 794 const content::PresentationSessionInfo& session, |
684 scoped_ptr<content::PresentationSessionMessage> message, | 795 scoped_ptr<content::PresentationSessionMessage> message, |
685 const SendMessageCallback& send_message_cb) { | 796 const content::SendMessageCallback& send_message_cb) { |
686 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 797 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
687 RenderFrameHostId(render_process_id, render_frame_id), | 798 frame_manager_->SendMessage(render_frame_host_id, session, message.Pass(), |
688 session.presentation_id); | 799 send_message_cb); |
689 if (route_id.empty()) { | |
690 DVLOG(1) << "No active route for " << session.presentation_id; | |
691 send_message_cb.Run(false); | |
692 return; | |
693 } | |
694 | |
695 if (message->is_binary()) { | |
696 router_->SendRouteBinaryMessage(route_id, message->data.Pass(), | |
697 send_message_cb); | |
698 } else { | |
699 router_->SendRouteMessage(route_id, message->message, send_message_cb); | |
700 } | |
701 } | 800 } |
702 | 801 |
703 bool PresentationServiceDelegateImpl::ListenForSessionStateChange( | 802 bool PresentationServiceDelegateImpl::ListenForSessionStateChange( |
704 int render_process_id, | 803 int render_process_id, |
705 int render_frame_id, | 804 int render_frame_id, |
706 content::PresentationSessionStateListener* listener) { | 805 content::PresentationSessionStateListener* listener) { |
707 return frame_manager_->ListenForSessionStateChange( | 806 return frame_manager_->ListenForSessionStateChange( |
708 RenderFrameHostId(render_process_id, render_frame_id), listener); | 807 RenderFrameHostId(render_process_id, render_frame_id), listener); |
709 } | 808 } |
710 | 809 |
810 void PresentationServiceDelegateImpl::GetPresentationReceiverSession( | |
811 int render_process_id, | |
812 int render_frame_id, | |
813 const content::PresentationReceiverSessionAvailableCallback& callback) { | |
814 // We only support receiver APIs in offscreen tabs created for offscreen | |
815 // presentations. | |
816 // See ReceiverPresentationServiceDelegateImpl for details. | |
817 NOTIMPLEMENTED(); | |
818 callback.Run(nullptr); | |
819 } | |
820 | |
821 std::vector<content::PresentationSessionInfo> | |
822 PresentationServiceDelegateImpl::GetPresentationReceiverSessions( | |
823 int render_process_id, | |
824 int render_frame_id) { | |
825 // See comment in |GetPresentationReceiverSession()|. | |
826 NOTIMPLEMENTED(); | |
827 return std::vector<content::PresentationSessionInfo>(); | |
828 } | |
829 | |
711 void PresentationServiceDelegateImpl::OnRouteResponse( | 830 void PresentationServiceDelegateImpl::OnRouteResponse( |
712 const MediaRoute* route, | 831 const MediaRoute* route, |
713 const std::string& presentation_id, | 832 const std::string& presentation_id, |
714 const std::string& error) { | 833 const std::string& error) { |
715 if (!route) | 834 if (!route) |
716 return; | 835 return; |
836 | |
717 const MediaSource& source = route->media_source(); | 837 const MediaSource& source = route->media_source(); |
718 DCHECK(!source.Empty()); | 838 DCHECK(!source.Empty()); |
719 if (!default_source_.Equals(source)) | 839 if (!default_source_.Equals(source)) |
720 return; | 840 return; |
841 | |
721 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); | 842 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); |
722 if (!main_frame) | 843 if (!main_frame) |
723 return; | 844 return; |
845 | |
724 RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame)); | 846 RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame)); |
725 frame_manager_->OnPresentationSessionStarted( | 847 content::PresentationSessionInfo session( |
726 render_frame_host_id, true, | 848 PresentationUrlFromMediaSource(source), presentation_id); |
727 content::PresentationSessionInfo(PresentationUrlFromMediaSource(source), | 849 |
728 presentation_id), | 850 frame_manager_->OnPresentationSessionStarted(render_frame_host_id, true, |
729 route->media_route_id()); | 851 session, *route); |
730 } | 852 } |
731 | 853 |
732 void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver( | 854 void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver( |
733 DefaultMediaSourceObserver* observer) { | 855 DefaultMediaSourceObserver* observer) { |
734 default_media_source_observers_.AddObserver(observer); | 856 default_media_source_observers_.AddObserver(observer); |
735 } | 857 } |
736 | 858 |
737 void PresentationServiceDelegateImpl::RemoveDefaultMediaSourceObserver( | 859 void PresentationServiceDelegateImpl::RemoveDefaultMediaSourceObserver( |
738 DefaultMediaSourceObserver* observer) { | 860 DefaultMediaSourceObserver* observer) { |
739 default_media_source_observers_.RemoveObserver(observer); | 861 default_media_source_observers_.RemoveObserver(observer); |
(...skipping 13 matching lines...) Expand all Loading... | |
753 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 875 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
754 int render_process_id, | 876 int render_process_id, |
755 int render_frame_id, | 877 int render_frame_id, |
756 const MediaSource::Id& source_id) const { | 878 const MediaSource::Id& source_id) const { |
757 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 879 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
758 return frame_manager_->HasScreenAvailabilityListenerForTest( | 880 return frame_manager_->HasScreenAvailabilityListenerForTest( |
759 render_frame_host_id, source_id); | 881 render_frame_host_id, source_id); |
760 } | 882 } |
761 | 883 |
762 } // namespace media_router | 884 } // namespace media_router |
OLD | NEW |