1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "base/metrics/histogram.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/install_tracker_factory.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/extension_uninstaller.h"
#include "chrome/browser/ui/apps/app_info_dialog.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/options_page_info.h"
#include "extensions/common/manifest_url_handlers.h"
#include "net/base/url_util.h"
#include "ui/app_list/app_list_folder_item.h"
#include "ui/app_list/app_list_item.h"
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/app_list_switches.h"
#include "ui/gfx/geometry/rect.h"
#if defined(ENABLE_RLZ)
#include "chrome/browser/rlz/rlz.h"
#endif
using extensions::ExtensionRegistry;
namespace {
const extensions::Extension* GetExtension(Profile* profile,
const std::string& extension_id) {
const ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
const extensions::Extension* extension =
service->GetInstalledExtension(extension_id);
return extension;
}
} // namespace
AppListControllerDelegate::~AppListControllerDelegate() {}
bool AppListControllerDelegate::ForceNativeDesktop() const {
return false;
}
void AppListControllerDelegate::ViewClosing() {}
gfx::Rect AppListControllerDelegate::GetAppListBounds() {
return gfx::Rect();
}
void AppListControllerDelegate::OnShowChildDialog() {
}
void AppListControllerDelegate::OnCloseChildDialog() {
}
std::string AppListControllerDelegate::AppListSourceToString(
AppListSource source) {
switch (source) {
case LAUNCH_FROM_APP_LIST:
return extension_urls::kLaunchSourceAppList;
case LAUNCH_FROM_APP_LIST_SEARCH:
return extension_urls::kLaunchSourceAppListSearch;
default:
return std::string();
}
}
bool AppListControllerDelegate::UserMayModifySettings(
Profile* profile,
const std::string& app_id) {
const extensions::Extension* extension = GetExtension(profile, app_id);
const extensions::ManagementPolicy* policy =
extensions::ExtensionSystem::Get(profile)->management_policy();
return extension &&
policy->UserMayModifySettings(extension, NULL);
}
bool AppListControllerDelegate::CanDoShowAppInfoFlow() {
return app_list::switches::IsAppInfoEnabled();
}
void AppListControllerDelegate::DoShowAppInfoFlow(
Profile* profile,
const std::string& extension_id) {
DCHECK(CanDoShowAppInfoFlow());
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
DCHECK(service);
const extensions::Extension* extension = service->GetInstalledExtension(
extension_id);
DCHECK(extension);
OnShowChildDialog();
UMA_HISTOGRAM_ENUMERATION("Apps.AppInfoDialog.Launches",
AppInfoLaunchSource::FROM_APP_LIST,
AppInfoLaunchSource::NUM_LAUNCH_SOURCES);
// Since the AppListControllerDelegate is a leaky singleton, passing its raw
// pointer around is OK.
ShowAppInfoInAppList(
GetAppListWindow(),
GetAppListBounds(),
profile,
extension,
base::Bind(&AppListControllerDelegate::OnCloseChildDialog,
base::Unretained(this)));
}
void AppListControllerDelegate::UninstallApp(Profile* profile,
const std::string& app_id) {
// ExtensionUninstall deletes itself when done or aborted.
ExtensionUninstaller* uninstaller =
new ExtensionUninstaller(profile, app_id, this);
uninstaller->Run();
}
bool AppListControllerDelegate::IsAppFromWebStore(
Profile* profile,
const std::string& app_id) {
const extensions::Extension* extension = GetExtension(profile, app_id);
return extension && extension->from_webstore();
}
void AppListControllerDelegate::ShowAppInWebStore(
Profile* profile,
const std::string& app_id,
bool is_search_result) {
const extensions::Extension* extension = GetExtension(profile, app_id);
if (!extension)
return;
const GURL url = extensions::ManifestURL::GetDetailsURL(extension);
DCHECK_NE(url, GURL::EmptyGURL());
const std::string source = AppListSourceToString(
is_search_result ?
AppListControllerDelegate::LAUNCH_FROM_APP_LIST_SEARCH :
AppListControllerDelegate::LAUNCH_FROM_APP_LIST);
OpenURL(profile,
net::AppendQueryParameter(url,
extension_urls::kWebstoreSourceField,
source),
ui::PAGE_TRANSITION_LINK,
CURRENT_TAB);
}
bool AppListControllerDelegate::HasOptionsPage(
Profile* profile,
const std::string& app_id) {
const extensions::Extension* extension = GetExtension(profile, app_id);
return extensions::util::IsAppLaunchableWithoutEnabling(app_id, profile) &&
extension && extensions::OptionsPageInfo::HasOptionsPage(extension);
}
void AppListControllerDelegate::ShowOptionsPage(
Profile* profile,
const std::string& app_id) {
const extensions::Extension* extension = GetExtension(profile, app_id);
if (!extension)
return;
OpenURL(profile,
extensions::OptionsPageInfo::GetOptionsPage(extension),
ui::PAGE_TRANSITION_LINK,
CURRENT_TAB);
}
extensions::LaunchType AppListControllerDelegate::GetExtensionLaunchType(
Profile* profile,
const std::string& app_id) {
return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile),
GetExtension(profile, app_id));
}
void AppListControllerDelegate::SetExtensionLaunchType(
Profile* profile,
const std::string& extension_id,
extensions::LaunchType launch_type) {
ExtensionService* service =
extensions::ExtensionSystem::Get(profile)->extension_service();
extensions::SetLaunchType(
service, extension_id, launch_type);
}
bool AppListControllerDelegate::IsExtensionInstalled(
Profile* profile, const std::string& app_id) {
return !!GetExtension(profile, app_id);
}
extensions::InstallTracker* AppListControllerDelegate::GetInstallTrackerFor(
Profile* profile) {
if (extensions::ExtensionSystem::Get(profile)->extension_service())
return extensions::InstallTrackerFactory::GetForBrowserContext(profile);
return NULL;
}
void AppListControllerDelegate::GetApps(Profile* profile,
extensions::ExtensionSet* out_apps) {
ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
DCHECK(registry);
out_apps->InsertAll(registry->enabled_extensions());
out_apps->InsertAll(registry->disabled_extensions());
out_apps->InsertAll(registry->terminated_extensions());
}
void AppListControllerDelegate::OnSearchStarted() {
#if defined(ENABLE_RLZ)
RLZTracker::RecordAppListSearch();
#endif
}
|