| 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/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
| 10 #include "content/public/renderer/render_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); | 52 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); |
| 53 return url.is_valid() ? url : GURL(); | 53 return url.is_valid() ? url : GURL(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 namespace content { | 58 namespace content { |
| 59 | 59 |
| 60 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) | 60 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) |
| 61 : RenderFrameObserver(render_frame), | 61 : RenderFrameObserver(render_frame), |
| 62 controller_(nullptr) { | 62 controller_(nullptr), |
| 63 binding_(this) { |
| 63 } | 64 } |
| 64 | 65 |
| 65 PresentationDispatcher::~PresentationDispatcher() { | 66 PresentationDispatcher::~PresentationDispatcher() { |
| 66 // Controller should be destroyed before the dispatcher when frame is | 67 // Controller should be destroyed before the dispatcher when frame is |
| 67 // destroyed. | 68 // destroyed. |
| 68 DCHECK(!controller_); | 69 DCHECK(!controller_); |
| 69 } | 70 } |
| 70 | 71 |
| 71 void PresentationDispatcher::setController( | 72 void PresentationDispatcher::setController( |
| 72 blink::WebPresentationController* controller) { | 73 blink::WebPresentationController* controller) { |
| 73 // There shouldn't be any swapping from one non-null controller to another. | 74 // There shouldn't be any swapping from one non-null controller to another. |
| 74 DCHECK(controller != controller_ && (!controller || !controller_)); | 75 DCHECK(controller != controller_ && (!controller || !controller_)); |
| 75 controller_ = controller; | 76 controller_ = controller; |
| 76 // The controller is set to null when the frame is about to be detached. | 77 // The controller is set to null when the frame is about to be detached. |
| 77 // Nothing is listening for screen availability anymore but the Mojo service | 78 // Nothing is listening for screen availability anymore but the Mojo service |
| 78 // will know about the frame being detached anyway. | 79 // will know about the frame being detached anyway. |
| 79 } | 80 } |
| 80 | 81 |
| 81 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | 82 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
| 82 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | |
| 83 DoUpdateAvailableChangeWatched(presentation_url.spec(), watched); | |
| 84 } | |
| 85 | |
| 86 void PresentationDispatcher::DoUpdateAvailableChangeWatched( | |
| 87 const std::string& presentation_url, bool watched) { | |
| 88 ConnectToPresentationServiceIfNeeded(); | 83 ConnectToPresentationServiceIfNeeded(); |
| 89 if (watched) { | 84 if (watched) |
| 90 presentation_service_->ListenForScreenAvailability( | 85 presentation_service_->ListenForScreenAvailability(); |
| 91 presentation_url, | 86 else |
| 92 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | 87 presentation_service_->StopListeningForScreenAvailability(); |
| 93 base::Unretained(this))); | |
| 94 } else { | |
| 95 presentation_service_->RemoveScreenAvailabilityListener(presentation_url); | |
| 96 } | |
| 97 } | 88 } |
| 98 | 89 |
| 99 void PresentationDispatcher::startSession( | 90 void PresentationDispatcher::startSession( |
| 100 const blink::WebString& presentationUrl, | 91 const blink::WebString& presentationUrl, |
| 101 const blink::WebString& presentationId, | 92 const blink::WebString& presentationId, |
| 102 blink::WebPresentationSessionClientCallbacks* callback) { | 93 blink::WebPresentationSessionClientCallbacks* callback) { |
| 103 DCHECK(callback); | 94 DCHECK(callback); |
| 104 ConnectToPresentationServiceIfNeeded(); | 95 ConnectToPresentationServiceIfNeeded(); |
| 105 | 96 |
| 106 // The dispatcher owns the service so |this| will be valid when | 97 // The dispatcher owns the service so |this| will be valid when |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 134 } |
| 144 | 135 |
| 145 void PresentationDispatcher::DidChangeDefaultPresentation() { | 136 void PresentationDispatcher::DidChangeDefaultPresentation() { |
| 146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | 137 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); |
| 147 | 138 |
| 148 ConnectToPresentationServiceIfNeeded(); | 139 ConnectToPresentationServiceIfNeeded(); |
| 149 presentation_service_->SetDefaultPresentationURL( | 140 presentation_service_->SetDefaultPresentationURL( |
| 150 presentation_url.spec(), mojo::String()); | 141 presentation_url.spec(), mojo::String()); |
| 151 } | 142 } |
| 152 | 143 |
| 153 void PresentationDispatcher::OnScreenAvailabilityChanged( | 144 void PresentationDispatcher::OnScreenAvailabilityUpdated(bool available) { |
| 154 const std::string& presentation_url, bool available) { | 145 if (controller_) |
| 155 if (!controller_) | 146 controller_->didChangeAvailability(available); |
| 156 return; | |
| 157 | |
| 158 // Reset the callback to get the next event. | |
| 159 DoUpdateAvailableChangeWatched(presentation_url, | |
| 160 controller_->isAvailableChangeWatched()); | |
| 161 | |
| 162 controller_->didChangeAvailability(available); | |
| 163 } | 147 } |
| 164 | 148 |
| 165 void PresentationDispatcher::OnDefaultSessionStarted( | 149 void PresentationDispatcher::OnDefaultSessionStarted( |
| 166 presentation::PresentationSessionInfoPtr session_info) { | 150 presentation::PresentationSessionInfoPtr session_info) { |
| 167 if (!controller_) | 151 if (!controller_) |
| 168 return; | 152 return; |
| 169 | 153 |
| 170 // Reset the callback to get the next event. | 154 // Reset the callback to get the next event. |
| 171 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 155 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
| 172 &PresentationDispatcher::OnDefaultSessionStarted, | 156 &PresentationDispatcher::OnDefaultSessionStarted, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 217 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
| 234 base::Unretained(this))); | 218 base::Unretained(this))); |
| 235 } | 219 } |
| 236 | 220 |
| 237 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 221 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| 238 if (presentation_service_.get()) | 222 if (presentation_service_.get()) |
| 239 return; | 223 return; |
| 240 | 224 |
| 241 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 225 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 242 &presentation_service_); | 226 &presentation_service_); |
| 227 presentation::PresentationServiceClientPtr client_ptr; |
| 228 binding_.Bind(GetProxy(&client_ptr)); |
| 229 presentation_service_->SetClient(client_ptr.Pass()); |
| 230 |
| 243 // TODO(imcheng): Uncomment these once they are implemented on the browser | 231 // TODO(imcheng): Uncomment these once they are implemented on the browser |
| 244 // side. (crbug.com/459006) | 232 // side. (crbug.com/459006) |
| 245 /* | 233 /* |
| 246 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 234 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
| 247 &PresentationDispatcher::OnDefaultSessionStarted, | 235 &PresentationDispatcher::OnDefaultSessionStarted, |
| 248 base::Unretained(this))); | 236 base::Unretained(this))); |
| 249 presentation_service_->ListenForSessionStateChange(base::Bind( | 237 presentation_service_->ListenForSessionStateChange(base::Bind( |
| 250 &PresentationDispatcher::OnSessionStateChange, | 238 &PresentationDispatcher::OnSessionStateChange, |
| 251 base::Unretained(this))); | 239 base::Unretained(this))); |
| 252 presentation_service_->ListenForSessionMessages( | 240 presentation_service_->ListenForSessionMessages( |
| 253 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, | 241 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, |
| 254 base::Unretained(this))); | 242 base::Unretained(this))); |
| 255 */ | 243 */ |
| 256 } | 244 } |
| 257 | 245 |
| 258 } // namespace content | 246 } // namespace content |
| OLD | NEW |