| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // There shouldn't be any swapping from one non-null controller to another. | 60 // There shouldn't be any swapping from one non-null controller to another. |
| 61 DCHECK(controller != controller_ && (!controller || !controller_)); | 61 DCHECK(controller != controller_ && (!controller || !controller_)); |
| 62 controller_ = controller; | 62 controller_ = controller; |
| 63 // The controller is set to null when the frame is about to be detached. | 63 // The controller is set to null when the frame is about to be detached. |
| 64 // Nothing is listening for screen availability anymore but the Mojo service | 64 // Nothing is listening for screen availability anymore but the Mojo service |
| 65 // will know about the frame being detached anyway. | 65 // will know about the frame being detached anyway. |
| 66 } | 66 } |
| 67 | 67 |
| 68 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | 68 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
| 69 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | 69 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); |
| 70 DoUpdateAvailableChangeWatched(presentation_url.spec(), watched); |
| 71 } |
| 70 | 72 |
| 73 void PresentationDispatcher::DoUpdateAvailableChangeWatched( |
| 74 const std::string& presentation_url, bool watched) { |
| 71 ConnectToPresentationServiceIfNeeded(); | 75 ConnectToPresentationServiceIfNeeded(); |
| 72 if (watched) { | 76 if (watched) { |
| 73 presentation_service_->GetScreenAvailability( | 77 presentation_service_->GetScreenAvailability( |
| 74 presentation_url.spec(), | 78 presentation_url, |
| 75 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | 79 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, |
| 76 base::Unretained(this))); | 80 base::Unretained(this))); |
| 77 } else { | 81 } else { |
| 78 presentation_service_->OnScreenAvailabilityListenerRemoved( | 82 presentation_service_->OnScreenAvailabilityListenerRemoved( |
| 79 presentation_url.spec()); | 83 presentation_url); |
| 80 } | 84 } |
| 81 } | 85 } |
| 82 | 86 |
| 83 void PresentationDispatcher::startSession( | 87 void PresentationDispatcher::startSession( |
| 84 const blink::WebString& presentationUrl, | 88 const blink::WebString& presentationUrl, |
| 85 const blink::WebString& presentationId, | 89 const blink::WebString& presentationId, |
| 86 blink::WebPresentationSessionClientCallbacks* callback) { | 90 blink::WebPresentationSessionClientCallbacks* callback) { |
| 87 DCHECK(callback); | 91 DCHECK(callback); |
| 88 ConnectToPresentationServiceIfNeeded(); | 92 ConnectToPresentationServiceIfNeeded(); |
| 89 | 93 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 117 } | 121 } |
| 118 | 122 |
| 119 void PresentationDispatcher::DidChangeDefaultPresentation() { | 123 void PresentationDispatcher::DidChangeDefaultPresentation() { |
| 120 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); | 124 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); |
| 121 | 125 |
| 122 ConnectToPresentationServiceIfNeeded(); | 126 ConnectToPresentationServiceIfNeeded(); |
| 123 presentation_service_->SetDefaultPresentationURL( | 127 presentation_service_->SetDefaultPresentationURL( |
| 124 presentation_url.spec(), mojo::String()); | 128 presentation_url.spec(), mojo::String()); |
| 125 } | 129 } |
| 126 | 130 |
| 127 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | 131 void PresentationDispatcher::OnScreenAvailabilityChanged( |
| 132 const std::string& presentation_url, bool available) { |
| 128 if (!controller_) | 133 if (!controller_) |
| 129 return; | 134 return; |
| 130 | 135 |
| 131 // Reset the callback to get the next event. | 136 // Reset the callback to get the next event. |
| 132 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | 137 DoUpdateAvailableChangeWatched(presentation_url, |
| 138 controller_->isAvailableChangeWatched()); |
| 133 | 139 |
| 134 controller_->didChangeAvailability(available); | 140 controller_->didChangeAvailability(available); |
| 135 } | 141 } |
| 136 | 142 |
| 137 void PresentationDispatcher::OnDefaultSessionStarted( | 143 void PresentationDispatcher::OnDefaultSessionStarted( |
| 138 presentation::PresentationSessionInfoPtr session_info) { | 144 presentation::PresentationSessionInfoPtr session_info) { |
| 139 if (!controller_) | 145 if (!controller_) |
| 140 return; | 146 return; |
| 141 | 147 |
| 142 // Reset the callback to get the next event. | 148 // Reset the callback to get the next event. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 153 } | 159 } |
| 154 | 160 |
| 155 void PresentationDispatcher::OnSessionCreated( | 161 void PresentationDispatcher::OnSessionCreated( |
| 156 blink::WebPresentationSessionClientCallbacks* callback, | 162 blink::WebPresentationSessionClientCallbacks* callback, |
| 157 presentation::PresentationSessionInfoPtr session_info, | 163 presentation::PresentationSessionInfoPtr session_info, |
| 158 presentation::PresentationErrorPtr error) { | 164 presentation::PresentationErrorPtr error) { |
| 159 DCHECK(callback); | 165 DCHECK(callback); |
| 160 if (!error.is_null()) { | 166 if (!error.is_null()) { |
| 161 DCHECK(session_info.is_null()); | 167 DCHECK(session_info.is_null()); |
| 162 callback->onError(new blink::WebPresentationError( | 168 callback->onError(new blink::WebPresentationError( |
| 163 GetWebPresentationErrorTypeFromMojo(error->errorType), | 169 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 164 blink::WebString::fromUTF8(error->message))); | 170 blink::WebString::fromUTF8(error->message))); |
| 165 return; | 171 return; |
| 166 } | 172 } |
| 167 | 173 |
| 168 DCHECK(!session_info.is_null()); | 174 DCHECK(!session_info.is_null()); |
| 169 PresentationSessionDispatcher* session_dispatcher = | 175 PresentationSessionDispatcher* session_dispatcher = |
| 170 new PresentationSessionDispatcher(session_info.Pass()); | 176 new PresentationSessionDispatcher(session_info.Pass()); |
| 171 presentation_session_dispatchers_.push_back(session_dispatcher); | 177 presentation_session_dispatchers_.push_back(session_dispatcher); |
| 172 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); | 178 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); |
| 173 } | 179 } |
| 174 | 180 |
| 175 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 181 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| 176 if (presentation_service_.get()) | 182 if (presentation_service_.get()) |
| 177 return; | 183 return; |
| 178 | 184 |
| 179 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 185 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 180 &presentation_service_); | 186 &presentation_service_); |
| 181 presentation_service_->ListenForDefaultSessionStart(base::Bind( | 187 presentation_service_->ListenForDefaultSessionStart(base::Bind( |
| 182 &PresentationDispatcher::OnDefaultSessionStarted, | 188 &PresentationDispatcher::OnDefaultSessionStarted, |
| 183 base::Unretained(this))); | 189 base::Unretained(this))); |
| 184 } | 190 } |
| 185 | 191 |
| 186 } // namespace content | 192 } // namespace content |
| OLD | NEW |