| 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.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/browser/extensions/extension_app_icon_loader.h" | 30 #include "chrome/browser/extensions/extension_app_icon_loader.h" |
| 31 #include "chrome/browser/extensions/extension_util.h" | 31 #include "chrome/browser/extensions/extension_util.h" |
| 32 #include "chrome/browser/extensions/launch_util.h" | 32 #include "chrome/browser/extensions/launch_util.h" |
| 33 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 33 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 34 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 34 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/profiles/profile_manager.h" | 36 #include "chrome/browser/profiles/profile_manager.h" |
| 37 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 37 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
| 38 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 38 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 39 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 39 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
| 40 #include "chrome/browser/ui/ash/launcher/app_tab_helper.h" |
| 40 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 41 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 41 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 42 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| 42 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 43 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 43 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 44 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 45 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 45 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 46 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
| 46 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 47 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 47 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | 48 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
| 48 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" | 49 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" |
| 49 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" | 50 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 using extensions::Extension; | 111 using extensions::Extension; |
| 111 using extensions::UnloadedExtensionInfo; | 112 using extensions::UnloadedExtensionInfo; |
| 112 using extension_misc::kGmailAppId; | 113 using extension_misc::kGmailAppId; |
| 113 using content::WebContents; | 114 using content::WebContents; |
| 114 | 115 |
| 115 // static | 116 // static |
| 116 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; | 117 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; |
| 117 | 118 |
| 118 namespace { | 119 namespace { |
| 119 | 120 |
| 120 // This will be used as placeholder in the list of the pinned applciatons. | |
| 121 // Note that this is NOT a valid extension identifier so that pre M31 versions | |
| 122 // will ignore it. | |
| 123 const char kAppShelfIdPlaceholder[] = "AppShelfIDPlaceholder--------"; | |
| 124 | |
| 125 int64_t GetDisplayIDForShelf(ash::Shelf* shelf) { | 121 int64_t GetDisplayIDForShelf(ash::Shelf* shelf) { |
| 126 aura::Window* root_window = | 122 aura::Window* root_window = |
| 127 shelf->shelf_widget()->GetNativeWindow()->GetRootWindow(); | 123 shelf->shelf_widget()->GetNativeWindow()->GetRootWindow(); |
| 128 gfx::Display display = | 124 gfx::Display display = |
| 129 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_window); | 125 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_window); |
| 130 DCHECK(display.is_valid()); | 126 DCHECK(display.is_valid()); |
| 131 return display.id(); | 127 return display.id(); |
| 132 } | 128 } |
| 133 | 129 |
| 134 // If prefs have synced and no user-set value exists at |local_path|, the value | 130 // If prefs have synced and no user-set value exists at |local_path|, the value |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // Only pinned by policy, which is not part of user-pinned | 192 // Only pinned by policy, which is not part of user-pinned |
| 197 if (app_id == app_id_) | 193 if (app_id == app_id_) |
| 198 return false; | 194 return false; |
| 199 } | 195 } |
| 200 } | 196 } |
| 201 } | 197 } |
| 202 // Default, user added new pins | 198 // Default, user added new pins |
| 203 return true; | 199 return true; |
| 204 } | 200 } |
| 205 | 201 |
| 206 void update_pinned_apps(const std::string& app_id, | |
| 207 bool valid_for_current_user, | |
| 208 std::vector<std::string>* pinned_apps, | |
| 209 bool* chrome_icon_added, | |
| 210 bool* app_list_icon_added) { | |
| 211 if (app_id == extension_misc::kChromeAppId) { | |
| 212 *chrome_icon_added = true; | |
| 213 pinned_apps->push_back(extension_misc::kChromeAppId); | |
| 214 } else if (app_id == kAppShelfIdPlaceholder) { | |
| 215 *app_list_icon_added = true; | |
| 216 pinned_apps->push_back(kAppShelfIdPlaceholder); | |
| 217 } else if (valid_for_current_user) { | |
| 218 // Note: In multi profile scenarios we only want to show pinnable apps | |
| 219 // here which is correct. Running applications from the other users will | |
| 220 // continue to run. So no need for multi profile modifications. | |
| 221 pinned_apps->push_back(app_id); | |
| 222 } | |
| 223 } | |
| 224 | |
| 225 } // namespace | 202 } // namespace |
| 226 | 203 |
| 227 #if defined(OS_CHROMEOS) | 204 #if defined(OS_CHROMEOS) |
| 228 // A class to get events from ChromeOS when a user gets changed or added. | 205 // A class to get events from ChromeOS when a user gets changed or added. |
| 229 class ChromeLauncherControllerUserSwitchObserver | 206 class ChromeLauncherControllerUserSwitchObserver |
| 230 : public user_manager::UserManager::UserSessionStateObserver { | 207 : public user_manager::UserManager::UserSessionStateObserver { |
| 231 public: | 208 public: |
| 232 ChromeLauncherControllerUserSwitchObserver( | 209 ChromeLauncherControllerUserSwitchObserver( |
| 233 ChromeLauncherController* controller) | 210 ChromeLauncherController* controller) |
| 234 : controller_(controller) { | 211 : controller_(controller) { |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 if (!IsAppForUserPinned(controller->app_id(), | 849 if (!IsAppForUserPinned(controller->app_id(), |
| 873 pinned_apps_pref.get(), | 850 pinned_apps_pref.get(), |
| 874 policy_pinned_apps_pref)) | 851 policy_pinned_apps_pref)) |
| 875 app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true); | 852 app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true); |
| 876 updater->Append(app_value); | 853 updater->Append(app_value); |
| 877 } | 854 } |
| 878 } | 855 } |
| 879 } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) { | 856 } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) { |
| 880 PersistChromeItemIndex(i); | 857 PersistChromeItemIndex(i); |
| 881 } else if (model_->items()[i].type == ash::TYPE_APP_LIST) { | 858 } else if (model_->items()[i].type == ash::TYPE_APP_LIST) { |
| 882 base::DictionaryValue* app_value = ash::CreateAppDict( | 859 base::DictionaryValue* app_value = |
| 883 kAppShelfIdPlaceholder); | 860 ash::CreateAppDict(ash::kPinnedAppsPlaceholder); |
| 884 if (app_value) | 861 if (app_value) |
| 885 updater->Append(app_value); | 862 updater->Append(app_value); |
| 886 } | 863 } |
| 887 } | 864 } |
| 888 } | 865 } |
| 889 pref_change_registrar_.Add( | 866 pref_change_registrar_.Add( |
| 890 prefs::kPinnedLauncherApps, | 867 prefs::kPinnedLauncherApps, |
| 891 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, | 868 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, |
| 892 base::Unretained(this))); | 869 base::Unretained(this))); |
| 893 } | 870 } |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 | 1473 |
| 1497 void ChromeLauncherController::UpdateAppLaunchersFromPref() { | 1474 void ChromeLauncherController::UpdateAppLaunchersFromPref() { |
| 1498 // There are various functions which will trigger a |PersistPinnedState| call | 1475 // There are various functions which will trigger a |PersistPinnedState| call |
| 1499 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu | 1476 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu |
| 1500 // model which will use weights to re-arrange the icons to new positions. | 1477 // model which will use weights to re-arrange the icons to new positions. |
| 1501 // Since this function is meant to synchronize the "is state" with the | 1478 // Since this function is meant to synchronize the "is state" with the |
| 1502 // "sync state", it makes no sense to store any changes by this function back | 1479 // "sync state", it makes no sense to store any changes by this function back |
| 1503 // into the pref state. Therefore we tell |persistPinnedState| to ignore any | 1480 // into the pref state. Therefore we tell |persistPinnedState| to ignore any |
| 1504 // invocations while we are running. | 1481 // invocations while we are running. |
| 1505 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1482 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
| 1506 std::vector<std::string> pinned_apps = GetListOfPinnedAppsAndBrowser(); | 1483 std::vector<std::string> pinned_apps = |
| 1484 ash::GetPinnedAppsFromPrefs(profile_->GetPrefs(), app_tab_helper_.get()); |
| 1507 | 1485 |
| 1508 int index = 0; | 1486 int index = 0; |
| 1509 int max_index = model_->item_count(); | 1487 int max_index = model_->item_count(); |
| 1510 | 1488 |
| 1511 // When one of the two special items cannot be moved (and we do not know where | 1489 // When one of the two special items cannot be moved (and we do not know where |
| 1512 // yet), we remember the current location in one of these variables. | 1490 // yet), we remember the current location in one of these variables. |
| 1513 int chrome_index = -1; | 1491 int chrome_index = -1; |
| 1514 int app_list_index = -1; | 1492 int app_list_index = -1; |
| 1515 | 1493 |
| 1516 // Walk the model and |pinned_apps| from the pref lockstep, adding and | 1494 // Walk the model and |pinned_apps| from the pref lockstep, adding and |
| 1517 // removing items as necessary. NB: This code uses plain old indexing instead | 1495 // removing items as necessary. NB: This code uses plain old indexing instead |
| 1518 // of iterators because of model mutations as part of the loop. | 1496 // of iterators because of model mutations as part of the loop. |
| 1519 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); | 1497 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); |
| 1520 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { | 1498 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { |
| 1521 // Check if we have an item which we need to handle. | 1499 // Check if we have an item which we need to handle. |
| 1522 if (*pref_app_id == extension_misc::kChromeAppId || | 1500 if (*pref_app_id == extension_misc::kChromeAppId || |
| 1523 *pref_app_id == kAppShelfIdPlaceholder || | 1501 *pref_app_id == ash::kPinnedAppsPlaceholder || |
| 1524 IsAppPinned(*pref_app_id)) { | 1502 IsAppPinned(*pref_app_id)) { |
| 1525 for (; index < max_index; ++index) { | 1503 for (; index < max_index; ++index) { |
| 1526 const ash::ShelfItem& item(model_->items()[index]); | 1504 const ash::ShelfItem& item(model_->items()[index]); |
| 1527 bool is_app_list = item.type == ash::TYPE_APP_LIST; | 1505 bool is_app_list = item.type == ash::TYPE_APP_LIST; |
| 1528 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; | 1506 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; |
| 1529 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) | 1507 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) |
| 1530 continue; | 1508 continue; |
| 1531 LauncherItemController* controller = GetLauncherItemController(item.id); | 1509 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1532 if ((kAppShelfIdPlaceholder == *pref_app_id && is_app_list) || | 1510 if ((ash::kPinnedAppsPlaceholder == *pref_app_id && is_app_list) || |
| 1533 (extension_misc::kChromeAppId == *pref_app_id && is_chrome) || | 1511 (extension_misc::kChromeAppId == *pref_app_id && is_chrome) || |
| 1534 (controller && controller->app_id() == *pref_app_id)) { | 1512 (controller && controller->app_id() == *pref_app_id)) { |
| 1535 // Check if an item needs to be moved here. | 1513 // Check if an item needs to be moved here. |
| 1536 MoveChromeOrApplistToFinalPosition( | 1514 MoveChromeOrApplistToFinalPosition( |
| 1537 is_chrome, is_app_list, index, &chrome_index, &app_list_index); | 1515 is_chrome, is_app_list, index, &chrome_index, &app_list_index); |
| 1538 ++pref_app_id; | 1516 ++pref_app_id; |
| 1539 break; | 1517 break; |
| 1540 } else { | 1518 } else { |
| 1541 if (is_chrome || is_app_list) { | 1519 if (is_chrome || is_app_list) { |
| 1542 // We cannot delete any of these shortcuts. As such we remember | 1520 // We cannot delete any of these shortcuts. As such we remember |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 else if (item.type == ash::TYPE_APP_LIST) | 1586 else if (item.type == ash::TYPE_APP_LIST) |
| 1609 app_list_index = index; | 1587 app_list_index = index; |
| 1610 ++index; | 1588 ++index; |
| 1611 } | 1589 } |
| 1612 } | 1590 } |
| 1613 | 1591 |
| 1614 // Append unprocessed items from the pref to the end of the model. | 1592 // Append unprocessed items from the pref to the end of the model. |
| 1615 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { | 1593 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { |
| 1616 // All items but the chrome and / or app list shortcut needs to be added. | 1594 // All items but the chrome and / or app list shortcut needs to be added. |
| 1617 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; | 1595 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; |
| 1618 bool is_app_list = *pref_app_id == kAppShelfIdPlaceholder; | 1596 bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder; |
| 1619 // Coming here we know the next item which can be finalized, either the | 1597 // Coming here we know the next item which can be finalized, either the |
| 1620 // chrome item or the app launcher. The final position is the end of the | 1598 // chrome item or the app launcher. The final position is the end of the |
| 1621 // list. The menu model will make sure that the item is grouped according | 1599 // list. The menu model will make sure that the item is grouped according |
| 1622 // to its weight (which we do not know here). | 1600 // to its weight (which we do not know here). |
| 1623 if (!is_chrome && !is_app_list) { | 1601 if (!is_chrome && !is_app_list) { |
| 1624 DoPinAppWithID(*pref_app_id); | 1602 DoPinAppWithID(*pref_app_id); |
| 1625 int target_index = FindInsertionPoint(false); | 1603 int target_index = FindInsertionPoint(false); |
| 1626 ash::ShelfID id = GetShelfIDForAppID(*pref_app_id); | 1604 ash::ShelfID id = GetShelfIDForAppID(*pref_app_id); |
| 1627 int source_index = model_->ItemIndexByID(id); | 1605 int source_index = model_->ItemIndexByID(id); |
| 1628 if (source_index != target_index) | 1606 if (source_index != target_index) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 id_to_item_controller_map_[id]->set_shelf_id(id); | 1761 id_to_item_controller_map_[id]->set_shelf_id(id); |
| 1784 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. | 1762 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. |
| 1785 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); | 1763 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); |
| 1786 return id; | 1764 return id; |
| 1787 } | 1765 } |
| 1788 | 1766 |
| 1789 void ChromeLauncherController::PersistChromeItemIndex(int index) { | 1767 void ChromeLauncherController::PersistChromeItemIndex(int index) { |
| 1790 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); | 1768 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); |
| 1791 } | 1769 } |
| 1792 | 1770 |
| 1793 int ChromeLauncherController::GetChromeIconIndexFromPref() const { | |
| 1794 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); | |
| 1795 const base::ListValue* pinned_apps_pref = | |
| 1796 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); | |
| 1797 return std::max(static_cast<size_t>(0), | |
| 1798 std::min(pinned_apps_pref->GetSize(), index)); | |
| 1799 } | |
| 1800 | |
| 1801 void ChromeLauncherController::MoveChromeOrApplistToFinalPosition( | 1771 void ChromeLauncherController::MoveChromeOrApplistToFinalPosition( |
| 1802 bool is_chrome, | 1772 bool is_chrome, |
| 1803 bool is_app_list, | 1773 bool is_app_list, |
| 1804 int target_index, | 1774 int target_index, |
| 1805 int* chrome_index, | 1775 int* chrome_index, |
| 1806 int* app_list_index) { | 1776 int* app_list_index) { |
| 1807 if (is_chrome && *chrome_index != -1) { | 1777 if (is_chrome && *chrome_index != -1) { |
| 1808 model_->Move(*chrome_index, target_index); | 1778 model_->Move(*chrome_index, target_index); |
| 1809 if (*app_list_index != -1 && | 1779 if (*app_list_index != -1 && |
| 1810 *chrome_index < *app_list_index && | 1780 *chrome_index < *app_list_index && |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1836 type == ash::TYPE_BROWSER_SHORTCUT) { | 1806 type == ash::TYPE_BROWSER_SHORTCUT) { |
| 1837 return i; | 1807 return i; |
| 1838 } | 1808 } |
| 1839 } | 1809 } |
| 1840 return 0; | 1810 return 0; |
| 1841 } | 1811 } |
| 1842 | 1812 |
| 1843 int ChromeLauncherController::GetChromeIconIndexForCreation() { | 1813 int ChromeLauncherController::GetChromeIconIndexForCreation() { |
| 1844 // We get the list of pinned apps as they currently would get pinned. | 1814 // We get the list of pinned apps as they currently would get pinned. |
| 1845 // Within this list the chrome icon will be the correct location. | 1815 // Within this list the chrome icon will be the correct location. |
| 1846 std::vector<std::string> pinned_apps = GetListOfPinnedAppsAndBrowser(); | 1816 std::vector<std::string> pinned_apps = |
| 1817 ash::GetPinnedAppsFromPrefs(profile_->GetPrefs(), app_tab_helper_.get()); |
| 1847 | 1818 |
| 1848 std::vector<std::string>::iterator it = | 1819 std::vector<std::string>::iterator it = |
| 1849 std::find(pinned_apps.begin(), | 1820 std::find(pinned_apps.begin(), |
| 1850 pinned_apps.end(), | 1821 pinned_apps.end(), |
| 1851 std::string(extension_misc::kChromeAppId)); | 1822 std::string(extension_misc::kChromeAppId)); |
| 1852 DCHECK(it != pinned_apps.end()); | 1823 DCHECK(it != pinned_apps.end()); |
| 1853 int index = it - pinned_apps.begin(); | 1824 int index = it - pinned_apps.begin(); |
| 1854 | 1825 |
| 1855 // We should do here a comparison between the is state and the "want to be" | 1826 // We should do here a comparison between the is state and the "want to be" |
| 1856 // state since some apps might be able to pin but are not yet. Instead - for | 1827 // state since some apps might be able to pin but are not yet. Instead - for |
| 1857 // the time being we clamp against the amount of known items and wait for the | 1828 // the time being we clamp against the amount of known items and wait for the |
| 1858 // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since | 1829 // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since |
| 1859 // the pinning will be done then. | 1830 // the pinning will be done then. |
| 1860 return std::min(model_->item_count(), index); | 1831 return std::min(model_->item_count(), index); |
| 1861 } | 1832 } |
| 1862 | 1833 |
| 1863 std::vector<std::string> | |
| 1864 ChromeLauncherController::GetListOfPinnedAppsAndBrowser() { | |
| 1865 // Adding the app list item to the list of items requires that the ID is not | |
| 1866 // a valid and known ID for the extension system. The ID was constructed that | |
| 1867 // way - but just to make sure... | |
| 1868 DCHECK(!app_tab_helper_->IsValidIDForCurrentUser(kAppShelfIdPlaceholder)); | |
| 1869 | |
| 1870 std::vector<std::string> pinned_apps; | |
| 1871 | |
| 1872 // Get the new incarnation of the list. | |
| 1873 const base::ListValue* pinned_apps_pref = | |
| 1874 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); | |
| 1875 | |
| 1876 const base::ListValue* policy_pinned_apps_pref = | |
| 1877 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); | |
| 1878 | |
| 1879 // Keep track of the addition of the chrome and the app list icon. | |
| 1880 bool chrome_icon_added = false; | |
| 1881 bool app_list_icon_added = false; | |
| 1882 size_t chrome_icon_index = GetChromeIconIndexFromPref(); | |
| 1883 | |
| 1884 // See if the chrome string is already in the pinned list and remove it if | |
| 1885 // needed. | |
| 1886 base::Value* chrome_app = ash::CreateAppDict(extension_misc::kChromeAppId); | |
| 1887 if (chrome_app) { | |
| 1888 chrome_icon_added = pinned_apps_pref->Find(*chrome_app) != | |
| 1889 pinned_apps_pref->end(); | |
| 1890 delete chrome_app; | |
| 1891 } | |
| 1892 | |
| 1893 if (policy_pinned_apps_pref) { | |
| 1894 for (size_t index = 0; index < policy_pinned_apps_pref->GetSize(); | |
| 1895 ++index) { | |
| 1896 const base::DictionaryValue* app = NULL; | |
| 1897 std::string app_id; | |
| 1898 if (policy_pinned_apps_pref->GetDictionary(index, &app) && | |
| 1899 app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) && | |
| 1900 (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == | |
| 1901 pinned_apps.end())) | |
| 1902 update_pinned_apps( | |
| 1903 app_id, app_tab_helper_->IsValidIDForCurrentUser(app_id), | |
| 1904 &pinned_apps, &chrome_icon_added, &app_list_icon_added); | |
| 1905 } | |
| 1906 } | |
| 1907 | |
| 1908 for (size_t index = 0; index < pinned_apps_pref->GetSize(); ++index) { | |
| 1909 // We need to position the chrome icon relative to it's place in the pinned | |
| 1910 // preference list - even if an item of that list isn't shown yet. | |
| 1911 if (index == chrome_icon_index && !chrome_icon_added) { | |
| 1912 pinned_apps.push_back(extension_misc::kChromeAppId); | |
| 1913 chrome_icon_added = true; | |
| 1914 } | |
| 1915 const base::DictionaryValue* app = NULL; | |
| 1916 std::string app_id; | |
| 1917 if (pinned_apps_pref->GetDictionary(index, &app) && | |
| 1918 app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) && | |
| 1919 (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == | |
| 1920 pinned_apps.end())) { | |
| 1921 bool pinned_by_policy; | |
| 1922 if (app->GetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, | |
| 1923 &pinned_by_policy) && | |
| 1924 pinned_by_policy) { | |
| 1925 continue; | |
| 1926 } | |
| 1927 update_pinned_apps( | |
| 1928 app_id, app_tab_helper_->IsValidIDForCurrentUser(app_id), | |
| 1929 &pinned_apps, &chrome_icon_added, &app_list_icon_added); | |
| 1930 } | |
| 1931 } | |
| 1932 | |
| 1933 // If not added yet, the chrome item will be the last item in the list. | |
| 1934 if (!chrome_icon_added) | |
| 1935 pinned_apps.push_back(extension_misc::kChromeAppId); | |
| 1936 | |
| 1937 // If not added yet, add the app list item either at the end or at the | |
| 1938 // beginning - depending on the shelf layout. | |
| 1939 if (!app_list_icon_added) { | |
| 1940 pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder); | |
| 1941 } | |
| 1942 return pinned_apps; | |
| 1943 } | |
| 1944 | |
| 1945 bool ChromeLauncherController::IsIncognito( | 1834 bool ChromeLauncherController::IsIncognito( |
| 1946 const content::WebContents* web_contents) const { | 1835 const content::WebContents* web_contents) const { |
| 1947 const Profile* profile = | 1836 const Profile* profile = |
| 1948 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1837 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 1949 return profile->IsOffTheRecord() && !profile->IsGuestSession() && | 1838 return profile->IsOffTheRecord() && !profile->IsGuestSession() && |
| 1950 !profile->IsSystemProfile(); | 1839 !profile->IsSystemProfile(); |
| 1951 } | 1840 } |
| 1952 | 1841 |
| 1953 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension( | 1842 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension( |
| 1954 const std::string& app_id, | 1843 const std::string& app_id, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 | 1877 |
| 1989 void ChromeLauncherController::AttachProfile(Profile* profile) { | 1878 void ChromeLauncherController::AttachProfile(Profile* profile) { |
| 1990 profile_ = profile; | 1879 profile_ = profile; |
| 1991 // Either add the profile to the list of known profiles and make it the active | 1880 // Either add the profile to the list of known profiles and make it the active |
| 1992 // one for some functions of AppTabHelper or create a new one. | 1881 // one for some functions of AppTabHelper or create a new one. |
| 1993 if (!app_tab_helper_.get()) | 1882 if (!app_tab_helper_.get()) |
| 1994 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); | 1883 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); |
| 1995 else | 1884 else |
| 1996 app_tab_helper_->SetCurrentUser(profile_); | 1885 app_tab_helper_->SetCurrentUser(profile_); |
| 1997 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded | 1886 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded |
| 1998 // image is associated with a profile (it's loader requires the profile). | 1887 // image is associated with a profile (its loader requires the profile). |
| 1999 // Since icon size changes are possible, the icon could be requested to be | 1888 // Since icon size changes are possible, the icon could be requested to be |
| 2000 // reloaded. However - having it not multi profile aware would cause problems | 1889 // reloaded. However - having it not multi profile aware would cause problems |
| 2001 // if the icon cache gets deleted upon user switch. | 1890 // if the icon cache gets deleted upon user switch. |
| 2002 std::unique_ptr<AppIconLoader> extension_app_icon_loader( | 1891 std::unique_ptr<AppIconLoader> extension_app_icon_loader( |
| 2003 new extensions::ExtensionAppIconLoader( | 1892 new extensions::ExtensionAppIconLoader( |
| 2004 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); | 1893 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); |
| 2005 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); | 1894 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); |
| 2006 | 1895 |
| 2007 #if defined(OS_CHROMEOS) | 1896 #if defined(OS_CHROMEOS) |
| 2008 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( | 1897 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2063 | 1952 |
| 2064 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | 1953 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( |
| 2065 const std::string& app_id) { | 1954 const std::string& app_id) { |
| 2066 for (const auto& app_icon_loader : app_icon_loaders_) { | 1955 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 2067 if (app_icon_loader->CanLoadImageForApp(app_id)) | 1956 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 2068 return app_icon_loader.get(); | 1957 return app_icon_loader.get(); |
| 2069 } | 1958 } |
| 2070 | 1959 |
| 2071 return nullptr; | 1960 return nullptr; |
| 2072 } | 1961 } |
| OLD | NEW |