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

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

Issue 2424183002: Remove Chromecast extension support from cast system tray menu. (Closed)
Patch Set: Additional removals 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/chromeos/cast/tray_cast.h" 5 #include "ash/common/system/chromeos/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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 306 }
307 307
308 CastTrayView::~CastTrayView() {} 308 CastTrayView::~CastTrayView() {}
309 309
310 // This view displays a list of cast receivers that can be clicked on and casted 310 // This view displays a list of cast receivers that can be clicked on and casted
311 // to. It is activated by clicking on the chevron inside of 311 // to. It is activated by clicking on the chevron inside of
312 // |CastSelectDefaultView|. 312 // |CastSelectDefaultView|.
313 class CastDetailedView : public TrayDetailsView { 313 class CastDetailedView : public TrayDetailsView {
314 public: 314 public:
315 CastDetailedView(SystemTrayItem* owner, 315 CastDetailedView(SystemTrayItem* owner,
316 LoginStatus login,
317 const CastConfigDelegate::ReceiversAndActivities& 316 const CastConfigDelegate::ReceiversAndActivities&
318 receivers_and_activities); 317 receivers_and_activities);
319 ~CastDetailedView() override; 318 ~CastDetailedView() override;
320 319
321 // Makes the detail view think the view associated with the given receiver_id 320 // Makes the detail view think the view associated with the given receiver_id
322 // was clicked. This will start a cast. 321 // was clicked. This will start a cast.
323 void SimulateViewClickedForTest(const std::string& receiver_id); 322 void SimulateViewClickedForTest(const std::string& receiver_id);
324 323
325 // Updates the list of available receivers. 324 // Updates the list of available receivers.
326 void UpdateReceiverList(const CastConfigDelegate::ReceiversAndActivities& 325 void UpdateReceiverList(const CastConfigDelegate::ReceiversAndActivities&
327 new_receivers_and_activities); 326 new_receivers_and_activities);
328 327
329 private: 328 private:
330 void CreateItems(); 329 void CreateItems();
331 330
332 void UpdateReceiverListFromCachedData(); 331 void UpdateReceiverListFromCachedData();
333 views::View* AddToReceiverList( 332 views::View* AddToReceiverList(
334 const CastConfigDelegate::ReceiverAndActivity& receiverActivity); 333 const CastConfigDelegate::ReceiverAndActivity& receiverActivity);
335 334
336 void AppendSettingsEntries();
337
338 // TrayDetailsView: 335 // TrayDetailsView:
339 void HandleViewClicked(views::View* view) override; 336 void HandleViewClicked(views::View* view) override;
340 337
341 LoginStatus login_;
342 views::View* options_ = nullptr;
343 // A mapping from the receiver id to the receiver/activity data. 338 // A mapping from the receiver id to the receiver/activity data.
344 std::map<std::string, CastConfigDelegate::ReceiverAndActivity> 339 std::map<std::string, CastConfigDelegate::ReceiverAndActivity>
345 receivers_and_activities_; 340 receivers_and_activities_;
346 // A mapping from the view pointer to the associated activity id. 341 // A mapping from the view pointer to the associated activity id.
347 std::map<views::View*, std::string> receiver_activity_map_; 342 std::map<views::View*, std::string> receiver_activity_map_;
348 343
349 DISALLOW_COPY_AND_ASSIGN(CastDetailedView); 344 DISALLOW_COPY_AND_ASSIGN(CastDetailedView);
350 }; 345 };
351 346
352 CastDetailedView::CastDetailedView( 347 CastDetailedView::CastDetailedView(
353 SystemTrayItem* owner, 348 SystemTrayItem* owner,
354 LoginStatus login,
355 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities) 349 const CastConfigDelegate::ReceiversAndActivities& receivers_and_activities)
356 : TrayDetailsView(owner), login_(login) { 350 : TrayDetailsView(owner) {
357 CreateItems(); 351 CreateItems();
358 UpdateReceiverList(receivers_and_activities); 352 UpdateReceiverList(receivers_and_activities);
359 } 353 }
360 354
361 CastDetailedView::~CastDetailedView() {} 355 CastDetailedView::~CastDetailedView() {}
362 356
363 void CastDetailedView::SimulateViewClickedForTest( 357 void CastDetailedView::SimulateViewClickedForTest(
364 const std::string& receiver_id) { 358 const std::string& receiver_id) {
365 for (auto& it : receiver_activity_map_) { 359 for (auto& it : receiver_activity_map_) {
366 if (it.second == receiver_id) { 360 if (it.second == receiver_id) {
367 HandleViewClicked(it.first); 361 HandleViewClicked(it.first);
368 break; 362 break;
369 } 363 }
370 } 364 }
371 } 365 }
372 366
373 void CastDetailedView::CreateItems() { 367 void CastDetailedView::CreateItems() {
374 CreateScrollableList(); 368 CreateScrollableList();
375 if (GetCastConfigDelegate()->HasOptions())
376 AppendSettingsEntries();
377 CreateTitleRow(IDS_ASH_STATUS_TRAY_CAST); 369 CreateTitleRow(IDS_ASH_STATUS_TRAY_CAST);
378 } 370 }
379 371
380 void CastDetailedView::UpdateReceiverList( 372 void CastDetailedView::UpdateReceiverList(
381 const CastConfigDelegate::ReceiversAndActivities& 373 const CastConfigDelegate::ReceiversAndActivities&
382 new_receivers_and_activities) { 374 new_receivers_and_activities) {
383 // Add/update existing. 375 // Add/update existing.
384 for (auto i = new_receivers_and_activities.begin(); 376 for (auto i = new_receivers_and_activities.begin();
385 i != new_receivers_and_activities.end(); ++i) { 377 i != new_receivers_and_activities.end(); ++i) {
386 receivers_and_activities_[i->receiver.id] = *i; 378 receivers_and_activities_[i->receiver.id] = *i;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 .ToImageSkia(); 426 .ToImageSkia();
435 const base::string16& name = receiverActivity.receiver.name; 427 const base::string16& name = receiverActivity.receiver.name;
436 container->AddIconAndLabelCustomSize( 428 container->AddIconAndLabelCustomSize(
437 *image, name, false, kTrayPopupDetailsIconWidth, 429 *image, name, false, kTrayPopupDetailsIconWidth,
438 kTrayPopupPaddingHorizontal, kTrayPopupPaddingBetweenItems); 430 kTrayPopupPaddingHorizontal, kTrayPopupPaddingBetweenItems);
439 431
440 scroll_content()->AddChildView(container); 432 scroll_content()->AddChildView(container);
441 return container; 433 return container;
442 } 434 }
443 435
444 void CastDetailedView::AppendSettingsEntries() {
445 if (MaterialDesignController::IsSystemTrayMenuMaterial())
446 return;
447
448 // Settings requires a browser window, hide it for non logged in user.
449 if (login_ == LoginStatus::NOT_LOGGED_IN || login_ == LoginStatus::LOCKED ||
450 WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen()) {
451 return;
452 }
453
454 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
455 HoverHighlightView* container = new HoverHighlightView(this);
456 container->AddLabel(rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_OPTIONS),
457 gfx::ALIGN_LEFT, false /* highlight */);
458
459 AddChildView(container);
460 options_ = container;
461 }
462
463 void CastDetailedView::HandleViewClicked(views::View* view) { 436 void CastDetailedView::HandleViewClicked(views::View* view) {
464 if (view == options_) {
465 GetCastConfigDelegate()->LaunchCastOptions();
466 return;
467 }
468
469 // Find the receiver we are going to cast to. 437 // Find the receiver we are going to cast to.
470 auto it = receiver_activity_map_.find(view); 438 auto it = receiver_activity_map_.find(view);
471 if (it != receiver_activity_map_.end()) { 439 if (it != receiver_activity_map_.end()) {
472 GetCastConfigDelegate()->CastToReceiver(it->second); 440 GetCastConfigDelegate()->CastToReceiver(it->second);
473 WmShell::Get()->RecordUserMetricsAction( 441 WmShell::Get()->RecordUserMetricsAction(
474 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST); 442 UMA_STATUS_AREA_DETAILED_CAST_VIEW_LAUNCH_CAST);
475 } 443 }
476 } 444 }
477 445
478 } // namespace tray 446 } // namespace tray
(...skipping 29 matching lines...) Expand all
508 views::View* TrayCast::CreateTrayView(LoginStatus status) { 476 views::View* TrayCast::CreateTrayView(LoginStatus status) {
509 CHECK(tray_ == nullptr); 477 CHECK(tray_ == nullptr);
510 tray_ = new tray::CastTrayView(this); 478 tray_ = new tray::CastTrayView(this);
511 tray_->SetVisible(is_casting_); 479 tray_->SetVisible(is_casting_);
512 return tray_; 480 return tray_;
513 } 481 }
514 482
515 views::View* TrayCast::CreateDefaultView(LoginStatus status) { 483 views::View* TrayCast::CreateDefaultView(LoginStatus status) {
516 CHECK(default_ == nullptr); 484 CHECK(default_ == nullptr);
517 485
518 if (HasCastExtension()) { 486 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
519 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate(); 487 if (cast_config_delegate) {
520
521 // Add the cast observer here instead of the ctor for two reasons: 488 // Add the cast observer here instead of the ctor for two reasons:
522 // - The ctor gets called too early in the initialization cycle (at least 489 // - The ctor gets called too early in the initialization cycle (at least
523 // for the tests); the correct profile hasn't been setup yet. 490 // for the tests); the correct profile hasn't been setup yet.
524 // - If we're using the cast extension backend (media router is disabled), 491 // - If we're using the cast extension backend (media router is disabled),
525 // then the user can install the extension at any point in time. The 492 // then the user can install the extension at any point in time. The
526 // return value of HasCastExtension() can change, so only checking it in 493 // return value of HasCastExtension() can change, so only checking it in
527 // the ctor isn't enough. 494 // the ctor isn't enough.
528 if (!added_observer_) { 495 if (!added_observer_) {
529 cast_config_delegate->AddObserver(this); 496 cast_config_delegate->AddObserver(this);
530 added_observer_ = true; 497 added_observer_ = true;
(...skipping 10 matching lines...) Expand all
541 default_->select_view()->set_id(SELECT_VIEW); 508 default_->select_view()->set_id(SELECT_VIEW);
542 default_->cast_view()->set_id(CAST_VIEW); 509 default_->cast_view()->set_id(CAST_VIEW);
543 510
544 UpdatePrimaryView(); 511 UpdatePrimaryView();
545 return default_; 512 return default_;
546 } 513 }
547 514
548 views::View* TrayCast::CreateDetailedView(LoginStatus status) { 515 views::View* TrayCast::CreateDetailedView(LoginStatus status) {
549 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_CAST_VIEW); 516 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_DETAILED_CAST_VIEW);
550 CHECK(detailed_ == nullptr); 517 CHECK(detailed_ == nullptr);
551 detailed_ = 518 detailed_ = new tray::CastDetailedView(this, receivers_and_activities_);
552 new tray::CastDetailedView(this, status, receivers_and_activities_);
553 return detailed_; 519 return detailed_;
554 } 520 }
555 521
556 void TrayCast::DestroyTrayView() { 522 void TrayCast::DestroyTrayView() {
557 tray_ = nullptr; 523 tray_ = nullptr;
558 } 524 }
559 525
560 void TrayCast::DestroyDefaultView() { 526 void TrayCast::DestroyDefaultView() {
561 default_ = nullptr; 527 default_ = nullptr;
562 } 528 }
563 529
564 void TrayCast::DestroyDetailedView() { 530 void TrayCast::DestroyDetailedView() {
565 detailed_ = nullptr; 531 detailed_ = nullptr;
566 } 532 }
567 533
568 bool TrayCast::HasCastExtension() {
569 CastConfigDelegate* cast_config_delegate = GetCastConfigDelegate();
570 return cast_config_delegate != nullptr &&
571 cast_config_delegate->HasCastExtension();
572 }
573
574 void TrayCast::OnDevicesUpdated( 534 void TrayCast::OnDevicesUpdated(
575 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) { 535 const CastConfigDelegate::ReceiversAndActivities& receivers_activities) {
576 receivers_and_activities_ = receivers_activities; 536 receivers_and_activities_ = receivers_activities;
577 537
578 if (default_) { 538 if (default_) {
579 bool has_receivers = !receivers_and_activities_.empty(); 539 bool has_receivers = !receivers_and_activities_.empty();
580 default_->SetVisible(has_receivers); 540 default_->SetVisible(has_receivers);
581 default_->cast_view()->UpdateLabel(receivers_and_activities_); 541 default_->cast_view()->UpdateLabel(receivers_and_activities_);
582 } 542 }
583 if (detailed_) 543 if (detailed_)
584 detailed_->UpdateReceiverList(receivers_and_activities_); 544 detailed_->UpdateReceiverList(receivers_and_activities_);
585 } 545 }
586 546
587 void TrayCast::UpdatePrimaryView() { 547 void TrayCast::UpdatePrimaryView() {
588 if (HasCastExtension() && !receivers_and_activities_.empty()) { 548 if (GetCastConfigDelegate() && !receivers_and_activities_.empty()) {
589 if (default_) { 549 if (default_) {
590 if (is_casting_) 550 if (is_casting_)
591 default_->ActivateCastView(); 551 default_->ActivateCastView();
592 else 552 else
593 default_->ActivateSelectView(); 553 default_->ActivateSelectView();
594 } 554 }
595 555
596 if (tray_) 556 if (tray_)
597 tray_->SetVisible(is_casting_); 557 tray_->SetVisible(is_casting_);
598 } else { 558 } else {
599 if (default_) 559 if (default_)
600 default_->SetVisible(false); 560 default_->SetVisible(false);
601 if (tray_) 561 if (tray_)
602 tray_->SetVisible(false); 562 tray_->SetVisible(false);
603 } 563 }
604 } 564 }
605 565
606 void TrayCast::OnCastingSessionStartedOrStopped(bool started) { 566 void TrayCast::OnCastingSessionStartedOrStopped(bool started) {
607 is_casting_ = started; 567 is_casting_ = started;
608 UpdatePrimaryView(); 568 UpdatePrimaryView();
609 } 569 }
610 570
611 } // namespace ash 571 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698