app_list_controller_delegate.cc revision 0f1bc08d4cfcc34181b0b5cbf065c40f687bf740
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_system.h" 9#include "chrome/browser/extensions/install_tracker_factory.h" 10#include "chrome/browser/extensions/management_policy.h" 11#include "chrome/browser/ui/app_list/extension_uninstaller.h" 12#include "chrome/browser/ui/browser_navigator.h" 13#include "chrome/common/extensions/extension.h" 14#include "chrome/common/extensions/extension_constants.h" 15#include "chrome/common/extensions/extension_set.h" 16#include "chrome/common/extensions/manifest_url_handler.h" 17#include "net/base/url_util.h" 18 19namespace { 20 21const extensions::Extension* GetExtension(Profile* profile, 22 const std::string& extension_id) { 23 const ExtensionService* service = 24 extensions::ExtensionSystem::Get(profile)->extension_service(); 25 const extensions::Extension* extension = 26 service->GetInstalledExtension(extension_id); 27 return extension; 28} 29 30} // namespace 31 32AppListControllerDelegate::~AppListControllerDelegate() {} 33 34void AppListControllerDelegate::ViewClosing() {} 35 36void AppListControllerDelegate::OnShowExtensionPrompt() {} 37void AppListControllerDelegate::OnCloseExtensionPrompt() {} 38 39std::string AppListControllerDelegate::AppListSourceToString( 40 AppListSource source) { 41 switch (source) { 42 case LAUNCH_FROM_APP_LIST: 43 return extension_urls::kLaunchSourceAppList; 44 case LAUNCH_FROM_APP_LIST_SEARCH: 45 return extension_urls::kLaunchSourceAppListSearch; 46 default: return std::string(); 47 } 48} 49 50bool AppListControllerDelegate::UserMayModifySettings( 51 Profile* profile, 52 const std::string& app_id) { 53 const extensions::Extension* extension = GetExtension(profile, app_id); 54 const extensions::ManagementPolicy* policy = 55 extensions::ExtensionSystem::Get(profile)->management_policy(); 56 return extension && 57 policy->UserMayModifySettings(extension, NULL); 58} 59 60void AppListControllerDelegate::UninstallApp(Profile* profile, 61 const std::string& app_id) { 62 // ExtensionUninstall deletes itself when done or aborted. 63 ExtensionUninstaller* uninstaller = 64 new ExtensionUninstaller(profile, app_id, this); 65 uninstaller->Run(); 66} 67 68bool AppListControllerDelegate::IsAppFromWebStore( 69 Profile* profile, 70 const std::string& app_id) { 71 const extensions::Extension* extension = GetExtension(profile, app_id); 72 return extension && extension->from_webstore(); 73} 74 75void AppListControllerDelegate::ShowAppInWebStore( 76 Profile* profile, 77 const std::string& app_id, 78 bool is_search_result) { 79 const extensions::Extension* extension = GetExtension(profile, app_id); 80 if (!extension) 81 return; 82 83 const GURL url = extensions::ManifestURL::GetDetailsURL(extension); 84 DCHECK_NE(url, GURL::EmptyGURL()); 85 86 const std::string source = AppListSourceToString( 87 is_search_result ? 88 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH : 89 AppListControllerDelegate::LAUNCH_FROM_APP_LIST); 90 chrome::NavigateParams params( 91 profile, 92 net::AppendQueryParameter(url, 93 extension_urls::kWebstoreSourceField, 94 source), 95 content::PAGE_TRANSITION_LINK); 96 chrome::Navigate(¶ms); 97} 98 99bool AppListControllerDelegate::HasOptionsPage( 100 Profile* profile, 101 const std::string& app_id) { 102 const ExtensionService* service = 103 extensions::ExtensionSystem::Get(profile)->extension_service(); 104 const extensions::Extension* extension = GetExtension(profile, app_id); 105 return service->IsExtensionEnabledForLauncher(app_id) && 106 extension && 107 !extensions::ManifestURL::GetOptionsPage(extension).is_empty(); 108} 109 110void AppListControllerDelegate::ShowOptionsPage( 111 Profile* profile, 112 const std::string& app_id) { 113 const extensions::Extension* extension = GetExtension(profile, app_id); 114 if (!extension) 115 return; 116 117 chrome::NavigateParams params( 118 profile, 119 extensions::ManifestURL::GetOptionsPage(extension), 120 content::PAGE_TRANSITION_LINK); 121 chrome::Navigate(¶ms); 122} 123 124extensions::ExtensionPrefs::LaunchType 125AppListControllerDelegate::GetExtensionLaunchType( 126 Profile* profile, 127 const std::string& app_id) { 128 ExtensionService* service = 129 extensions::ExtensionSystem::Get(profile)->extension_service(); 130 return service->extension_prefs()-> 131 GetLaunchType(GetExtension(profile, app_id), 132 extensions::ExtensionPrefs::LAUNCH_DEFAULT); 133} 134 135void AppListControllerDelegate::SetExtensionLaunchType( 136 Profile* profile, 137 const std::string& extension_id, 138 extensions::ExtensionPrefs::LaunchType launch_type) { 139 ExtensionService* service = 140 extensions::ExtensionSystem::Get(profile)->extension_service(); 141 service->extension_prefs()->SetLaunchType(extension_id, launch_type); 142} 143 144bool AppListControllerDelegate::IsExtensionInstalled( 145 Profile* profile, const std::string& app_id) { 146 return !!GetExtension(profile, app_id); 147} 148 149extensions::InstallTracker* AppListControllerDelegate::GetInstallTrackerFor( 150 Profile* profile) { 151 if (extensions::ExtensionSystem::Get(profile)->extension_service()) 152 return extensions::InstallTrackerFactory::GetForProfile(profile); 153 return NULL; 154} 155 156void AppListControllerDelegate::GetApps(Profile* profile, 157 ExtensionSet* out_apps) { 158 ExtensionService* service = 159 extensions::ExtensionSystem::Get(profile)->extension_service(); 160 if (!service) 161 return; 162 out_apps->InsertAll(*service->extensions()); 163 out_apps->InsertAll(*service->disabled_extensions()); 164 out_apps->InsertAll(*service->terminated_extensions()); 165} 166