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.
5 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
7 #include "base/metrics/histogram.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/extension_uninstaller.h"
13 #include "chrome/browser/ui/apps/app_info_dialog.h"
14 #include "chrome/common/extensions/extension_constants.h"
15 #include "extensions/browser/extension_prefs.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/management_policy.h"
19 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_set.h"
21 #include "extensions/common/manifest_handlers/options_page_info.h"
22 #include "extensions/common/manifest_url_handlers.h"
23 #include "net/base/url_util.h"
24 #include "ui/app_list/app_list_folder_item.h"
25 #include "ui/app_list/app_list_item.h"
26 #include "ui/app_list/app_list_model.h"
27 #include "ui/app_list/app_list_switches.h"
28 #include "ui/gfx/geometry/rect.h"
30 #if defined(ENABLE_RLZ)
31 #include "components/rlz/rlz_tracker.h"
34 using extensions::ExtensionRegistry
;
38 const extensions::Extension
* GetExtension(Profile
* profile
,
39 const std::string
& extension_id
) {
40 const ExtensionRegistry
* registry
= ExtensionRegistry::Get(profile
);
41 const extensions::Extension
* extension
=
42 registry
->GetInstalledExtension(extension_id
);
48 AppListControllerDelegate::~AppListControllerDelegate() {}
50 bool AppListControllerDelegate::ForceNativeDesktop() const {
54 void AppListControllerDelegate::ViewClosing() {}
56 gfx::Rect
AppListControllerDelegate::GetAppListBounds() {
60 void AppListControllerDelegate::OnShowChildDialog() {
62 void AppListControllerDelegate::OnCloseChildDialog() {
65 std::string
AppListControllerDelegate::AppListSourceToString(
66 AppListSource source
) {
68 case LAUNCH_FROM_APP_LIST
:
69 return extension_urls::kLaunchSourceAppList
;
70 case LAUNCH_FROM_APP_LIST_SEARCH
:
71 return extension_urls::kLaunchSourceAppListSearch
;
77 bool AppListControllerDelegate::UserMayModifySettings(
79 const std::string
& app_id
) {
80 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
81 const extensions::ManagementPolicy
* policy
=
82 extensions::ExtensionSystem::Get(profile
)->management_policy();
84 policy
->UserMayModifySettings(extension
, NULL
);
87 bool AppListControllerDelegate::CanDoShowAppInfoFlow() {
88 #if defined(OS_MACOSX)
89 // Cocoa app list doesn't yet support the app info dialog.
90 if (!app_list::switches::IsMacViewsAppListEnabled())
93 return CanShowAppInfoDialog();
96 void AppListControllerDelegate::DoShowAppInfoFlow(
98 const std::string
& extension_id
) {
99 DCHECK(CanDoShowAppInfoFlow());
100 const extensions::Extension
* extension
= GetExtension(profile
, extension_id
);
105 UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches",
106 AppInfoLaunchSource::FROM_APP_LIST
,
107 AppInfoLaunchSource::NUM_LAUNCH_SOURCES
);
109 // Since the AppListControllerDelegate is a leaky singleton, passing its raw
110 // pointer around is OK.
111 ShowAppInfoInAppList(
116 base::Bind(&AppListControllerDelegate::OnCloseChildDialog
,
117 base::Unretained(this)));
120 void AppListControllerDelegate::UninstallApp(Profile
* profile
,
121 const std::string
& app_id
) {
122 // ExtensionUninstall deletes itself when done or aborted.
123 ExtensionUninstaller
* uninstaller
=
124 new ExtensionUninstaller(profile
, app_id
, this);
128 bool AppListControllerDelegate::IsAppFromWebStore(
130 const std::string
& app_id
) {
131 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
132 return extension
&& extension
->from_webstore();
135 void AppListControllerDelegate::ShowAppInWebStore(
137 const std::string
& app_id
,
138 bool is_search_result
) {
139 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
143 const GURL url
= extensions::ManifestURL::GetDetailsURL(extension
);
144 DCHECK_NE(url
, GURL::EmptyGURL());
146 const std::string source
= AppListSourceToString(
148 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH
:
149 AppListControllerDelegate::LAUNCH_FROM_APP_LIST
);
151 net::AppendQueryParameter(url
,
152 extension_urls::kWebstoreSourceField
,
154 ui::PAGE_TRANSITION_LINK
,
158 bool AppListControllerDelegate::HasOptionsPage(
160 const std::string
& app_id
) {
161 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
162 return extensions::util::IsAppLaunchableWithoutEnabling(app_id
, profile
) &&
163 extension
&& extensions::OptionsPageInfo::HasOptionsPage(extension
);
166 void AppListControllerDelegate::ShowOptionsPage(
168 const std::string
& app_id
) {
169 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
174 extensions::OptionsPageInfo::GetOptionsPage(extension
),
175 ui::PAGE_TRANSITION_LINK
,
179 extensions::LaunchType
AppListControllerDelegate::GetExtensionLaunchType(
181 const std::string
& app_id
) {
182 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile
),
183 GetExtension(profile
, app_id
));
186 void AppListControllerDelegate::SetExtensionLaunchType(
188 const std::string
& extension_id
,
189 extensions::LaunchType launch_type
) {
190 extensions::SetLaunchType(profile
, extension_id
, launch_type
);
193 bool AppListControllerDelegate::IsExtensionInstalled(
194 Profile
* profile
, const std::string
& app_id
) {
195 return !!GetExtension(profile
, app_id
);
198 extensions::InstallTracker
* AppListControllerDelegate::GetInstallTrackerFor(
200 if (extensions::ExtensionSystem::Get(profile
)->extension_service())
201 return extensions::InstallTrackerFactory::GetForBrowserContext(profile
);
205 void AppListControllerDelegate::GetApps(Profile
* profile
,
206 extensions::ExtensionSet
* out_apps
) {
207 ExtensionRegistry
* registry
= ExtensionRegistry::Get(profile
);
209 out_apps
->InsertAll(registry
->enabled_extensions());
210 out_apps
->InsertAll(registry
->disabled_extensions());
211 out_apps
->InsertAll(registry
->terminated_extensions());
214 void AppListControllerDelegate::OnSearchStarted() {
215 #if defined(ENABLE_RLZ)
216 rlz::RLZTracker::RecordAppListSearch();