#include "chrome/browser/web_applications/web_app_registrar.h"
#include <algorithm>
#include <bitset>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/enum_set.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/to_string.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom-shared.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/proto/proto_helpers.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/proto/web_app_proto_package.pb.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/browser/web_applications/web_app_install_utils.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar_observer.h"
#include "chrome/browser/web_applications/web_app_translation_manager.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/chrome_features.h"
#include "components/webapps/common/web_app_id.h"
#include "content/public/browser/isolated_web_apps_policy.h"
#include "content/public/browser/storage_partition_config.h"
#include "content/public/common/content_features.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/manifest/manifest_util.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/web_applications/chromeos_web_app_experiments.h"
#include "chromeos/constants/chromeos_features.h"
#endif
namespace web_app {
namespace {
InstallStateSet;
bool WebAppSourceSupported(const WebApp& web_app) { … }
bool IsLinkCapturingDisabledByDefaultBasedOnFlagState() { … }
}
WebAppRegistrar::WebAppRegistrar(Profile* profile) : … { … }
WebAppRegistrar::~WebAppRegistrar() { … }
bool WebAppRegistrar::IsLocallyInstalled(const GURL& start_url) const { … }
blink::ParsedPermissionsPolicy WebAppRegistrar::GetPermissionsPolicy(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsPlaceholderApp(
const webapps::AppId& app_id,
const WebAppManagement::Type source_type) const { … }
std::optional<webapps::AppId> WebAppRegistrar::LookupPlaceholderAppId(
const GURL& install_url,
const WebAppManagement::Type source_type) const { … }
void WebAppRegistrar::AddObserver(WebAppRegistrarObserver* observer) { … }
void WebAppRegistrar::RemoveObserver(WebAppRegistrarObserver* observer) { … }
void WebAppRegistrar::NotifyWebAppProtocolSettingsChanged() { … }
void WebAppRegistrar::NotifyWebAppFileHandlerApprovalStateChanged(
const webapps::AppId& app_id) { … }
void WebAppRegistrar::NotifyWebAppsWillBeUpdatedFromSync(
const std::vector<const WebApp*>& new_apps_state) { … }
void WebAppRegistrar::NotifyWebAppDisabledStateChanged(
const webapps::AppId& app_id,
bool is_disabled) { … }
void WebAppRegistrar::NotifyWebAppsDisabledModeChanged() { … }
void WebAppRegistrar::NotifyWebAppLastBadgingTimeChanged(
const webapps::AppId& app_id,
const base::Time& time) { … }
void WebAppRegistrar::NotifyWebAppLastLaunchTimeChanged(
const webapps::AppId& app_id,
const base::Time& time) { … }
void WebAppRegistrar::NotifyWebAppFirstInstallTimeChanged(
const webapps::AppId& app_id,
const base::Time& time) { … }
void WebAppRegistrar::NotifyWebAppUserDisplayModeChanged(
const webapps::AppId& app_id,
mojom::UserDisplayMode user_display_mode) { … }
void WebAppRegistrar::NotifyWebAppRunOnOsLoginModeChanged(
const webapps::AppId& app_id,
RunOnOsLoginMode run_on_os_login_mode) { … }
void WebAppRegistrar::NotifyWebAppSettingsPolicyChanged() { … }
#if !BUILDFLAG(IS_CHROMEOS)
void WebAppRegistrar::NotifyWebAppUserLinkCapturingPreferencesChanged(
const webapps::AppId& app_id,
bool is_preferred) { … }
#endif
base::flat_map<webapps::AppId, base::flat_set<GURL>>
WebAppRegistrar::GetExternallyInstalledApps(
ExternalInstallSource install_source) const { … }
std::optional<webapps::AppId> WebAppRegistrar::LookupExternalAppId(
const GURL& install_url) const { … }
bool WebAppRegistrar::HasExternalApp(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::HasExternalAppWithInstallSource(
const webapps::AppId& app_id,
ExternalInstallSource install_source) const { … }
GURL WebAppRegistrar::GetAppLaunchUrl(const webapps::AppId& app_id) const { … }
GURL WebAppRegistrar::GetAppScope(const webapps::AppId& app_id) const { … }
int WebAppRegistrar::GetAppExtendedScopeScore(
const GURL& url,
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsUrlInAppScope(const GURL& url,
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsUrlInAppExtendedScope(
const GURL& url,
const webapps::AppId& app_id) const { … }
int WebAppRegistrar::GetUrlInAppScopeScore(const std::string& url_spec,
const webapps::AppId& app_id) const { … }
std::optional<webapps::AppId> WebAppRegistrar::FindAppWithUrlInScope(
const GURL& url) const { … }
bool WebAppRegistrar::DoesScopeContainAnyApp(const GURL& scope) const { … }
std::vector<webapps::AppId> WebAppRegistrar::FindAppsInScope(
const GURL& scope) const { … }
std::optional<webapps::AppId> WebAppRegistrar::FindInstalledAppWithUrlInScope(
const GURL& url,
bool window_only,
bool exclude_diy_apps) const { … }
bool WebAppRegistrar::IsNonLocallyInstalledAppWithUrlInScope(
const GURL& url) const { … }
bool WebAppRegistrar::IsShortcutApp(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsSystemApp(const webapps::AppId& app_id) const { … }
DisplayMode WebAppRegistrar::GetAppEffectiveDisplayMode(
const webapps::AppId& app_id) const { … }
DisplayMode WebAppRegistrar::GetEffectiveDisplayModeFromManifest(
const webapps::AppId& app_id) const { … }
GURL WebAppRegistrar::GetComputedManifestId(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsTabbedWindowModeEnabled(
const webapps::AppId& app_id) const { … }
GURL WebAppRegistrar::GetAppNewTabUrl(const webapps::AppId& app_id) const { … }
std::optional<GURL> WebAppRegistrar::GetAppPinnedHomeTabUrl(
const webapps::AppId& app_id) const { … }
std::optional<proto::WebAppOsIntegrationState>
WebAppRegistrar::GetAppCurrentOsIntegrationState(
const webapps::AppId& app_id) const { … }
#if BUILDFLAG(IS_MAC)
bool WebAppRegistrar::AlwaysShowToolbarInFullscreen(
const webapps::AppId& app_id) const {
auto* web_app = GetAppById(app_id);
return web_app ? web_app->always_show_toolbar_in_fullscreen() : true;
}
void WebAppRegistrar::NotifyAlwaysShowToolbarInFullscreenChanged(
const webapps::AppId& app_id,
bool show) {
for (WebAppRegistrarObserver& observer : observers_) {
observer.OnAlwaysShowToolbarInFullscreenChanged(app_id, show);
}
}
#endif
const WebApp* WebAppRegistrar::GetAppById(const webapps::AppId& app_id) const { … }
const WebApp* WebAppRegistrar::GetAppByStartUrl(const GURL& start_url) const { … }
std::vector<webapps::AppId>
WebAppRegistrar::GetAppsFromSyncAndPendingInstallation() const { … }
std::vector<webapps::AppId> WebAppRegistrar::GetAppsPendingUninstall() const { … }
bool WebAppRegistrar::AppsExistWithExternalConfigData() const { … }
void WebAppRegistrar::SetProvider(base::PassKey<WebAppProvider>,
WebAppProvider& provider) { … }
void WebAppRegistrar::Start() { … }
base::WeakPtr<WebAppRegistrar> WebAppRegistrar::AsWeakPtr() { … }
std::optional<webapps::AppId> WebAppRegistrar::LookUpAppIdByInstallUrl(
const GURL& install_url) const { … }
const WebApp* WebAppRegistrar::LookUpAppByInstallSourceInstallUrl(
WebAppManagement::Type install_source,
const GURL& install_url) const { … }
bool WebAppRegistrar::IsNotInRegistrar(const webapps::AppId& app_id) const { … }
std::optional<proto::InstallState> WebAppRegistrar::GetInstallState(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsInstallState(
const webapps::AppId& app_id,
std::initializer_list<proto::InstallState> states) const { … }
std::optional<webapps::AppId> WebAppRegistrar::FindBestAppWithUrlInScope(
const GURL& url,
std::initializer_list<proto::InstallState> states) const { … }
std::optional<webapps::AppId> WebAppRegistrar::FindBestAppWithUrlInScope(
const GURL& url,
std::initializer_list<proto::InstallState> states,
AppFilterOptions options) const { … }
std::vector<webapps::AppId> WebAppRegistrar::FindAllAppsWithUrlInScope(
const GURL& url,
std::initializer_list<proto::InstallState> states) const { … }
std::vector<webapps::AppId> WebAppRegistrar::FindAllAppsNestedInUrl(
const GURL& outer_scope,
std::initializer_list<proto::InstallState> states) const { … }
bool WebAppRegistrar::DoesScopeContainAnyApp(
const GURL& scope,
std::initializer_list<proto::InstallState> allowed_states) const { … }
bool WebAppRegistrar::IsInstalled(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsUninstalling(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsLocallyInstalled(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsActivelyInstalled(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsIsolated(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsInstalledByDefaultManagement(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsInstalledByPolicy(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::WasInstalledByDefaultOnly(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::WasInstalledByUser(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::WasInstalledByOem(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::WasInstalledBySubApp(const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::CanUserUninstallWebApp(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsPreventCloseEnabled(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsAllowedLaunchProtocol(
const webapps::AppId& app_id,
const std::string& protocol_scheme) const { … }
bool WebAppRegistrar::IsDisallowedLaunchProtocol(
const webapps::AppId& app_id,
const std::string& protocol_scheme) const { … }
bool WebAppRegistrar::IsRegisteredLaunchProtocol(
const webapps::AppId& app_id,
const std::string& protocol_scheme) const { … }
base::flat_set<std::string> WebAppRegistrar::GetAllAllowedLaunchProtocols()
const { … }
base::flat_set<std::string> WebAppRegistrar::GetAllDisallowedLaunchProtocols()
const { … }
int WebAppRegistrar::CountUserInstalledApps() const { … }
int WebAppRegistrar::CountUserInstalledDiyApps() const { … }
std::vector<content::StoragePartitionConfig>
WebAppRegistrar::GetIsolatedWebAppStoragePartitionConfigs(
const webapps::AppId& isolated_web_app_id) const { … }
std::optional<content::StoragePartitionConfig>
WebAppRegistrar::SaveAndGetInMemoryControlledFramePartitionConfig(
const IsolatedWebAppUrlInfo& url_info,
const std::string& partition_name) { … }
bool WebAppRegistrar::CanCaptureLinksInScope(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::CapturesLinksInScope(const webapps::AppId& app_id) const { … }
std::optional<webapps::AppId> WebAppRegistrar::FindAppThatCapturesLinksInScope(
const GURL& url) const { … }
bool WebAppRegistrar::IsLinkCapturableByApp(const webapps::AppId& app,
const GURL& url) const { … }
std::vector<webapps::AppId> WebAppRegistrar::GetOverlappingAppsMatchingScope(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::AppScopesMatchForUserLinkCapturing(
const webapps::AppId& app_id1,
const webapps::AppId& app_id2) const { … }
base::flat_map<webapps::AppId, std::string>
WebAppRegistrar::GetAllAppsControllingUrl(const GURL& url) const { … }
bool WebAppRegistrar::IsPreferredAppForCapturingUrl(
const GURL& url,
const webapps::AppId& app_id) { … }
bool WebAppRegistrar::IsDiyApp(const webapps::AppId& app_id) const { … }
std::string WebAppRegistrar::GetAppShortName(
const webapps::AppId& app_id) const { … }
std::string WebAppRegistrar::GetAppDescription(
const webapps::AppId& app_id) const { … }
std::optional<SkColor> WebAppRegistrar::GetAppThemeColor(
const webapps::AppId& app_id) const { … }
std::optional<SkColor> WebAppRegistrar::GetAppDarkModeThemeColor(
const webapps::AppId& app_id) const { … }
std::optional<SkColor> WebAppRegistrar::GetAppBackgroundColor(
const webapps::AppId& app_id) const { … }
std::optional<SkColor> WebAppRegistrar::GetAppDarkModeBackgroundColor(
const webapps::AppId& app_id) const { … }
const GURL& WebAppRegistrar::GetAppStartUrl(
const webapps::AppId& app_id) const { … }
webapps::ManifestId WebAppRegistrar::GetAppManifestId(
const webapps::AppId& app_id) const { … }
const std::string* WebAppRegistrar::GetAppLaunchQueryParams(
const webapps::AppId& app_id) const { … }
const apps::ShareTarget* WebAppRegistrar::GetAppShareTarget(
const webapps::AppId& app_id) const { … }
const apps::FileHandlers* WebAppRegistrar::GetAppFileHandlers(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::IsAppFileHandlerPermissionBlocked(
const webapps::AppId& app_id) const { … }
ApiApprovalState WebAppRegistrar::GetAppFileHandlerApprovalState(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::ExpectThatFileHandlersAreRegisteredWithOs(
const webapps::AppId& app_id) const { … }
std::optional<GURL> WebAppRegistrar::GetAppScopeInternal(
const webapps::AppId& app_id) const { … }
DisplayMode WebAppRegistrar::GetAppDisplayMode(
const webapps::AppId& app_id) const { … }
std::optional<mojom::UserDisplayMode> WebAppRegistrar::GetAppUserDisplayMode(
const webapps::AppId& app_id) const { … }
std::vector<DisplayMode> WebAppRegistrar::GetAppDisplayModeOverride(
const webapps::AppId& app_id) const { … }
apps::UrlHandlers WebAppRegistrar::GetAppUrlHandlers(
const webapps::AppId& app_id) const { … }
base::flat_set<ScopeExtensionInfo> WebAppRegistrar::GetScopeExtensions(
const webapps::AppId& app_id) const { … }
base::flat_set<ScopeExtensionInfo> WebAppRegistrar::GetValidatedScopeExtensions(
const webapps::AppId& app_id) const { … }
GURL WebAppRegistrar::GetAppManifestUrl(const webapps::AppId& app_id) const { … }
base::Time WebAppRegistrar::GetAppLastBadgingTime(
const webapps::AppId& app_id) const { … }
base::Time WebAppRegistrar::GetAppLastLaunchTime(
const webapps::AppId& app_id) const { … }
base::Time WebAppRegistrar::GetAppFirstInstallTime(
const webapps::AppId& app_id) const { … }
std::optional<webapps::WebappInstallSource>
WebAppRegistrar::GetLatestAppInstallSource(const webapps::AppId& app_id) const { … }
std::vector<apps::IconInfo> WebAppRegistrar::GetAppIconInfos(
const webapps::AppId& app_id) const { … }
SortedSizesPx WebAppRegistrar::GetAppDownloadedIconSizesAny(
const webapps::AppId& app_id) const { … }
std::vector<WebAppShortcutsMenuItemInfo>
WebAppRegistrar::GetAppShortcutsMenuItemInfos(
const webapps::AppId& app_id) const { … }
std::vector<webapps::AppId> WebAppRegistrar::GetAppIds() const { … }
std::vector<webapps::AppId> WebAppRegistrar::GetAllSubAppIds(
const webapps::AppId& parent_app_id) const { … }
base::flat_map<webapps::AppId, webapps::AppId>
WebAppRegistrar::GetSubAppToParentMap() const { … }
ValueWithPolicy<RunOnOsLoginMode> WebAppRegistrar::GetAppRunOnOsLoginMode(
const webapps::AppId& app_id) const { … }
bool WebAppRegistrar::GetWindowControlsOverlayEnabled(
const webapps::AppId& app_id) const { … }
WebAppRegistrar::AppSet::AppSet(const WebAppRegistrar* registrar, Filter filter)
: … { … }
WebAppRegistrar::AppSet::~AppSet() { … }
WebAppRegistrar::AppSet::iterator WebAppRegistrar::AppSet::begin() { … }
WebAppRegistrar::AppSet::iterator WebAppRegistrar::AppSet::end() { … }
WebAppRegistrar::AppSet::const_iterator WebAppRegistrar::AppSet::begin() const { … }
WebAppRegistrar::AppSet::const_iterator WebAppRegistrar::AppSet::end() const { … }
WebAppRegistrar::AppSet WebAppRegistrar::GetAppsIncludingStubs() const { … }
WebAppRegistrar::AppSet WebAppRegistrar::GetApps() const { … }
base::Value WebAppRegistrar::AsDebugValue() const { … }
void WebAppRegistrar::SetRegistry(Registry&& registry) { … }
void WebAppRegistrar::CountMutation() { … }
WebAppRegistrarMutable::WebAppRegistrarMutable(Profile* profile)
: … { … }
WebAppRegistrarMutable::~WebAppRegistrarMutable() = default;
void WebAppRegistrarMutable::InitRegistry(Registry&& registry) { … }
WebApp* WebAppRegistrarMutable::GetAppByIdMutable(
const webapps::AppId& app_id) { … }
WebAppRegistrar::AppSet WebAppRegistrarMutable::GetAppsMutable() { … }
bool IsRegistryEqual(const Registry& registry,
const Registry& registry2,
bool exclude_current_os_integration) { … }
std::vector<webapps::AppId> WebAppRegistrar::GetAppIdsForAppSet(
const AppSet& app_set) const { … }
int WebAppRegistrar::CountUserInstalledNotLocallyInstalledApps() const { … }
std::tuple<DiyAppCount, InstallableAppCount>
WebAppRegistrar::CountTotalUserInstalledAppsIncludingDiy() const { … }
}