Chromium Code Reviews| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 blink::WebPresentationController* controller) { | 49 blink::WebPresentationController* controller) { |
| 50 // There shouldn't be any swapping from one non-null controller to another. | 50 // There shouldn't be any swapping from one non-null controller to another. |
| 51 DCHECK(controller != controller_ && (!controller || !controller_)); | 51 DCHECK(controller != controller_ && (!controller || !controller_)); |
| 52 controller_ = controller; | 52 controller_ = controller; |
| 53 // The controller is set to null when the frame is about to be detached. | 53 // The controller is set to null when the frame is about to be detached. |
| 54 // Nothing is listening for screen availability anymore but the Mojo service | 54 // Nothing is listening for screen availability anymore but the Mojo service |
| 55 // will know about the frame being detached anyway. | 55 // will know about the frame being detached anyway. |
| 56 } | 56 } |
| 57 | 57 |
| 58 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { | 58 void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { |
| 59 DoUpdateAvailableChangeWatched(std::string(), watched); | |
|
whywhat
2015/03/13 17:44:35
note: string() should be replaced with GetPresenta
imcheng
2015/03/13 23:36:46
Acknowledged.
| |
| 60 } | |
| 61 | |
| 62 void PresentationDispatcher::DoUpdateAvailableChangeWatched( | |
| 63 const std::string& presentation_url, bool watched) { | |
| 59 ConnectToPresentationServiceIfNeeded(); | 64 ConnectToPresentationServiceIfNeeded(); |
| 60 if (watched) { | 65 if (watched) { |
| 61 presentation_service_->GetScreenAvailability( | 66 presentation_service_->GetScreenAvailability( |
| 62 mojo::String(), | 67 presentation_url, |
| 63 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, | 68 base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, |
| 64 base::Unretained(this))); | 69 base::Unretained(this))); |
| 65 } else { | 70 } else { |
| 66 presentation_service_->OnScreenAvailabilityListenerRemoved(); | 71 presentation_service_->OnScreenAvailabilityListenerRemoved( |
| 72 presentation_url); | |
| 67 } | 73 } |
| 68 } | 74 } |
| 69 | 75 |
| 70 void PresentationDispatcher::startSession( | 76 void PresentationDispatcher::startSession( |
| 71 const blink::WebString& presentationUrl, | 77 const blink::WebString& presentationUrl, |
| 72 const blink::WebString& presentationId, | 78 const blink::WebString& presentationId, |
| 73 blink::WebPresentationSessionClientCallbacks* callback) { | 79 blink::WebPresentationSessionClientCallbacks* callback) { |
| 74 DCHECK(callback); | 80 DCHECK(callback); |
| 75 ConnectToPresentationServiceIfNeeded(); | 81 ConnectToPresentationServiceIfNeeded(); |
| 76 | 82 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 96 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 102 // OnSessionCreated() is called. |callback| needs to be alive and also needs |
| 97 // to be destroyed so we transfer its ownership to the mojo callback. | 103 // to be destroyed so we transfer its ownership to the mojo callback. |
| 98 presentation_service_->JoinSession( | 104 presentation_service_->JoinSession( |
| 99 presentationUrl.utf8(), | 105 presentationUrl.utf8(), |
| 100 presentationId.utf8(), | 106 presentationId.utf8(), |
| 101 base::Bind(&PresentationDispatcher::OnSessionCreated, | 107 base::Bind(&PresentationDispatcher::OnSessionCreated, |
| 102 base::Unretained(this), | 108 base::Unretained(this), |
| 103 base::Owned(callback))); | 109 base::Owned(callback))); |
| 104 } | 110 } |
| 105 | 111 |
| 106 void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { | 112 void PresentationDispatcher::OnScreenAvailabilityChanged( |
| 113 const std::string& presentation_url, bool available) { | |
| 107 if (!controller_) | 114 if (!controller_) |
| 108 return; | 115 return; |
| 109 | 116 |
| 110 // Reset the callback to get the next event. | 117 // Reset the callback to get the next event. |
| 111 updateAvailableChangeWatched(controller_->isAvailableChangeWatched()); | 118 DoUpdateAvailableChangeWatched(presentation_url, |
| 119 controller_->isAvailableChangeWatched()); | |
| 112 | 120 |
| 113 controller_->didChangeAvailability(available); | 121 controller_->didChangeAvailability(available); |
| 114 } | 122 } |
| 115 | 123 |
| 116 void PresentationDispatcher::OnSessionCreated( | 124 void PresentationDispatcher::OnSessionCreated( |
| 117 blink::WebPresentationSessionClientCallbacks* callback, | 125 blink::WebPresentationSessionClientCallbacks* callback, |
| 118 presentation::PresentationSessionInfoPtr session_info, | 126 presentation::PresentationSessionInfoPtr session_info, |
| 119 presentation::PresentationErrorPtr error) { | 127 presentation::PresentationErrorPtr error) { |
| 120 DCHECK(callback); | 128 DCHECK(callback); |
| 121 if (!error.is_null()) { | 129 if (!error.is_null()) { |
| 122 DCHECK(session_info.is_null()); | 130 DCHECK(session_info.is_null()); |
| 123 callback->onError(new blink::WebPresentationError( | 131 callback->onError(new blink::WebPresentationError( |
| 124 GetWebPresentationErrorTypeFromMojo(error->errorType), | 132 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 125 blink::WebString::fromUTF8(error->message))); | 133 blink::WebString::fromUTF8(error->message))); |
| 126 return; | 134 return; |
| 127 } | 135 } |
| 128 | 136 |
| 129 DCHECK(!session_info.is_null()); | 137 DCHECK(!session_info.is_null()); |
| 130 PresentationSessionDispatcher* session_dispatcher = | 138 PresentationSessionDispatcher* session_dispatcher = |
| 131 new PresentationSessionDispatcher(session_info.Pass()); | 139 new PresentationSessionDispatcher(session_info.Pass()); |
| 132 presentation_session_dispatchers_.push_back(session_dispatcher); | 140 presentation_session_dispatchers_.push_back(session_dispatcher); |
| 133 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); | 141 callback->onSuccess(new PresentationSessionClient(session_dispatcher)); |
| 134 } | 142 } |
| 135 | 143 |
| 136 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { | 144 void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { |
| 137 if (presentation_service_.get()) | 145 if (presentation_service_.get()) |
| 138 return; | 146 return; |
| 139 | 147 |
| 140 render_frame()->GetServiceRegistry()->ConnectToRemoteService( | 148 render_frame()->GetServiceRegistry()->ConnectToRemoteService( |
| 141 &presentation_service_); | 149 &presentation_service_); |
| 142 } | 150 } |
| 143 | 151 |
| 144 } // namespace content | 152 } // namespace content |
| OLD | NEW |