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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc

Issue 2064813002: Fixing the order of methods in ChromeLauncherControllerImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@launcher_controller_mus_6
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 std::string app_id = iter->second->app_id(); 426 std::string app_id = iter->second->app_id();
427 iter->second = AppShortcutLauncherItemController::Create(app_id, this); 427 iter->second = AppShortcutLauncherItemController::Create(app_id, this);
428 iter->second->set_shelf_id(id); 428 iter->second->set_shelf_id(id);
429 // Existing controller is destroyed and replaced by registering again. 429 // Existing controller is destroyed and replaced by registering again.
430 SetShelfItemDelegate(id, iter->second); 430 SetShelfItemDelegate(id, iter->second);
431 } else { 431 } else {
432 LauncherItemClosed(id); 432 LauncherItemClosed(id);
433 } 433 }
434 } 434 }
435 435
436 AppListControllerDelegate::Pinnable ChromeLauncherControllerImpl::GetPinnable(
437 const std::string& app_id) {
438 for (size_t i = 0; i < kPinProhibitedExtensionIdsLength; ++i) {
439 if (kPinProhibitedExtensionIds[i] == app_id)
440 return AppListControllerDelegate::NO_PIN;
441 }
442
443 const base::ListValue* pref =
444 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
445 if (!pref)
446 return AppListControllerDelegate::PIN_EDITABLE;
447
448 // Pinned ARC apps policy defines the package name of the apps, that must
449 // be pinned. All the launch activities of any package in policy are pinned.
450 // In turn the input parameter to this function is app_id, which
451 // is 32 chars hash. In case of ARC app this is a hash of
452 // (package name + activity). This means that we must identify the package
453 // from the hash, and check if this package is pinned by policy.
454 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(GetProfile());
455 std::string arc_app_packege_name;
456 if (arc_prefs) {
457 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
458 arc_prefs->GetApp(app_id);
459 if (app_info)
460 arc_app_packege_name = app_info->package_name;
461 }
462
463 for (size_t index = 0; index < pref->GetSize(); ++index) {
464 const base::DictionaryValue* app = nullptr;
465 std::string app_id_or_package;
466 if (pref->GetDictionary(index, &app) &&
467 app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id_or_package) &&
468 (app_id == app_id_or_package ||
469 arc_app_packege_name == app_id_or_package)) {
470 return AppListControllerDelegate::PIN_FIXED;
471 }
472 }
473 return AppListControllerDelegate::PIN_EDITABLE;
474 }
475
476 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { 436 void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) {
477 DCHECK(HasShelfIDToAppIDMapping(id)); 437 DCHECK(HasShelfIDToAppIDMapping(id));
478 438
479 int index = model_->ItemIndexByID(id); 439 int index = model_->ItemIndexByID(id);
480 DCHECK_GE(index, 0); 440 DCHECK_GE(index, 0);
481 441
482 ash::ShelfItem item = model_->items()[index]; 442 ash::ShelfItem item = model_->items()[index];
483 443
484 if (item.type == ash::TYPE_PLATFORM_APP || 444 if (item.type == ash::TYPE_PLATFORM_APP ||
485 item.type == ash::TYPE_WINDOWED_APP) { 445 item.type == ash::TYPE_WINDOWED_APP) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id)); 584 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id));
625 585
626 // An extension can be unloaded/updated/unavailable at any time. 586 // An extension can be unloaded/updated/unavailable at any time.
627 if (!extension) 587 if (!extension)
628 return extensions::LAUNCH_TYPE_DEFAULT; 588 return extensions::LAUNCH_TYPE_DEFAULT;
629 589
630 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), 590 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_),
631 extension); 591 extension);
632 } 592 }
633 593
634 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID(
635 const std::string& app_id) {
636 for (IDToItemControllerMap::const_iterator i =
637 id_to_item_controller_map_.begin();
638 i != id_to_item_controller_map_.end(); ++i) {
639 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL)
640 continue; // Don't include panels
641 if (i->second->app_id() == app_id)
642 return i->first;
643 }
644 return 0;
645 }
646
647 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping(
648 ash::ShelfID id) const {
649 return id_to_item_controller_map_.find(id) !=
650 id_to_item_controller_map_.end();
651 }
652
653 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID(
654 ash::ShelfID id) {
655 LauncherItemController* controller = GetLauncherItemController(id);
656 return controller ? controller->app_id() : base::EmptyString();
657 }
658
659 void ChromeLauncherControllerImpl::OnAppImageUpdated(
660 const std::string& id,
661 const gfx::ImageSkia& image) {
662 // TODO: need to get this working for shortcuts.
663 for (IDToItemControllerMap::const_iterator i =
664 id_to_item_controller_map_.begin();
665 i != id_to_item_controller_map_.end(); ++i) {
666 LauncherItemController* controller = i->second;
667 if (controller->app_id() != id)
668 continue;
669 if (controller->image_set_by_controller())
670 continue;
671 int index = model_->ItemIndexByID(i->first);
672 if (index == -1)
673 continue;
674 ash::ShelfItem item = model_->items()[index];
675 item.image = image;
676 model_->Set(index, item);
677 // It's possible we're waiting on more than one item, so don't break.
678 }
679 }
680
681 void ChromeLauncherControllerImpl::SetLauncherItemImage( 594 void ChromeLauncherControllerImpl::SetLauncherItemImage(
682 ash::ShelfID shelf_id, 595 ash::ShelfID shelf_id,
683 const gfx::ImageSkia& image) { 596 const gfx::ImageSkia& image) {
684 int index = model_->ItemIndexByID(shelf_id); 597 int index = model_->ItemIndexByID(shelf_id);
685 if (index == -1) 598 if (index == -1)
686 return; 599 return;
687 ash::ShelfItem item = model_->items()[index]; 600 ash::ShelfItem item = model_->items()[index];
688 item.image = image; 601 item.image = image;
689 model_->Set(index, item); 602 model_->Set(index, item);
690 } 603 }
691 604
692 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) {
693 for (IDToItemControllerMap::const_iterator i =
694 id_to_item_controller_map_.begin();
695 i != id_to_item_controller_map_.end(); ++i) {
696 if (IsPinned(i->first) && i->second->app_id() == app_id)
697 return true;
698 }
699 return false;
700 }
701
702 bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher( 605 bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher(
703 const std::string& app_id) { 606 const std::string& app_id) {
704 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id)); 607 int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id));
705 if (index < 0) 608 if (index < 0)
706 return false; 609 return false;
707 610
708 ash::ShelfItemType type = model_->items()[index].type; 611 ash::ShelfItemType type = model_->items()[index].type;
709 return type == ash::TYPE_WINDOWED_APP; 612 return type == ash::TYPE_WINDOWED_APP;
710 } 613 }
711 614
712 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) {
713 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
714 DoPinAppWithID(app_id);
715 else
716 NOTREACHED();
717 }
718
719 void ChromeLauncherControllerImpl::SetLaunchType( 615 void ChromeLauncherControllerImpl::SetLaunchType(
720 ash::ShelfID id, 616 ash::ShelfID id,
721 extensions::LaunchType launch_type) { 617 extensions::LaunchType launch_type) {
722 LauncherItemController* controller = GetLauncherItemController(id); 618 LauncherItemController* controller = GetLauncherItemController(id);
723 if (!controller) 619 if (!controller)
724 return; 620 return;
725 621
726 extensions::SetLaunchType(profile_, controller->app_id(), launch_type); 622 extensions::SetLaunchType(profile_, controller->app_id(), launch_type);
727 } 623 }
728 624
729 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) {
730 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
731 DoUnpinAppWithID(app_id);
732 else
733 NOTREACHED();
734 }
735
736 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate(
737 ash::ShelfID id,
738 ash::ShelfItemDelegate* item_delegate) {
739 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
740 // get into this state in the first place.
741 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
742 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second)
743 return;
744 LOG(ERROR) << "Unexpected change of shelf item id: " << id;
745 id_to_item_controller_map_.erase(iter);
746 }
747
748 void ChromeLauncherControllerImpl::PersistPinnedState() { 625 void ChromeLauncherControllerImpl::PersistPinnedState() {
749 if (ignore_persist_pinned_state_change_) 626 if (ignore_persist_pinned_state_change_)
750 return; 627 return;
751 // It is a coding error to call PersistPinnedState() if the pinned apps are 628 // It is a coding error to call PersistPinnedState() if the pinned apps are
752 // not user-editable. The code should check earlier and not perform any 629 // not user-editable. The code should check earlier and not perform any
753 // modification actions that trigger persisting the state. 630 // modification actions that trigger persisting the state.
754 // Mutating kPinnedLauncherApps is going to notify us and trigger us to 631 // Mutating kPinnedLauncherApps is going to notify us and trigger us to
755 // process the change. We don't want that to happen so remove ourselves as a 632 // process the change. We don't want that to happen so remove ourselves as a
756 // listener. 633 // listener.
757 pref_change_registrar_.Remove(prefs::kPinnedLauncherApps); 634 pref_change_registrar_.Remove(prefs::kPinnedLauncherApps);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 if (window->IsActive() && allow_minimize) { 793 if (window->IsActive() && allow_minimize) {
917 window->Minimize(); 794 window->Minimize();
918 return ash::ShelfItemDelegate::kNoAction; 795 return ash::ShelfItemDelegate::kNoAction;
919 } 796 }
920 797
921 window->Show(); 798 window->Show();
922 window->Activate(); 799 window->Activate();
923 return ash::ShelfItemDelegate::kExistingWindowActivated; 800 return ash::ShelfItemDelegate::kExistingWindowActivated;
924 } 801 }
925 802
803 void ChromeLauncherControllerImpl::ActiveUserChanged(
804 const std::string& user_email) {
805 // Store the order of running applications for the user which gets inactive.
806 RememberUnpinnedRunningApplicationOrder();
807 // Coming here the default profile is already switched. All profile specific
808 // resources get released and the new profile gets attached instead.
809 ReleaseProfile();
810 // When coming here, the active user has already be changed so that we can
811 // set it as active.
812 AttachProfile(ProfileManager::GetActiveUserProfile());
813 // Update the V1 applications.
814 browser_status_monitor_->ActiveUserChanged(user_email);
815 // Switch the running applications to the new user.
816 for (auto& controller : app_window_controllers_)
817 controller->ActiveUserChanged(user_email);
818 // Update the user specific shell properties from the new user profile.
819 UpdateAppLaunchersFromPref();
820 SetShelfBehaviorsFromPrefs();
821 SetVirtualKeyboardBehaviorFromPrefs();
822
823 // Restore the order of running, but unpinned applications for the activated
824 // user.
825 RestoreUnpinnedRunningApplicationOrder(user_email);
826 // Inform the system tray of the change.
827 ash::WmShell::Get()->system_tray_delegate()->ActiveUserWasChanged();
828 // Force on-screen keyboard to reset.
829 if (keyboard::IsKeyboardEnabled())
830 ash::Shell::GetInstance()->CreateKeyboard();
831 }
832
833 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession(
834 Profile* profile) {
835 // Switch the running applications to the new user.
836 for (auto& controller : app_window_controllers_)
837 controller->AdditionalUserAddedToSession(profile);
838 }
839
840 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList(
841 const ash::ShelfItem& item,
842 int event_flags) {
843 // Make sure that there is a controller associated with the id and that the
844 // extension itself is a valid application and not a panel.
845 LauncherItemController* controller = GetLauncherItemController(item.id);
846 if (!controller || !GetShelfIDForAppID(controller->app_id()))
847 return ChromeLauncherAppMenuItems();
848
849 return controller->GetApplicationList(event_flags);
850 }
851
852 std::vector<content::WebContents*>
853 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId(
854 const std::string& app_id) {
855 ash::ShelfID id = GetShelfIDForAppID(app_id);
856
857 // If there is no such an item pinned to the launcher, no menu gets created.
858 if (id) {
859 LauncherItemController* controller = GetLauncherItemController(id);
860 DCHECK(controller);
861 if (controller->type() == LauncherItemController::TYPE_SHORTCUT)
862 return GetV1ApplicationsFromController(controller);
863 }
864 return std::vector<content::WebContents*>();
865 }
866
867 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id,
868 int index) {
869 ash::ShelfID id = GetShelfIDForAppID(app_id);
870 if (id) {
871 LauncherItemController* controller = GetLauncherItemController(id);
872 if (controller && controller->type() == LauncherItemController::TYPE_APP) {
873 AppWindowLauncherItemController* app_window_controller =
874 static_cast<AppWindowLauncherItemController*>(controller);
875 app_window_controller->ActivateIndexedApp(index);
876 }
877 }
878 }
879
880 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication(
881 content::WebContents* web_contents,
882 const std::string& app_id) {
883 if ((web_contents_to_app_id_.find(web_contents) !=
884 web_contents_to_app_id_.end()) &&
885 (web_contents_to_app_id_[web_contents] == app_id))
886 return true;
887 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents));
888 }
889
890 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp(
891 content::WebContents* web_contents) {
892 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId);
893 if (id) {
894 const GURL url = web_contents->GetURL();
895 // We need to extend the application matching for the gMail app beyond the
896 // manifest file's specification. This is required because of the namespace
897 // overlap with the offline app ("/mail/mu/").
898 if (!base::MatchPattern(url.path(), "/mail/mu/*") &&
899 base::MatchPattern(url.path(), "/mail/*") &&
900 GetExtensionForAppID(kGmailAppId) &&
901 GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url))
902 return true;
903 }
904 return false;
905 }
906
907 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon(
908 content::WebContents* web_contents) const {
909 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
910 if (IsIncognito(web_contents))
911 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER);
912 favicon::FaviconDriver* favicon_driver =
913 favicon::ContentFaviconDriver::FromWebContents(web_contents);
914 gfx::Image result = favicon_driver->GetFavicon();
915 if (result.IsEmpty())
916 return rb.GetImageNamed(IDR_DEFAULT_FAVICON);
917 return result;
918 }
919
920 base::string16 ChromeLauncherControllerImpl::GetAppListTitle(
921 content::WebContents* web_contents) const {
922 base::string16 title = web_contents->GetTitle();
923 if (!title.empty())
924 return title;
925 WebContentsToAppIDMap::const_iterator iter =
926 web_contents_to_app_id_.find(web_contents);
927 if (iter != web_contents_to_app_id_.end()) {
928 std::string app_id = iter->second;
929 const extensions::Extension* extension = GetExtensionForAppID(app_id);
930 if (extension)
931 return base::UTF8ToUTF16(extension->name());
932 }
933 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
934 }
935
936 BrowserShortcutLauncherItemController*
937 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() {
938 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
939 i != id_to_item_controller_map_.end(); ++i) {
940 int index = model_->ItemIndexByID(i->first);
941 const ash::ShelfItem& item = model_->items()[index];
942 if (item.type == ash::TYPE_BROWSER_SHORTCUT)
943 return static_cast<BrowserShortcutLauncherItemController*>(i->second);
944 }
945 NOTREACHED()
946 << "There should be always be a BrowserShortcutLauncherItemController.";
947 return nullptr;
948 }
949
950 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController(
951 const ash::ShelfID id) {
952 if (!HasShelfIDToAppIDMapping(id))
953 return NULL;
954 return id_to_item_controller_map_[id];
955 }
956
957 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) {
958 // If running multi user mode with separate desktops, we have to check if the
959 // browser is from the active user.
960 if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
961 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED)
962 return true;
963 return multi_user_util::IsProfileFromActiveUser(browser->profile());
964 }
965
966 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser(
967 ash::Shelf* shelf,
968 const std::string& user_id) const {
969 Profile* other_profile = multi_user_util::GetProfileFromAccountId(
970 AccountId::FromUserEmail(user_id));
971 if (other_profile == profile_)
972 return false;
973
974 // Note: The Auto hide state from preferences is not the same as the actual
975 // visibility of the shelf. Depending on all the various states (full screen,
976 // no window on desktop, multi user, ..) the shelf could be shown - or not.
977 PrefService* prefs = profile_->GetPrefs();
978 PrefService* other_prefs = other_profile->GetPrefs();
979 const int64_t display = GetDisplayIDForShelf(shelf);
980 bool currently_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
981 ash::GetShelfAutoHideBehaviorPref(prefs, display);
982 bool other_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
983 ash::GetShelfAutoHideBehaviorPref(other_prefs, display);
984
985 return currently_shown != other_shown ||
986 ash::GetShelfAlignmentPref(prefs, display) !=
987 ash::GetShelfAlignmentPref(other_prefs, display);
988 }
989
990 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch(
991 Profile* profile) {
992 if (user_switch_observer_.get())
993 user_switch_observer_->OnUserProfileReadyToSwitch(profile);
994 }
995
996 AppListControllerDelegate::Pinnable ChromeLauncherControllerImpl::GetPinnable(
997 const std::string& app_id) {
998 for (size_t i = 0; i < kPinProhibitedExtensionIdsLength; ++i) {
999 if (kPinProhibitedExtensionIds[i] == app_id)
1000 return AppListControllerDelegate::NO_PIN;
1001 }
1002
1003 const base::ListValue* pref =
1004 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps);
1005 if (!pref)
1006 return AppListControllerDelegate::PIN_EDITABLE;
1007
1008 // Pinned ARC apps policy defines the package name of the apps, that must
1009 // be pinned. All the launch activities of any package in policy are pinned.
1010 // In turn the input parameter to this function is app_id, which
1011 // is 32 chars hash. In case of ARC app this is a hash of
1012 // (package name + activity). This means that we must identify the package
1013 // from the hash, and check if this package is pinned by policy.
1014 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(GetProfile());
1015 std::string arc_app_packege_name;
1016 if (arc_prefs) {
1017 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
1018 arc_prefs->GetApp(app_id);
1019 if (app_info)
1020 arc_app_packege_name = app_info->package_name;
1021 }
1022
1023 for (size_t index = 0; index < pref->GetSize(); ++index) {
1024 const base::DictionaryValue* app = nullptr;
1025 std::string app_id_or_package;
1026 if (pref->GetDictionary(index, &app) &&
1027 app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id_or_package) &&
1028 (app_id == app_id_or_package ||
1029 arc_app_packege_name == app_id_or_package)) {
1030 return AppListControllerDelegate::PIN_FIXED;
1031 }
1032 }
1033 return AppListControllerDelegate::PIN_EDITABLE;
1034 }
1035
926 ArcAppDeferredLauncherController* 1036 ArcAppDeferredLauncherController*
927 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { 1037 ChromeLauncherControllerImpl::GetArcDeferredLauncher() {
928 return arc_deferred_launcher_.get(); 1038 return arc_deferred_launcher_.get();
929 } 1039 }
930 1040
1041 ///////////////////////////////////////////////////////////////////////////////
1042 // ash::ShelfDelegate:
1043
931 void ChromeLauncherControllerImpl::OnShelfCreated(ash::Shelf* shelf) { 1044 void ChromeLauncherControllerImpl::OnShelfCreated(ash::Shelf* shelf) {
932 PrefService* prefs = profile_->GetPrefs(); 1045 PrefService* prefs = profile_->GetPrefs();
933 const int64_t display = GetDisplayIDForShelf(shelf); 1046 const int64_t display = GetDisplayIDForShelf(shelf);
934 1047
935 shelf->SetAutoHideBehavior(ash::GetShelfAutoHideBehaviorPref(prefs, display)); 1048 shelf->SetAutoHideBehavior(ash::GetShelfAutoHideBehaviorPref(prefs, display));
936 1049
937 if (ash::ShelfWidget::ShelfAlignmentAllowed()) 1050 if (ash::ShelfWidget::ShelfAlignmentAllowed())
938 shelf->SetAlignment(ash::GetShelfAlignmentPref(prefs, display)); 1051 shelf->SetAlignment(ash::GetShelfAlignmentPref(prefs, display));
939 } 1052 }
940 1053
(...skipping 10 matching lines...) Expand all
951 GetDisplayIDForShelf(shelf), 1064 GetDisplayIDForShelf(shelf),
952 shelf->auto_hide_behavior()); 1065 shelf->auto_hide_behavior());
953 } 1066 }
954 1067
955 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged( 1068 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged(
956 ash::Shelf* shelf) {} 1069 ash::Shelf* shelf) {}
957 1070
958 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( 1071 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged(
959 ash::Shelf* shelf) {} 1072 ash::Shelf* shelf) {}
960 1073
1074 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID(
1075 const std::string& app_id) {
1076 for (IDToItemControllerMap::const_iterator i =
1077 id_to_item_controller_map_.begin();
1078 i != id_to_item_controller_map_.end(); ++i) {
1079 if (i->second->type() == LauncherItemController::TYPE_APP_PANEL)
1080 continue; // Don't include panels
1081 if (i->second->app_id() == app_id)
1082 return i->first;
1083 }
1084 return 0;
1085 }
1086
1087 bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping(
1088 ash::ShelfID id) const {
1089 return id_to_item_controller_map_.find(id) !=
1090 id_to_item_controller_map_.end();
1091 }
1092
1093 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID(
1094 ash::ShelfID id) {
1095 LauncherItemController* controller = GetLauncherItemController(id);
1096 return controller ? controller->app_id() : base::EmptyString();
1097 }
1098
1099 bool ChromeLauncherControllerImpl::GetAppIDForShelfIDConst(
msw 2016/06/13 19:15:25 This is unused and not actually a ShelfDelegate ov
mfomitchev 2016/06/13 20:32:29 This, will remove in a separate CL (don't want to
1100 ash::ShelfID id,
1101 std::string* app_id) const {
1102 auto app = id_to_item_controller_map_.find(id);
1103 if (app == id_to_item_controller_map_.end()) {
1104 return false;
1105 } else {
1106 *app_id = app->second->app_id();
1107 return true;
1108 }
1109 }
1110
1111 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) {
1112 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
1113 DoPinAppWithID(app_id);
1114 else
1115 NOTREACHED();
1116 }
1117
1118 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) {
1119 for (IDToItemControllerMap::const_iterator i =
1120 id_to_item_controller_map_.begin();
1121 i != id_to_item_controller_map_.end(); ++i) {
1122 if (IsPinned(i->first) && i->second->app_id() == app_id)
1123 return true;
1124 }
1125 return false;
1126 }
1127
1128 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) {
1129 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE)
1130 DoUnpinAppWithID(app_id);
1131 else
1132 NOTREACHED();
1133 }
1134
1135 ///////////////////////////////////////////////////////////////////////////////
1136 // ash::ShelfItemDelegateManagerObserver:
1137
1138 void ChromeLauncherControllerImpl::OnSetShelfItemDelegate(
1139 ash::ShelfID id,
1140 ash::ShelfItemDelegate* item_delegate) {
1141 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we
1142 // get into this state in the first place.
1143 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1144 if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second)
1145 return;
1146 LOG(ERROR) << "Unexpected change of shelf item id: " << id;
1147 id_to_item_controller_map_.erase(iter);
1148 }
1149
1150 ///////////////////////////////////////////////////////////////////////////////
1151 // ash::ShelfModelObserver:
1152
961 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { 1153 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) {
962 // The app list launcher can get added to the shelf after we applied the 1154 // The app list launcher can get added to the shelf after we applied the
963 // preferences. In that case the item might be at the wrong spot. As such we 1155 // preferences. In that case the item might be at the wrong spot. As such we
964 // call the function again. 1156 // call the function again.
965 if (model_->items()[index].type == ash::TYPE_APP_LIST) 1157 if (model_->items()[index].type == ash::TYPE_APP_LIST)
966 UpdateAppLaunchersFromPref(); 1158 UpdateAppLaunchersFromPref();
967 } 1159 }
968 1160
969 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, 1161 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index,
970 ash::ShelfID id) { 1162 ash::ShelfID id) {
(...skipping 15 matching lines...) Expand all
986 // it is the app list with the alternate shelf layout. 1178 // it is the app list with the alternate shelf layout.
987 if ((HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) || 1179 if ((HasShelfIDToAppIDMapping(item.id) && IsPinned(item.id)) ||
988 item.type == ash::TYPE_APP_LIST) 1180 item.type == ash::TYPE_APP_LIST)
989 PersistPinnedState(); 1181 PersistPinnedState();
990 } 1182 }
991 1183
992 void ChromeLauncherControllerImpl::ShelfItemChanged( 1184 void ChromeLauncherControllerImpl::ShelfItemChanged(
993 int index, 1185 int index,
994 const ash::ShelfItem& old_item) {} 1186 const ash::ShelfItem& old_item) {}
995 1187
996 void ChromeLauncherControllerImpl::ActiveUserChanged( 1188 ///////////////////////////////////////////////////////////////////////////////
997 const std::string& user_email) { 1189 // ash::WindowTreeHostManager::Observer:
998 // Store the order of running applications for the user which gets inactive. 1190
999 RememberUnpinnedRunningApplicationOrder(); 1191 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() {
1000 // Coming here the default profile is already switched. All profile specific
1001 // resources get released and the new profile gets attached instead.
1002 ReleaseProfile();
1003 // When coming here, the active user has already be changed so that we can
1004 // set it as active.
1005 AttachProfile(ProfileManager::GetActiveUserProfile());
1006 // Update the V1 applications.
1007 browser_status_monitor_->ActiveUserChanged(user_email);
1008 // Switch the running applications to the new user.
1009 for (auto& controller : app_window_controllers_)
1010 controller->ActiveUserChanged(user_email);
1011 // Update the user specific shell properties from the new user profile.
1012 UpdateAppLaunchersFromPref();
1013 SetShelfBehaviorsFromPrefs(); 1192 SetShelfBehaviorsFromPrefs();
1014 SetVirtualKeyboardBehaviorFromPrefs();
1015
1016 // Restore the order of running, but unpinned applications for the activated
1017 // user.
1018 RestoreUnpinnedRunningApplicationOrder(user_email);
1019 // Inform the system tray of the change.
1020 ash::WmShell::Get()->system_tray_delegate()->ActiveUserWasChanged();
1021 // Force on-screen keyboard to reset.
1022 if (keyboard::IsKeyboardEnabled())
1023 ash::Shell::GetInstance()->CreateKeyboard();
1024 } 1193 }
1025 1194
1026 void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( 1195 ///////////////////////////////////////////////////////////////////////////////
1027 Profile* profile) { 1196 // LauncherAppUpdater:
1028 // Switch the running applications to the new user.
1029 for (auto& controller : app_window_controllers_)
1030 controller->AdditionalUserAddedToSession(profile);
1031 }
1032 1197
1033 void ChromeLauncherControllerImpl::OnAppInstalled( 1198 void ChromeLauncherControllerImpl::OnAppInstalled(
1034 content::BrowserContext* browser_context, 1199 content::BrowserContext* browser_context,
1035 const std::string& app_id) { 1200 const std::string& app_id) {
1036 if (IsAppPinned(app_id)) { 1201 if (IsAppPinned(app_id)) {
1037 // Clear and re-fetch to ensure icon is up-to-date. 1202 // Clear and re-fetch to ensure icon is up-to-date.
1038 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1203 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1039 if (app_icon_loader) { 1204 if (app_icon_loader) {
1040 app_icon_loader->ClearImage(app_id); 1205 app_icon_loader->ClearImage(app_id);
1041 app_icon_loader->FetchImage(app_id); 1206 app_icon_loader->FetchImage(app_id);
(...skipping 22 matching lines...) Expand all
1064 1229
1065 if (IsAppPinned(app_id)) { 1230 if (IsAppPinned(app_id)) {
1066 if (profile == profile_) 1231 if (profile == profile_)
1067 DoUnpinAppWithID(app_id); 1232 DoUnpinAppWithID(app_id);
1068 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1233 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1069 if (app_icon_loader) 1234 if (app_icon_loader)
1070 app_icon_loader->ClearImage(app_id); 1235 app_icon_loader->ClearImage(app_id);
1071 } 1236 }
1072 } 1237 }
1073 1238
1074 void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { 1239 ///////////////////////////////////////////////////////////////////////////////
1075 SetShelfBehaviorsFromPrefs(); 1240 // AppSyncUIStateObserver:
1076 }
1077 1241
1078 void ChromeLauncherControllerImpl::OnAppSyncUIStatusChanged() { 1242 void ChromeLauncherControllerImpl::OnAppSyncUIStatusChanged() {
1079 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) 1243 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING)
1080 model_->set_status(ash::ShelfModel::STATUS_LOADING); 1244 model_->set_status(ash::ShelfModel::STATUS_LOADING);
1081 else 1245 else
1082 model_->set_status(ash::ShelfModel::STATUS_NORMAL); 1246 model_->set_status(ash::ShelfModel::STATUS_NORMAL);
1083 } 1247 }
1084 1248
1085 ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( 1249 ///////////////////////////////////////////////////////////////////////////////
1086 const ash::ShelfItem& item, 1250 // AppIconLoaderDelegate:
1087 int event_flags) {
1088 // Make sure that there is a controller associated with the id and that the
1089 // extension itself is a valid application and not a panel.
1090 LauncherItemController* controller = GetLauncherItemController(item.id);
1091 if (!controller || !GetShelfIDForAppID(controller->app_id()))
1092 return ChromeLauncherAppMenuItems();
1093 1251
1094 return controller->GetApplicationList(event_flags); 1252 void ChromeLauncherControllerImpl::OnAppImageUpdated(
1095 } 1253 const std::string& id,
1096 1254 const gfx::ImageSkia& image) {
1097 std::vector<content::WebContents*> 1255 // TODO: need to get this working for shortcuts.
1098 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( 1256 for (IDToItemControllerMap::const_iterator i =
1099 const std::string& app_id) { 1257 id_to_item_controller_map_.begin();
1100 ash::ShelfID id = GetShelfIDForAppID(app_id); 1258 i != id_to_item_controller_map_.end(); ++i) {
1101 1259 LauncherItemController* controller = i->second;
1102 // If there is no such an item pinned to the launcher, no menu gets created. 1260 if (controller->app_id() != id)
1103 if (id) { 1261 continue;
1104 LauncherItemController* controller = GetLauncherItemController(id); 1262 if (controller->image_set_by_controller())
1105 DCHECK(controller); 1263 continue;
1106 if (controller->type() == LauncherItemController::TYPE_SHORTCUT) 1264 int index = model_->ItemIndexByID(i->first);
1107 return GetV1ApplicationsFromController(controller); 1265 if (index == -1)
1108 } 1266 continue;
1109 return std::vector<content::WebContents*>(); 1267 ash::ShelfItem item = model_->items()[index];
1110 } 1268 item.image = image;
1111 1269 model_->Set(index, item);
1112 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, 1270 // It's possible we're waiting on more than one item, so don't break.
1113 int index) {
1114 ash::ShelfID id = GetShelfIDForAppID(app_id);
1115 if (id) {
1116 LauncherItemController* controller = GetLauncherItemController(id);
1117 if (controller && controller->type() == LauncherItemController::TYPE_APP) {
1118 AppWindowLauncherItemController* app_window_controller =
1119 static_cast<AppWindowLauncherItemController*>(controller);
1120 app_window_controller->ActivateIndexedApp(index);
1121 }
1122 } 1271 }
1123 } 1272 }
1124 1273
1125 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( 1274 ///////////////////////////////////////////////////////////////////////////////
1126 content::WebContents* web_contents, 1275 // ChromeLauncherControllerImpl protected:
1127 const std::string& app_id) {
1128 if ((web_contents_to_app_id_.find(web_contents) !=
1129 web_contents_to_app_id_.end()) &&
1130 (web_contents_to_app_id_[web_contents] == app_id))
1131 return true;
1132 return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents));
1133 }
1134
1135 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp(
1136 content::WebContents* web_contents) {
1137 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId);
1138 if (id) {
1139 const GURL url = web_contents->GetURL();
1140 // We need to extend the application matching for the gMail app beyond the
1141 // manifest file's specification. This is required because of the namespace
1142 // overlap with the offline app ("/mail/mu/").
1143 if (!base::MatchPattern(url.path(), "/mail/mu/*") &&
1144 base::MatchPattern(url.path(), "/mail/*") &&
1145 GetExtensionForAppID(kGmailAppId) &&
1146 GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url))
1147 return true;
1148 }
1149 return false;
1150 }
1151
1152 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon(
1153 content::WebContents* web_contents) const {
1154 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1155 if (IsIncognito(web_contents))
1156 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER);
1157 favicon::FaviconDriver* favicon_driver =
1158 favicon::ContentFaviconDriver::FromWebContents(web_contents);
1159 gfx::Image result = favicon_driver->GetFavicon();
1160 if (result.IsEmpty())
1161 return rb.GetImageNamed(IDR_DEFAULT_FAVICON);
1162 return result;
1163 }
1164
1165 base::string16 ChromeLauncherControllerImpl::GetAppListTitle(
1166 content::WebContents* web_contents) const {
1167 base::string16 title = web_contents->GetTitle();
1168 if (!title.empty())
1169 return title;
1170 WebContentsToAppIDMap::const_iterator iter =
1171 web_contents_to_app_id_.find(web_contents);
1172 if (iter != web_contents_to_app_id_.end()) {
1173 std::string app_id = iter->second;
1174 const extensions::Extension* extension = GetExtensionForAppID(app_id);
1175 if (extension)
1176 return base::UTF8ToUTF16(extension->name());
1177 }
1178 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
1179 }
1180 1276
1181 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( 1277 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem(
1182 const std::string& app_id, 1278 const std::string& app_id,
1183 int index) { 1279 int index) {
1184 return CreateAppShortcutLauncherItemWithType(app_id, index, 1280 return CreateAppShortcutLauncherItemWithType(app_id, index,
1185 ash::TYPE_APP_SHORTCUT); 1281 ash::TYPE_APP_SHORTCUT);
1186 } 1282 }
1187 1283
1188 void ChromeLauncherControllerImpl::SetLauncherControllerHelperForTest( 1284 void ChromeLauncherControllerImpl::SetLauncherControllerHelperForTest(
1189 LauncherControllerHelper* helper) { 1285 LauncherControllerHelper* helper) {
1190 launcher_controller_helper_.reset(helper); 1286 launcher_controller_helper_.reset(helper);
1191 } 1287 }
1192 1288
1193 void ChromeLauncherControllerImpl::SetAppIconLoadersForTest( 1289 void ChromeLauncherControllerImpl::SetAppIconLoadersForTest(
1194 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { 1290 std::vector<std::unique_ptr<AppIconLoader>>& loaders) {
1195 app_icon_loaders_.clear(); 1291 app_icon_loaders_.clear();
1196 for (auto& loader : loaders) 1292 for (auto& loader : loaders)
1197 app_icon_loaders_.push_back(std::move(loader)); 1293 app_icon_loaders_.push_back(std::move(loader));
1198 } 1294 }
1199 1295
1200 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( 1296 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest(
1201 ash::ShelfID id) { 1297 ash::ShelfID id) {
1202 return id_to_item_controller_map_[id]->app_id(); 1298 return id_to_item_controller_map_[id]->app_id();
1203 } 1299 }
1204 1300
1205 bool ChromeLauncherControllerImpl::GetAppIDForShelfIDConst(
1206 ash::ShelfID id,
1207 std::string* app_id) const {
1208 auto app = id_to_item_controller_map_.find(id);
1209 if (app == id_to_item_controller_map_.end()) {
1210 return false;
1211 } else {
1212 *app_id = app->second->app_id();
1213 return true;
1214 }
1215 }
1216
1217 void ChromeLauncherControllerImpl::SetShelfItemDelegateManagerForTest( 1301 void ChromeLauncherControllerImpl::SetShelfItemDelegateManagerForTest(
1218 ash::ShelfItemDelegateManager* manager) { 1302 ash::ShelfItemDelegateManager* manager) {
1219 if (item_delegate_manager_) 1303 if (item_delegate_manager_)
1220 item_delegate_manager_->RemoveObserver(this); 1304 item_delegate_manager_->RemoveObserver(this);
1221 1305
1222 item_delegate_manager_ = manager; 1306 item_delegate_manager_ = manager;
1223 1307
1224 if (item_delegate_manager_) 1308 if (item_delegate_manager_)
1225 item_delegate_manager_->AddObserver(this); 1309 item_delegate_manager_->AddObserver(this);
1226 } 1310 }
1227 1311
1312 ///////////////////////////////////////////////////////////////////////////////
1313 // ChromeLauncherControllerImpl private:
1314
1228 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { 1315 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() {
1229 RunningAppListIds list; 1316 RunningAppListIds list;
1230 for (int i = 0; i < model_->item_count(); i++) { 1317 for (int i = 0; i < model_->item_count(); i++) {
1231 ash::ShelfItemType type = model_->items()[i].type; 1318 ash::ShelfItemType type = model_->items()[i].type;
1232 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) 1319 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP)
1233 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); 1320 list.push_back(GetAppIDForShelfID(model_->items()[i].id));
1234 } 1321 }
1235 const std::string user_email = 1322 const std::string user_email =
1236 multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail(); 1323 multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail();
1237 last_used_running_application_order_[user_email] = list; 1324 last_used_running_application_order_[user_email] = list;
(...skipping 29 matching lines...) Expand all
1267 const std::string& app_id, 1354 const std::string& app_id,
1268 int index, 1355 int index,
1269 ash::ShelfItemType shelf_item_type) { 1356 ash::ShelfItemType shelf_item_type) {
1270 AppShortcutLauncherItemController* controller = 1357 AppShortcutLauncherItemController* controller =
1271 AppShortcutLauncherItemController::Create(app_id, this); 1358 AppShortcutLauncherItemController::Create(app_id, this);
1272 ash::ShelfID shelf_id = InsertAppLauncherItem( 1359 ash::ShelfID shelf_id = InsertAppLauncherItem(
1273 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type); 1360 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type);
1274 return shelf_id; 1361 return shelf_id;
1275 } 1362 }
1276 1363
1277 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController(
1278 const ash::ShelfID id) {
1279 if (!HasShelfIDToAppIDMapping(id))
1280 return NULL;
1281 return id_to_item_controller_map_[id];
1282 }
1283
1284 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) {
1285 // If running multi user mode with separate desktops, we have to check if the
1286 // browser is from the active user.
1287 if (chrome::MultiUserWindowManager::GetMultiProfileMode() !=
1288 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED)
1289 return true;
1290 return multi_user_util::IsProfileFromActiveUser(browser->profile());
1291 }
1292
1293 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser(
1294 ash::Shelf* shelf,
1295 const std::string& user_id) const {
1296 Profile* other_profile = multi_user_util::GetProfileFromAccountId(
1297 AccountId::FromUserEmail(user_id));
1298 if (other_profile == profile_)
1299 return false;
1300
1301 // Note: The Auto hide state from preferences is not the same as the actual
1302 // visibility of the shelf. Depending on all the various states (full screen,
1303 // no window on desktop, multi user, ..) the shelf could be shown - or not.
1304 PrefService* prefs = profile_->GetPrefs();
1305 PrefService* other_prefs = other_profile->GetPrefs();
1306 const int64_t display = GetDisplayIDForShelf(shelf);
1307 bool currently_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
1308 ash::GetShelfAutoHideBehaviorPref(prefs, display);
1309 bool other_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER ==
1310 ash::GetShelfAutoHideBehaviorPref(other_prefs, display);
1311
1312 return currently_shown != other_shown ||
1313 ash::GetShelfAlignmentPref(prefs, display) !=
1314 ash::GetShelfAlignmentPref(other_prefs, display);
1315 }
1316
1317 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch(
1318 Profile* profile) {
1319 if (user_switch_observer_.get())
1320 user_switch_observer_->OnUserProfileReadyToSwitch(profile);
1321 }
1322
1323 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { 1364 void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) {
1324 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1365 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1325 CHECK(iter != id_to_item_controller_map_.end()); 1366 CHECK(iter != id_to_item_controller_map_.end());
1326 CHECK(iter->second); 1367 CHECK(iter->second);
1327 const std::string& app_id = iter->second->app_id(); 1368 const std::string& app_id = iter->second->app_id();
1328 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); 1369 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id);
1329 if (app_icon_loader) 1370 if (app_icon_loader)
1330 app_icon_loader->ClearImage(app_id); 1371 app_icon_loader->ClearImage(app_id);
1331 id_to_item_controller_map_.erase(iter); 1372 id_to_item_controller_map_.erase(iter);
1332 int index = model_->ItemIndexByID(id); 1373 int index = model_->ItemIndexByID(id);
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 1685
1645 std::vector<content::WebContents*> 1686 std::vector<content::WebContents*>
1646 ChromeLauncherControllerImpl::GetV1ApplicationsFromController( 1687 ChromeLauncherControllerImpl::GetV1ApplicationsFromController(
1647 LauncherItemController* controller) { 1688 LauncherItemController* controller) {
1648 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); 1689 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT);
1649 AppShortcutLauncherItemController* app_controller = 1690 AppShortcutLauncherItemController* app_controller =
1650 static_cast<AppShortcutLauncherItemController*>(controller); 1691 static_cast<AppShortcutLauncherItemController*>(controller);
1651 return app_controller->GetRunningApplications(); 1692 return app_controller->GetRunningApplications();
1652 } 1693 }
1653 1694
1654 BrowserShortcutLauncherItemController*
1655 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() {
1656 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
1657 i != id_to_item_controller_map_.end(); ++i) {
1658 int index = model_->ItemIndexByID(i->first);
1659 const ash::ShelfItem& item = model_->items()[index];
1660 if (item.type == ash::TYPE_BROWSER_SHORTCUT)
1661 return static_cast<BrowserShortcutLauncherItemController*>(i->second);
1662 }
1663 NOTREACHED()
1664 << "There should be always be a BrowserShortcutLauncherItemController.";
1665 return nullptr;
1666 }
1667
1668 ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { 1695 ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() {
1669 ash::ShelfItem browser_shortcut; 1696 ash::ShelfItem browser_shortcut;
1670 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1697 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1671 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1698 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1672 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1699 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1673 ash::ShelfID id = model_->next_id(); 1700 ash::ShelfID id = model_->next_id();
1674 size_t index = GetChromeIconIndexForCreation(); 1701 size_t index = GetChromeIconIndexForCreation();
1675 model_->AddAt(index, browser_shortcut); 1702 model_->AddAt(index, browser_shortcut);
1676 id_to_item_controller_map_[id] = 1703 id_to_item_controller_map_[id] =
1677 new BrowserShortcutLauncherItemController(this, model_); 1704 new BrowserShortcutLauncherItemController(this, model_);
1678 id_to_item_controller_map_[id]->set_shelf_id(id); 1705 id_to_item_controller_map_[id]->set_shelf_id(id);
1679 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. 1706 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController.
1680 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); 1707 SetShelfItemDelegate(id, id_to_item_controller_map_[id]);
1681 return id; 1708 return id;
1682 } 1709 }
1683 1710
1711 bool ChromeLauncherControllerImpl::IsIncognito(
1712 const content::WebContents* web_contents) const {
1713 const Profile* profile =
1714 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1715 return profile->IsOffTheRecord() && !profile->IsGuestSession() &&
1716 !profile->IsSystemProfile();
1717 }
1718
1684 void ChromeLauncherControllerImpl::PersistChromeItemIndex(int index) { 1719 void ChromeLauncherControllerImpl::PersistChromeItemIndex(int index) {
1685 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); 1720 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index);
1686 } 1721 }
1687 1722
1688 void ChromeLauncherControllerImpl::MoveChromeOrApplistToFinalPosition( 1723 void ChromeLauncherControllerImpl::MoveChromeOrApplistToFinalPosition(
1689 bool is_chrome, 1724 bool is_chrome,
1690 bool is_app_list, 1725 bool is_app_list,
1691 int target_index, 1726 int target_index,
1692 int* chrome_index, 1727 int* chrome_index,
1693 int* app_list_index) { 1728 int* app_list_index) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 int index = it - pinned_apps.begin(); 1773 int index = it - pinned_apps.begin();
1739 1774
1740 // We should do here a comparison between the is state and the "want to be" 1775 // We should do here a comparison between the is state and the "want to be"
1741 // state since some apps might be able to pin but are not yet. Instead - for 1776 // state since some apps might be able to pin but are not yet. Instead - for
1742 // the time being we clamp against the amount of known items and wait for the 1777 // the time being we clamp against the amount of known items and wait for the
1743 // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since 1778 // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since
1744 // the pinning will be done then. 1779 // the pinning will be done then.
1745 return std::min(model_->item_count(), index); 1780 return std::min(model_->item_count(), index);
1746 } 1781 }
1747 1782
1748 bool ChromeLauncherControllerImpl::IsIncognito(
1749 const content::WebContents* web_contents) const {
1750 const Profile* profile =
1751 Profile::FromBrowserContext(web_contents->GetBrowserContext());
1752 return profile->IsOffTheRecord() && !profile->IsGuestSession() &&
1753 !profile->IsSystemProfile();
1754 }
1755
1756 void ChromeLauncherControllerImpl::CloseWindowedAppsFromRemovedExtension( 1783 void ChromeLauncherControllerImpl::CloseWindowedAppsFromRemovedExtension(
1757 const std::string& app_id, 1784 const std::string& app_id,
1758 const Profile* profile) { 1785 const Profile* profile) {
1759 // This function cannot rely on the controller's enumeration functionality 1786 // This function cannot rely on the controller's enumeration functionality
1760 // since the extension has already be unloaded. 1787 // since the extension has already be unloaded.
1761 const BrowserList* browser_list = BrowserList::GetInstance(); 1788 const BrowserList* browser_list = BrowserList::GetInstance();
1762 std::vector<Browser*> browser_to_close; 1789 std::vector<Browser*> browser_to_close;
1763 for (BrowserList::const_reverse_iterator it = 1790 for (BrowserList::const_reverse_iterator it =
1764 browser_list->begin_last_active(); 1791 browser_list->begin_last_active();
1765 it != browser_list->end_last_active(); ++it) { 1792 it != browser_list->end_last_active(); ++it) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1867 1894
1868 AppIconLoader* ChromeLauncherControllerImpl::GetAppIconLoaderForApp( 1895 AppIconLoader* ChromeLauncherControllerImpl::GetAppIconLoaderForApp(
1869 const std::string& app_id) { 1896 const std::string& app_id) {
1870 for (const auto& app_icon_loader : app_icon_loaders_) { 1897 for (const auto& app_icon_loader : app_icon_loaders_) {
1871 if (app_icon_loader->CanLoadImageForApp(app_id)) 1898 if (app_icon_loader->CanLoadImageForApp(app_id))
1872 return app_icon_loader.get(); 1899 return app_icon_loader.get();
1873 } 1900 }
1874 1901
1875 return nullptr; 1902 return nullptr;
1876 } 1903 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698