| 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 if (extensions::util::MaybeApplyChromeBadge( |
| 958 profile_, extension_misc::kChromeAppId, &item.image)) { |
| 959 model_->Set(index, item); |
| 960 } |
| 961 break; |
| 962 } |
| 963 } |
| 964 } |
| 965 |
| 950 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( | 966 LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
| 951 const ash::ShelfID id) { | 967 const ash::ShelfID id) { |
| 952 if (!HasShelfIDToAppIDMapping(id)) | 968 if (!HasShelfIDToAppIDMapping(id)) |
| 953 return NULL; | 969 return NULL; |
| 954 return id_to_item_controller_map_[id]; | 970 return id_to_item_controller_map_[id]; |
| 955 } | 971 } |
| 956 | 972 |
| 957 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { | 973 bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { |
| 958 // If running multi user mode with separate desktops, we have to check if the | 974 // If running multi user mode with separate desktops, we have to check if the |
| 959 // browser is from the active user. | 975 // 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); | 1150 app_icon_loader->FetchImage(app_id); |
| 1135 } | 1151 } |
| 1136 } | 1152 } |
| 1137 | 1153 |
| 1138 UpdateAppLaunchersFromPref(); | 1154 UpdateAppLaunchersFromPref(); |
| 1139 } | 1155 } |
| 1140 | 1156 |
| 1141 void ChromeLauncherControllerImpl::OnAppUpdated( | 1157 void ChromeLauncherControllerImpl::OnAppUpdated( |
| 1142 content::BrowserContext* browser_context, | 1158 content::BrowserContext* browser_context, |
| 1143 const std::string& app_id) { | 1159 const std::string& app_id) { |
| 1160 if (app_id == extension_misc::kChromeAppId) { |
| 1161 MayUpdateBrowserShortcutItem(); |
| 1162 return; |
| 1163 } |
| 1164 |
| 1144 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1165 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
| 1145 if (app_icon_loader) | 1166 if (app_icon_loader) |
| 1146 app_icon_loader->UpdateImage(app_id); | 1167 app_icon_loader->UpdateImage(app_id); |
| 1147 } | 1168 } |
| 1148 | 1169 |
| 1149 void ChromeLauncherControllerImpl::OnAppUninstalled( | 1170 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( |
| 1150 content::BrowserContext* browser_context, | 1171 content::BrowserContext* browser_context, |
| 1151 const std::string& app_id) { | 1172 const std::string& app_id) { |
| 1152 // Since we might have windowed apps of this type which might have | 1173 // Since we might have windowed apps of this type which might have |
| 1153 // outstanding locks which needs to be removed. | 1174 // outstanding locks which needs to be removed. |
| 1154 const Profile* profile = Profile::FromBrowserContext(browser_context); | 1175 const Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1155 if (GetShelfIDForAppID(app_id)) | 1176 if (GetShelfIDForAppID(app_id)) |
| 1156 CloseWindowedAppsFromRemovedExtension(app_id, profile); | 1177 CloseWindowedAppsFromRemovedExtension(app_id, profile); |
| 1157 | 1178 |
| 1158 if (IsAppPinned(app_id)) { | 1179 if (IsAppPinned(app_id)) { |
| 1159 if (profile == profile_) | 1180 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 | 1363 // 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. | 1364 // yet), we remember the current location in one of these variables. |
| 1344 int chrome_index = -1; | 1365 int chrome_index = -1; |
| 1345 int app_list_index = -1; | 1366 int app_list_index = -1; |
| 1346 | 1367 |
| 1347 // Walk the model and |pinned_apps| from the pref lockstep, adding and | 1368 // 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 | 1369 // removing items as necessary. NB: This code uses plain old indexing instead |
| 1349 // of iterators because of model mutations as part of the loop. | 1370 // of iterators because of model mutations as part of the loop. |
| 1350 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); | 1371 std::vector<std::string>::const_iterator pref_app_id(pinned_apps.begin()); |
| 1351 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { | 1372 for (; index < max_index && pref_app_id != pinned_apps.end(); ++index) { |
| 1373 // Update apps icon if applicable. |
| 1374 OnAppUpdated(profile_, *pref_app_id); |
| 1352 // Check if we have an item which we need to handle. | 1375 // Check if we have an item which we need to handle. |
| 1353 if (*pref_app_id == extension_misc::kChromeAppId || | 1376 if (*pref_app_id == extension_misc::kChromeAppId || |
| 1354 *pref_app_id == ash::kPinnedAppsPlaceholder || | 1377 *pref_app_id == ash::kPinnedAppsPlaceholder || |
| 1355 IsAppPinned(*pref_app_id)) { | 1378 IsAppPinned(*pref_app_id)) { |
| 1356 for (; index < max_index; ++index) { | 1379 for (; index < max_index; ++index) { |
| 1357 const ash::ShelfItem& item(model_->items()[index]); | 1380 const ash::ShelfItem& item(model_->items()[index]); |
| 1358 bool is_app_list = item.type == ash::TYPE_APP_LIST; | 1381 bool is_app_list = item.type == ash::TYPE_APP_LIST; |
| 1359 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; | 1382 bool is_chrome = item.type == ash::TYPE_BROWSER_SHORTCUT; |
| 1360 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) | 1383 if (item.type != ash::TYPE_APP_SHORTCUT && !is_app_list && !is_chrome) |
| 1361 continue; | 1384 continue; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 if (item.type == ash::TYPE_BROWSER_SHORTCUT) | 1459 if (item.type == ash::TYPE_BROWSER_SHORTCUT) |
| 1437 chrome_index = index; | 1460 chrome_index = index; |
| 1438 else if (item.type == ash::TYPE_APP_LIST) | 1461 else if (item.type == ash::TYPE_APP_LIST) |
| 1439 app_list_index = index; | 1462 app_list_index = index; |
| 1440 ++index; | 1463 ++index; |
| 1441 } | 1464 } |
| 1442 } | 1465 } |
| 1443 | 1466 |
| 1444 // Append unprocessed items from the pref to the end of the model. | 1467 // Append unprocessed items from the pref to the end of the model. |
| 1445 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { | 1468 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) { |
| 1469 // Update apps icon if applicable. |
| 1470 OnAppUpdated(profile_, *pref_app_id); |
| 1446 // All items but the chrome and / or app list shortcut needs to be added. | 1471 // All items but the chrome and / or app list shortcut needs to be added. |
| 1447 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; | 1472 bool is_chrome = *pref_app_id == extension_misc::kChromeAppId; |
| 1448 bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder; | 1473 bool is_app_list = *pref_app_id == ash::kPinnedAppsPlaceholder; |
| 1449 // Coming here we know the next item which can be finalized, either the | 1474 // 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 | 1475 // 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 | 1476 // list. The menu model will make sure that the item is grouped according |
| 1452 // to its weight (which we do not know here). | 1477 // to its weight (which we do not know here). |
| 1453 if (!is_chrome && !is_app_list) { | 1478 if (!is_chrome && !is_app_list) { |
| 1454 DoPinAppWithID(*pref_app_id); | 1479 DoPinAppWithID(*pref_app_id); |
| 1455 int target_index = FindInsertionPoint(false); | 1480 int target_index = FindInsertionPoint(false); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 } | 1611 } |
| 1587 | 1612 |
| 1588 ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { | 1613 ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { |
| 1589 ash::ShelfItem browser_shortcut; | 1614 ash::ShelfItem browser_shortcut; |
| 1590 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1615 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
| 1591 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1616 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1592 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1617 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
| 1593 ash::ShelfID id = model_->next_id(); | 1618 ash::ShelfID id = model_->next_id(); |
| 1594 size_t index = GetChromeIconIndexForCreation(); | 1619 size_t index = GetChromeIconIndexForCreation(); |
| 1595 model_->AddAt(index, browser_shortcut); | 1620 model_->AddAt(index, browser_shortcut); |
| 1621 MayUpdateBrowserShortcutItem(); |
| 1596 id_to_item_controller_map_[id] = | 1622 id_to_item_controller_map_[id] = |
| 1597 new BrowserShortcutLauncherItemController(this, model_); | 1623 new BrowserShortcutLauncherItemController(this, model_); |
| 1598 id_to_item_controller_map_[id]->set_shelf_id(id); | 1624 id_to_item_controller_map_[id]->set_shelf_id(id); |
| 1599 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. | 1625 // ShelfItemDelegateManager owns BrowserShortcutLauncherItemController. |
| 1600 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); | 1626 SetShelfItemDelegate(id, id_to_item_controller_map_[id]); |
| 1601 return id; | 1627 return id; |
| 1602 } | 1628 } |
| 1603 | 1629 |
| 1604 bool ChromeLauncherControllerImpl::IsIncognito( | 1630 bool ChromeLauncherControllerImpl::IsIncognito( |
| 1605 const content::WebContents* web_contents) const { | 1631 const content::WebContents* web_contents) const { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1882 continue; | 1908 continue; |
| 1883 int index = model_->ItemIndexByID(i->first); | 1909 int index = model_->ItemIndexByID(i->first); |
| 1884 if (index == -1) | 1910 if (index == -1) |
| 1885 continue; | 1911 continue; |
| 1886 ash::ShelfItem item = model_->items()[index]; | 1912 ash::ShelfItem item = model_->items()[index]; |
| 1887 item.image = image; | 1913 item.image = image; |
| 1888 model_->Set(index, item); | 1914 model_->Set(index, item); |
| 1889 // It's possible we're waiting on more than one item, so don't break. | 1915 // It's possible we're waiting on more than one item, so don't break. |
| 1890 } | 1916 } |
| 1891 } | 1917 } |
| OLD | NEW |