Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.cc

Issue 2148643002: [Presentation API] Adds DOMString[] constructor to PresentationRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix PresentationAvailabilityCallbacks Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "content/public/common/presentation_constants.h" 14 #include "content/public/common/presentation_constants.h"
15 #include "content/public/renderer/render_frame.h" 15 #include "content/public/renderer/render_frame.h"
16 #include "content/renderer/presentation/presentation_connection_client.h" 16 #include "content/renderer/presentation/presentation_connection_client.h"
17 #include "services/shell/public/cpp/interface_provider.h" 17 #include "services/shell/public/cpp/interface_provider.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebURL.h" 19 #include "third_party/WebKit/public/platform/WebVector.h"
20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h" 20 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nAvailabilityObserver.h"
21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" 22 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
23 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" 23 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" 24 #include "third_party/WebKit/public/web/WebLocalFrame.h"
25 #include "url/gurl.h" 25 #include "url/gurl.h"
26 26
27 namespace { 27 namespace {
28 28
29 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( 29 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 blink::WebPresentationController* controller) { 93 blink::WebPresentationController* controller) {
94 // There shouldn't be any swapping from one non-null controller to another. 94 // There shouldn't be any swapping from one non-null controller to another.
95 DCHECK(controller != controller_ && (!controller || !controller_)); 95 DCHECK(controller != controller_ && (!controller || !controller_));
96 controller_ = controller; 96 controller_ = controller;
97 // The controller is set to null when the frame is about to be detached. 97 // The controller is set to null when the frame is about to be detached.
98 // Nothing is listening for screen availability anymore but the Mojo service 98 // Nothing is listening for screen availability anymore but the Mojo service
99 // will know about the frame being detached anyway. 99 // will know about the frame being detached anyway.
100 } 100 }
101 101
102 void PresentationDispatcher::startSession( 102 void PresentationDispatcher::startSession(
103 const blink::WebString& presentationUrl, 103 const blink::WebVector<blink::WebString>& presentationUrls,
104 blink::WebPresentationConnectionClientCallbacks* callback) { 104 blink::WebPresentationConnectionClientCallbacks* callback) {
105 DCHECK(callback); 105 DCHECK(callback);
106 ConnectToPresentationServiceIfNeeded(); 106 ConnectToPresentationServiceIfNeeded();
107 107
108 // TODO(mfoltz): Pass all URLs to PresentationService.
mlamouri (slow - plz ping) 2016/07/19 12:45:03 Should this be implemented first? or at least, I t
mark a. foltz 2016/07/19 17:38:47 We don't know which URL is valid yet (they all nee
mlamouri (slow - plz ping) 2016/07/20 13:02:10 Maybe the simplest change would be to pass all the
109
108 // The dispatcher owns the service so |this| will be valid when 110 // The dispatcher owns the service so |this| will be valid when
109 // OnSessionCreated() is called. |callback| needs to be alive and also needs 111 // OnSessionCreated() is called. |callback| needs to be alive and also needs
110 // to be destroyed so we transfer its ownership to the mojo callback. 112 // to be destroyed so we transfer its ownership to the mojo callback.
111 presentation_service_->StartSession( 113 presentation_service_->StartSession(
112 presentationUrl.utf8(), 114 presentationUrls[0].utf8(),
113 base::Bind(&PresentationDispatcher::OnSessionCreated, 115 base::Bind(&PresentationDispatcher::OnSessionCreated,
114 base::Unretained(this), 116 base::Unretained(this),
115 base::Owned(callback))); 117 base::Owned(callback)));
116 } 118 }
117 119
118 void PresentationDispatcher::joinSession( 120 void PresentationDispatcher::joinSession(
119 const blink::WebString& presentationUrl, 121 const blink::WebVector<blink::WebString>& presentationUrls,
120 const blink::WebString& presentationId, 122 const blink::WebString& presentationId,
121 blink::WebPresentationConnectionClientCallbacks* callback) { 123 blink::WebPresentationConnectionClientCallbacks* callback) {
122 DCHECK(callback); 124 DCHECK(callback);
123 ConnectToPresentationServiceIfNeeded(); 125 ConnectToPresentationServiceIfNeeded();
124 126
127 // TODO(mfoltz): Pass all URLs to PresentationService.
128
125 // The dispatcher owns the service so |this| will be valid when 129 // The dispatcher owns the service so |this| will be valid when
126 // OnSessionCreated() is called. |callback| needs to be alive and also needs 130 // OnSessionCreated() is called. |callback| needs to be alive and also needs
127 // to be destroyed so we transfer its ownership to the mojo callback. 131 // to be destroyed so we transfer its ownership to the mojo callback.
128 presentation_service_->JoinSession( 132 presentation_service_->JoinSession(
129 presentationUrl.utf8(), 133 presentationUrls[0].utf8(),
130 presentationId.utf8(), 134 presentationId.utf8(),
131 base::Bind(&PresentationDispatcher::OnSessionCreated, 135 base::Bind(&PresentationDispatcher::OnSessionCreated,
132 base::Unretained(this), 136 base::Unretained(this),
133 base::Owned(callback))); 137 base::Owned(callback)));
134 } 138 }
135 139
136 void PresentationDispatcher::sendString( 140 void PresentationDispatcher::sendString(
137 const blink::WebString& presentationUrl, 141 const blink::WebString& presentationUrl,
138 const blink::WebString& presentationId, 142 const blink::WebString& presentationId,
139 const blink::WebString& message) { 143 const blink::WebString& message) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void PresentationDispatcher::terminateSession( 238 void PresentationDispatcher::terminateSession(
235 const blink::WebString& presentationUrl, 239 const blink::WebString& presentationUrl,
236 const blink::WebString& presentationId) { 240 const blink::WebString& presentationId) {
237 ConnectToPresentationServiceIfNeeded(); 241 ConnectToPresentationServiceIfNeeded();
238 242
239 presentation_service_->Terminate(presentationUrl.utf8(), 243 presentation_service_->Terminate(presentationUrl.utf8(),
240 presentationId.utf8()); 244 presentationId.utf8());
241 } 245 }
242 246
243 void PresentationDispatcher::getAvailability( 247 void PresentationDispatcher::getAvailability(
244 const blink::WebString& availabilityUrl, 248 const blink::WebVector<blink::WebString>& availabilityUrls,
245 blink::WebPresentationAvailabilityCallbacks* callbacks) { 249 blink::WebPresentationAvailabilityCallbacks* callbacks) {
246 const std::string& availability_url = availabilityUrl.utf8(); 250 // TODO(mfoltz): Pass all URLs to PresentationService.
251 const std::string& availability_url = availabilityUrls[0].utf8();
247 AvailabilityStatus* status = nullptr; 252 AvailabilityStatus* status = nullptr;
248 auto status_it = availability_status_.find(availability_url); 253 auto status_it = availability_status_.find(availability_url);
249 if (status_it == availability_status_.end()) { 254 if (status_it == availability_status_.end()) {
250 status = new AvailabilityStatus(availability_url); 255 status = new AvailabilityStatus(availability_url);
251 availability_status_[availability_url] = base::WrapUnique(status); 256 availability_status_[availability_url] = base::WrapUnique(status);
252 } else { 257 } else {
253 status = status_it->second.get(); 258 status = status_it->second.get();
254 } 259 }
255 DCHECK(status); 260 DCHECK(status);
256 261
257 if (status->listening_state == ListeningState::ACTIVE) { 262 if (status->listening_state == ListeningState::ACTIVE) {
258 callbacks->onSuccess(status->last_known_availability); 263 callbacks->onSuccess(status->last_known_availability);
259 delete callbacks; 264 delete callbacks;
260 return; 265 return;
261 } 266 }
262 267
263 status->availability_callbacks.Add(callbacks); 268 status->availability_callbacks.Add(callbacks);
264 UpdateListeningState(status); 269 UpdateListeningState(status);
265 } 270 }
266 271
267 void PresentationDispatcher::startListening( 272 void PresentationDispatcher::startListening(
268 blink::WebPresentationAvailabilityObserver* observer) { 273 blink::WebPresentationAvailabilityObserver* observer) {
269 const std::string& availability_url = observer->url().string().utf8(); 274 // TODO(mfoltz): Pass all URLs to PresentationService.
275 const std::string& availability_url = observer->urls()[0].string().utf8();
270 auto status_it = availability_status_.find(availability_url); 276 auto status_it = availability_status_.find(availability_url);
271 if (status_it == availability_status_.end()) { 277 if (status_it == availability_status_.end()) {
272 DLOG(WARNING) << "Start listening for availability for unknown URL " 278 DLOG(WARNING) << "Start listening for availability for unknown URL "
273 << availability_url; 279 << availability_url;
274 return; 280 return;
275 } 281 }
276 status_it->second->availability_observers.insert(observer); 282 status_it->second->availability_observers.insert(observer);
277 UpdateListeningState(status_it->second.get()); 283 UpdateListeningState(status_it->second.get());
278 } 284 }
279 285
280 void PresentationDispatcher::stopListening( 286 void PresentationDispatcher::stopListening(
281 blink::WebPresentationAvailabilityObserver* observer) { 287 blink::WebPresentationAvailabilityObserver* observer) {
282 const std::string& availability_url = observer->url().string().utf8(); 288 // TODO(mfoltz): Pass all URLs to PresentationService.
289 const std::string& availability_url = observer->urls()[0].string().utf8();
283 auto status_it = availability_status_.find(availability_url); 290 auto status_it = availability_status_.find(availability_url);
284 if (status_it == availability_status_.end()) { 291 if (status_it == availability_status_.end()) {
285 DLOG(WARNING) << "Stop listening for availability for unknown URL " 292 DLOG(WARNING) << "Stop listening for availability for unknown URL "
286 << availability_url; 293 << availability_url;
287 return; 294 return;
288 } 295 }
289 status_it->second->availability_observers.erase(observer); 296 status_it->second->availability_observers.erase(observer);
290 UpdateListeningState(status_it->second.get()); 297 UpdateListeningState(status_it->second.get());
291 } 298 }
292 299
293 void PresentationDispatcher::setDefaultPresentationUrl( 300 void PresentationDispatcher::setDefaultPresentationUrls(
294 const blink::WebString& url) { 301 const blink::WebVector<blink::WebString>& urls) {
295 ConnectToPresentationServiceIfNeeded(); 302 ConnectToPresentationServiceIfNeeded();
296 presentation_service_->SetDefaultPresentationURL(url.utf8()); 303 // TODO(mfoltz): Pass all URLs to PresentationService.
304 presentation_service_->SetDefaultPresentationURL(urls[0].utf8());
297 } 305 }
298 306
299 void PresentationDispatcher::DidCommitProvisionalLoad( 307 void PresentationDispatcher::DidCommitProvisionalLoad(
300 bool is_new_navigation, 308 bool is_new_navigation,
301 bool is_same_page_navigation) { 309 bool is_same_page_navigation) {
302 blink::WebFrame* frame = render_frame()->GetWebFrame(); 310 blink::WebFrame* frame = render_frame()->GetWebFrame();
303 // If not top-level navigation. 311 // If not top-level navigation.
304 if (frame->parent() || is_same_page_navigation) 312 if (frame->parent() || is_same_page_navigation)
305 return; 313 return;
306 314
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( 536 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
529 const std::string& availability_url) 537 const std::string& availability_url)
530 : url(availability_url), 538 : url(availability_url),
531 last_known_availability(false), 539 last_known_availability(false),
532 listening_state(ListeningState::INACTIVE) {} 540 listening_state(ListeningState::INACTIVE) {}
533 541
534 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { 542 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() {
535 } 543 }
536 544
537 } // namespace content 545 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698