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 |
11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
13 #include "ash/multi_profile_uma.h" | 13 #include "ash/multi_profile_uma.h" |
14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
15 #include "ash/shelf/shelf.h" | 15 #include "ash/shelf/shelf.h" |
16 #include "ash/shelf/shelf_item_delegate_manager.h" | 16 #include "ash/shelf/shelf_item_delegate_manager.h" |
17 #include "ash/shelf/shelf_model.h" | 17 #include "ash/shelf/shelf_model.h" |
18 #include "ash/shell.h" | 18 #include "ash/shell.h" |
19 #include "ash/system/tray/system_tray_delegate.h" | 19 #include "ash/system/tray/system_tray_delegate.h" |
20 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
22 #include "base/macros.h" | 22 #include "base/macros.h" |
23 #include "base/strings/pattern.h" | 23 #include "base/strings/pattern.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
| 30 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
30 #include "chrome/browser/defaults.h" | 31 #include "chrome/browser/defaults.h" |
31 #include "chrome/browser/extensions/extension_app_icon_loader.h" | 32 #include "chrome/browser/extensions/extension_app_icon_loader.h" |
32 #include "chrome/browser/extensions/extension_util.h" | 33 #include "chrome/browser/extensions/extension_util.h" |
33 #include "chrome/browser/extensions/launch_util.h" | 34 #include "chrome/browser/extensions/launch_util.h" |
34 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 35 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
35 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 36 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
36 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
37 #include "chrome/browser/profiles/profile_manager.h" | 38 #include "chrome/browser/profiles/profile_manager.h" |
38 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 39 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
39 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 40 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 41 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
40 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 42 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
41 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 43 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
42 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 44 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
43 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 45 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
44 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 46 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
46 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 48 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
47 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 49 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
48 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 50 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
49 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 51 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (app_id == app_id_) | 176 if (app_id == app_id_) |
175 return false; | 177 return false; |
176 } | 178 } |
177 } | 179 } |
178 } | 180 } |
179 // Default, user added new pins | 181 // Default, user added new pins |
180 return true; | 182 return true; |
181 } | 183 } |
182 | 184 |
183 const char* const kPinProhibitedExtensionIds[] = { | 185 const char* const kPinProhibitedExtensionIds[] = { |
184 "cnbgggchhmkkdmeppjobngjoejnihlei", // Arc Support | 186 ArcSupportHost::kHostAppId, arc::kPlayStoreAppId, |
185 }; | 187 }; |
186 | 188 |
187 const size_t kPinProhibitedExtensionIdsLength = | 189 const size_t kPinProhibitedExtensionIdsLength = |
188 arraysize(kPinProhibitedExtensionIds); | 190 arraysize(kPinProhibitedExtensionIds); |
189 | 191 |
190 } // namespace | 192 } // namespace |
191 | 193 |
192 // A class to get events from ChromeOS when a user gets changed or added. | 194 // A class to get events from ChromeOS when a user gets changed or added. |
193 class ChromeLauncherControllerUserSwitchObserver | 195 class ChromeLauncherControllerUserSwitchObserver |
194 : public user_manager::UserManager::UserSessionStateObserver { | 196 : public user_manager::UserManager::UserSessionStateObserver { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 440 } |
439 | 441 |
440 void ChromeLauncherController::CloseLauncherItem(ash::ShelfID id) { | 442 void ChromeLauncherController::CloseLauncherItem(ash::ShelfID id) { |
441 CHECK(id); | 443 CHECK(id); |
442 if (IsPinned(id)) { | 444 if (IsPinned(id)) { |
443 // Create a new shortcut controller. | 445 // Create a new shortcut controller. |
444 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 446 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
445 CHECK(iter != id_to_item_controller_map_.end()); | 447 CHECK(iter != id_to_item_controller_map_.end()); |
446 SetItemStatus(id, ash::STATUS_CLOSED); | 448 SetItemStatus(id, ash::STATUS_CLOSED); |
447 std::string app_id = iter->second->app_id(); | 449 std::string app_id = iter->second->app_id(); |
448 iter->second = new AppShortcutLauncherItemController(app_id, this); | 450 iter->second = AppShortcutLauncherItemController::Create(app_id, this); |
449 iter->second->set_shelf_id(id); | 451 iter->second->set_shelf_id(id); |
450 // Existing controller is destroyed and replaced by registering again. | 452 // Existing controller is destroyed and replaced by registering again. |
451 SetShelfItemDelegate(id, iter->second); | 453 SetShelfItemDelegate(id, iter->second); |
452 } else { | 454 } else { |
453 LauncherItemClosed(id); | 455 LauncherItemClosed(id); |
454 } | 456 } |
455 } | 457 } |
456 | 458 |
457 AppListControllerDelegate::Pinnable ChromeLauncherController::GetPinnable( | 459 AppListControllerDelegate::Pinnable ChromeLauncherController::GetPinnable( |
458 const std::string& app_id) { | 460 const std::string& app_id) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 ash::ShelfID id = GetShelfIDForAppID(app_id); | 628 ash::ShelfID id = GetShelfIDForAppID(app_id); |
627 if (id) { | 629 if (id) { |
628 LauncherItemController* controller = GetLauncherItemController(id); | 630 LauncherItemController* controller = GetLauncherItemController(id); |
629 controller->Activate(source); | 631 controller->Activate(source); |
630 return; | 632 return; |
631 } | 633 } |
632 | 634 |
633 // Create a temporary application launcher item and use it to see if there are | 635 // Create a temporary application launcher item and use it to see if there are |
634 // running instances. | 636 // running instances. |
635 std::unique_ptr<AppShortcutLauncherItemController> app_controller( | 637 std::unique_ptr<AppShortcutLauncherItemController> app_controller( |
636 new AppShortcutLauncherItemController(app_id, this)); | 638 AppShortcutLauncherItemController::Create(app_id, this)); |
637 if (!app_controller->GetRunningApplications().empty()) | 639 if (!app_controller->GetRunningApplications().empty()) |
638 app_controller->Activate(source); | 640 app_controller->Activate(source); |
639 else | 641 else |
640 LaunchApp(app_id, source, event_flags); | 642 LaunchApp(app_id, source, event_flags); |
641 } | 643 } |
642 | 644 |
643 extensions::LaunchType ChromeLauncherController::GetLaunchType( | 645 extensions::LaunchType ChromeLauncherController::GetLaunchType( |
644 ash::ShelfID id) { | 646 ash::ShelfID id) { |
645 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id)); | 647 const Extension* extension = GetExtensionForAppID(GetAppIDForShelfID(id)); |
646 | 648 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 | 798 |
797 const base::ListValue* policy_pinned_apps_pref = | 799 const base::ListValue* policy_pinned_apps_pref = |
798 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); | 800 profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); |
799 | 801 |
800 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); | 802 ListPrefUpdate updater(profile_->GetPrefs(), prefs::kPinnedLauncherApps); |
801 updater->Clear(); | 803 updater->Clear(); |
802 for (size_t i = 0; i < model_->items().size(); ++i) { | 804 for (size_t i = 0; i < model_->items().size(); ++i) { |
803 if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) { | 805 if (model_->items()[i].type == ash::TYPE_APP_SHORTCUT) { |
804 ash::ShelfID id = model_->items()[i].id; | 806 ash::ShelfID id = model_->items()[i].id; |
805 LauncherItemController* controller = GetLauncherItemController(id); | 807 LauncherItemController* controller = GetLauncherItemController(id); |
806 if (controller && IsPinned(id)) { | 808 // Don't persist pinning state for apps that are handled internally and |
| 809 // have pinnable state AppListControllerDelegate::NO_PIN. |
| 810 if (controller && IsPinned(id) && |
| 811 GetPinnable(controller->app_id()) != |
| 812 AppListControllerDelegate::NO_PIN) { |
807 base::DictionaryValue* app_value = ash::CreateAppDict( | 813 base::DictionaryValue* app_value = ash::CreateAppDict( |
808 controller->app_id()); | 814 controller->app_id()); |
809 if (app_value) { | 815 if (app_value) { |
810 if (!IsAppForUserPinned(controller->app_id(), | 816 if (!IsAppForUserPinned(controller->app_id(), |
811 pinned_apps_pref.get(), | 817 pinned_apps_pref.get(), |
812 policy_pinned_apps_pref)) | 818 policy_pinned_apps_pref)) |
813 app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true); | 819 app_value->SetBoolean(ash::kPinnedAppsPrefPinnedByPolicy, true); |
814 updater->Append(app_value); | 820 updater->Append(app_value); |
815 } | 821 } |
816 } | 822 } |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 } | 1297 } |
1292 } | 1298 } |
1293 } | 1299 } |
1294 } | 1300 } |
1295 | 1301 |
1296 ash::ShelfID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( | 1302 ash::ShelfID ChromeLauncherController::CreateAppShortcutLauncherItemWithType( |
1297 const std::string& app_id, | 1303 const std::string& app_id, |
1298 int index, | 1304 int index, |
1299 ash::ShelfItemType shelf_item_type) { | 1305 ash::ShelfItemType shelf_item_type) { |
1300 AppShortcutLauncherItemController* controller = | 1306 AppShortcutLauncherItemController* controller = |
1301 new AppShortcutLauncherItemController(app_id, this); | 1307 AppShortcutLauncherItemController::Create(app_id, this); |
1302 ash::ShelfID shelf_id = InsertAppLauncherItem( | 1308 ash::ShelfID shelf_id = InsertAppLauncherItem( |
1303 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type); | 1309 controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type); |
1304 return shelf_id; | 1310 return shelf_id; |
1305 } | 1311 } |
1306 | 1312 |
1307 LauncherItemController* ChromeLauncherController::GetLauncherItemController( | 1313 LauncherItemController* ChromeLauncherController::GetLauncherItemController( |
1308 const ash::ShelfID id) { | 1314 const ash::ShelfID id) { |
1309 if (!HasShelfIDToAppIDMapping(id)) | 1315 if (!HasShelfIDToAppIDMapping(id)) |
1310 return NULL; | 1316 return NULL; |
1311 return id_to_item_controller_map_[id]; | 1317 return id_to_item_controller_map_[id]; |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 | 1898 |
1893 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | 1899 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( |
1894 const std::string& app_id) { | 1900 const std::string& app_id) { |
1895 for (const auto& app_icon_loader : app_icon_loaders_) { | 1901 for (const auto& app_icon_loader : app_icon_loaders_) { |
1896 if (app_icon_loader->CanLoadImageForApp(app_id)) | 1902 if (app_icon_loader->CanLoadImageForApp(app_id)) |
1897 return app_icon_loader.get(); | 1903 return app_icon_loader.get(); |
1898 } | 1904 } |
1899 | 1905 |
1900 return nullptr; | 1906 return nullptr; |
1901 } | 1907 } |
OLD | NEW |