| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // There shouldn't be any swapping from one non-null controller to another. | 96 // There shouldn't be any swapping from one non-null controller to another. |
| 97 DCHECK(controller != controller_ && (!controller || !controller_)); | 97 DCHECK(controller != controller_ && (!controller || !controller_)); |
| 98 controller_ = controller; | 98 controller_ = controller; |
| 99 // The controller is set to null when the frame is about to be detached. | 99 // The controller is set to null when the frame is about to be detached. |
| 100 // Nothing is listening for screen availability anymore but the Mojo service | 100 // Nothing is listening for screen availability anymore but the Mojo service |
| 101 // will know about the frame being detached anyway. | 101 // will know about the frame being detached anyway. |
| 102 } | 102 } |
| 103 | 103 |
| 104 void PresentationDispatcher::startSession( | 104 void PresentationDispatcher::startSession( |
| 105 const blink::WebVector<blink::WebURL>& presentationUrls, | 105 const blink::WebVector<blink::WebURL>& presentationUrls, |
| 106 blink::WebPresentationConnectionClientCallbacks* callback) { | 106 std::unique_ptr<blink::WebPresentationConnectionClientCallbacks> callback) { |
| 107 DCHECK(callback); | 107 DCHECK(callback); |
| 108 ConnectToPresentationServiceIfNeeded(); | 108 ConnectToPresentationServiceIfNeeded(); |
| 109 | 109 |
| 110 std::vector<GURL> urls; | 110 std::vector<GURL> urls; |
| 111 for (const auto& url : presentationUrls) | 111 for (const auto& url : presentationUrls) |
| 112 urls.push_back(url); | 112 urls.push_back(url); |
| 113 | 113 |
| 114 // The dispatcher owns the service so |this| will be valid when | 114 // The dispatcher owns the service so |this| will be valid when |
| 115 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 115 // OnSessionCreated() is called. |callback| needs to be alive and also needs |
| 116 // to be destroyed so we transfer its ownership to the mojo callback. | 116 // to be destroyed so we transfer its ownership to the mojo callback. |
| 117 presentation_service_->StartSession( | 117 presentation_service_->StartSession( |
| 118 urls, base::Bind(&PresentationDispatcher::OnSessionCreated, | 118 urls, base::Bind(&PresentationDispatcher::OnSessionCreated, |
| 119 base::Unretained(this), base::Owned(callback))); | 119 base::Unretained(this), base::Passed(&callback))); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void PresentationDispatcher::joinSession( | 122 void PresentationDispatcher::joinSession( |
| 123 const blink::WebVector<blink::WebURL>& presentationUrls, | 123 const blink::WebVector<blink::WebURL>& presentationUrls, |
| 124 const blink::WebString& presentationId, | 124 const blink::WebString& presentationId, |
| 125 blink::WebPresentationConnectionClientCallbacks* callback) { | 125 std::unique_ptr<blink::WebPresentationConnectionClientCallbacks> callback) { |
| 126 DCHECK(callback); | 126 DCHECK(callback); |
| 127 ConnectToPresentationServiceIfNeeded(); | 127 ConnectToPresentationServiceIfNeeded(); |
| 128 | 128 |
| 129 std::vector<GURL> urls; | 129 std::vector<GURL> urls; |
| 130 for (const auto& url : presentationUrls) | 130 for (const auto& url : presentationUrls) |
| 131 urls.push_back(url); | 131 urls.push_back(url); |
| 132 | 132 |
| 133 // The dispatcher owns the service so |this| will be valid when | 133 // The dispatcher owns the service so |this| will be valid when |
| 134 // OnSessionCreated() is called. |callback| needs to be alive and also needs | 134 // OnSessionCreated() is called. |callback| needs to be alive and also needs |
| 135 // to be destroyed so we transfer its ownership to the mojo callback. | 135 // to be destroyed so we transfer its ownership to the mojo callback. |
| 136 presentation_service_->JoinSession( | 136 presentation_service_->JoinSession( |
| 137 urls, presentationId.utf8(), | 137 urls, presentationId.utf8(), |
| 138 base::Bind(&PresentationDispatcher::OnSessionCreated, | 138 base::Bind(&PresentationDispatcher::OnSessionCreated, |
| 139 base::Unretained(this), base::Owned(callback))); | 139 base::Unretained(this), base::Passed(&callback))); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PresentationDispatcher::sendString(const blink::WebURL& presentationUrl, | 142 void PresentationDispatcher::sendString(const blink::WebURL& presentationUrl, |
| 143 const blink::WebString& presentationId, | 143 const blink::WebString& presentationId, |
| 144 const blink::WebString& message) { | 144 const blink::WebString& message) { |
| 145 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { | 145 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { |
| 146 // TODO(crbug.com/459008): Limit the size of individual messages to 64k | 146 // TODO(crbug.com/459008): Limit the size of individual messages to 64k |
| 147 // for now. Consider throwing DOMException or splitting bigger messages | 147 // for now. Consider throwing DOMException or splitting bigger messages |
| 148 // into smaller chunks later. | 148 // into smaller chunks later. |
| 149 LOG(WARNING) << "message size exceeded limit!"; | 149 LOG(WARNING) << "message size exceeded limit!"; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 237 |
| 238 void PresentationDispatcher::terminateSession( | 238 void PresentationDispatcher::terminateSession( |
| 239 const blink::WebURL& presentationUrl, | 239 const blink::WebURL& presentationUrl, |
| 240 const blink::WebString& presentationId) { | 240 const blink::WebString& presentationId) { |
| 241 ConnectToPresentationServiceIfNeeded(); | 241 ConnectToPresentationServiceIfNeeded(); |
| 242 presentation_service_->Terminate(presentationUrl, presentationId.utf8()); | 242 presentation_service_->Terminate(presentationUrl, presentationId.utf8()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void PresentationDispatcher::getAvailability( | 245 void PresentationDispatcher::getAvailability( |
| 246 const blink::WebURL& availabilityUrl, | 246 const blink::WebURL& availabilityUrl, |
| 247 blink::WebPresentationAvailabilityCallbacks* callbacks) { | 247 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) { |
| 248 AvailabilityStatus* status = nullptr; | 248 AvailabilityStatus* status = nullptr; |
| 249 auto status_it = availability_status_.find(availabilityUrl); | 249 auto status_it = availability_status_.find(availabilityUrl); |
| 250 if (status_it == availability_status_.end()) { | 250 if (status_it == availability_status_.end()) { |
| 251 status = new AvailabilityStatus(availabilityUrl); | 251 status = new AvailabilityStatus(availabilityUrl); |
| 252 availability_status_[availabilityUrl] = base::WrapUnique(status); | 252 availability_status_[availabilityUrl] = base::WrapUnique(status); |
| 253 } else { | 253 } else { |
| 254 status = status_it->second.get(); | 254 status = status_it->second.get(); |
| 255 } | 255 } |
| 256 DCHECK(status); | 256 DCHECK(status); |
| 257 | 257 |
| 258 if (status->listening_state == ListeningState::ACTIVE) { | 258 if (status->listening_state == ListeningState::ACTIVE) { |
| 259 base::ThreadTaskRunnerHandle::Get()->PostTask( | 259 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 260 FROM_HERE, | 260 FROM_HERE, |
| 261 base::Bind(&blink::WebPresentationAvailabilityCallbacks::onSuccess, | 261 base::Bind(&blink::WebPresentationAvailabilityCallbacks::onSuccess, |
| 262 base::Owned(callbacks), | 262 base::Passed(&callbacks), status->last_known_availability)); |
| 263 status->last_known_availability)); | |
| 264 return; | 263 return; |
| 265 } | 264 } |
| 266 | 265 |
| 267 status->availability_callbacks.Add(callbacks); | 266 status->availability_callbacks.Add(std::move(callbacks)); |
| 268 UpdateListeningState(status); | 267 UpdateListeningState(status); |
| 269 } | 268 } |
| 270 | 269 |
| 271 void PresentationDispatcher::startListening( | 270 void PresentationDispatcher::startListening( |
| 272 blink::WebPresentationAvailabilityObserver* observer) { | 271 blink::WebPresentationAvailabilityObserver* observer) { |
| 273 auto status_it = availability_status_.find(observer->url()); | 272 auto status_it = availability_status_.find(observer->url()); |
| 274 if (status_it == availability_status_.end()) { | 273 if (status_it == availability_status_.end()) { |
| 275 DLOG(WARNING) << "Start listening for availability for unknown URL " | 274 DLOG(WARNING) << "Start listening for availability for unknown URL " |
| 276 << GURL(observer->url()); | 275 << GURL(observer->url()); |
| 277 return; | 276 return; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 return; | 376 return; |
| 378 | 377 |
| 379 if (!session_info.is_null()) { | 378 if (!session_info.is_null()) { |
| 380 presentation_service_->ListenForSessionMessages(session_info.Clone()); | 379 presentation_service_->ListenForSessionMessages(session_info.Clone()); |
| 381 controller_->didStartDefaultSession( | 380 controller_->didStartDefaultSession( |
| 382 new PresentationConnectionClient(std::move(session_info))); | 381 new PresentationConnectionClient(std::move(session_info))); |
| 383 } | 382 } |
| 384 } | 383 } |
| 385 | 384 |
| 386 void PresentationDispatcher::OnSessionCreated( | 385 void PresentationDispatcher::OnSessionCreated( |
| 387 blink::WebPresentationConnectionClientCallbacks* callback, | 386 std::unique_ptr<blink::WebPresentationConnectionClientCallbacks> callback, |
| 388 blink::mojom::PresentationSessionInfoPtr session_info, | 387 blink::mojom::PresentationSessionInfoPtr session_info, |
| 389 blink::mojom::PresentationErrorPtr error) { | 388 blink::mojom::PresentationErrorPtr error) { |
| 390 DCHECK(callback); | 389 DCHECK(callback); |
| 391 if (!error.is_null()) { | 390 if (!error.is_null()) { |
| 392 DCHECK(session_info.is_null()); | 391 DCHECK(session_info.is_null()); |
| 393 callback->onError(blink::WebPresentationError( | 392 callback->onError(blink::WebPresentationError( |
| 394 GetWebPresentationErrorTypeFromMojo(error->error_type), | 393 GetWebPresentationErrorTypeFromMojo(error->error_type), |
| 395 blink::WebString::fromUTF8(error->message))); | 394 blink::WebString::fromUTF8(error->message))); |
| 396 return; | 395 return; |
| 397 } | 396 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( | 546 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( |
| 548 const GURL& availability_url) | 547 const GURL& availability_url) |
| 549 : url(availability_url), | 548 : url(availability_url), |
| 550 last_known_availability(false), | 549 last_known_availability(false), |
| 551 listening_state(ListeningState::INACTIVE) {} | 550 listening_state(ListeningState::INACTIVE) {} |
| 552 | 551 |
| 553 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { | 552 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { |
| 554 } | 553 } |
| 555 | 554 |
| 556 } // namespace content | 555 } // namespace content |
| OLD | NEW |