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