app_list_controller_delegate.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 6 7#include "chrome/browser/extensions/extension_service.h" 8#include "chrome/browser/extensions/extension_util.h" 9#include "chrome/browser/extensions/install_tracker_factory.h" 10#include "chrome/browser/extensions/launch_util.h" 11#include "chrome/browser/profiles/profile.h" 12#include "chrome/browser/ui/app_list/app_list_syncable_service.h" 13#include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" 14#include "chrome/browser/ui/app_list/extension_uninstaller.h" 15#include "chrome/browser/ui/apps/app_info_dialog.h" 16#include "chrome/browser/ui/browser_navigator.h" 17#include "chrome/common/extensions/extension_constants.h" 18#include "chrome/common/extensions/manifest_url_handler.h" 19#include "extensions/browser/extension_prefs.h" 20#include "extensions/browser/extension_registry.h" 21#include "extensions/browser/extension_system.h" 22#include "extensions/browser/management_policy.h" 23#include "extensions/common/extension.h" 24#include "extensions/common/extension_set.h" 25#include "net/base/url_util.h" 26#include "ui/app_list/app_list_folder_item.h" 27#include "ui/app_list/app_list_item.h" 28#include "ui/app_list/app_list_model.h" 29#include "ui/app_list/app_list_switches.h" 30 31#if defined(ENABLE_RLZ) 32#include "chrome/browser/rlz/rlz.h" 33#endif 34 35using extensions::ExtensionRegistry; 36 37namespace { 38 39const extensions::Extension* GetExtension(Profile* profile, 40 const std::string& extension_id) { 41 const ExtensionService* service = 42 extensions::ExtensionSystem::Get(profile)->extension_service(); 43 const extensions::Extension* extension = 44 service->GetInstalledExtension(extension_id); 45 return extension; 46} 47 48} // namespace 49 50AppListControllerDelegate::~AppListControllerDelegate() {} 51 52bool AppListControllerDelegate::ForceNativeDesktop() const { 53 return false; 54} 55 56void AppListControllerDelegate::ViewClosing() {} 57 58gfx::Rect AppListControllerDelegate::GetAppListBounds() { 59 return gfx::Rect(); 60} 61 62void AppListControllerDelegate::OnShowChildDialog() { 63} 64void AppListControllerDelegate::OnCloseChildDialog() { 65} 66 67std::string AppListControllerDelegate::AppListSourceToString( 68 AppListSource source) { 69 switch (source) { 70 case LAUNCH_FROM_APP_LIST: 71 return extension_urls::kLaunchSourceAppList; 72 case LAUNCH_FROM_APP_LIST_SEARCH: 73 return extension_urls::kLaunchSourceAppListSearch; 74 default: 75 return std::string(); 76 } 77} 78 79bool AppListControllerDelegate::UserMayModifySettings( 80 Profile* profile, 81 const std::string& app_id) { 82 const extensions::Extension* extension = GetExtension(profile, app_id); 83 const extensions::ManagementPolicy* policy = 84 extensions::ExtensionSystem::Get(profile)->management_policy(); 85 return extension && 86 policy->UserMayModifySettings(extension, NULL); 87} 88 89bool AppListControllerDelegate::CanDoShowAppInfoFlow() { 90 return app_list::switches::IsAppInfoEnabled(); 91} 92 93void AppListControllerDelegate::DoShowAppInfoFlow( 94 Profile* profile, 95 const std::string& extension_id) { 96 DCHECK(CanDoShowAppInfoFlow()); 97 ExtensionService* service = 98 extensions::ExtensionSystem::Get(profile)->extension_service(); 99 DCHECK(service); 100 const extensions::Extension* extension = service->GetInstalledExtension( 101 extension_id); 102 DCHECK(extension); 103 104 OnShowChildDialog(); 105 106 // Since the AppListControllerDelegate is a leaky singleton, passing its 107 // raw pointer around is OK. 108 ShowAppInfoDialog(this, profile, extension); 109} 110 111void AppListControllerDelegate::UninstallApp(Profile* profile, 112 const std::string& app_id) { 113 // ExtensionUninstall deletes itself when done or aborted. 114 ExtensionUninstaller* uninstaller = 115 new ExtensionUninstaller(profile, app_id, this); 116 uninstaller->Run(); 117} 118 119bool AppListControllerDelegate::IsAppFromWebStore( 120 Profile* profile, 121 const std::string& app_id) { 122 const extensions::Extension* extension = GetExtension(profile, app_id); 123 return extension && extension->from_webstore(); 124} 125 126void AppListControllerDelegate::ShowAppInWebStore( 127 Profile* profile, 128 const std::string& app_id, 129 bool is_search_result) { 130 const extensions::Extension* extension = GetExtension(profile, app_id); 131 if (!extension) 132 return; 133 134 const GURL url = extensions::ManifestURL::GetDetailsURL(extension); 135 DCHECK_NE(url, GURL::EmptyGURL()); 136 137 const std::string source = AppListSourceToString( 138 is_search_result ? 139 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH : 140 AppListControllerDelegate::LAUNCH_FROM_APP_LIST); 141 chrome::NavigateParams params( 142 profile, 143 net::AppendQueryParameter(url, 144 extension_urls::kWebstoreSourceField, 145 source), 146 content::PAGE_TRANSITION_LINK); 147 chrome::Navigate(¶ms); 148} 149 150bool AppListControllerDelegate::HasOptionsPage( 151 Profile* profile, 152 const std::string& app_id) { 153 const extensions::Extension* extension = GetExtension(profile, app_id); 154 return extensions::util::IsAppLaunchableWithoutEnabling(app_id, profile) && 155 extension && 156 !extensions::ManifestURL::GetOptionsPage(extension).is_empty(); 157} 158 159void AppListControllerDelegate::ShowOptionsPage( 160 Profile* profile, 161 const std::string& app_id) { 162 const extensions::Extension* extension = GetExtension(profile, app_id); 163 if (!extension) 164 return; 165 166 chrome::NavigateParams params( 167 profile, 168 extensions::ManifestURL::GetOptionsPage(extension), 169 content::PAGE_TRANSITION_LINK); 170 chrome::Navigate(¶ms); 171} 172 173extensions::LaunchType AppListControllerDelegate::GetExtensionLaunchType( 174 Profile* profile, 175 const std::string& app_id) { 176 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile), 177 GetExtension(profile, app_id)); 178} 179 180void AppListControllerDelegate::SetExtensionLaunchType( 181 Profile* profile, 182 const std::string& extension_id, 183 extensions::LaunchType launch_type) { 184 ExtensionService* service = 185 extensions::ExtensionSystem::Get(profile)->extension_service(); 186 extensions::SetLaunchType( 187 service, extension_id, launch_type); 188} 189 190bool AppListControllerDelegate::IsExtensionInstalled( 191 Profile* profile, const std::string& app_id) { 192 return !!GetExtension(profile, app_id); 193} 194 195extensions::InstallTracker* AppListControllerDelegate::GetInstallTrackerFor( 196 Profile* profile) { 197 if (extensions::ExtensionSystem::Get(profile)->extension_service()) 198 return extensions::InstallTrackerFactory::GetForProfile(profile); 199 return NULL; 200} 201 202void AppListControllerDelegate::GetApps(Profile* profile, 203 extensions::ExtensionSet* out_apps) { 204 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); 205 DCHECK(registry); 206 out_apps->InsertAll(registry->enabled_extensions()); 207 out_apps->InsertAll(registry->disabled_extensions()); 208 out_apps->InsertAll(registry->terminated_extensions()); 209} 210 211void AppListControllerDelegate::OnSearchStarted() { 212#if defined(ENABLE_RLZ) 213 RLZTracker::RecordAppListSearch(); 214#endif 215} 216