#include "chrome/browser/web_applications/web_app_utils.h"
#include <iterator>
#include <map>
#include <optional>
#include <set>
#include <utility>
#include "base/base64.h"
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/enum_set.h"
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom-shared.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_icon_manager.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_isolated_world_ids.h"
#include "chrome/grit/generated_resources.h"
#include "components/grit/components_resources.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "components/services/app_service/public/cpp/run_on_os_login_types.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/alternative_error_page_override_info.mojom-forward.h"
#include "content/public/common/alternative_error_page_override_info.mojom.h"
#include "content/public/common/content_features.h"
#include "mojo/public/cpp/bindings/struct_ptr.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom-shared.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/codec/png_codec.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#include "base/feature_list.h"
#include "chrome/browser/ash/crosapi/browser_util.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_types.h"
#include "components/user_manager/user_manager.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/crosapi/mojom/app_service.mojom.h"
#include "chromeos/lacros/lacros_service.h"
#include "chromeos/startup/browser_params_proxy.h"
#endif
namespace web_app {
namespace {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
bool g_skip_main_profile_check_for_testing = false;
#endif
GURL EncodeIconAsUrl(const SkBitmap& bitmap) { … }
class AppIconFetcherTask : public content::WebContentsObserver { … };
DisplayMode ResolveAppDisplayModeForStandaloneLaunchContainer(
DisplayMode app_display_mode) { … }
std::optional<DisplayMode> TryResolveUserDisplayMode(
mojom::UserDisplayMode user_display_mode) { … }
std::optional<DisplayMode> TryResolveOverridesDisplayMode(
const std::vector<DisplayMode>& display_mode_overrides) { … }
DisplayMode ResolveNonIsolatedEffectiveDisplayMode(
DisplayMode app_display_mode,
const std::vector<DisplayMode>& display_mode_overrides,
mojom::UserDisplayMode user_display_mode) { … }
}
constexpr base::FilePath::CharType kManifestResourcesDirectoryName[] = …);
constexpr base::FilePath::CharType kTempDirectoryName[] = …);
bool AreWebAppsEnabled(Profile* profile) { … }
bool AreWebAppsUserInstallable(Profile* profile) { … }
content::BrowserContext* GetBrowserContextForWebApps(
content::BrowserContext* context) { … }
content::BrowserContext* GetBrowserContextForWebAppMetrics(
content::BrowserContext* context) { … }
base::FilePath GetWebAppsRootDirectory(Profile* profile) { … }
base::FilePath GetManifestResourcesDirectory(
const base::FilePath& web_apps_root_directory) { … }
base::FilePath GetManifestResourcesDirectory(Profile* profile) { … }
base::FilePath GetManifestResourcesDirectoryForApp(
const base::FilePath& web_apps_root_directory,
const webapps::AppId& app_id) { … }
base::FilePath GetWebAppsTempDirectory(
const base::FilePath& web_apps_root_directory) { … }
std::string GetProfileCategoryForLogging(Profile* profile) { … }
bool IsChromeOsDataMandatory() { … }
bool AreAppsLocallyInstalledBySync() { … }
bool AreNewFileHandlersASubsetOfOld(const apps::FileHandlers& old_handlers,
const apps::FileHandlers& new_handlers) { … }
std::tuple<std::u16string, size_t>
GetFileTypeAssociationsHandledByWebAppForDisplay(Profile* profile,
const webapps::AppId& app_id) { … }
std::vector<std::u16string> TransformFileExtensionsForDisplay(
const std::set<std::string>& extensions) { … }
bool IsRunOnOsLoginModeEnabledForAutostart(RunOnOsLoginMode login_mode) { … }
#if BUILDFLAG(IS_CHROMEOS)
bool IsWebAppsCrosapiEnabled() {
#if BUILDFLAG(IS_CHROMEOS_ASH)
return crosapi::browser_util::IsLacrosEnabled();
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
auto* lacros_service = chromeos::LacrosService::Get();
return lacros_service &&
lacros_service->IsAvailable<crosapi::mojom::AppPublisher>();
#endif
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void SetSkipMainProfileCheckForTesting(bool skip_check) {
g_skip_main_profile_check_for_testing = skip_check;
}
bool IsMainProfileCheckSkippedForTesting() {
return g_skip_main_profile_check_for_testing;
}
#endif
bool HasAnySpecifiedSourcesAndNoOtherSources(
WebAppManagementTypes sources,
WebAppManagementTypes specified_sources) { … }
bool CanUserUninstallWebApp(const webapps::AppId& app_id,
WebAppManagementTypes sources) { … }
webapps::AppId GetAppIdFromAppSettingsUrl(const GURL& url) { … }
bool IsInScope(const GURL& url, const GURL& scope) { … }
DisplayMode ResolveEffectiveDisplayMode(
DisplayMode app_display_mode,
const std::vector<DisplayMode>& app_display_mode_overrides,
mojom::UserDisplayMode user_display_mode,
bool is_isolated) { … }
apps::LaunchContainer ConvertDisplayModeToAppLaunchContainer(
DisplayMode display_mode) { … }
apps::RunOnOsLoginMode ConvertOsLoginMode(RunOnOsLoginMode login_mode) { … }
const char* IconsDownloadedResultToString(IconsDownloadedResult result) { … }
content::mojom::AlternativeErrorPageOverrideInfoPtr ConstructWebAppErrorPage(
const GURL& url,
content::RenderFrameHost* render_frame_host,
content::BrowserContext* browser_context,
std::u16string message,
std::u16string supplementary_icon) { … }
bool IsValidScopeForLinkCapturing(const GURL& scope) { … }
bool WillBeSystemWebApp(const webapps::AppId& app_id,
WebAppManagementTypes sources) { … }
}