| OLD | NEW |
| 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 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/chromeos/extensions/gfx_utils.h" | 32 #include "chrome/browser/chromeos/extensions/gfx_utils.h" |
| 33 #include "chrome/browser/defaults.h" | 33 #include "chrome/browser/defaults.h" |
| 34 #include "chrome/browser/extensions/extension_app_icon_loader.h" | 34 #include "chrome/browser/extensions/extension_app_icon_loader.h" |
| 35 #include "chrome/browser/extensions/extension_util.h" | 35 #include "chrome/browser/extensions/extension_util.h" |
| 36 #include "chrome/browser/extensions/launch_util.h" | 36 #include "chrome/browser/extensions/launch_util.h" |
| 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 38 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
| 39 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
| 40 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 40 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 41 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 41 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 42 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | |
| 43 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 42 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 44 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 43 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
| 45 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 44 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 46 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 45 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 47 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 46 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
| 48 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 49 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 48 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| 50 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 49 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
| 51 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 50 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 52 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 51 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 53 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 52 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 54 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 53 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 55 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 54 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
| 56 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 55 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 56 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 57 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | 57 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
| 58 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" | 58 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" |
| 59 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 59 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 60 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" | 60 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
| 61 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 61 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 62 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr
oller.h" | 62 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr
oller.h" |
| 63 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" | 63 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" |
| 64 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 64 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 65 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 65 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 66 #include "chrome/browser/ui/browser.h" | 66 #include "chrome/browser/ui/browser.h" |
| 67 #include "chrome/browser/ui/browser_finder.h" | 67 #include "chrome/browser/ui/browser_finder.h" |
| 68 #include "chrome/browser/ui/browser_list.h" | 68 #include "chrome/browser/ui/browser_list.h" |
| 69 #include "chrome/browser/ui/browser_tabstrip.h" | 69 #include "chrome/browser/ui/browser_tabstrip.h" |
| 70 #include "chrome/browser/ui/browser_window.h" | 70 #include "chrome/browser/ui/browser_window.h" |
| 71 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 71 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 72 #include "chrome/browser/web_applications/web_app.h" | 72 #include "chrome/browser/web_applications/web_app.h" |
| 73 #include "chrome/common/chrome_switches.h" | 73 #include "chrome/common/chrome_switches.h" |
| 74 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 74 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 75 #include "chrome/common/pref_names.h" | 75 #include "chrome/common/pref_names.h" |
| 76 #include "chrome/common/url_constants.h" | 76 #include "chrome/common/url_constants.h" |
| 77 #include "chrome/grit/generated_resources.h" | 77 #include "chrome/grit/generated_resources.h" |
| 78 #include "components/favicon/content/content_favicon_driver.h" | 78 #include "components/favicon/content/content_favicon_driver.h" |
| 79 #include "components/prefs/scoped_user_pref_update.h" | 79 #include "components/prefs/scoped_user_pref_update.h" |
| 80 #include "components/signin/core/account_id/account_id.h" | 80 #include "components/signin/core/account_id/account_id.h" |
| 81 #include "components/strings/grit/components_strings.h" | 81 #include "components/strings/grit/components_strings.h" |
| 82 #include "components/user_manager/user_manager.h" | 82 #include "components/user_manager/user_manager.h" |
| 83 #include "content/public/browser/navigation_entry.h" | 83 #include "content/public/browser/navigation_entry.h" |
| 84 #include "content/public/browser/web_contents.h" | 84 #include "content/public/browser/web_contents.h" |
| 85 #include "extensions/browser/extension_prefs.h" | 85 #include "extensions/browser/extension_prefs.h" |
| 86 #include "extensions/browser/extension_registry.h" | |
| 87 #include "extensions/browser/extension_system.h" | 86 #include "extensions/browser/extension_system.h" |
| 88 #include "extensions/browser/extension_util.h" | 87 #include "extensions/browser/extension_util.h" |
| 89 #include "extensions/common/constants.h" | 88 #include "extensions/common/constants.h" |
| 90 #include "extensions/common/extension.h" | 89 #include "extensions/common/extension.h" |
| 91 #include "extensions/common/extension_resource.h" | 90 #include "extensions/common/extension_resource.h" |
| 92 #include "extensions/common/manifest_handlers/icons_handler.h" | 91 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 93 #include "extensions/common/url_pattern.h" | 92 #include "extensions/common/url_pattern.h" |
| 94 #include "grit/ash_resources.h" | 93 #include "grit/ash_resources.h" |
| 95 #include "grit/theme_resources.h" | 94 #include "grit/theme_resources.h" |
| 96 #include "ui/aura/window.h" | 95 #include "ui/aura/window.h" |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 if (!controller) | 479 if (!controller) |
| 481 return false; | 480 return false; |
| 482 return controller->IsOpen(); | 481 return controller->IsOpen(); |
| 483 } | 482 } |
| 484 | 483 |
| 485 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { | 484 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { |
| 486 if (!HasShelfIDToAppIDMapping(id)) | 485 if (!HasShelfIDToAppIDMapping(id)) |
| 487 return false; | 486 return false; |
| 488 | 487 |
| 489 std::string app_id = GetAppIDForShelfID(id); | 488 std::string app_id = GetAppIDForShelfID(id); |
| 490 const Extension* extension = GetExtensionForAppID(app_id); | 489 const Extension* extension = GetExtensionForAppID(app_id, profile_); |
| 491 // An extension can be synced / updated at any time and therefore not be | 490 // An extension can be synced / updated at any time and therefore not be |
| 492 // available. | 491 // available. |
| 493 return extension ? extension->is_platform_app() : false; | 492 return extension ? extension->is_platform_app() : false; |
| 494 } | 493 } |
| 495 | 494 |
| 496 void ChromeLauncherControllerImpl::LaunchApp(const std::string& app_id, | 495 void ChromeLauncherControllerImpl::LaunchApp(const std::string& app_id, |
| 497 ash::LaunchSource source, | 496 ash::LaunchSource source, |
| 498 int event_flags) { | 497 int event_flags) { |
| 499 launcher_controller_helper_->LaunchApp(app_id, source, event_flags); | 498 launcher_controller_helper_->LaunchApp(app_id, source, event_flags); |
| 500 } | 499 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 515 std::unique_ptr<AppShortcutLauncherItemController> app_controller( | 514 std::unique_ptr<AppShortcutLauncherItemController> app_controller( |
| 516 AppShortcutLauncherItemController::Create(app_id, this)); | 515 AppShortcutLauncherItemController::Create(app_id, this)); |
| 517 if (!app_controller->GetRunningApplications().empty()) | 516 if (!app_controller->GetRunningApplications().empty()) |
| 518 app_controller->Activate(source); | 517 app_controller->Activate(source); |
| 519 else | 518 else |
| 520 LaunchApp(app_id, source, event_flags); | 519 LaunchApp(app_id, source, event_flags); |
| 521 } | 520 } |
| 522 | 521 |
| 523 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( | 522 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( |
| 524 ash::ShelfID id) { | 523 ash::ShelfID id) { |
| 525 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id)); | 524 const Extension* extension = |
| 525 GetExtensionForAppID(GetAppIDForShelfID(id), profile_); |
| 526 | 526 |
| 527 // An extension can be unloaded/updated/unavailable at any time. | 527 // An extension can be unloaded/updated/unavailable at any time. |
| 528 if (!extension) | 528 if (!extension) |
| 529 return extensions::LAUNCH_TYPE_DEFAULT; | 529 return extensions::LAUNCH_TYPE_DEFAULT; |
| 530 | 530 |
| 531 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), | 531 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), |
| 532 extension); | 532 extension); |
| 533 } | 533 } |
| 534 | 534 |
| 535 void ChromeLauncherControllerImpl::SetLauncherItemImage( | 535 void ChromeLauncherControllerImpl::SetLauncherItemImage( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 ash::ShelfItemType type = model_->items()[index].type; | 640 ash::ShelfItemType type = model_->items()[index].type; |
| 641 if (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_WINDOWED_APP) { | 641 if (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_WINDOWED_APP) { |
| 642 AppShortcutLauncherItemController* app_controller = | 642 AppShortcutLauncherItemController* app_controller = |
| 643 static_cast<AppShortcutLauncherItemController*>(controller); | 643 static_cast<AppShortcutLauncherItemController*>(controller); |
| 644 app_controller->set_refocus_url(url); | 644 app_controller->set_refocus_url(url); |
| 645 } else { | 645 } else { |
| 646 NOTREACHED() << "Invalid launcher type"; | 646 NOTREACHED() << "Invalid launcher type"; |
| 647 } | 647 } |
| 648 } | 648 } |
| 649 | 649 |
| 650 const Extension* ChromeLauncherControllerImpl::GetExtensionForAppID( | |
| 651 const std::string& app_id) const { | |
| 652 return extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( | |
| 653 app_id, extensions::ExtensionRegistry::EVERYTHING); | |
| 654 } | |
| 655 | |
| 656 ash::ShelfItemDelegate::PerformedAction | 650 ash::ShelfItemDelegate::PerformedAction |
| 657 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( | 651 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
| 658 ui::BaseWindow* window, | 652 ui::BaseWindow* window, |
| 659 bool allow_minimize) { | 653 bool allow_minimize) { |
| 660 // In separated desktop mode we might have to teleport a window back to the | 654 // In separated desktop mode we might have to teleport a window back to the |
| 661 // current user. | 655 // current user. |
| 662 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == | 656 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == |
| 663 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) { | 657 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) { |
| 664 aura::Window* native_window = window->GetNativeWindow(); | 658 aura::Window* native_window = window->GetNativeWindow(); |
| 665 const AccountId& current_account_id = | 659 const AccountId& current_account_id = |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( | 769 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( |
| 776 content::WebContents* web_contents) { | 770 content::WebContents* web_contents) { |
| 777 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); | 771 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); |
| 778 if (id) { | 772 if (id) { |
| 779 const GURL url = web_contents->GetURL(); | 773 const GURL url = web_contents->GetURL(); |
| 780 // We need to extend the application matching for the gMail app beyond the | 774 // We need to extend the application matching for the gMail app beyond the |
| 781 // manifest file's specification. This is required because of the namespace | 775 // manifest file's specification. This is required because of the namespace |
| 782 // overlap with the offline app ("/mail/mu/"). | 776 // overlap with the offline app ("/mail/mu/"). |
| 783 if (!base::MatchPattern(url.path(), "/mail/mu/*") && | 777 if (!base::MatchPattern(url.path(), "/mail/mu/*") && |
| 784 base::MatchPattern(url.path(), "/mail/*") && | 778 base::MatchPattern(url.path(), "/mail/*") && |
| 785 GetExtensionForAppID(kGmailAppId) && | 779 GetExtensionForAppID(kGmailAppId, profile_) && |
| 786 GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url)) | 780 GetExtensionForAppID(kGmailAppId, profile_)->OverlapsWithOrigin(url)) |
| 787 return true; | 781 return true; |
| 788 } | 782 } |
| 789 return false; | 783 return false; |
| 790 } | 784 } |
| 791 | 785 |
| 792 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( | 786 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( |
| 793 content::WebContents* web_contents) const { | 787 content::WebContents* web_contents) const { |
| 794 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 788 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 795 if (IsIncognito(web_contents)) | 789 if (IsIncognito(web_contents)) |
| 796 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); | 790 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); |
| 797 favicon::FaviconDriver* favicon_driver = | 791 favicon::FaviconDriver* favicon_driver = |
| 798 favicon::ContentFaviconDriver::FromWebContents(web_contents); | 792 favicon::ContentFaviconDriver::FromWebContents(web_contents); |
| 799 gfx::Image result = favicon_driver->GetFavicon(); | 793 gfx::Image result = favicon_driver->GetFavicon(); |
| 800 if (result.IsEmpty()) | 794 if (result.IsEmpty()) |
| 801 return rb.GetImageNamed(IDR_DEFAULT_FAVICON); | 795 return rb.GetImageNamed(IDR_DEFAULT_FAVICON); |
| 802 return result; | 796 return result; |
| 803 } | 797 } |
| 804 | 798 |
| 805 base::string16 ChromeLauncherControllerImpl::GetAppListTitle( | 799 base::string16 ChromeLauncherControllerImpl::GetAppListTitle( |
| 806 content::WebContents* web_contents) const { | 800 content::WebContents* web_contents) const { |
| 807 base::string16 title = web_contents->GetTitle(); | 801 base::string16 title = web_contents->GetTitle(); |
| 808 if (!title.empty()) | 802 if (!title.empty()) |
| 809 return title; | 803 return title; |
| 810 WebContentsToAppIDMap::const_iterator iter = | 804 WebContentsToAppIDMap::const_iterator iter = |
| 811 web_contents_to_app_id_.find(web_contents); | 805 web_contents_to_app_id_.find(web_contents); |
| 812 if (iter != web_contents_to_app_id_.end()) { | 806 if (iter != web_contents_to_app_id_.end()) { |
| 813 std::string app_id = iter->second; | 807 std::string app_id = iter->second; |
| 814 const extensions::Extension* extension = GetExtensionForAppID(app_id); | 808 const extensions::Extension* extension = |
| 809 GetExtensionForAppID(app_id, profile_); |
| 815 if (extension) | 810 if (extension) |
| 816 return base::UTF8ToUTF16(extension->name()); | 811 return base::UTF8ToUTF16(extension->name()); |
| 817 } | 812 } |
| 818 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 813 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 819 } | 814 } |
| 820 | 815 |
| 821 BrowserShortcutLauncherItemController* | 816 BrowserShortcutLauncherItemController* |
| 822 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { | 817 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { |
| 823 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 818 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| 824 i != id_to_item_controller_map_.end(); ++i) { | 819 i != id_to_item_controller_map_.end(); ++i) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 846 } | 841 } |
| 847 } | 842 } |
| 848 | 843 |
| 849 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( | 844 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
| 850 const ash::ShelfID id) { | 845 const ash::ShelfID id) { |
| 851 if (!HasShelfIDToAppIDMapping(id)) | 846 if (!HasShelfIDToAppIDMapping(id)) |
| 852 return NULL; | 847 return NULL; |
| 853 return id_to_item_controller_map_[id]; | 848 return id_to_item_controller_map_[id]; |
| 854 } | 849 } |
| 855 | 850 |
| 856 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { | |
| 857 // If running multi user mode with separate desktops, we have to check if the | |
| 858 // browser is from the active user. | |
| 859 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != | |
| 860 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) | |
| 861 return true; | |
| 862 return multi_user_util::IsProfileFromActiveUser(browser->profile()); | |
| 863 } | |
| 864 | |
| 865 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( | 851 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
| 866 ash::Shelf* shelf, | 852 ash::Shelf* shelf, |
| 867 const std::string& user_id) const { | 853 const std::string& user_id) const { |
| 868 Profile* other_profile = multi_user_util::GetProfileFromAccountId( | 854 Profile* other_profile = multi_user_util::GetProfileFromAccountId( |
| 869 AccountId::FromUserEmail(user_id)); | 855 AccountId::FromUserEmail(user_id)); |
| 870 if (other_profile == profile_) | 856 if (other_profile == profile_) |
| 871 return false; | 857 return false; |
| 872 | 858 |
| 873 // Note: The Auto hide state from preferences is not the same as the actual | 859 // Note: The Auto hide state from preferences is not the same as the actual |
| 874 // visibility of the shelf. Depending on all the various states (full screen, | 860 // visibility of the shelf. Depending on all the various states (full screen, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 887 ash::launcher::GetShelfAlignmentPref(prefs, display) != | 873 ash::launcher::GetShelfAlignmentPref(prefs, display) != |
| 888 ash::launcher::GetShelfAlignmentPref(other_prefs, display); | 874 ash::launcher::GetShelfAlignmentPref(other_prefs, display); |
| 889 } | 875 } |
| 890 | 876 |
| 891 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( | 877 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( |
| 892 Profile* profile) { | 878 Profile* profile) { |
| 893 if (user_switch_observer_.get()) | 879 if (user_switch_observer_.get()) |
| 894 user_switch_observer_->OnUserProfileReadyToSwitch(profile); | 880 user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
| 895 } | 881 } |
| 896 | 882 |
| 897 AppListControllerDelegate::Pinnable ChromeLauncherControllerImpl::GetPinnable( | |
| 898 const std::string& app_id) { | |
| 899 const base::ListValue* pref = | |
| 900 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); | |
| 901 if (!pref) | |
| 902 return AppListControllerDelegate::PIN_EDITABLE; | |
| 903 | |
| 904 // Pinned ARC apps policy defines the package name of the apps, that must | |
| 905 // be pinned. All the launch activities of any package in policy are pinned. | |
| 906 // In turn the input parameter to this function is app_id, which | |
| 907 // is 32 chars hash. In case of ARC app this is a hash of | |
| 908 // (package name + activity). This means that we must identify the package | |
| 909 // from the hash, and check if this package is pinned by policy. | |
| 910 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(GetProfile()); | |
| 911 std::string arc_app_packege_name; | |
| 912 if (arc_prefs) { | |
| 913 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | |
| 914 arc_prefs->GetApp(app_id); | |
| 915 if (app_info) | |
| 916 arc_app_packege_name = app_info->package_name; | |
| 917 } | |
| 918 | |
| 919 for (size_t index = 0; index < pref->GetSize(); ++index) { | |
| 920 const base::DictionaryValue* app = nullptr; | |
| 921 std::string app_id_or_package; | |
| 922 if (pref->GetDictionary(index, &app) && | |
| 923 app->GetString(ash::launcher::kPinnedAppsPrefAppIDPath, | |
| 924 &app_id_or_package) && | |
| 925 (app_id == app_id_or_package || | |
| 926 arc_app_packege_name == app_id_or_package)) { | |
| 927 return AppListControllerDelegate::PIN_FIXED; | |
| 928 } | |
| 929 } | |
| 930 return AppListControllerDelegate::PIN_EDITABLE; | |
| 931 } | |
| 932 | |
| 933 ArcAppDeferredLauncherController* | 883 ArcAppDeferredLauncherController* |
| 934 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { | 884 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { |
| 935 return arc_deferred_launcher_.get(); | 885 return arc_deferred_launcher_.get(); |
| 936 } | 886 } |
| 937 | 887 |
| 938 /////////////////////////////////////////////////////////////////////////////// | 888 /////////////////////////////////////////////////////////////////////////////// |
| 939 // ash::ShelfDelegate: | 889 // ash::ShelfDelegate: |
| 940 | 890 |
| 941 void ChromeLauncherControllerImpl::OnShelfCreated(ash::Shelf* shelf) { | 891 void ChromeLauncherControllerImpl::OnShelfCreated(ash::Shelf* shelf) { |
| 942 PrefService* prefs = profile_->GetPrefs(); | 892 PrefService* prefs = profile_->GetPrefs(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 id_to_item_controller_map_.end(); | 938 id_to_item_controller_map_.end(); |
| 989 } | 939 } |
| 990 | 940 |
| 991 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( | 941 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( |
| 992 ash::ShelfID id) { | 942 ash::ShelfID id) { |
| 993 LauncherItemController* controller = GetLauncherItemController(id); | 943 LauncherItemController* controller = GetLauncherItemController(id); |
| 994 return controller ? controller->app_id() : base::EmptyString(); | 944 return controller ? controller->app_id() : base::EmptyString(); |
| 995 } | 945 } |
| 996 | 946 |
| 997 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { | 947 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { |
| 998 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) | 948 if (GetPinnableForAppID(app_id, profile_) == |
| 949 AppListControllerDelegate::PIN_EDITABLE) |
| 999 DoPinAppWithID(app_id); | 950 DoPinAppWithID(app_id); |
| 1000 else | 951 else |
| 1001 NOTREACHED(); | 952 NOTREACHED(); |
| 1002 } | 953 } |
| 1003 | 954 |
| 1004 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { | 955 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { |
| 1005 for (IDToItemControllerMap::const_iterator i = | 956 for (IDToItemControllerMap::const_iterator i = |
| 1006 id_to_item_controller_map_.begin(); | 957 id_to_item_controller_map_.begin(); |
| 1007 i != id_to_item_controller_map_.end(); ++i) { | 958 i != id_to_item_controller_map_.end(); ++i) { |
| 1008 if (IsPinned(i->first) && i->second->app_id() == app_id) | 959 if (IsPinned(i->first) && i->second->app_id() == app_id) |
| 1009 return true; | 960 return true; |
| 1010 } | 961 } |
| 1011 return false; | 962 return false; |
| 1012 } | 963 } |
| 1013 | 964 |
| 1014 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { | 965 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
| 1015 if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) | 966 if (GetPinnableForAppID(app_id, profile_) == |
| 967 AppListControllerDelegate::PIN_EDITABLE) |
| 1016 DoUnpinAppWithID(app_id); | 968 DoUnpinAppWithID(app_id); |
| 1017 else | 969 else |
| 1018 NOTREACHED(); | 970 NOTREACHED(); |
| 1019 } | 971 } |
| 1020 | 972 |
| 1021 /////////////////////////////////////////////////////////////////////////////// | 973 /////////////////////////////////////////////////////////////////////////////// |
| 1022 // LauncherAppUpdater::Delegate: | 974 // LauncherAppUpdater::Delegate: |
| 1023 | 975 |
| 1024 void ChromeLauncherControllerImpl::OnAppInstalled( | 976 void ChromeLauncherControllerImpl::OnAppInstalled( |
| 1025 content::BrowserContext* browser_context, | 977 content::BrowserContext* browser_context, |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 if (index == -1) | 1720 if (index == -1) |
| 1769 continue; | 1721 continue; |
| 1770 ash::ShelfItem item = model_->items()[index]; | 1722 ash::ShelfItem item = model_->items()[index]; |
| 1771 item.image = image; | 1723 item.image = image; |
| 1772 if (arc_deferred_launcher_) | 1724 if (arc_deferred_launcher_) |
| 1773 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1725 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1774 model_->Set(index, item); | 1726 model_->Set(index, item); |
| 1775 // It's possible we're waiting on more than one item, so don't break. | 1727 // It's possible we're waiting on more than one item, so don't break. |
| 1776 } | 1728 } |
| 1777 } | 1729 } |
| OLD | NEW |