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
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/app_list/app_list_controller_delegate.h"
#include <utility>
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.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/chrome_pages.h"
#include "chrome/browser/ui/webui/ash/settings/app_management/app_management_uma.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/launch_util.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 "rlz/buildflags/buildflags.h"
#include "ui/gfx/geometry/rect.h"
#if BUILDFLAG(ENABLE_RLZ)
#include "components/rlz/rlz_tracker.h" // nogncheck
#endif
using extensions::ExtensionRegistry;
namespace {
const extensions::Extension* GetExtension(Profile* profile,
const std::string& extension_id) {
const ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
const extensions::Extension* extension =
registry->GetInstalledExtension(extension_id);
return extension;
}
} // namespace
AppListControllerDelegate::AppListControllerDelegate() = default;
AppListControllerDelegate::~AppListControllerDelegate() = default;
void AppListControllerDelegate::DoShowAppInfoFlow(Profile* profile,
const std::string& app_id) {
auto app_type = apps::AppServiceProxyFactory::GetForProfile(profile)
->AppRegistryCache()
.GetAppType(app_id);
DCHECK_NE(app_type, apps::AppType::kUnknown);
if (app_type == apps::AppType::kWeb ||
app_type == apps::AppType::kSystemWeb) {
chrome::ShowAppManagementPage(profile, app_id,
ash::settings::AppManagementEntryPoint::
kAppListContextMenuAppInfoWebApp);
} else {
chrome::ShowAppManagementPage(profile, app_id,
ash::settings::AppManagementEntryPoint::
kAppListContextMenuAppInfoChromeApp);
}
}
void AppListControllerDelegate::UninstallApp(Profile* profile,
const std::string& app_id) {
apps::AppServiceProxyFactory::GetForProfile(profile)->Uninstall(
app_id, apps::UninstallSource::kAppList, GetAppListWindow());
}
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, WindowOpenDisposition::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) {
extensions::SetLaunchType(profile, extension_id, launch_type);
}
void AppListControllerDelegate::OnSearchStarted() {
#if BUILDFLAG(ENABLE_RLZ)
rlz::RLZTracker::RecordAppListSearch();
#endif
}
std::vector<std::string> AppListControllerDelegate::GetAppIdsForUrl(
Profile* profile,
const GURL& url,
bool exclude_browsers,
bool exclude_browser_tab_apps) {
auto* proxy = apps::AppServiceProxyFactory::GetForProfile(profile);
if (proxy) {
return proxy->GetAppIdsForUrl(url, exclude_browsers,
exclude_browser_tab_apps);
}
return std::vector<std::string>{};
}
void AppListControllerDelegate::LaunchAppWithUrl(
Profile* profile,
const std::string& app_id,
int32_t event_flags,
const GURL& url,
apps::LaunchSource launch_source) {
auto* proxy = apps::AppServiceProxyFactory::GetForProfile(profile);
DCHECK(proxy);
proxy->LaunchAppWithUrl(app_id, event_flags, url, launch_source);
}
|