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