Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / app_list_controller_delegate.cc
blob76a54164fb0aaec1429c4779f8ba2571a025dc49
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"
32 #endif
34 using extensions::ExtensionRegistry;
36 namespace {
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);
43 return extension;
46 } // namespace
48 AppListControllerDelegate::~AppListControllerDelegate() {}
50 bool AppListControllerDelegate::ForceNativeDesktop() const {
51 return false;
54 void AppListControllerDelegate::ViewClosing() {}
56 gfx::Rect AppListControllerDelegate::GetAppListBounds() {
57 return gfx::Rect();
60 void AppListControllerDelegate::OnShowChildDialog() {
62 void AppListControllerDelegate::OnCloseChildDialog() {
65 std::string AppListControllerDelegate::AppListSourceToString(
66 AppListSource source) {
67 switch (source) {
68 case LAUNCH_FROM_APP_LIST:
69 return extension_urls::kLaunchSourceAppList;
70 case LAUNCH_FROM_APP_LIST_SEARCH:
71 return extension_urls::kLaunchSourceAppListSearch;
72 default:
73 return std::string();
77 bool AppListControllerDelegate::UserMayModifySettings(
78 Profile* profile,
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();
83 return extension &&
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())
91 return false;
92 #endif
93 return CanShowAppInfoDialog();
96 void AppListControllerDelegate::DoShowAppInfoFlow(
97 Profile* profile,
98 const std::string& extension_id) {
99 DCHECK(CanDoShowAppInfoFlow());
100 const extensions::Extension* extension = GetExtension(profile, extension_id);
101 DCHECK(extension);
103 OnShowChildDialog();
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(
112 GetAppListWindow(),
113 GetAppListBounds(),
114 profile,
115 extension,
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);
125 uninstaller->Run();
128 bool AppListControllerDelegate::IsAppFromWebStore(
129 Profile* profile,
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(
136 Profile* profile,
137 const std::string& app_id,
138 bool is_search_result) {
139 const extensions::Extension* extension = GetExtension(profile, app_id);
140 if (!extension)
141 return;
143 const GURL url = extensions::ManifestURL::GetDetailsURL(extension);
144 DCHECK_NE(url, GURL::EmptyGURL());
146 const std::string source = AppListSourceToString(
147 is_search_result ?
148 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH :
149 AppListControllerDelegate::LAUNCH_FROM_APP_LIST);
150 OpenURL(profile,
151 net::AppendQueryParameter(url,
152 extension_urls::kWebstoreSourceField,
153 source),
154 ui::PAGE_TRANSITION_LINK,
155 CURRENT_TAB);
158 bool AppListControllerDelegate::HasOptionsPage(
159 Profile* profile,
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(
167 Profile* profile,
168 const std::string& app_id) {
169 const extensions::Extension* extension = GetExtension(profile, app_id);
170 if (!extension)
171 return;
173 OpenURL(profile,
174 extensions::OptionsPageInfo::GetOptionsPage(extension),
175 ui::PAGE_TRANSITION_LINK,
176 CURRENT_TAB);
179 extensions::LaunchType AppListControllerDelegate::GetExtensionLaunchType(
180 Profile* profile,
181 const std::string& app_id) {
182 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile),
183 GetExtension(profile, app_id));
186 void AppListControllerDelegate::SetExtensionLaunchType(
187 Profile* profile,
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(
199 Profile* profile) {
200 if (extensions::ExtensionSystem::Get(profile)->extension_service())
201 return extensions::InstallTrackerFactory::GetForBrowserContext(profile);
202 return NULL;
205 void AppListControllerDelegate::GetApps(Profile* profile,
206 extensions::ExtensionSet* out_apps) {
207 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
208 DCHECK(registry);
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();
217 #endif