Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / app_list / app_list_controller_delegate.cc
blobaf06152815759297534b9d221fbb20eff6e729df
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;
25 namespace {
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);
33 return extension;
36 } // namespace
38 AppListControllerDelegate::~AppListControllerDelegate() {}
40 bool AppListControllerDelegate::ForceNativeDesktop() const {
41 return false;
44 void AppListControllerDelegate::ViewClosing() {}
46 void AppListControllerDelegate::OnShowExtensionPrompt() {}
47 void AppListControllerDelegate::OnCloseExtensionPrompt() {}
49 std::string AppListControllerDelegate::AppListSourceToString(
50 AppListSource source) {
51 switch (source) {
52 case LAUNCH_FROM_APP_LIST:
53 return extension_urls::kLaunchSourceAppList;
54 case LAUNCH_FROM_APP_LIST_SEARCH:
55 return extension_urls::kLaunchSourceAppListSearch;
56 default:
57 return std::string();
61 bool AppListControllerDelegate::UserMayModifySettings(
62 Profile* profile,
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();
67 return extension &&
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);
76 uninstaller->Run();
79 bool AppListControllerDelegate::IsAppFromWebStore(
80 Profile* profile,
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(
87 Profile* profile,
88 const std::string& app_id,
89 bool is_search_result) {
90 const extensions::Extension* extension = GetExtension(profile, app_id);
91 if (!extension)
92 return;
94 const GURL url = extensions::ManifestURL::GetDetailsURL(extension);
95 DCHECK_NE(url, GURL::EmptyGURL());
97 const std::string source = AppListSourceToString(
98 is_search_result ?
99 AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH :
100 AppListControllerDelegate::LAUNCH_FROM_APP_LIST);
101 chrome::NavigateParams params(
102 profile,
103 net::AppendQueryParameter(url,
104 extension_urls::kWebstoreSourceField,
105 source),
106 content::PAGE_TRANSITION_LINK);
107 chrome::Navigate(&params);
110 bool AppListControllerDelegate::HasOptionsPage(
111 Profile* profile,
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) &&
117 extension &&
118 !extensions::ManifestURL::GetOptionsPage(extension).is_empty();
121 void AppListControllerDelegate::ShowOptionsPage(
122 Profile* profile,
123 const std::string& app_id) {
124 const extensions::Extension* extension = GetExtension(profile, app_id);
125 if (!extension)
126 return;
128 chrome::NavigateParams params(
129 profile,
130 extensions::ManifestURL::GetOptionsPage(extension),
131 content::PAGE_TRANSITION_LINK);
132 chrome::Navigate(&params);
135 extensions::LaunchType AppListControllerDelegate::GetExtensionLaunchType(
136 Profile* profile,
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(
145 Profile* profile,
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(
160 Profile* profile) {
161 if (extensions::ExtensionSystem::Get(profile)->extension_service())
162 return extensions::InstallTrackerFactory::GetForProfile(profile);
163 return NULL;
166 void AppListControllerDelegate::GetApps(Profile* profile,
167 extensions::ExtensionSet* out_apps) {
168 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
169 DCHECK(registry);
170 out_apps->InsertAll(registry->enabled_extensions());
171 out_apps->InsertAll(registry->disabled_extensions());
172 out_apps->InsertAll(registry->terminated_extensions());