| 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 27 matching lines...) Expand all Loading... |
| 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_window_launcher_controller.h" | 40 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
| 41 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 41 #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" | 42 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 43 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 43 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
| 44 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.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_browser.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_tab.h" | 46 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 47 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | 47 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
| 48 #include "chrome/browser/ui/ash/launcher/launcher_app_tab_helper.h" | 48 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 49 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" | 49 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" |
| 50 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 50 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 51 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 51 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 52 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 52 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 53 #include "chrome/browser/ui/browser.h" | 53 #include "chrome/browser/ui/browser.h" |
| 54 #include "chrome/browser/ui/browser_commands.h" | 54 #include "chrome/browser/ui/browser_commands.h" |
| 55 #include "chrome/browser/ui/browser_finder.h" | 55 #include "chrome/browser/ui/browser_finder.h" |
| 56 #include "chrome/browser/ui/browser_list.h" | 56 #include "chrome/browser/ui/browser_list.h" |
| 57 #include "chrome/browser/ui/browser_tabstrip.h" | 57 #include "chrome/browser/ui/browser_tabstrip.h" |
| 58 #include "chrome/browser/ui/browser_window.h" | 58 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 using extensions::Extension; | 110 using extensions::Extension; |
| 111 using extensions::UnloadedExtensionInfo; | 111 using extensions::UnloadedExtensionInfo; |
| 112 using extension_misc::kGmailAppId; | 112 using extension_misc::kGmailAppId; |
| 113 using content::WebContents; | 113 using content::WebContents; |
| 114 | 114 |
| 115 // static | 115 // static |
| 116 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; | 116 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; |
| 117 | 117 |
| 118 namespace { | 118 namespace { |
| 119 | 119 |
| 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) { | 120 int64_t GetDisplayIDForShelf(ash::Shelf* shelf) { |
| 126 aura::Window* root_window = | 121 aura::Window* root_window = |
| 127 shelf->shelf_widget()->GetNativeWindow()->GetRootWindow(); | 122 shelf->shelf_widget()->GetNativeWindow()->GetRootWindow(); |
| 128 display::Display display = | 123 display::Display display = |
| 129 display::Screen::GetScreen()->GetDisplayNearestWindow(root_window); | 124 display::Screen::GetScreen()->GetDisplayNearestWindow(root_window); |
| 130 DCHECK(display.is_valid()); | 125 DCHECK(display.is_valid()); |
| 131 return display.id(); | 126 return display.id(); |
| 132 } | 127 } |
| 133 | 128 |
| 134 // If prefs have synced and no user-set value exists at |local_path|, the value | 129 // 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 | 191 // Only pinned by policy, which is not part of user-pinned |
| 197 if (app_id == app_id_) | 192 if (app_id == app_id_) |
| 198 return false; | 193 return false; |
| 199 } | 194 } |
| 200 } | 195 } |
| 201 } | 196 } |
| 202 // Default, user added new pins | 197 // Default, user added new pins |
| 203 return true; | 198 return true; |
| 204 } | 199 } |
| 205 | 200 |
| 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 const char* const kPinProhibitedExtensionIds[] = { | 201 const char* const kPinProhibitedExtensionIds[] = { |
| 226 #if defined(OS_CHROMEOS) | 202 #if defined(OS_CHROMEOS) |
| 227 "cnbgggchhmkkdmeppjobngjoejnihlei", // Arc Support | 203 "cnbgggchhmkkdmeppjobngjoejnihlei", // Arc Support |
| 228 #endif | 204 #endif |
| 229 }; | 205 }; |
| 230 | 206 |
| 231 const size_t kPinProhibitedExtensionIdsLength = | 207 const size_t kPinProhibitedExtensionIdsLength = |
| 232 arraysize(kPinProhibitedExtensionIds); | 208 arraysize(kPinProhibitedExtensionIds); |
| 233 | 209 |
| 234 } // namespace | 210 } // namespace |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 if (!IsAppForUserPinned(controller->app_id(), | 863 if (!IsAppForUserPinned(controller->app_id(), |
| 888 pinned_apps_pref.get(), | 864 pinned_apps_pref.get(), |
| 889 policy_pinned_apps_pref)) | 865 policy_pinned_apps_pref)) |
| 890 app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true); | 866 app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true); |
| 891 updater->Append(app_value); | 867 updater->Append(app_value); |
| 892 } | 868 } |
| 893 } | 869 } |
| 894 } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) { | 870 } else if (model_->items()[i].type == ash::TYPE_BROWSER_SHORTCUT) { |
| 895 PersistChromeItemIndex(i); | 871 PersistChromeItemIndex(i); |
| 896 } else if (model_->items()[i].type == ash::TYPE_APP_LIST) { | 872 } else if (model_->items()[i].type == ash::TYPE_APP_LIST) { |
| 897 base::DictionaryValue* app_value = ash::CreateAppDict( | 873 base::DictionaryValue* app_value = |
| 898 kAppShelfIdPlaceholder); | 874 ash::CreateAppDict(ash::kPinnedAppsPlaceholder); |
| 899 if (app_value) | 875 if (app_value) |
| 900 updater->Append(app_value); | 876 updater->Append(app_value); |
| 901 } | 877 } |
| 902 } | 878 } |
| 903 } | 879 } |
| 904 pref_change_registrar_.Add( | 880 pref_change_registrar_.Add( |
| 905 prefs::kPinnedLauncherApps, | 881 prefs::kPinnedLauncherApps, |
| 906 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, | 882 base::Bind(&ChromeLauncherController::UpdateAppLaunchersFromPref, |
| 907 base::Unretained(this))); | 883 base::Unretained(this))); |
| 908 } | 884 } |
| 909 | 885 |
| 910 ash::ShelfModel* ChromeLauncherController::model() { | 886 ash::ShelfModel* ChromeLauncherController::model() { |
| 911 return model_; | 887 return model_; |
| 912 } | 888 } |
| 913 | 889 |
| 914 Profile* ChromeLauncherController::profile() { | 890 Profile* ChromeLauncherController::profile() { |
| 915 return profile_; | 891 return profile_; |
| 916 } | 892 } |
| 917 | 893 |
| 918 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, | 894 void ChromeLauncherController::UpdateAppState(content::WebContents* contents, |
| 919 AppState app_state) { | 895 AppState app_state) { |
| 920 std::string app_id = app_tab_helper_->GetAppID(contents); | 896 std::string app_id = launcher_controller_helper_->GetAppID(contents); |
| 921 | 897 |
| 922 // Check if the gMail app is loaded and it matches the given content. | 898 // Check if the gMail app is loaded and it matches the given content. |
| 923 // This special treatment is needed to address crbug.com/234268. | 899 // This special treatment is needed to address crbug.com/234268. |
| 924 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 900 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
| 925 app_id = kGmailAppId; | 901 app_id = kGmailAppId; |
| 926 | 902 |
| 927 // Check the old |app_id| for a tab. If the contents has changed we need to | 903 // Check the old |app_id| for a tab. If the contents has changed we need to |
| 928 // remove it from the previous app. | 904 // remove it from the previous app. |
| 929 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { | 905 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { |
| 930 std::string last_app_id = web_contents_to_app_id_[contents]; | 906 std::string last_app_id = web_contents_to_app_id_[contents]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 949 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || | 925 SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || |
| 950 app_state == APP_STATE_ACTIVE) ? ash::STATUS_ACTIVE : | 926 app_state == APP_STATE_ACTIVE) ? ash::STATUS_ACTIVE : |
| 951 GetAppState(app_id)); | 927 GetAppState(app_id)); |
| 952 } | 928 } |
| 953 } | 929 } |
| 954 | 930 |
| 955 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents( | 931 ash::ShelfID ChromeLauncherController::GetShelfIDForWebContents( |
| 956 content::WebContents* contents) { | 932 content::WebContents* contents) { |
| 957 DCHECK(contents); | 933 DCHECK(contents); |
| 958 | 934 |
| 959 std::string app_id = app_tab_helper_->GetAppID(contents); | 935 std::string app_id = launcher_controller_helper_->GetAppID(contents); |
| 960 | 936 |
| 961 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 937 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
| 962 app_id = kGmailAppId; | 938 app_id = kGmailAppId; |
| 963 | 939 |
| 964 ash::ShelfID id = GetShelfIDForAppID(app_id); | 940 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 965 | 941 |
| 966 if (app_id.empty() || !id) { | 942 if (app_id.empty() || !id) { |
| 967 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); | 943 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
| 968 return model_->items()[browser_index].id; | 944 return model_->items()[browser_index].id; |
| 969 } | 945 } |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 } | 1274 } |
| 1299 | 1275 |
| 1300 ash::ShelfID ChromeLauncherController::CreateAppShortcutLauncherItem( | 1276 ash::ShelfID ChromeLauncherController::CreateAppShortcutLauncherItem( |
| 1301 const std::string& app_id, | 1277 const std::string& app_id, |
| 1302 int index) { | 1278 int index) { |
| 1303 return CreateAppShortcutLauncherItemWithType(app_id, | 1279 return CreateAppShortcutLauncherItemWithType(app_id, |
| 1304 index, | 1280 index, |
| 1305 ash::TYPE_APP_SHORTCUT); | 1281 ash::TYPE_APP_SHORTCUT); |
| 1306 } | 1282 } |
| 1307 | 1283 |
| 1308 void ChromeLauncherController::SetAppTabHelperForTest(AppTabHelper* helper) { | 1284 void ChromeLauncherController::SetLauncherControllerHelperForTest( |
| 1309 app_tab_helper_.reset(helper); | 1285 LauncherControllerHelper* helper) { |
| 1286 launcher_controller_helper_.reset(helper); |
| 1310 } | 1287 } |
| 1311 | 1288 |
| 1312 void ChromeLauncherController::SetAppIconLoadersForTest( | 1289 void ChromeLauncherController::SetAppIconLoadersForTest( |
| 1313 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { | 1290 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { |
| 1314 app_icon_loaders_.clear(); | 1291 app_icon_loaders_.clear(); |
| 1315 for (auto& loader : loaders) | 1292 for (auto& loader : loaders) |
| 1316 app_icon_loaders_.push_back(std::move(loader)); | 1293 app_icon_loaders_.push_back(std::move(loader)); |
| 1317 } | 1294 } |
| 1318 | 1295 |
| 1319 const std::string& ChromeLauncherController::GetAppIdFromShelfIdForTest( | 1296 const std::string& ChromeLauncherController::GetAppIdFromShelfIdForTest( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 | 1488 |
| 1512 void ChromeLauncherController::UpdateAppLaunchersFromPref() { | 1489 void ChromeLauncherController::UpdateAppLaunchersFromPref() { |
| 1513 // There are various functions which will trigger a |PersistPinnedState| call | 1490 // There are various functions which will trigger a |PersistPinnedState| call |
| 1514 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu | 1491 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu |
| 1515 // model which will use weights to re-arrange the icons to new positions. | 1492 // model which will use weights to re-arrange the icons to new positions. |
| 1516 // Since this function is meant to synchronize the "is state" with the | 1493 // Since this function is meant to synchronize the "is state" with the |
| 1517 // "sync state", it makes no sense to store any changes by this function back | 1494 // "sync state", it makes no sense to store any changes by this function back |
| 1518 // into the pref state. Therefore we tell |persistPinnedState| to ignore any | 1495 // into the pref state. Therefore we tell |persistPinnedState| to ignore any |
| 1519 // invocations while we are running. | 1496 // invocations while we are running. |
| 1520 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1497 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
| 1521 std::vector<std::string> pinned_apps = GetListOfPinnedAppsAndBrowser(); | 1498 std::vector<std::string> pinned_apps = ash::GetPinnedAppsFromPrefs( |
| 1499 profile_->GetPrefs(), launcher_controller_helper_.get()); |
| 1522 | 1500 |
| 1523 int index = 0; | 1501 int index = 0; |
| 1524 int max_index = model_->item_count(); | 1502 int max_index = model_->item_count(); |
| 1525 | 1503 |
| 1526 // When one of the two special items cannot be moved (and we do not know where | 1504 // When one of the two special items cannot be moved (and we do not know where |
| 1527 // yet), we remember the current location in one of these variables. | 1505 // yet), we remember the current location in one of these variables. |
| 1528 int chrome_index = -1; | 1506 int chrome_index = -1; |
| 1529 int app_list_index = -1; | 1507 int app_list_index = -1; |
| 1530 | 1508 |
| 1531 // Walk the model and |pinned_apps| from the pref lockstep, adding and | 1509 // Walk the model and |pinned_apps| from the pref lockstep, adding and |
| 1532 // removing items as necessary. NB: This code uses plain old indexing instead | 1510 // removing items as necessary. NB: This code uses plain old indexing instead |
| 1533 // of iterators because of model mutations as part of the loop. | 1511 // of iterators because of model mutations as part of the loop. |
| 1534 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); | 1512 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); |
| 1535 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { | 1513 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { |
| 1536 // Check if we have an item which we need to handle. | 1514 // Check if we have an item which we need to handle. |
| 1537 if (*pref_app_id == extension_misc::kChromeAppId || | 1515 if (*pref_app_id == extension_misc::kChromeAppId || |
| 1538 *pref_app_id == kAppShelfIdPlaceholder || | 1516 *pref_app_id == ash::kPinnedAppsPlaceholder || |
| 1539 IsAppPinned(*pref_app_id)) { | 1517 IsAppPinned(*pref_app_id)) { |
| 1540 for (; index < max_index; ++index) { | 1518 for (; index < max_index; ++index) { |
| 1541 const ash::ShelfItem& item(model_->items()[index]); | 1519 const ash::ShelfItem& item(model_->items()[index]); |
| 1542 bool is_app_list = item.type == ash::TYPE_APP_LIST; | 1520 bool is_app_list = item.type == ash::TYPE_APP_LIST; |
| 1543 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; | 1521 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; |
| 1544 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) | 1522 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) |
| 1545 continue; | 1523 continue; |
| 1546 LauncherItemController* controller = GetLauncherItemController(item.id); | 1524 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1547 if ((kAppShelfIdPlaceholder == *pref_app_id && is_app_list) || | 1525 if ((ash::kPinnedAppsPlaceholder == *pref_app_id && is_app_list) || |
| 1548 (extension_misc::kChromeAppId == *pref_app_id && is_chrome) || | 1526 (extension_misc::kChromeAppId == *pref_app_id && is_chrome) || |
| 1549 (controller && controller->app_id() == *pref_app_id)) { | 1527 (controller && controller->app_id() == *pref_app_id)) { |
| 1550 // Check if an item needs to be moved here. | 1528 // Check if an item needs to be moved here. |
| 1551 MoveChromeOrApplistToFinalPosition( | 1529 MoveChromeOrApplistToFinalPosition( |
| 1552 is_chrome, is_app_list, index, &chrome_index, &app_list_index); | 1530 is_chrome, is_app_list, index, &chrome_index, &app_list_index); |
| 1553 ++pref_app_id; | 1531 ++pref_app_id; |
| 1554 break; | 1532 break; |
| 1555 } else { | 1533 } else { |
| 1556 if (is_chrome || is_app_list) { | 1534 if (is_chrome || is_app_list) { |
| 1557 // We cannot delete any of these shortcuts. As such we remember | 1535 // We cannot delete any of these shortcuts. As such we remember |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 else if (item.type == ash::TYPE_APP_LIST) | 1601 else if (item.type == ash::TYPE_APP_LIST) |
| 1624 app_list_index = index; | 1602 app_list_index = index; |
| 1625 ++index; | 1603 ++index; |
| 1626 } | 1604 } |
| 1627 } | 1605 } |
| 1628 | 1606 |
| 1629 // Append unprocessed items from the pref to the end of the model. | 1607 // Append unprocessed items from the pref to the end of the model. |
| 1630 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { | 1608 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { |
| 1631 // All items but the chrome and / or app list shortcut needs to be added. | 1609 // All items but the chrome and / or app list shortcut needs to be added. |
| 1632 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; | 1610 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; |
| 1633 bool is_app_list = *pref_app_id == kAppShelfIdPlaceholder; | 1611 bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder; |
| 1634 // Coming here we know the next item which can be finalized, either the | 1612 // Coming here we know the next item which can be finalized, either the |
| 1635 // chrome item or the app launcher. The final position is the end of the | 1613 // chrome item or the app launcher. The final position is the end of the |
| 1636 // list. The menu model will make sure that the item is grouped according | 1614 // list. The menu model will make sure that the item is grouped according |
| 1637 // to its weight (which we do not know here). | 1615 // to its weight (which we do not know here). |
| 1638 if (!is_chrome && !is_app_list) { | 1616 if (!is_chrome && !is_app_list) { |
| 1639 DoPinAppWithID(*pref_app_id); | 1617 DoPinAppWithID(*pref_app_id); |
| 1640 int target_index = FindInsertionPoint(false); | 1618 int target_index = FindInsertionPoint(false); |
| 1641 ash::ShelfID id = GetShelfIDForAppID(*pref_app_id); | 1619 ash::ShelfID id = GetShelfIDForAppID(*pref_app_id); |
| 1642 int source_index = model_->ItemIndexByID(id); | 1620 int source_index = model_->ItemIndexByID(id); |
| 1643 if (source_index != target_index) | 1621 if (source_index != target_index) |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 id_to_item_controller_map_[id]->set_shelf_id(id); | 1776 id_to_item_controller_map_[id]->set_shelf_id(id); |
| 1799 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. | 1777 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. |
| 1800 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); | 1778 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); |
| 1801 return id; | 1779 return id; |
| 1802 } | 1780 } |
| 1803 | 1781 |
| 1804 void ChromeLauncherController::PersistChromeItemIndex(int index) { | 1782 void ChromeLauncherController::PersistChromeItemIndex(int index) { |
| 1805 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); | 1783 profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); |
| 1806 } | 1784 } |
| 1807 | 1785 |
| 1808 int ChromeLauncherController::GetChromeIconIndexFromPref() const { | |
| 1809 size_t index = profile_->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex); | |
| 1810 const base::ListValue* pinned_apps_pref = | |
| 1811 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); | |
| 1812 return std::max(static_cast<size_t>(0), | |
| 1813 std::min(pinned_apps_pref->GetSize(), index)); | |
| 1814 } | |
| 1815 | |
| 1816 void ChromeLauncherController::MoveChromeOrApplistToFinalPosition( | 1786 void ChromeLauncherController::MoveChromeOrApplistToFinalPosition( |
| 1817 bool is_chrome, | 1787 bool is_chrome, |
| 1818 bool is_app_list, | 1788 bool is_app_list, |
| 1819 int target_index, | 1789 int target_index, |
| 1820 int* chrome_index, | 1790 int* chrome_index, |
| 1821 int* app_list_index) { | 1791 int* app_list_index) { |
| 1822 if (is_chrome && *chrome_index != -1) { | 1792 if (is_chrome && *chrome_index != -1) { |
| 1823 model_->Move(*chrome_index, target_index); | 1793 model_->Move(*chrome_index, target_index); |
| 1824 if (*app_list_index != -1 && | 1794 if (*app_list_index != -1 && |
| 1825 *chrome_index < *app_list_index && | 1795 *chrome_index < *app_list_index && |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1851 type == ash::TYPE_BROWSER_SHORTCUT) { | 1821 type == ash::TYPE_BROWSER_SHORTCUT) { |
| 1852 return i; | 1822 return i; |
| 1853 } | 1823 } |
| 1854 } | 1824 } |
| 1855 return 0; | 1825 return 0; |
| 1856 } | 1826 } |
| 1857 | 1827 |
| 1858 int ChromeLauncherController::GetChromeIconIndexForCreation() { | 1828 int ChromeLauncherController::GetChromeIconIndexForCreation() { |
| 1859 // We get the list of pinned apps as they currently would get pinned. | 1829 // We get the list of pinned apps as they currently would get pinned. |
| 1860 // Within this list the chrome icon will be the correct location. | 1830 // Within this list the chrome icon will be the correct location. |
| 1861 std::vector<std::string> pinned_apps = GetListOfPinnedAppsAndBrowser(); | 1831 std::vector<std::string> pinned_apps = ash::GetPinnedAppsFromPrefs( |
| 1832 profile_->GetPrefs(), launcher_controller_helper_.get()); |
| 1862 | 1833 |
| 1863 std::vector<std::string>::iterator it = | 1834 std::vector<std::string>::iterator it = |
| 1864 std::find(pinned_apps.begin(), | 1835 std::find(pinned_apps.begin(), |
| 1865 pinned_apps.end(), | 1836 pinned_apps.end(), |
| 1866 std::string(extension_misc::kChromeAppId)); | 1837 std::string(extension_misc::kChromeAppId)); |
| 1867 DCHECK(it != pinned_apps.end()); | 1838 DCHECK(it != pinned_apps.end()); |
| 1868 int index = it - pinned_apps.begin(); | 1839 int index = it - pinned_apps.begin(); |
| 1869 | 1840 |
| 1870 // We should do here a comparison between the is state and the "want to be" | 1841 // We should do here a comparison between the is state and the "want to be" |
| 1871 // state since some apps might be able to pin but are not yet. Instead - for | 1842 // state since some apps might be able to pin but are not yet. Instead - for |
| 1872 // the time being we clamp against the amount of known items and wait for the | 1843 // the time being we clamp against the amount of known items and wait for the |
| 1873 // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since | 1844 // next |UpdateAppLaunchersFromPref()| call to correct it - it will come since |
| 1874 // the pinning will be done then. | 1845 // the pinning will be done then. |
| 1875 return std::min(model_->item_count(), index); | 1846 return std::min(model_->item_count(), index); |
| 1876 } | 1847 } |
| 1877 | 1848 |
| 1878 std::vector<std::string> | |
| 1879 ChromeLauncherController::GetListOfPinnedAppsAndBrowser() { | |
| 1880 // Adding the app list item to the list of items requires that the ID is not | |
| 1881 // a valid and known ID for the extension system. The ID was constructed that | |
| 1882 // way - but just to make sure... | |
| 1883 DCHECK(!app_tab_helper_->IsValidIDForCurrentUser(kAppShelfIdPlaceholder)); | |
| 1884 | |
| 1885 std::vector<std::string> pinned_apps; | |
| 1886 | |
| 1887 // Get the new incarnation of the list. | |
| 1888 const base::ListValue* pinned_apps_pref = | |
| 1889 profile_->GetPrefs()->GetList(prefs::kPinnedLauncherApps); | |
| 1890 | |
| 1891 const base::ListValue* policy_pinned_apps_pref = | |
| 1892 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); | |
| 1893 | |
| 1894 // Keep track of the addition of the chrome and the app list icon. | |
| 1895 bool chrome_icon_added = false; | |
| 1896 bool app_list_icon_added = false; | |
| 1897 size_t chrome_icon_index = GetChromeIconIndexFromPref(); | |
| 1898 | |
| 1899 // See if the chrome string is already in the pinned list and remove it if | |
| 1900 // needed. | |
| 1901 base::Value* chrome_app = ash::CreateAppDict(extension_misc::kChromeAppId); | |
| 1902 if (chrome_app) { | |
| 1903 chrome_icon_added = pinned_apps_pref->Find(*chrome_app) != | |
| 1904 pinned_apps_pref->end(); | |
| 1905 delete chrome_app; | |
| 1906 } | |
| 1907 | |
| 1908 if (policy_pinned_apps_pref) { | |
| 1909 for (size_t index = 0; index < policy_pinned_apps_pref->GetSize(); | |
| 1910 ++index) { | |
| 1911 const base::DictionaryValue* app = NULL; | |
| 1912 std::string app_id; | |
| 1913 if (policy_pinned_apps_pref->GetDictionary(index, &app) && | |
| 1914 app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) && | |
| 1915 (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == | |
| 1916 pinned_apps.end())) | |
| 1917 update_pinned_apps( | |
| 1918 app_id, app_tab_helper_->IsValidIDForCurrentUser(app_id), | |
| 1919 &pinned_apps, &chrome_icon_added, &app_list_icon_added); | |
| 1920 } | |
| 1921 } | |
| 1922 | |
| 1923 for (size_t index = 0; index < pinned_apps_pref->GetSize(); ++index) { | |
| 1924 // We need to position the chrome icon relative to it's place in the pinned | |
| 1925 // preference list - even if an item of that list isn't shown yet. | |
| 1926 if (index == chrome_icon_index && !chrome_icon_added) { | |
| 1927 pinned_apps.push_back(extension_misc::kChromeAppId); | |
| 1928 chrome_icon_added = true; | |
| 1929 } | |
| 1930 const base::DictionaryValue* app = NULL; | |
| 1931 std::string app_id; | |
| 1932 if (pinned_apps_pref->GetDictionary(index, &app) && | |
| 1933 app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id) && | |
| 1934 (std::find(pinned_apps.begin(), pinned_apps.end(), app_id) == | |
| 1935 pinned_apps.end())) { | |
| 1936 bool pinned_by_policy; | |
| 1937 if (app->GetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, | |
| 1938 &pinned_by_policy) && | |
| 1939 pinned_by_policy) { | |
| 1940 continue; | |
| 1941 } | |
| 1942 update_pinned_apps( | |
| 1943 app_id, app_tab_helper_->IsValidIDForCurrentUser(app_id), | |
| 1944 &pinned_apps, &chrome_icon_added, &app_list_icon_added); | |
| 1945 } | |
| 1946 } | |
| 1947 | |
| 1948 // If not added yet, the chrome item will be the last item in the list. | |
| 1949 if (!chrome_icon_added) | |
| 1950 pinned_apps.push_back(extension_misc::kChromeAppId); | |
| 1951 | |
| 1952 // If not added yet, add the app list item either at the end or at the | |
| 1953 // beginning - depending on the shelf layout. | |
| 1954 if (!app_list_icon_added) { | |
| 1955 pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder); | |
| 1956 } | |
| 1957 return pinned_apps; | |
| 1958 } | |
| 1959 | |
| 1960 bool ChromeLauncherController::IsIncognito( | 1849 bool ChromeLauncherController::IsIncognito( |
| 1961 const content::WebContents* web_contents) const { | 1850 const content::WebContents* web_contents) const { |
| 1962 const Profile* profile = | 1851 const Profile* profile = |
| 1963 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1852 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 1964 return profile->IsOffTheRecord() && !profile->IsGuestSession() && | 1853 return profile->IsOffTheRecord() && !profile->IsGuestSession() && |
| 1965 !profile->IsSystemProfile(); | 1854 !profile->IsSystemProfile(); |
| 1966 } | 1855 } |
| 1967 | 1856 |
| 1968 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension( | 1857 void ChromeLauncherController::CloseWindowedAppsFromRemovedExtension( |
| 1969 const std::string& app_id, | 1858 const std::string& app_id, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1997 DCHECK_GT(id, 0); | 1886 DCHECK_GT(id, 0); |
| 1998 DCHECK(item_delegate); | 1887 DCHECK(item_delegate); |
| 1999 DCHECK(item_delegate_manager_); | 1888 DCHECK(item_delegate_manager_); |
| 2000 item_delegate_manager_->SetShelfItemDelegate( | 1889 item_delegate_manager_->SetShelfItemDelegate( |
| 2001 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); | 1890 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); |
| 2002 } | 1891 } |
| 2003 | 1892 |
| 2004 void ChromeLauncherController::AttachProfile(Profile* profile) { | 1893 void ChromeLauncherController::AttachProfile(Profile* profile) { |
| 2005 profile_ = profile; | 1894 profile_ = profile; |
| 2006 // Either add the profile to the list of known profiles and make it the active | 1895 // Either add the profile to the list of known profiles and make it the active |
| 2007 // one for some functions of AppTabHelper or create a new one. | 1896 // one for some functions of LauncherControllerHelper or create a new one. |
| 2008 if (!app_tab_helper_.get()) | 1897 if (!launcher_controller_helper_.get()) |
| 2009 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); | 1898 launcher_controller_helper_.reset(new LauncherControllerHelper(profile_)); |
| 2010 else | 1899 else |
| 2011 app_tab_helper_->SetCurrentUser(profile_); | 1900 launcher_controller_helper_->SetCurrentUser(profile_); |
| 2012 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded | 1901 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded |
| 2013 // image is associated with a profile (it's loader requires the profile). | 1902 // image is associated with a profile (its loader requires the profile). |
| 2014 // Since icon size changes are possible, the icon could be requested to be | 1903 // Since icon size changes are possible, the icon could be requested to be |
| 2015 // reloaded. However - having it not multi profile aware would cause problems | 1904 // reloaded. However - having it not multi profile aware would cause problems |
| 2016 // if the icon cache gets deleted upon user switch. | 1905 // if the icon cache gets deleted upon user switch. |
| 2017 std::unique_ptr<AppIconLoader> extension_app_icon_loader( | 1906 std::unique_ptr<AppIconLoader> extension_app_icon_loader( |
| 2018 new extensions::ExtensionAppIconLoader( | 1907 new extensions::ExtensionAppIconLoader( |
| 2019 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); | 1908 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); |
| 2020 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); | 1909 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); |
| 2021 | 1910 |
| 2022 #if defined(OS_CHROMEOS) | 1911 #if defined(OS_CHROMEOS) |
| 2023 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( | 1912 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 | 1967 |
| 2079 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | 1968 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( |
| 2080 const std::string& app_id) { | 1969 const std::string& app_id) { |
| 2081 for (const auto& app_icon_loader : app_icon_loaders_) { | 1970 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 2082 if (app_icon_loader->CanLoadImageForApp(app_id)) | 1971 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 2083 return app_icon_loader.get(); | 1972 return app_icon_loader.get(); |
| 2084 } | 1973 } |
| 2085 | 1974 |
| 2086 return nullptr; | 1975 return nullptr; |
| 2087 } | 1976 } |
| OLD | NEW |