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

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

Issue 2174693004: [Presentation API] Add support to content/ for multiple URLs per PresentationRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing TODO Created 4 years, 4 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 std::vector<std::string> urls(presentationUrls.size());
109 std::transform(presentationUrls.begin(), presentationUrls.end(), urls.begin(),
110 [](const blink::WebString& url) { return url.utf8(); });
111
108 // The dispatcher owns the service so |this| will be valid when 112 // The dispatcher owns the service so |this| will be valid when
109 // OnSessionCreated() is called. |callback| needs to be alive and also needs 113 // OnSessionCreated() is called. |callback| needs to be alive and also needs
110 // to be destroyed so we transfer its ownership to the mojo callback. 114 // to be destroyed so we transfer its ownership to the mojo callback.
111 presentation_service_->StartSession( 115 presentation_service_->StartSession(
112 presentationUrl.utf8(), 116 urls, base::Bind(&PresentationDispatcher::OnSessionCreated,
113 base::Bind(&PresentationDispatcher::OnSessionCreated, 117 base::Unretained(this), base::Owned(callback)));
114 base::Unretained(this),
115 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 std::vector<std::string> urls(presentationUrls.size());
128 std::transform(presentationUrls.begin(), presentationUrls.end(), urls.begin(),
129 [](const blink::WebString& url) { return url.utf8(); });
130
125 // The dispatcher owns the service so |this| will be valid when 131 // The dispatcher owns the service so |this| will be valid when
126 // OnSessionCreated() is called. |callback| needs to be alive and also needs 132 // OnSessionCreated() is called. |callback| needs to be alive and also needs
127 // to be destroyed so we transfer its ownership to the mojo callback. 133 // to be destroyed so we transfer its ownership to the mojo callback.
128 presentation_service_->JoinSession( 134 presentation_service_->JoinSession(
129 presentationUrl.utf8(), 135 urls, presentationId.utf8(),
130 presentationId.utf8(),
131 base::Bind(&PresentationDispatcher::OnSessionCreated, 136 base::Bind(&PresentationDispatcher::OnSessionCreated,
132 base::Unretained(this), 137 base::Unretained(this), base::Owned(callback)));
133 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) {
140 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { 144 if (message.utf8().size() > kMaxPresentationSessionMessageSize) {
141 // TODO(crbug.com/459008): Limit the size of individual messages to 64k 145 // TODO(crbug.com/459008): Limit the size of individual messages to 64k
142 // for now. Consider throwing DOMException or splitting bigger messages 146 // for now. Consider throwing DOMException or splitting bigger messages
143 // into smaller chunks later. 147 // into smaller chunks later.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 auto status_it = availability_status_.find(availability_url); 287 auto status_it = availability_status_.find(availability_url);
284 if (status_it == availability_status_.end()) { 288 if (status_it == availability_status_.end()) {
285 DLOG(WARNING) << "Stop listening for availability for unknown URL " 289 DLOG(WARNING) << "Stop listening for availability for unknown URL "
286 << availability_url; 290 << availability_url;
287 return; 291 return;
288 } 292 }
289 status_it->second->availability_observers.erase(observer); 293 status_it->second->availability_observers.erase(observer);
290 UpdateListeningState(status_it->second.get()); 294 UpdateListeningState(status_it->second.get());
291 } 295 }
292 296
293 void PresentationDispatcher::setDefaultPresentationUrl( 297 void PresentationDispatcher::setDefaultPresentationUrls(
294 const blink::WebString& url) { 298 const blink::WebVector<blink::WebString>& presentationUrls) {
295 ConnectToPresentationServiceIfNeeded(); 299 ConnectToPresentationServiceIfNeeded();
296 presentation_service_->SetDefaultPresentationURL(url.utf8()); 300
301 std::vector<std::string> urls(presentationUrls.size());
302 std::transform(presentationUrls.begin(), presentationUrls.end(), urls.begin(),
303 [](const blink::WebString& url) { return url.utf8(); });
304 presentation_service_->SetDefaultPresentationUrls(urls);
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( 535 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
528 const std::string& availability_url) 536 const std::string& availability_url)
529 : url(availability_url), 537 : url(availability_url),
530 last_known_availability(false), 538 last_known_availability(false),
531 listening_state(ListeningState::INACTIVE) {} 539 listening_state(ListeningState::INACTIVE) {}
532 540
533 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { 541 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() {
534 } 542 }
535 543
536 } // namespace content 544 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698