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 11 matching lines...) Expand all Loading... |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/macros.h" | 23 #include "base/macros.h" |
24 #include "base/strings/pattern.h" | 24 #include "base/strings/pattern.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/chrome_notification_types.h" | 30 #include "chrome/browser/chrome_notification_types.h" |
31 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 31 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 32 #include "chrome/browser/chromeos/extensions/gfx_utils.h" |
32 #include "chrome/browser/defaults.h" | 33 #include "chrome/browser/defaults.h" |
33 #include "chrome/browser/extensions/extension_app_icon_loader.h" | 34 #include "chrome/browser/extensions/extension_app_icon_loader.h" |
34 #include "chrome/browser/extensions/extension_util.h" | 35 #include "chrome/browser/extensions/extension_util.h" |
35 #include "chrome/browser/extensions/launch_util.h" | 36 #include "chrome/browser/extensions/launch_util.h" |
36 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
37 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
38 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
39 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 40 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
40 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 41 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
41 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 42 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 int index = model_->ItemIndexByID(i->first); | 941 int index = model_->ItemIndexByID(i->first); |
941 const ash::ShelfItem& item = model_->items()[index]; | 942 const ash::ShelfItem& item = model_->items()[index]; |
942 if (item.type == ash::TYPE_BROWSER_SHORTCUT) | 943 if (item.type == ash::TYPE_BROWSER_SHORTCUT) |
943 return static_cast<BrowserShortcutLauncherItemController*>(i->second); | 944 return static_cast<BrowserShortcutLauncherItemController*>(i->second); |
944 } | 945 } |
945 NOTREACHED() | 946 NOTREACHED() |
946 << "There should be always be a BrowserShortcutLauncherItemController."; | 947 << "There should be always be a BrowserShortcutLauncherItemController."; |
947 return nullptr; | 948 return nullptr; |
948 } | 949 } |
949 | 950 |
| 951 void ChromeLauncherControllerImpl::MayUpdateBrowserShortcutItem() { |
| 952 for (size_t index = 0; index < model_->items().size(); index++) { |
| 953 ash::ShelfItem item = model_->items()[index]; |
| 954 if (item.type == ash::TYPE_BROWSER_SHORTCUT) { |
| 955 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 956 item.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
| 957 extensions::util::MaybeApplyChromeBadge( |
| 958 profile_, extension_misc::kChromeAppId, &item.image); |
| 959 model_->Set(index, item); |
| 960 break; |
| 961 } |
| 962 } |
| 963 } |
| 964 |
950 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( | 965 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
951 const ash::ShelfID id) { | 966 const ash::ShelfID id) { |
952 if (!HasShelfIDToAppIDMapping(id)) | 967 if (!HasShelfIDToAppIDMapping(id)) |
953 return NULL; | 968 return NULL; |
954 return id_to_item_controller_map_[id]; | 969 return id_to_item_controller_map_[id]; |
955 } | 970 } |
956 | 971 |
957 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { | 972 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { |
958 // If running multi user mode with separate desktops, we have to check if the | 973 // If running multi user mode with separate desktops, we have to check if the |
959 // browser is from the active user. | 974 // browser is from the active user. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 app_icon_loader->FetchImage(app_id); | 1149 app_icon_loader->FetchImage(app_id); |
1135 } | 1150 } |
1136 } | 1151 } |
1137 | 1152 |
1138 UpdateAppLaunchersFromPref(); | 1153 UpdateAppLaunchersFromPref(); |
1139 } | 1154 } |
1140 | 1155 |
1141 void ChromeLauncherControllerImpl::OnAppUpdated( | 1156 void ChromeLauncherControllerImpl::OnAppUpdated( |
1142 content::BrowserContext* browser_context, | 1157 content::BrowserContext* browser_context, |
1143 const std::string& app_id) { | 1158 const std::string& app_id) { |
| 1159 if (app_id == extension_misc::kChromeAppId) { |
| 1160 MayUpdateBrowserShortcutItem(); |
| 1161 return; |
| 1162 } |
| 1163 |
1144 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1164 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
1145 if (app_icon_loader) | 1165 if (app_icon_loader) |
1146 app_icon_loader->UpdateImage(app_id); | 1166 app_icon_loader->UpdateImage(app_id); |
1147 } | 1167 } |
1148 | 1168 |
1149 void ChromeLauncherControllerImpl::OnAppUninstalled( | 1169 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( |
1150 content::BrowserContext* browser_context, | 1170 content::BrowserContext* browser_context, |
1151 const std::string& app_id) { | 1171 const std::string& app_id) { |
1152 // Since we might have windowed apps of this type which might have | 1172 // Since we might have windowed apps of this type which might have |
1153 // outstanding locks which needs to be removed. | 1173 // outstanding locks which needs to be removed. |
1154 const Profile* profile = Profile::FromBrowserContext(browser_context); | 1174 const Profile* profile = Profile::FromBrowserContext(browser_context); |
1155 if (GetShelfIDForAppID(app_id)) | 1175 if (GetShelfIDForAppID(app_id)) |
1156 CloseWindowedAppsFromRemovedExtension(app_id, profile); | 1176 CloseWindowedAppsFromRemovedExtension(app_id, profile); |
1157 | 1177 |
1158 if (IsAppPinned(app_id)) { | 1178 if (IsAppPinned(app_id)) { |
1159 if (profile == profile_) | 1179 if (profile == profile_) |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 // When one of the two special items cannot be moved (and we do not know where | 1362 // When one of the two special items cannot be moved (and we do not know where |
1343 // yet), we remember the current location in one of these variables. | 1363 // yet), we remember the current location in one of these variables. |
1344 int chrome_index = -1; | 1364 int chrome_index = -1; |
1345 int app_list_index = -1; | 1365 int app_list_index = -1; |
1346 | 1366 |
1347 // Walk the model and |pinned_apps| from the pref lockstep, adding and | 1367 // Walk the model and |pinned_apps| from the pref lockstep, adding and |
1348 // removing items as necessary. NB: This code uses plain old indexing instead | 1368 // removing items as necessary. NB: This code uses plain old indexing instead |
1349 // of iterators because of model mutations as part of the loop. | 1369 // of iterators because of model mutations as part of the loop. |
1350 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); | 1370 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); |
1351 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { | 1371 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { |
| 1372 // Update apps icon if applicable. |
| 1373 OnAppUpdated(profile_, *pref_app_id); |
1352 // Check if we have an item which we need to handle. | 1374 // Check if we have an item which we need to handle. |
1353 if (*pref_app_id == extension_misc::kChromeAppId || | 1375 if (*pref_app_id == extension_misc::kChromeAppId || |
1354 *pref_app_id == ash::kPinnedAppsPlaceholder || | 1376 *pref_app_id == ash::kPinnedAppsPlaceholder || |
1355 IsAppPinned(*pref_app_id)) { | 1377 IsAppPinned(*pref_app_id)) { |
1356 for (; index < max_index; ++index) { | 1378 for (; index < max_index; ++index) { |
1357 const ash::ShelfItem& item(model_->items()[index]); | 1379 const ash::ShelfItem& item(model_->items()[index]); |
1358 bool is_app_list = item.type == ash::TYPE_APP_LIST; | 1380 bool is_app_list = item.type == ash::TYPE_APP_LIST; |
1359 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; | 1381 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; |
1360 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) | 1382 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) |
1361 continue; | 1383 continue; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 if (item.type == ash::TYPE_BROWSER_SHORTCUT) | 1458 if (item.type == ash::TYPE_BROWSER_SHORTCUT) |
1437 chrome_index = index; | 1459 chrome_index = index; |
1438 else if (item.type == ash::TYPE_APP_LIST) | 1460 else if (item.type == ash::TYPE_APP_LIST) |
1439 app_list_index = index; | 1461 app_list_index = index; |
1440 ++index; | 1462 ++index; |
1441 } | 1463 } |
1442 } | 1464 } |
1443 | 1465 |
1444 // Append unprocessed items from the pref to the end of the model. | 1466 // Append unprocessed items from the pref to the end of the model. |
1445 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { | 1467 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { |
| 1468 // Update apps icon if applicable. |
| 1469 OnAppUpdated(profile_, *pref_app_id); |
1446 // All items but the chrome and / or app list shortcut needs to be added. | 1470 // All items but the chrome and / or app list shortcut needs to be added. |
1447 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; | 1471 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; |
1448 bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder; | 1472 bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder; |
1449 // Coming here we know the next item which can be finalized, either the | 1473 // Coming here we know the next item which can be finalized, either the |
1450 // chrome item or the app launcher. The final position is the end of the | 1474 // chrome item or the app launcher. The final position is the end of the |
1451 // list. The menu model will make sure that the item is grouped according | 1475 // list. The menu model will make sure that the item is grouped according |
1452 // to its weight (which we do not know here). | 1476 // to its weight (which we do not know here). |
1453 if (!is_chrome && !is_app_list) { | 1477 if (!is_chrome && !is_app_list) { |
1454 DoPinAppWithID(*pref_app_id); | 1478 DoPinAppWithID(*pref_app_id); |
1455 int target_index = FindInsertionPoint(false); | 1479 int target_index = FindInsertionPoint(false); |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 continue; | 1906 continue; |
1883 int index = model_->ItemIndexByID(i->first); | 1907 int index = model_->ItemIndexByID(i->first); |
1884 if (index == -1) | 1908 if (index == -1) |
1885 continue; | 1909 continue; |
1886 ash::ShelfItem item = model_->items()[index]; | 1910 ash::ShelfItem item = model_->items()[index]; |
1887 item.image = image; | 1911 item.image = image; |
1888 model_->Set(index, item); | 1912 model_->Set(index, item); |
1889 // It's possible we're waiting on more than one item, so don't break. | 1913 // It's possible we're waiting on more than one item, so don't break. |
1890 } | 1914 } |
1891 } | 1915 } |
OLD | NEW |