| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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" |
| 59 #include "chrome/browser/ui/extensions/app_launch_params.h" | |
| 60 #include "chrome/browser/ui/extensions/application_launch.h" | |
| 61 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | |
| 62 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 59 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 63 #include "chrome/browser/web_applications/web_app.h" | 60 #include "chrome/browser/web_applications/web_app.h" |
| 64 #include "chrome/common/chrome_switches.h" | 61 #include "chrome/common/chrome_switches.h" |
| 65 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 62 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 66 #include "chrome/common/pref_names.h" | 63 #include "chrome/common/pref_names.h" |
| 67 #include "chrome/common/url_constants.h" | 64 #include "chrome/common/url_constants.h" |
| 68 #include "chrome/grit/generated_resources.h" | 65 #include "chrome/grit/generated_resources.h" |
| 69 #include "components/favicon/content/content_favicon_driver.h" | 66 #include "components/favicon/content/content_favicon_driver.h" |
| 70 #include "components/prefs/scoped_user_pref_update.h" | 67 #include "components/prefs/scoped_user_pref_update.h" |
| 71 #include "components/signin/core/account_id/account_id.h" | 68 #include "components/signin/core/account_id/account_id.h" |
| 72 #include "components/strings/grit/components_strings.h" | 69 #include "components/strings/grit/components_strings.h" |
| 73 #include "components/syncable_prefs/pref_service_syncable.h" | 70 #include "components/syncable_prefs/pref_service_syncable.h" |
| 74 #include "content/public/browser/navigation_entry.h" | 71 #include "content/public/browser/navigation_entry.h" |
| 75 #include "content/public/browser/web_contents.h" | 72 #include "content/public/browser/web_contents.h" |
| 76 #include "extensions/browser/extension_prefs.h" | 73 #include "extensions/browser/extension_prefs.h" |
| 77 #include "extensions/browser/extension_registry.h" | 74 #include "extensions/browser/extension_registry.h" |
| 78 #include "extensions/browser/extension_system.h" | 75 #include "extensions/browser/extension_system.h" |
| 79 #include "extensions/browser/extension_util.h" | 76 #include "extensions/browser/extension_util.h" |
| 80 #include "extensions/common/constants.h" | 77 #include "extensions/common/constants.h" |
| 81 #include "extensions/common/extension.h" | 78 #include "extensions/common/extension.h" |
| 82 #include "extensions/common/extension_resource.h" | 79 #include "extensions/common/extension_resource.h" |
| 83 #include "extensions/common/manifest_handlers/icons_handler.h" | 80 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 84 #include "extensions/common/url_pattern.h" | 81 #include "extensions/common/url_pattern.h" |
| 85 #include "grit/ash_resources.h" | 82 #include "grit/ash_resources.h" |
| 86 #include "grit/theme_resources.h" | 83 #include "grit/theme_resources.h" |
| 87 #include "net/base/url_util.h" | |
| 88 #include "ui/aura/window.h" | 84 #include "ui/aura/window.h" |
| 89 #include "ui/aura/window_event_dispatcher.h" | 85 #include "ui/aura/window_event_dispatcher.h" |
| 90 #include "ui/base/l10n/l10n_util.h" | 86 #include "ui/base/l10n/l10n_util.h" |
| 91 #include "ui/base/resource/resource_bundle.h" | 87 #include "ui/base/resource/resource_bundle.h" |
| 92 #include "ui/base/window_open_disposition.h" | 88 #include "ui/base/window_open_disposition.h" |
| 93 #include "ui/keyboard/keyboard_util.h" | 89 #include "ui/keyboard/keyboard_util.h" |
| 94 #include "ui/resources/grit/ui_resources.h" | 90 #include "ui/resources/grit/ui_resources.h" |
| 95 #include "ui/wm/core/window_animations.h" | 91 #include "ui/wm/core/window_animations.h" |
| 96 | 92 |
| 97 #if defined(OS_CHROMEOS) | 93 #if defined(OS_CHROMEOS) |
| 98 #include "chrome/browser/browser_process.h" | 94 #include "chrome/browser/browser_process.h" |
| 99 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | 95 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" |
| 100 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 96 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 101 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | |
| 102 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 97 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
| 103 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 98 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
| 104 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" | 99 #include "chrome/browser/ui/ash/launcher/launcher_arc_app_updater.h" |
| 105 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr
oller.h" | 100 #include "chrome/browser/ui/ash/launcher/multi_profile_app_window_launcher_contr
oller.h" |
| 106 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" | 101 #include "chrome/browser/ui/ash/launcher/multi_profile_browser_status_monitor.h" |
| 107 #include "components/user_manager/user_manager.h" | 102 #include "components/user_manager/user_manager.h" |
| 108 #endif | 103 #endif |
| 109 | 104 |
| 110 using extensions::Extension; | 105 using extensions::Extension; |
| 111 using extensions::UnloadedExtensionInfo; | 106 using extensions::UnloadedExtensionInfo; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 133 const char* local_path, | 128 const char* local_path, |
| 134 const char* synced_path) { | 129 const char* synced_path) { |
| 135 if (!pref_service->FindPreference(local_path)->HasUserSetting() && | 130 if (!pref_service->FindPreference(local_path)->HasUserSetting() && |
| 136 pref_service->IsSyncing()) { | 131 pref_service->IsSyncing()) { |
| 137 // First time the user is using this machine, propagate from remote to | 132 // First time the user is using this machine, propagate from remote to |
| 138 // local. | 133 // local. |
| 139 pref_service->SetString(local_path, pref_service->GetString(synced_path)); | 134 pref_service->SetString(local_path, pref_service->GetString(synced_path)); |
| 140 } | 135 } |
| 141 } | 136 } |
| 142 | 137 |
| 143 std::string GetSourceFromAppListSource(ash::LaunchSource source) { | |
| 144 switch (source) { | |
| 145 case ash::LAUNCH_FROM_APP_LIST: | |
| 146 return std::string(extension_urls::kLaunchSourceAppList); | |
| 147 case ash::LAUNCH_FROM_APP_LIST_SEARCH: | |
| 148 return std::string(extension_urls::kLaunchSourceAppListSearch); | |
| 149 default: return std::string(); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 /* | 138 /* |
| 154 * Return whether an app is pinned only by user. | 139 * Return whether an app is pinned only by user. |
| 155 * This function doesn't expect an app_id neither pinned by user nor by | 140 * This function doesn't expect an app_id neither pinned by user nor by |
| 156 * policy, the app_id in the arguments list MUST be pinned by either of | 141 * policy, the app_id in the arguments list MUST be pinned by either of |
| 157 * those. Invalid input may lead to unexpected result. | 142 * those. Invalid input may lead to unexpected result. |
| 158 * If this app is pinned by policy, but not by user, false is returned. | 143 * If this app is pinned by policy, but not by user, false is returned. |
| 159 * If this app is pinned by both policy and user, false is returned. | 144 * If this app is pinned by both policy and user, false is returned. |
| 160 * If this app is pinned not by policy, but by user, true is returned. | 145 * If this app is pinned not by policy, but by user, true is returned. |
| 161 */ | 146 */ |
| 162 bool IsAppForUserPinned(const std::string& app_id, | 147 bool IsAppForUserPinned(const std::string& app_id, |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 std::string app_id = GetAppIDForShelfID(id); | 610 std::string app_id = GetAppIDForShelfID(id); |
| 626 const Extension* extension = GetExtensionForAppID(app_id); | 611 const Extension* extension = GetExtensionForAppID(app_id); |
| 627 // An extension can be synced / updated at any time and therefore not be | 612 // An extension can be synced / updated at any time and therefore not be |
| 628 // available. | 613 // available. |
| 629 return extension ? extension->is_platform_app() : false; | 614 return extension ? extension->is_platform_app() : false; |
| 630 } | 615 } |
| 631 | 616 |
| 632 void ChromeLauncherController::LaunchApp(const std::string& app_id, | 617 void ChromeLauncherController::LaunchApp(const std::string& app_id, |
| 633 ash::LaunchSource source, | 618 ash::LaunchSource source, |
| 634 int event_flags) { | 619 int event_flags) { |
| 635 #if defined(OS_CHROMEOS) | 620 launcher_controller_helper_->LaunchApp(app_id, source, event_flags); |
| 636 if (ArcAppListPrefs::Get(profile_)->IsRegistered(app_id)) { | |
| 637 arc::LaunchApp(profile_, app_id); | |
| 638 return; | |
| 639 } | |
| 640 #endif | |
| 641 | |
| 642 // |extension| could be NULL when it is being unloaded for updating. | |
| 643 const Extension* extension = GetExtensionForAppID(app_id); | |
| 644 if (!extension) | |
| 645 return; | |
| 646 | |
| 647 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, profile_)) { | |
| 648 // Do nothing if there is already a running enable flow. | |
| 649 if (extension_enable_flow_) | |
| 650 return; | |
| 651 | |
| 652 extension_enable_flow_.reset( | |
| 653 new ExtensionEnableFlow(profile_, app_id, this)); | |
| 654 extension_enable_flow_->StartForNativeWindow(NULL); | |
| 655 return; | |
| 656 } | |
| 657 | |
| 658 // The app will be created for the currently active profile. | |
| 659 AppLaunchParams params = CreateAppLaunchParamsWithEventFlags( | |
| 660 profile_, extension, event_flags, extensions::SOURCE_APP_LAUNCHER); | |
| 661 if (source != ash::LAUNCH_FROM_UNKNOWN && | |
| 662 app_id == extensions::kWebStoreAppId) { | |
| 663 // Get the corresponding source string. | |
| 664 std::string source_value = GetSourceFromAppListSource(source); | |
| 665 | |
| 666 // Set an override URL to include the source. | |
| 667 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); | |
| 668 params.override_url = net::AppendQueryParameter( | |
| 669 extension_url, extension_urls::kWebstoreSourceField, source_value); | |
| 670 } | |
| 671 | |
| 672 OpenApplication(params); | |
| 673 } | 621 } |
| 674 | 622 |
| 675 void ChromeLauncherController::ActivateApp(const std::string& app_id, | 623 void ChromeLauncherController::ActivateApp(const std::string& app_id, |
| 676 ash::LaunchSource source, | 624 ash::LaunchSource source, |
| 677 int event_flags) { | 625 int event_flags) { |
| 678 // If there is an existing non-shortcut controller for this app, open it. | 626 // If there is an existing non-shortcut controller for this app, open it. |
| 679 ash::ShelfID id = GetShelfIDForAppID(app_id); | 627 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 680 if (id) { | 628 if (id) { |
| 681 LauncherItemController* controller = GetLauncherItemController(id); | 629 LauncherItemController* controller = GetLauncherItemController(id); |
| 682 controller->Activate(source); | 630 controller->Activate(source); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 prefs::kShelfAutoHideBehavior); | 1107 prefs::kShelfAutoHideBehavior); |
| 1160 } | 1108 } |
| 1161 | 1109 |
| 1162 void ChromeLauncherController::OnAppSyncUIStatusChanged() { | 1110 void ChromeLauncherController::OnAppSyncUIStatusChanged() { |
| 1163 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) | 1111 if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) |
| 1164 model_->set_status(ash::ShelfModel::STATUS_LOADING); | 1112 model_->set_status(ash::ShelfModel::STATUS_LOADING); |
| 1165 else | 1113 else |
| 1166 model_->set_status(ash::ShelfModel::STATUS_NORMAL); | 1114 model_->set_status(ash::ShelfModel::STATUS_NORMAL); |
| 1167 } | 1115 } |
| 1168 | 1116 |
| 1169 void ChromeLauncherController::ExtensionEnableFlowFinished() { | |
| 1170 LaunchApp(extension_enable_flow_->extension_id(), | |
| 1171 ash::LAUNCH_FROM_UNKNOWN, | |
| 1172 ui::EF_NONE); | |
| 1173 extension_enable_flow_.reset(); | |
| 1174 } | |
| 1175 | |
| 1176 void ChromeLauncherController::ExtensionEnableFlowAborted(bool user_initiated) { | |
| 1177 extension_enable_flow_.reset(); | |
| 1178 } | |
| 1179 | |
| 1180 ChromeLauncherAppMenuItems ChromeLauncherController::GetApplicationList( | 1117 ChromeLauncherAppMenuItems ChromeLauncherController::GetApplicationList( |
| 1181 const ash::ShelfItem& item, | 1118 const ash::ShelfItem& item, |
| 1182 int event_flags) { | 1119 int event_flags) { |
| 1183 // Make sure that there is a controller associated with the id and that the | 1120 // Make sure that there is a controller associated with the id and that the |
| 1184 // extension itself is a valid application and not a panel. | 1121 // extension itself is a valid application and not a panel. |
| 1185 LauncherItemController* controller = GetLauncherItemController(item.id); | 1122 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1186 if (!controller || !GetShelfIDForAppID(controller->app_id())) | 1123 if (!controller || !GetShelfIDForAppID(controller->app_id())) |
| 1187 return ChromeLauncherAppMenuItems(); | 1124 return ChromeLauncherAppMenuItems(); |
| 1188 | 1125 |
| 1189 return controller->GetApplicationList(event_flags); | 1126 return controller->GetApplicationList(event_flags); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1967 | 1904 |
| 1968 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( | 1905 AppIconLoader* ChromeLauncherController::GetAppIconLoaderForApp( |
| 1969 const std::string& app_id) { | 1906 const std::string& app_id) { |
| 1970 for (const auto& app_icon_loader : app_icon_loaders_) { | 1907 for (const auto& app_icon_loader : app_icon_loaders_) { |
| 1971 if (app_icon_loader->CanLoadImageForApp(app_id)) | 1908 if (app_icon_loader->CanLoadImageForApp(app_id)) |
| 1972 return app_icon_loader.get(); | 1909 return app_icon_loader.get(); |
| 1973 } | 1910 } |
| 1974 | 1911 |
| 1975 return nullptr; | 1912 return nullptr; |
| 1976 } | 1913 } |
| OLD | NEW |