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

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

Issue 2340433003: [Presentation API] 1-UA: notify receiver page when receiver connection becomes available (blink sid… (Closed)
Patch Set: resolve code review comments from mlamouri Created 4 years, 3 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/WebVector.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/WebPresentatio nReceiver.h"
23 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" 24 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" 25 #include "third_party/WebKit/public/web/WebLocalFrame.h"
25 #include "url/gurl.h" 26 #include "url/gurl.h"
26 27
27 namespace { 28 namespace {
28 29
29 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( 30 blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo(
30 blink::mojom::PresentationErrorType mojoErrorType) { 31 blink::mojom::PresentationErrorType mojoErrorType) {
31 switch (mojoErrorType) { 32 switch (mojoErrorType) {
32 case blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS: 33 case blink::mojom::PresentationErrorType::NO_AVAILABLE_SCREENS:
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 void PresentationDispatcher::setDefaultPresentationUrls( 296 void PresentationDispatcher::setDefaultPresentationUrls(
296 const blink::WebVector<blink::WebString>& presentationUrls) { 297 const blink::WebVector<blink::WebString>& presentationUrls) {
297 ConnectToPresentationServiceIfNeeded(); 298 ConnectToPresentationServiceIfNeeded();
298 299
299 std::vector<GURL> urls(presentationUrls.size()); 300 std::vector<GURL> urls(presentationUrls.size());
300 std::transform(presentationUrls.begin(), presentationUrls.end(), urls.begin(), 301 std::transform(presentationUrls.begin(), presentationUrls.end(), urls.begin(),
301 [](const blink::WebString& url) { return GURL(url.utf8()); }); 302 [](const blink::WebString& url) { return GURL(url.utf8()); });
302 presentation_service_->SetDefaultPresentationUrls(urls); 303 presentation_service_->SetDefaultPresentationUrls(urls);
303 } 304 }
304 305
306 void PresentationDispatcher::setReceiver(
307 blink::WebPresentationReceiver* receiver) {
308 ConnectToPresentationServiceIfNeeded();
309 m_receiver = receiver;
310 }
311
305 void PresentationDispatcher::DidCommitProvisionalLoad( 312 void PresentationDispatcher::DidCommitProvisionalLoad(
306 bool is_new_navigation, 313 bool is_new_navigation,
307 bool is_same_page_navigation) { 314 bool is_same_page_navigation) {
308 blink::WebFrame* frame = render_frame()->GetWebFrame(); 315 blink::WebFrame* frame = render_frame()->GetWebFrame();
309 // If not top-level navigation. 316 // If not top-level navigation.
310 if (frame->parent() || is_same_page_navigation) 317 if (frame->parent() || is_same_page_navigation)
311 return; 318 return;
312 319
313 // Remove all pending send message requests. 320 // Remove all pending send message requests.
314 MessageRequestQueue empty; 321 MessageRequestQueue empty;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 blink::WebString::fromUTF8(error->message))); 395 blink::WebString::fromUTF8(error->message)));
389 return; 396 return;
390 } 397 }
391 398
392 DCHECK(!session_info.is_null()); 399 DCHECK(!session_info.is_null());
393 presentation_service_->ListenForSessionMessages(session_info.Clone()); 400 presentation_service_->ListenForSessionMessages(session_info.Clone());
394 callback->onSuccess( 401 callback->onSuccess(
395 base::MakeUnique<PresentationConnectionClient>(std::move(session_info))); 402 base::MakeUnique<PresentationConnectionClient>(std::move(session_info)));
396 } 403 }
397 404
405 void PresentationDispatcher::OnReceiverConnectionAvailable(
406 blink::mojom::PresentationSessionInfoPtr session_info) {
407 if (m_receiver)
mark a. foltz 2016/09/15 16:53:18 What if this is called before m_receiver is set?
zhaobin 2016/09/15 18:56:03 Yes. Going to send out another CL with queuing log
408 m_receiver->onReceiverConnectionAvailable(
409 new PresentationConnectionClient(std::move(session_info)));
mlamouri (slow - plz ping) 2016/09/15 10:49:39 style: add {} when the statement is wrapped in mor
zhaobin 2016/09/15 18:56:03 Done.
410 }
411
398 void PresentationDispatcher::OnConnectionStateChanged( 412 void PresentationDispatcher::OnConnectionStateChanged(
399 blink::mojom::PresentationSessionInfoPtr connection, 413 blink::mojom::PresentationSessionInfoPtr connection,
400 blink::mojom::PresentationConnectionState state) { 414 blink::mojom::PresentationConnectionState state) {
401 if (!controller_) 415 if (!controller_)
402 return; 416 return;
403 417
404 DCHECK(!connection.is_null()); 418 DCHECK(!connection.is_null());
405 controller_->didChangeSessionState( 419 controller_->didChangeSessionState(
406 new PresentationConnectionClient(std::move(connection)), 420 new PresentationConnectionClient(std::move(connection)),
407 GetWebPresentationConnectionStateFromMojo(state)); 421 GetWebPresentationConnectionStateFromMojo(state));
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus( 547 PresentationDispatcher::AvailabilityStatus::AvailabilityStatus(
534 const std::string& availability_url) 548 const std::string& availability_url)
535 : url(availability_url), 549 : url(availability_url),
536 last_known_availability(false), 550 last_known_availability(false),
537 listening_state(ListeningState::INACTIVE) {} 551 listening_state(ListeningState::INACTIVE) {}
538 552
539 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() { 553 PresentationDispatcher::AvailabilityStatus::~AvailabilityStatus() {
540 } 554 }
541 555
542 } // namespace content 556 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698