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

Side by Side Diff: ash/common/system/cast/tray_cast.cc

Issue 2424183002: Remove Chromecast extension support from cast system tray menu. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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 "ash/common/system/cast/tray_cast.h" 5 #include "ash/common/system/cast/tray_cast.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/session/session_state_delegate.h" 8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/wm_shelf_util.h" 9 #include "ash/common/shelf/wm_shelf_util.h"
10 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" 10 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); 379 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
380 Layout(); 380 Layout();
381 } 381 }
382 382
383 // This view displays a list of cast receivers that can be clicked on and casted 383 // This view displays a list of cast receivers that can be clicked on and casted
384 // to. It is activated by clicking on the chevron inside of 384 // to. It is activated by clicking on the chevron inside of
385 // |CastSelectDefaultView|. 385 // |CastSelectDefaultView|.
386 class CastDetailedView : public TrayDetailsView { 386 class CastDetailedView : public TrayDetailsView {
387 public: 387 public:
388 CastDetailedView(SystemTrayItem* owner, 388 CastDetailedView(SystemTrayItem* owner,
389 LoginStatus login,
390 const CastConfigDelegate::ReceiversAndActivities& 389 const CastConfigDelegate::ReceiversAndActivities&
391 receivers_and_activities); 390 receivers_and_activities);
392 ~CastDetailedView() override; 391 ~CastDetailedView() override;
393 392
394 // Makes the detail view think the view associated with the given receiver_id 393 // Makes the detail view think the view associated with the given receiver_id
395 // was clicked. This will start a cast. 394 // was clicked. This will start a cast.
396 void SimulateViewClickedForTest(const std::string& receiver_id); 395 void SimulateViewClickedForTest(const std::string& receiver_id);
397 396
398 // Updates the list of available receivers. 397 // Updates the list of available receivers.
399 void UpdateReceiverList(const CastConfigDelegate::ReceiversAndActivities& 398 void UpdateReceiverList(const CastConfigDelegate::ReceiversAndActivities&
400 new_receivers_and_activities); 399 new_receivers_and_activities);
401 400
402 private: 401 private:
403 void CreateItems(); 402 void CreateItems();
404 403
405 void UpdateReceiverListFromCachedData(); 404 void UpdateReceiverListFromCachedData();
406 views::View* AddToReceiverList( 405 views::View* AddToReceiverList(
407 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); 406 const CastConfigDelegate::ReceiverAndActivity& receiverActivity);
408 407
409 void AppendSettingsEntries();
410
411 // TrayDetailsView: 408 // TrayDetailsView:
412 void HandleViewClicked(views::View* view) override; 409 void HandleViewClicked(views::View* view) override;
413 410
414 LoginStatus login_;
415 views::View* options_ = nullptr;
416 // A mapping from the receiver id to the receiver/activity data. 411 // A mapping from the receiver id to the receiver/activity data.
417 std::map<std::string, CastConfigDelegate::ReceiverAndActivity> 412 std::map<std::string, CastConfigDelegate::ReceiverAndActivity>
418 receivers_and_activities_; 413 receivers_and_activities_;
419 // A mapping from the view pointer to the associated activity id. 414 // A mapping from the view pointer to the associated activity id.
420 std::map<views::View*, std::string> receiver_activity_map_; 415 std::map<views::View*, std::string> receiver_activity_map_;
421 416
422 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); 417 DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
423 }; 418 };
424 419
425 CastDetailedView::CastDetailedView( 420 CastDetailedView::CastDetailedView(
426 SystemTrayItem* owner, 421 SystemTrayItem* owner,
427 LoginStatus login,
428 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities) 422 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities)
429 : TrayDetailsView(owner), login_(login) { 423 : TrayDetailsView(owner) {
430 CreateItems(); 424 CreateItems();
431 UpdateReceiverList(receivers_and_activities); 425 UpdateReceiverList(receivers_and_activities);
432 } 426 }
433 427
434 CastDetailedView::~CastDetailedView() {} 428 CastDetailedView::~CastDetailedView() {}
435 429
436 void CastDetailedView::SimulateViewClickedForTest( 430 void CastDetailedView::SimulateViewClickedForTest(
437 const std::string& receiver_id) { 431 const std::string& receiver_id) {
438 for (auto& it : receiver_activity_map_) { 432 for (auto& it : receiver_activity_map_) {
439 if (it.second == receiver_id) { 433 if (it.second == receiver_id) {
440 HandleViewClicked(it.first); 434 HandleViewClicked(it.first);
441 break; 435 break;
442 } 436 }
443 } 437 }
444 } 438 }
445 439
446 void CastDetailedView::CreateItems() { 440 void CastDetailedView::CreateItems() {
447 CreateScrollableList(); 441 CreateScrollableList();
448 if (GetCastConfigDelegate()->HasOptions())
449 AppendSettingsEntries();
450 CreateTitleRow(IDS_ASH_STATUS_TRAY_CAST); 442 CreateTitleRow(IDS_ASH_STATUS_TRAY_CAST);
451 } 443 }
452 444
453 void CastDetailedView::UpdateReceiverList( 445 void CastDetailedView::UpdateReceiverList(
454 const CastConfigDelegate::ReceiversAndActivities& 446 const CastConfigDelegate::ReceiversAndActivities&
455 new_receivers_and_activities) { 447 new_receivers_and_activities) {
456 // Add/update existing. 448 // Add/update existing.
457 for (auto i = new_receivers_and_activities.begin(); 449 for (auto i = new_receivers_and_activities.begin();
458 i != new_receivers_and_activities.end(); ++i) { 450 i != new_receivers_and_activities.end(); ++i) {
459 receivers_and_activities_[i->receiver.id] = *i; 451 receivers_and_activities_[i->receiver.id] = *i;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 .ToImageSkia(); 499 .ToImageSkia();
508 const base::string16& name = receiverActivity.receiver.name; 500 const base::string16& name = receiverActivity.receiver.name;
509 container->AddIconAndLabelCustomSize( 501 container->AddIconAndLabelCustomSize(
510 *image, name, false, kTrayPopupDetailsIconWidth, 502 *image, name, false, kTrayPopupDetailsIconWidth,
511 kTrayPopupPaddingHorizontal, kTrayPopupPaddingBetweenItems); 503 kTrayPopupPaddingHorizontal, kTrayPopupPaddingBetweenItems);
512 504
513 scroll_content()->AddChildView(container); 505 scroll_content()->AddChildView(container);
514 return container; 506 return container;
515 } 507 }
516 508
517 void CastDetailedView::AppendSettingsEntries() {
518 if (MaterialDesignController::IsSystemTrayMenuMaterial())
519 return;
520
521 // Settings requires a browser window, hide it for non logged in user.
522 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED ||
523 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) {
524 return;
525 }
526
527 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
528 HoverHighlightView* container = new HoverHighlightView(this);
529 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS),
530 gfx::ALIGN_LEFT, false /* highlight */);
531
532 AddChildView(container);
533 options_ = container;
534 }
535
536 void CastDetailedView::HandleViewClicked(views::View* view) { 509 void CastDetailedView::HandleViewClicked(views::View* view) {
537 if (view == options_) {
538 GetCastConfigDelegate()->LaunchCastOptions();
539 return;
540 }
541
542 // Find the receiver we are going to cast to. 510 // Find the receiver we are going to cast to.
543 auto it = receiver_activity_map_.find(view); 511 auto it = receiver_activity_map_.find(view);
544 if (it != receiver_activity_map_.end()) { 512 if (it != receiver_activity_map_.end()) {
545 GetCastConfigDelegate()->CastToReceiver(it->second); 513 GetCastConfigDelegate()->CastToReceiver(it->second);
546 WmShell::Get()->RecordUserMetricsAction( 514 WmShell::Get()->RecordUserMetricsAction(
547 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST); 515 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST);
548 } 516 }
549 } 517 }
550 518
551 } // namespace tray 519 } // namespace tray
(...skipping 29 matching lines...) Expand all
581 views::View* TrayCast::CreateTrayView(LoginStatus status) { 549 views::View* TrayCast::CreateTrayView(LoginStatus status) {
582 CHECK(tray_ == nullptr); 550 CHECK(tray_ == nullptr);
583 tray_ = new tray::CastTrayView(this); 551 tray_ = new tray::CastTrayView(this);
584 tray_->SetVisible(is_casting_); 552 tray_->SetVisible(is_casting_);
585 return tray_; 553 return tray_;
586 } 554 }
587 555
588 views::View* TrayCast::CreateDefaultView(LoginStatus status) { 556 views::View* TrayCast::CreateDefaultView(LoginStatus status) {
589 CHECK(default_ == nullptr); 557 CHECK(default_ == nullptr);
590 558
591 if (HasCastExtension()) { 559 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
592 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); 560 if (cast_config_delegate) {
593
594 // Add the cast observer here instead of the ctor for two reasons: 561 // Add the cast observer here instead of the ctor for two reasons:
595 // - The ctor gets called too early in the initialization cycle (at least 562 // - The ctor gets called too early in the initialization cycle (at least
596 // for the tests); the correct profile hasn't been setup yet. 563 // for the tests); the correct profile hasn't been setup yet.
597 // - If we're using the cast extension backend (media router is disabled), 564 // - If we're using the cast extension backend (media router is disabled),
598 // then the user can install the extension at any point in time. The 565 // then the user can install the extension at any point in time. The
599 // return value of HasCastExtension() can change, so only checking it in 566 // return value of HasCastExtension() can change, so only checking it in
600 // the ctor isn't enough. 567 // the ctor isn't enough.
601 if (!added_observer_) { 568 if (!added_observer_) {
602 cast_config_delegate->AddObserver(this); 569 cast_config_delegate->AddObserver(this);
603 added_observer_ = true; 570 added_observer_ = true;
(...skipping 10 matching lines...) Expand all
614 default_->select_view()->set_id(SELECT_VIEW); 581 default_->select_view()->set_id(SELECT_VIEW);
615 default_->cast_view()->set_id(CAST_VIEW); 582 default_->cast_view()->set_id(CAST_VIEW);
616 583
617 UpdatePrimaryView(); 584 UpdatePrimaryView();
618 return default_; 585 return default_;
619 } 586 }
620 587
621 views::View* TrayCast::CreateDetailedView(LoginStatus status) { 588 views::View* TrayCast::CreateDetailedView(LoginStatus status) {
622 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_CAST_VIEW); 589 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_CAST_VIEW);
623 CHECK(detailed_ == nullptr); 590 CHECK(detailed_ == nullptr);
624 detailed_ = 591 detailed_ = new tray::CastDetailedView(this, receivers_and_activities_);
625 new tray::CastDetailedView(this, status, receivers_and_activities_);
626 return detailed_; 592 return detailed_;
627 } 593 }
628 594
629 void TrayCast::DestroyTrayView() { 595 void TrayCast::DestroyTrayView() {
630 tray_ = nullptr; 596 tray_ = nullptr;
631 } 597 }
632 598
633 void TrayCast::DestroyDefaultView() { 599 void TrayCast::DestroyDefaultView() {
634 default_ = nullptr; 600 default_ = nullptr;
635 } 601 }
636 602
637 void TrayCast::DestroyDetailedView() { 603 void TrayCast::DestroyDetailedView() {
638 detailed_ = nullptr; 604 detailed_ = nullptr;
639 } 605 }
640 606
641 bool TrayCast::HasCastExtension() {
642 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
643 return cast_config_delegate != nullptr &&
644 cast_config_delegate->HasCastExtension();
645 }
646
647 void TrayCast::OnDevicesUpdated( 607 void TrayCast::OnDevicesUpdated(
648 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { 608 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) {
649 receivers_and_activities_ = receivers_activities; 609 receivers_and_activities_ = receivers_activities;
650 610
651 if (default_) { 611 if (default_) {
652 bool has_receivers = !receivers_and_activities_.empty(); 612 bool has_receivers = !receivers_and_activities_.empty();
653 default_->SetVisible(has_receivers); 613 default_->SetVisible(has_receivers);
654 default_->cast_view()->UpdateLabel(receivers_and_activities_); 614 default_->cast_view()->UpdateLabel(receivers_and_activities_);
655 } 615 }
656 if (detailed_) 616 if (detailed_)
657 detailed_->UpdateReceiverList(receivers_and_activities_); 617 detailed_->UpdateReceiverList(receivers_and_activities_);
658 } 618 }
659 619
660 void TrayCast::UpdatePrimaryView() { 620 void TrayCast::UpdatePrimaryView() {
661 if (HasCastExtension() && !receivers_and_activities_.empty()) { 621 if (GetCastConfigDelegate() && !receivers_and_activities_.empty()) {
662 if (default_) { 622 if (default_) {
663 if (is_casting_) 623 if (is_casting_)
664 default_->ActivateCastView(); 624 default_->ActivateCastView();
665 else 625 else
666 default_->ActivateSelectView(); 626 default_->ActivateSelectView();
667 } 627 }
668 628
669 if (tray_) 629 if (tray_)
670 tray_->SetVisible(is_casting_); 630 tray_->SetVisible(is_casting_);
671 } else { 631 } else {
672 if (default_) 632 if (default_)
673 default_->SetVisible(false); 633 default_->SetVisible(false);
674 if (tray_) 634 if (tray_)
675 tray_->SetVisible(false); 635 tray_->SetVisible(false);
676 } 636 }
677 } 637 }
678 638
679 void TrayCast::OnCastingSessionStartedOrStopped(bool started) { 639 void TrayCast::OnCastingSessionStartedOrStopped(bool started) {
680 is_casting_ = started; 640 is_casting_ = started;
681 UpdatePrimaryView(); 641 UpdatePrimaryView();
682 } 642 }
683 643
684 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 644 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
685 if (tray_) 645 if (tray_)
686 tray_->UpdateAlignment(alignment); 646 tray_->UpdateAlignment(alignment);
687 } 647 }
688 648
689 } // namespace ash 649 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698