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 "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/browser/extensions/install_tracker_factory.h"
11 #include "chrome/browser/extensions/launch_util.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/app_list/extension_uninstaller.h"
14 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/common/extensions/manifest_url_handler.h"
17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/management_policy.h"
19 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_set.h"
21 #include "net/base/url_util.h"
23 using extensions::ExtensionRegistry
;
27 const extensions::Extension
* GetExtension(Profile
* profile
,
28 const std::string
& extension_id
) {
29 const ExtensionService
* service
=
30 extensions::ExtensionSystem::Get(profile
)->extension_service();
31 const extensions::Extension
* extension
=
32 service
->GetInstalledExtension(extension_id
);
38 AppListControllerDelegate::~AppListControllerDelegate() {}
40 bool AppListControllerDelegate::ForceNativeDesktop() const {
44 void AppListControllerDelegate::ViewClosing() {}
46 void AppListControllerDelegate::OnShowExtensionPrompt() {}
47 void AppListControllerDelegate::OnCloseExtensionPrompt() {}
49 std::string
AppListControllerDelegate::AppListSourceToString(
50 AppListSource source
) {
52 case LAUNCH_FROM_APP_LIST
:
53 return extension_urls::kLaunchSourceAppList
;
54 case LAUNCH_FROM_APP_LIST_SEARCH
:
55 return extension_urls::kLaunchSourceAppListSearch
;
61 bool AppListControllerDelegate::UserMayModifySettings(
63 const std::string
& app_id
) {
64 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
65 const extensions::ManagementPolicy
* policy
=
66 extensions::ExtensionSystem::Get(profile
)->management_policy();
68 policy
->UserMayModifySettings(extension
, NULL
);
71 void AppListControllerDelegate::UninstallApp(Profile
* profile
,
72 const std::string
& app_id
) {
73 // ExtensionUninstall deletes itself when done or aborted.
74 ExtensionUninstaller
* uninstaller
=
75 new ExtensionUninstaller(profile
, app_id
, this);
79 bool AppListControllerDelegate::IsAppFromWebStore(
81 const std::string
& app_id
) {
82 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
83 return extension
&& extension
->from_webstore();
86 void AppListControllerDelegate::ShowAppInWebStore(
88 const std::string
& app_id
,
89 bool is_search_result
) {
90 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
94 const GURL url
= extensions::ManifestURL::GetDetailsURL(extension
);
95 DCHECK_NE(url
, GURL::EmptyGURL());
97 const std::string source
= AppListSourceToString(
99 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH
:
100 AppListControllerDelegate::LAUNCH_FROM_APP_LIST
);
101 chrome::NavigateParams
params(
103 net::AppendQueryParameter(url
,
104 extension_urls::kWebstoreSourceField
,
106 content::PAGE_TRANSITION_LINK
);
107 chrome::Navigate(¶ms
);
110 bool AppListControllerDelegate::HasOptionsPage(
112 const std::string
& app_id
) {
113 const ExtensionService
* service
=
114 extensions::ExtensionSystem::Get(profile
)->extension_service();
115 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
116 return extension_util::IsAppLaunchableWithoutEnabling(app_id
, service
) &&
118 !extensions::ManifestURL::GetOptionsPage(extension
).is_empty();
121 void AppListControllerDelegate::ShowOptionsPage(
123 const std::string
& app_id
) {
124 const extensions::Extension
* extension
= GetExtension(profile
, app_id
);
128 chrome::NavigateParams
params(
130 extensions::ManifestURL::GetOptionsPage(extension
),
131 content::PAGE_TRANSITION_LINK
);
132 chrome::Navigate(¶ms
);
135 extensions::LaunchType
AppListControllerDelegate::GetExtensionLaunchType(
137 const std::string
& app_id
) {
138 ExtensionService
* service
=
139 extensions::ExtensionSystem::Get(profile
)->extension_service();
140 return extensions::GetLaunchType(service
->extension_prefs(),
141 GetExtension(profile
, app_id
));
144 void AppListControllerDelegate::SetExtensionLaunchType(
146 const std::string
& extension_id
,
147 extensions::LaunchType launch_type
) {
148 ExtensionService
* service
=
149 extensions::ExtensionSystem::Get(profile
)->extension_service();
150 extensions::SetLaunchType(
151 service
, extension_id
, launch_type
);
154 bool AppListControllerDelegate::IsExtensionInstalled(
155 Profile
* profile
, const std::string
& app_id
) {
156 return !!GetExtension(profile
, app_id
);
159 extensions::InstallTracker
* AppListControllerDelegate::GetInstallTrackerFor(
161 if (extensions::ExtensionSystem::Get(profile
)->extension_service())
162 return extensions::InstallTrackerFactory::GetForProfile(profile
);
166 void AppListControllerDelegate::GetApps(Profile
* profile
,
167 extensions::ExtensionSet
* out_apps
) {
168 ExtensionRegistry
* registry
= ExtensionRegistry::Get(profile
);
170 out_apps
->InsertAll(registry
->enabled_extensions());
171 out_apps
->InsertAll(registry
->disabled_extensions());
172 out_apps
->InsertAll(registry
->terminated_extensions());