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 "content/renderer/presentation/presentation_dispatcher.h" | 5 #include "content/renderer/presentation/presentation_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/presentation/presentation_service.mojom.h" | 8 #include "content/common/presentation/presentation_service.mojom.h" |
9 #include "content/public/common/presentation_constants.h" | 9 #include "content/public/common/presentation_constants.h" |
10 #include "content/public/common/service_registry.h" | 10 #include "content/public/common/service_registry.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); | 53 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); |
54 return url.is_valid() ? url : GURL(); | 54 return url.is_valid() ? url : GURL(); |
55 } | 55 } |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 namespace content { | 59 namespace content { |
60 | 60 |
61 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 61 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
62 : RenderFrameObserver(render_frame), | 62 : RenderFrameObserver(render_frame), |
63 controller_(nullptr) { | 63 controller_(nullptr), |
| 64 binding_(this) { |
64 } | 65 } |
65 | 66 |
66 PresentationDispatcher::~PresentationDispatcher() { | 67 PresentationDispatcher::~PresentationDispatcher() { |
67 // Controller should be destroyed before the dispatcher when frame is | 68 // Controller should be destroyed before the dispatcher when frame is |
68 // destroyed. | 69 // destroyed. |
69 DCHECK(!controller_); | 70 DCHECK(!controller_); |
70 } | 71 } |
71 | 72 |
72 void PresentationDispatcher::setController( | 73 void PresentationDispatcher::setController( |
73 blink::WebPresentationController* controller) { | 74 blink::WebPresentationController* controller) { |
74 // There shouldn't be any swapping from one non-null controller to another. | 75 // There shouldn't be any swapping from one non-null controller to another. |
75 DCHECK(controller != controller_ && (!controller || !controller_)); | 76 DCHECK(controller != controller_ && (!controller || !controller_)); |
76 controller_ = controller; | 77 controller_ = controller; |
77 // The controller is set to null when the frame is about to be detached. | 78 // The controller is set to null when the frame is about to be detached. |
78 // Nothing is listening for screen availability anymore but the Mojo service | 79 // Nothing is listening for screen availability anymore but the Mojo service |
79 // will know about the frame being detached anyway. | 80 // will know about the frame being detached anyway. |
80 } | 81 } |
81 | 82 |
82 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | 83 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
83 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | |
84 DoUpdateAvailableChangeWatched(presentation_url.spec(), watched); | |
85 } | |
86 | |
87 void PresentationDispatcher::DoUpdateAvailableChangeWatched( | |
88 const std::string& presentation_url, bool watched) { | |
89 ConnectToPresentationServiceIfNeeded(); | 84 ConnectToPresentationServiceIfNeeded(); |
90 if (watched) { | 85 if (watched) |
91 presentation_service_->ListenForScreenAvailability( | 86 presentation_service_->ListenForScreenAvailability(); |
92 presentation_url, | 87 else |
93 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | 88 presentation_service_->StopListeningForScreenAvailability(); |
94 base::Unretained(this))); | |
95 } else { | |
96 presentation_service_->RemoveScreenAvailabilityListener(presentation_url); | |
97 } | |
98 } | 89 } |
99 | 90 |
100 void PresentationDispatcher::startSession( | 91 void PresentationDispatcher::startSession( |
101 const blink::WebString& presentationUrl, | 92 const blink::WebString& presentationUrl, |
102 const blink::WebString& presentationId, | 93 const blink::WebString& presentationId, |
103 blink::WebPresentationSessionClientCallbacks* callback) { | 94 blink::WebPresentationSessionClientCallbacks* callback) { |
104 DCHECK(callback); | 95 DCHECK(callback); |
105 ConnectToPresentationServiceIfNeeded(); | 96 ConnectToPresentationServiceIfNeeded(); |
106 | 97 |
107 // The dispatcher owns the service so |this| will be valid when | 98 // The dispatcher owns the service so |this| will be valid when |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 254 blink::WebFrame* frame = render_frame()->GetWebFrame(); |
264 // If not top-level navigation. | 255 // If not top-level navigation. |
265 if (frame->parent() || is_same_page_navigation) | 256 if (frame->parent() || is_same_page_navigation) |
266 return; | 257 return; |
267 | 258 |
268 // Remove all pending send message requests. | 259 // Remove all pending send message requests. |
269 MessageRequestQueue empty; | 260 MessageRequestQueue empty; |
270 std::swap(message_request_queue_, empty); | 261 std::swap(message_request_queue_, empty); |
271 } | 262 } |
272 | 263 |
273 void PresentationDispatcher::OnScreenAvailabilityChanged( | 264 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
274 const std::string& presentation_url, bool available) { | 265 if (controller_) |
275 if (!controller_) | 266 controller_->didChangeAvailability(available); |
276 return; | |
277 | |
278 // Reset the callback to get the next event. | |
279 DoUpdateAvailableChangeWatched(presentation_url, | |
280 controller_->isAvailableChangeWatched()); | |
281 | |
282 controller_->didChangeAvailability(available); | |
283 } | 267 } |
284 | 268 |
285 void PresentationDispatcher::OnDefaultSessionStarted( | 269 void PresentationDispatcher::OnDefaultSessionStarted( |
286 presentation::PresentationSessionInfoPtr session_info) { | 270 presentation::PresentationSessionInfoPtr session_info) { |
287 if (!controller_) | 271 if (!controller_) |
288 return; | 272 return; |
289 | 273 |
290 // Reset the callback to get the next event. | 274 // Reset the callback to get the next event. |
291 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 275 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
292 &PresentationDispatcher::OnDefaultSessionStarted, | 276 &PresentationDispatcher::OnDefaultSessionStarted, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 337 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
354 base::Unretained(this))); | 338 base::Unretained(this))); |
355 } | 339 } |
356 | 340 |
357 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 341 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
358 if (presentation_service_.get()) | 342 if (presentation_service_.get()) |
359 return; | 343 return; |
360 | 344 |
361 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 345 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
362 &presentation_service_); | 346 &presentation_service_); |
| 347 presentation::PresentationServiceClientPtr client_ptr; |
| 348 binding_.Bind(GetProxy(&client_ptr)); |
| 349 presentation_service_->SetClient(client_ptr.Pass()); |
| 350 |
363 // TODO(imcheng): Uncomment these once they are implemented on the browser | 351 // TODO(imcheng): Uncomment these once they are implemented on the browser |
364 // side. (crbug.com/459006) | 352 // side. (crbug.com/459006) |
365 /* | 353 /* |
366 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 354 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
367 &PresentationDispatcher::OnDefaultSessionStarted, | 355 &PresentationDispatcher::OnDefaultSessionStarted, |
368 base::Unretained(this))); | 356 base::Unretained(this))); |
369 presentation_service_->ListenForSessionStateChange(base::Bind( | 357 presentation_service_->ListenForSessionStateChange(base::Bind( |
370 &PresentationDispatcher::OnSessionStateChange, | 358 &PresentationDispatcher::OnSessionStateChange, |
371 base::Unretained(this))); | 359 base::Unretained(this))); |
372 presentation_service_->ListenForSessionMessages( | 360 presentation_service_->ListenForSessionMessages( |
373 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 361 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
374 base::Unretained(this))); | 362 base::Unretained(this))); |
375 */ | 363 */ |
376 } | 364 } |
377 | 365 |
378 } // namespace content | 366 } // namespace content |
OLD | NEW |