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

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: Updated unittests. 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 mojo::Array<mojo::String> urls(presentationUrls.size());
109 for (size_t i = 0; i < presentationUrls.size(); ++i)
110 urls[i] = presentationUrls[i].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 std::move(urls),
113 base::Bind(&PresentationDispatcher::OnSessionCreated, 117 base::Bind(&PresentationDispatcher::OnSessionCreated,
114 base::Unretained(this), 118 base::Unretained(this), base::Owned(callback)));
115 base::Owned(callback)));
116 } 119 }
117 120
118 void PresentationDispatcher::joinSession( 121 void PresentationDispatcher::joinSession(
119 const blink::WebString& presentationUrl, 122 const blink::WebVector<blink::WebString>& presentationUrls,
120 const blink::WebString& presentationId, 123 const blink::WebString& presentationId,
121 blink::WebPresentationConnectionClientCallbacks* callback) { 124 blink::WebPresentationConnectionClientCallbacks* callback) {
122 DCHECK(callback); 125 DCHECK(callback);
123 ConnectToPresentationServiceIfNeeded(); 126 ConnectToPresentationServiceIfNeeded();
124 127
128 mojo::Array<mojo::String> urls(presentationUrls.size());
129 for (size_t i = 0; i < presentationUrls.size(); ++i)
130 urls[i] = presentationUrls[i].utf8();
131
125 // The dispatcher owns the service so |this| will be valid when 132 // The dispatcher owns the service so |this| will be valid when
126 // OnSessionCreated() is called. |callback| needs to be alive and also needs 133 // OnSessionCreated() is called. |callback| needs to be alive and also needs
127 // to be destroyed so we transfer its ownership to the mojo callback. 134 // to be destroyed so we transfer its ownership to the mojo callback.
128 presentation_service_->JoinSession( 135 presentation_service_->JoinSession(
129 presentationUrl.utf8(), 136 std::move(urls), presentationId.utf8(),
130 presentationId.utf8(),
131 base::Bind(&PresentationDispatcher::OnSessionCreated, 137 base::Bind(&PresentationDispatcher::OnSessionCreated,
132 base::Unretained(this), 138 base::Unretained(this), base::Owned(callback)));
133 base::Owned(callback)));
134 } 139 }
135 140
136 void PresentationDispatcher::sendString( 141 void PresentationDispatcher::sendString(
137 const blink::WebString& presentationUrl, 142 const blink::WebString& presentationUrl,
138 const blink::WebString& presentationId, 143 const blink::WebString& presentationId,
139 const blink::WebString& message) { 144 const blink::WebString& message) {
140 if (message.utf8().size() > kMaxPresentationSessionMessageSize) { 145 if (message.utf8().size() > kMaxPresentationSessionMessageSize) {
141 // 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
142 // for now. Consider throwing DOMException or splitting bigger messages 147 // for now. Consider throwing DOMException or splitting bigger messages
143 // into smaller chunks later. 148 // 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); 288 auto status_it = availability_status_.find(availability_url);
284 if (status_it == availability_status_.end()) { 289 if (status_it == availability_status_.end()) {
285 DLOG(WARNING) << "Stop listening for availability for unknown URL " 290 DLOG(WARNING) << "Stop listening for availability for unknown URL "
286 << availability_url; 291 << availability_url;
287 return; 292 return;
288 } 293 }
289 status_it->second->availability_observers.erase(observer); 294 status_it->second->availability_observers.erase(observer);
290 UpdateListeningState(status_it->second.get()); 295 UpdateListeningState(status_it->second.get());
291 } 296 }
292 297
293 void PresentationDispatcher::setDefaultPresentationUrl( 298 void PresentationDispatcher::setDefaultPresentationUrls(
294 const blink::WebString& url) { 299 const blink::WebVector<blink::WebString>& presentationUrls) {
295 ConnectToPresentationServiceIfNeeded(); 300 ConnectToPresentationServiceIfNeeded();
296 presentation_service_->SetDefaultPresentationURL(url.utf8()); 301 mojo::Array<mojo::String> urls(presentationUrls.size());
302 for (size_t i = 0; i < presentationUrls.size(); ++i)
303 urls[i] = presentationUrls[i].utf8();
304
305 presentation_service_->SetDefaultPresentationUrls(std::move(urls));
297 } 306 }
298 307
299 void PresentationDispatcher::DidCommitProvisionalLoad( 308 void PresentationDispatcher::DidCommitProvisionalLoad(
300 bool is_new_navigation, 309 bool is_new_navigation,
301 bool is_same_page_navigation) { 310 bool is_same_page_navigation) {
302 blink::WebFrame* frame = render_frame()->GetWebFrame(); 311 blink::WebFrame* frame = render_frame()->GetWebFrame();
303 // If not top-level navigation. 312 // If not top-level navigation.
304 if (frame->parent() || is_same_page_navigation) 313 if (frame->parent() || is_same_page_navigation)
305 return; 314 return;
306 315
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( 537 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
529 const std::string& availability_url) 538 const std::string& availability_url)
530 : url(availability_url), 539 : url(availability_url),
531 last_known_availability(false), 540 last_known_availability(false),
532 listening_state(ListeningState::INACTIVE) {} 541 listening_state(ListeningState::INACTIVE) {}
533 542
534 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { 543 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() {
535 } 544 }
536 545
537 } // namespace content 546 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698